1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
22 |
|
|
23 |
package org.jsampler.view.fantasia; |
package org.jsampler.view.fantasia; |
24 |
|
|
|
import java.awt.BorderLayout; |
|
|
import java.awt.Component; |
|
|
|
|
|
import java.awt.event.ActionEvent; |
|
25 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
26 |
|
|
27 |
|
import javax.swing.BorderFactory; |
28 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
|
import javax.swing.ListSelectionModel; |
|
|
|
|
|
import javax.swing.event.ListSelectionEvent; |
|
|
import javax.swing.event.ListSelectionListener; |
|
|
|
|
|
import net.sf.juife.ComponentList; |
|
|
import net.sf.juife.ComponentListModel; |
|
|
import net.sf.juife.DefaultComponentListModel; |
|
29 |
|
|
30 |
import org.jsampler.CC; |
import org.jsampler.CC; |
31 |
import org.jsampler.SamplerChannelModel; |
import org.jsampler.SamplerChannelModel; |
32 |
|
|
33 |
import org.jsampler.view.JSChannel; |
import org.jsampler.view.JSChannel; |
34 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.SessionViewConfig.ChannelConfig; |
35 |
|
|
36 |
|
import org.jsampler.view.std.StdChannelsPane; |
37 |
|
|
38 |
|
|
39 |
/** |
/** |
40 |
* |
* |
41 |
* @author Grigor Iliev |
* @author Grigor Iliev |
42 |
*/ |
*/ |
43 |
public class ChannelsPane extends JSChannelsPane { |
public class ChannelsPane extends StdChannelsPane { |
|
private final ChannelListPane chnList = new ChannelListPane(); |
|
|
private final DefaultComponentListModel listModel = new DefaultComponentListModel(); |
|
|
|
|
44 |
private ActionListener listener; |
private ActionListener listener; |
45 |
|
|
46 |
/** |
/** |
66 |
|
|
67 |
listener = l; |
listener = l; |
68 |
|
|
69 |
|
removeAll(); |
70 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
71 |
|
|
|
chnList.setModel(listModel); |
|
|
chnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
|
|
|
|
72 |
add(chnList); |
add(chnList); |
73 |
|
setBorder(BorderFactory.createEmptyBorder()); |
74 |
} |
} |
75 |
|
|
76 |
class ChannelListPane extends ComponentList { |
@Override |
77 |
|
protected ChannelList |
78 |
|
createChannelList() { return new FantasiaChannelList(); } |
79 |
|
|
80 |
|
@Override |
81 |
|
protected ChannelListModel |
82 |
|
createChannelListModel() { return new FantasiaChannelListModel(); } |
83 |
|
|
84 |
|
class FantasiaChannelList extends ChannelList { |
85 |
|
@Override |
86 |
public java.awt.Dimension |
public java.awt.Dimension |
87 |
getMaximumSize() { return getPreferredSize(); } |
getMaximumSize() { return getPreferredSize(); } |
88 |
} |
} |
89 |
|
|
90 |
public void |
class FantasiaChannelListModel extends ChannelListModel { |
91 |
setSelectedChannel(JSChannel channel) { |
@Override |
92 |
chnList.setSelectedComponent(channel, true); |
public boolean |
93 |
|
getComponentListIsAdjusting() { |
94 |
|
boolean b = CC.getSamplerModel().getChannelListIsAdjusting(); |
95 |
|
return super.getComponentListIsAdjusting() || b; |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
@Override |
100 |
|
protected JSChannel |
101 |
|
createChannel(SamplerChannelModel channelModel) { |
102 |
|
return new Channel(channelModel, listener); |
103 |
} |
} |
104 |
|
|
105 |
/** |
/** |
106 |
* Adds new channel to this channels pane. |
* Adds new channel to this channels pane. |
107 |
* @param channelModel The sampler channel model to be used by the new channel. |
* @param channelModel The sampler channel model to be used by the new channel. |
108 |
*/ |
*/ |
109 |
|
@Override |
110 |
public void |
public void |
111 |
addChannel(SamplerChannelModel channelModel) { |
addChannel(SamplerChannelModel channelModel) { |
112 |
Channel channel = new Channel(channelModel, listener); |
addChannel(channelModel, null); |
|
listModel.add(channel); |
|
|
if(channel.getChannelInfo().getEngine() == null) channel.expandChannel(false); |
|
|
chnList.setSelectedComponent(channel, true); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Adds the specified channels to this channels pane. |
|
|
* @param chns The channels to be added. |
|
|
*/ |
|
|
public void |
|
|
addChannels(JSChannel[] chns) { |
|
|
if(chns == null || chns.length == 0) return; |
|
|
|
|
|
for(JSChannel c : chns) listModel.add(c); |
|
|
|
|
|
chnList.setSelectedIndex(listModel.getSize() - 1); |
|
113 |
} |
} |
114 |
|
|
115 |
/** |
@Override |
|
* Removes the specified channel from this channels pane. |
|
|
* This method is invoked when a sampler channel is removed in the back-end. |
|
|
* @param chn The channel to be removed from this channels pane. |
|
|
*/ |
|
116 |
public void |
public void |
117 |
removeChannel(JSChannel chn) { |
addChannel(SamplerChannelModel channelModel, ChannelConfig config) { |
118 |
listModel.remove(chn); |
Channel channel = null; |
|
} |
|
|
|
|
|
/** |
|
|
* Determines whether there is at least one selected channel. |
|
|
* @return <code>true</code> if there is at least one selected channel, |
|
|
* <code>false</code> otherwise. |
|
|
*/ |
|
|
public boolean |
|
|
hasSelectedChannel() { return !chnList.isSelectionEmpty(); } |
|
|
|
|
|
/** |
|
|
* Gets the first channel in this channels pane. |
|
|
* @return The first channel in this channels pane or <code>null</code> if |
|
|
* the channels pane is empty. |
|
|
*/ |
|
|
public JSChannel |
|
|
getFirstChannel() { return listModel.size() == 0 ? null : (JSChannel)listModel.get(0); } |
|
|
|
|
|
/** |
|
|
* Gets the last channel in this channels pane. |
|
|
* @return The last channel in this channels pane or <code>null</code> if |
|
|
* the channels pane is empty. |
|
|
*/ |
|
|
public JSChannel |
|
|
getLastChannel() { |
|
|
return listModel.size() == 0 ? null : (JSChannel)listModel.get(listModel.size()-1); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Gets the channel at the specified index. |
|
|
* @return The channel at the specified index. |
|
|
* @throws ArrayIndexOutOfBoundsException If the index is out of range. |
|
|
*/ |
|
|
public JSChannel |
|
|
getChannel(int idx) { return (JSChannel)listModel.get(idx); } |
|
|
|
|
|
/** |
|
|
* Gets an array of all channels in this channels pane. |
|
|
* @return An array of all channels in this channels pane. |
|
|
*/ |
|
|
public JSChannel[] |
|
|
getChannels() { |
|
|
JSChannel[] chns = new JSChannel[listModel.size()]; |
|
|
for(int i = 0; i < listModel.size(); i++) chns[i] = (JSChannel)listModel.get(i); |
|
|
return chns; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Gets the number of channels in this channels pane. |
|
|
* @return The number of channels in this channels pane. |
|
|
*/ |
|
|
public int |
|
|
getChannelCount() { return listModel.size(); } |
|
|
|
|
|
/** |
|
|
* Gets an array of all selected channels. |
|
|
* The channels are sorted in increasing index order. |
|
|
* @return The selected channels or an empty array if nothing is selected. |
|
|
*/ |
|
|
public JSChannel[] |
|
|
getSelectedChannels() { |
|
|
Component[] cS = chnList.getSelectedComponents(); |
|
|
JSChannel[] chns = new JSChannel[cS.length]; |
|
|
for(int i = 0; i < cS.length; i++) chns[i] = (JSChannel)cS[i]; |
|
|
return chns; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Gets the number of the selected channels. |
|
|
* @return The number of the selected channels. |
|
|
*/ |
|
|
public int |
|
|
getSelectedChannelCount() { return chnList.getSelectedIndices().length; } |
|
|
|
|
|
/** |
|
|
* Removes all selected channels in this channels pane. |
|
|
* Notice that this method does not remove any channels in the back-end. |
|
|
* It is invoked after the channels are already removed in the back-end. |
|
|
* @return The number of removed channels. |
|
|
*/ |
|
|
public int |
|
|
removeSelectedChannels() { |
|
|
int[] l = chnList.getSelectedIndices(); |
|
|
ComponentListModel model = chnList.getModel(); |
|
119 |
|
|
120 |
for(;;) { |
if(config != null) { |
121 |
int i = chnList.getMinSelectionIndex(); |
switch(config.type) { |
122 |
if(i == -1) break; |
case SMALL: |
123 |
model.remove(i); |
channel = new Channel(channelModel, listener, ChannelView.Type.SMALL); |
124 |
|
break; |
125 |
|
case NORMAL: |
126 |
|
channel = new Channel(channelModel, listener, ChannelView.Type.NORMAL); |
127 |
|
break; |
128 |
|
} |
129 |
} |
} |
130 |
|
if(channel == null) channel = new Channel(channelModel, listener); |
131 |
return l.length; |
if(config != null) { |
132 |
} |
if(config.expanded) channel.expandChannel(false); |
133 |
|
} else { |
134 |
/** |
if(channel.getChannelInfo().getEngine() == null) { |
135 |
* Registers the specified listener for receiving list selection events. |
channel.expandChannel(false); |
136 |
* @param listener The <code>ListSelectionListener</code> to register. |
} |
137 |
*/ |
} |
138 |
public void |
listModel.add(channel); |
139 |
addListSelectionListener(ListSelectionListener listener) { |
chnList.setSelectedComponent(channel, true); |
|
listenerList.add(ListSelectionListener.class, listener); //TODO: Remove this? |
|
|
chnList.addListSelectionListener(listener); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Removes the specified listener. |
|
|
* @param listener The <code>ListSelectionListener</code> to remove. |
|
|
*/ |
|
|
public void |
|
|
removeListSelectionListener(ListSelectionListener listener) { |
|
|
listenerList.remove(ListSelectionListener.class, listener); //TODO: Remove this? |
|
|
chnList.removeListSelectionListener(listener); |
|
140 |
} |
} |
|
|
|
|
/** |
|
|
* Determines whether the channel list UI should be automatically updated |
|
|
* when channel is added/removed. The default value is <code>true</code>. |
|
|
* @see updateChannelListUI |
|
|
*/ |
|
|
public boolean |
|
|
getAutoUpdate() { return chnList.getAutoUpdate(); } |
|
|
|
|
|
/** |
|
|
* Determines whether the channel list UI should be automatically updated |
|
|
* when channel is added/removed. |
|
|
* @see updateChannelListUI |
|
|
*/ |
|
|
public void |
|
|
setAutoUpdate(boolean b) { chnList.setAutoUpdate(b); } |
|
|
|
|
|
/** |
|
|
* Updates the channel list UI. |
|
|
* @see setAutoUpdate |
|
|
*/ |
|
|
public void |
|
|
updateChannelListUI() { chnList.updateList(); } |
|
141 |
} |
} |