1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2006 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 |
* |
* |
26 |
import java.awt.Component; |
import java.awt.Component; |
27 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
28 |
|
|
|
import java.awt.event.KeyEvent; |
|
29 |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
30 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
31 |
|
|
32 |
import java.util.Vector; |
import java.util.Vector; |
33 |
|
|
34 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
|
import javax.swing.JComponent; |
|
35 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
36 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
37 |
import javax.swing.JPopupMenu; |
import javax.swing.JPopupMenu; |
38 |
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
|
import javax.swing.KeyStroke; |
|
|
import javax.swing.ListCellRenderer; |
|
39 |
import javax.swing.ListSelectionModel; |
import javax.swing.ListSelectionModel; |
40 |
|
|
41 |
import javax.swing.event.ListSelectionEvent; |
import javax.swing.event.ListSelectionEvent; |
51 |
import org.jsampler.view.JSChannel; |
import org.jsampler.view.JSChannel; |
52 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
53 |
|
|
54 |
import org.linuxsampler.lscp.SamplerChannel; |
import static org.jsampler.view.classic.A4n.a4n; |
|
|
|
55 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
56 |
|
|
57 |
|
|
92 |
|
|
93 |
} |
} |
94 |
|
|
95 |
|
@Override |
96 |
public void |
public void |
97 |
setSelectedChannel(JSChannel channel) { |
setSelectedChannel(JSChannel channel) { |
98 |
chnList.setSelectedComponent(channel, true); |
chnList.setSelectedComponent(channel, true); |
102 |
* Adds new channel to this channels pane. |
* Adds new channel to this channels pane. |
103 |
* @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. |
104 |
*/ |
*/ |
105 |
|
@Override |
106 |
public void |
public void |
107 |
addChannel(SamplerChannelModel channelModel) { |
addChannel(SamplerChannelModel channelModel) { |
108 |
Channel channel = new Channel(channelModel); |
Channel channel = new Channel(channelModel); |
116 |
* Adds the specified channels to this channels pane. |
* Adds the specified channels to this channels pane. |
117 |
* @param chns The channels to be added. |
* @param chns The channels to be added. |
118 |
*/ |
*/ |
119 |
|
@Override |
120 |
public void |
public void |
121 |
addChannels(JSChannel[] chns) { |
addChannels(JSChannel[] chns) { |
122 |
if(chns == null || chns.length == 0) return; |
if(chns == null || chns.length == 0) return; |
134 |
* This method is invoked when a sampler channel is removed in the back-end. |
* This method is invoked when a sampler channel is removed in the back-end. |
135 |
* @param chn The channel to be removed from this channels pane. |
* @param chn The channel to be removed from this channels pane. |
136 |
*/ |
*/ |
137 |
|
@Override |
138 |
public void |
public void |
139 |
removeChannel(JSChannel chn) { listModel.remove(chn); } |
removeChannel(JSChannel chn) { listModel.remove(chn); } |
140 |
|
|
143 |
* @return The first channel in this channels pane or <code>null</code> if |
* @return The first channel in this channels pane or <code>null</code> if |
144 |
* the channels pane is empty. |
* the channels pane is empty. |
145 |
*/ |
*/ |
146 |
|
@Override |
147 |
public JSChannel |
public JSChannel |
148 |
getFirstChannel() { return listModel.size() == 0 ? null : (JSChannel)listModel.get(0); } |
getFirstChannel() { return listModel.size() == 0 ? null : (JSChannel)listModel.get(0); } |
149 |
|
|
152 |
* @return The last channel in this channels pane or <code>null</code> if |
* @return The last channel in this channels pane or <code>null</code> if |
153 |
* the channels pane is empty. |
* the channels pane is empty. |
154 |
*/ |
*/ |
155 |
|
@Override |
156 |
public JSChannel |
public JSChannel |
157 |
getLastChannel() { |
getLastChannel() { |
158 |
return listModel.size() == 0 ? null : (JSChannel)listModel.get(listModel.size()-1); |
return listModel.size() == 0 ? null : (JSChannel)listModel.get(listModel.size()-1); |
163 |
* @return The channel at the specified index. |
* @return The channel at the specified index. |
164 |
* @throws ArrayIndexOutOfBoundsException If the index is out of range. |
* @throws ArrayIndexOutOfBoundsException If the index is out of range. |
165 |
*/ |
*/ |
166 |
|
@Override |
167 |
public JSChannel |
public JSChannel |
168 |
getChannel(int idx) { return (JSChannel)listModel.get(idx); } |
getChannel(int idx) { return (JSChannel)listModel.get(idx); } |
169 |
|
|
171 |
* Gets an array with all channels in this channels pane. |
* Gets an array with all channels in this channels pane. |
172 |
* @return An array with all channels in this channels pane. |
* @return An array with all channels in this channels pane. |
173 |
*/ |
*/ |
174 |
|
@Override |
175 |
public JSChannel[] |
public JSChannel[] |
176 |
getChannels() { |
getChannels() { |
177 |
JSChannel[] chns = new JSChannel[listModel.size()]; |
JSChannel[] chns = new JSChannel[listModel.size()]; |
183 |
* Gets the number of channels in this channels pane. |
* Gets the number of channels in this channels pane. |
184 |
* @return The number of channels in this channels pane. |
* @return The number of channels in this channels pane. |
185 |
*/ |
*/ |
186 |
|
@Override |
187 |
public int |
public int |
188 |
getChannelCount() { return listModel.size(); } |
getChannelCount() { return listModel.size(); } |
189 |
|
|
192 |
* @return <code>true</code> if there is at least one selected channel, |
* @return <code>true</code> if there is at least one selected channel, |
193 |
* <code>false</code> otherwise. |
* <code>false</code> otherwise. |
194 |
*/ |
*/ |
195 |
|
@Override |
196 |
public boolean |
public boolean |
197 |
hasSelectedChannel() { return !chnList.isSelectionEmpty(); } |
hasSelectedChannel() { return !chnList.isSelectionEmpty(); } |
198 |
|
|
200 |
* Gets the number of the selected channels. |
* Gets the number of the selected channels. |
201 |
* @return The number of the selected channels. |
* @return The number of the selected channels. |
202 |
*/ |
*/ |
203 |
|
@Override |
204 |
public int |
public int |
205 |
getSelectedChannelCount() { return chnList.getSelectedIndices().length; } |
getSelectedChannelCount() { return chnList.getSelectedIndices().length; } |
206 |
|
|
209 |
* The channels are sorted in increasing index order. |
* The channels are sorted in increasing index order. |
210 |
* @return The selected channels or an empty array if nothing is selected. |
* @return The selected channels or an empty array if nothing is selected. |
211 |
*/ |
*/ |
212 |
|
@Override |
213 |
public JSChannel[] |
public JSChannel[] |
214 |
getSelectedChannels() { |
getSelectedChannels() { |
215 |
Component[] cS = chnList.getSelectedComponents(); |
Component[] cS = chnList.getSelectedComponents(); |
224 |
* It is invoked after the channels are already removed in the back-end. |
* It is invoked after the channels are already removed in the back-end. |
225 |
* @return The number of removed channels. |
* @return The number of removed channels. |
226 |
*/ |
*/ |
227 |
|
@Override |
228 |
public int |
public int |
229 |
removeSelectedChannels() { |
removeSelectedChannels() { |
230 |
int[] l = chnList.getSelectedIndices(); |
int[] l = chnList.getSelectedIndices(); |
240 |
} |
} |
241 |
|
|
242 |
/** Selects all channels. */ |
/** Selects all channels. */ |
243 |
|
@Override |
244 |
public void |
public void |
245 |
selectAllChannels() { chnList.selectAll(); } |
selectAll() { chnList.selectAll(); } |
246 |
|
|
247 |
/** Deselects all selected channels. */ |
/** Deselects all selected channels. */ |
248 |
|
@Override |
249 |
public void |
public void |
250 |
deselectChannels() { chnList.clearSelection(); } |
clearSelection() { chnList.clearSelection(); } |
251 |
|
|
252 |
/** |
/** |
253 |
* Registers the specified listener for receiving list selection events. |
* Registers the specified listener for receiving list selection events. |
254 |
* @param listener The <code>ListSelectionListener</code> to register. |
* @param listener The <code>ListSelectionListener</code> to register. |
255 |
*/ |
*/ |
256 |
|
@Override |
257 |
public void |
public void |
258 |
addListSelectionListener(ListSelectionListener listener) { |
addListSelectionListener(ListSelectionListener listener) { |
259 |
listenerList.add(ListSelectionListener.class, listener); |
listenerList.add(ListSelectionListener.class, listener); |
263 |
* Removes the specified listener. |
* Removes the specified listener. |
264 |
* @param listener The <code>ListSelectionListener</code> to remove. |
* @param listener The <code>ListSelectionListener</code> to remove. |
265 |
*/ |
*/ |
266 |
|
@Override |
267 |
public void |
public void |
268 |
removeListSelectionListener(ListSelectionListener listener) { |
removeListSelectionListener(ListSelectionListener listener) { |
269 |
listenerList.remove(ListSelectionListener.class, listener); |
listenerList.remove(ListSelectionListener.class, listener); |
276 |
* @param e A <code>ListSelectionEvent</code> |
* @param e A <code>ListSelectionEvent</code> |
277 |
* instance providing the event information. |
* instance providing the event information. |
278 |
*/ |
*/ |
279 |
|
@Override |
280 |
public void |
public void |
281 |
valueChanged(ListSelectionEvent e) { |
valueChanged(ListSelectionEvent e) { |
282 |
ListSelectionEvent e2 = null; |
ListSelectionEvent e2 = null; |
301 |
* when channel is added/removed. The default value is <code>true</code>. |
* when channel is added/removed. The default value is <code>true</code>. |
302 |
* @see updateChannelListUI |
* @see updateChannelListUI |
303 |
*/ |
*/ |
304 |
|
@Override |
305 |
public boolean |
public boolean |
306 |
getAutoUpdate() { return chnList.getAutoUpdate(); } |
getAutoUpdate() { return chnList.getAutoUpdate(); } |
307 |
|
|
310 |
* when channel is added/removed. |
* when channel is added/removed. |
311 |
* @see updateChannelListUI |
* @see updateChannelListUI |
312 |
*/ |
*/ |
313 |
|
@Override |
314 |
public void |
public void |
315 |
setAutoUpdate(boolean b) { chnList.setAutoUpdate(b); } |
setAutoUpdate(boolean b) { chnList.setAutoUpdate(b); } |
316 |
|
|
318 |
* Updates the channel list UI. |
* Updates the channel list UI. |
319 |
* @see setAutoUpdate |
* @see setAutoUpdate |
320 |
*/ |
*/ |
321 |
|
@Override |
322 |
public void |
public void |
323 |
updateChannelListUI() { chnList.updateList(); } |
updateChannelListUI() { chnList.updateList(); } |
324 |
|
|
325 |
|
|
326 |
|
@Override |
327 |
public void |
public void |
328 |
moveSelectedChannelsOnTop() { |
moveSelectedChannelsOnTop() { |
329 |
JSChannel[] chns = getSelectedChannels(); |
JSChannel[] chns = getSelectedChannels(); |
342 |
chnList.ensureIndexIsVisible(0); |
chnList.ensureIndexIsVisible(0); |
343 |
} |
} |
344 |
|
|
345 |
|
@Override |
346 |
public void |
public void |
347 |
moveSelectedChannelsUp() { |
moveSelectedChannelsUp() { |
348 |
JSChannel[] chns = getSelectedChannels(); |
JSChannel[] chns = getSelectedChannels(); |
362 |
chnList.ensureIndexIsVisible(si[0]); |
chnList.ensureIndexIsVisible(si[0]); |
363 |
} |
} |
364 |
|
|
365 |
|
@Override |
366 |
public void |
public void |
367 |
moveSelectedChannelsDown() { |
moveSelectedChannelsDown() { |
368 |
JSChannel[] chns = getSelectedChannels(); |
JSChannel[] chns = getSelectedChannels(); |
380 |
chnList.ensureIndexIsVisible(si[si.length - 1]); |
chnList.ensureIndexIsVisible(si[si.length - 1]); |
381 |
} |
} |
382 |
|
|
383 |
|
@Override |
384 |
public void |
public void |
385 |
moveSelectedChannelsAtBottom() { |
moveSelectedChannelsAtBottom() { |
386 |
JSChannel[] chns = getSelectedChannels(); |
JSChannel[] chns = getSelectedChannels(); |
412 |
private final JMenu submenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab")); |
private final JMenu submenu = new JMenu(i18n.getMenuLabel("channels.MoveToTab")); |
413 |
|
|
414 |
ContextMenu() { |
ContextMenu() { |
415 |
JMenuItem mi = new JMenuItem(A4n.moveChannelsOnTop); |
JMenuItem mi = new JMenuItem(a4n.moveChannelsOnTop); |
416 |
mi.setIcon(null); |
mi.setIcon(null); |
417 |
cmenu.add(mi); |
cmenu.add(mi); |
418 |
|
|
419 |
mi = new JMenuItem(A4n.moveChannelsUp); |
mi = new JMenuItem(a4n.moveChannelsUp); |
420 |
mi.setIcon(null); |
mi.setIcon(null); |
421 |
cmenu.add(mi); |
cmenu.add(mi); |
422 |
|
|
423 |
mi = new JMenuItem(A4n.moveChannelsDown); |
mi = new JMenuItem(a4n.moveChannelsDown); |
424 |
mi.setIcon(null); |
mi.setIcon(null); |
425 |
cmenu.add(mi); |
cmenu.add(mi); |
426 |
|
|
427 |
mi = new JMenuItem(A4n.moveChannelsAtBottom); |
mi = new JMenuItem(a4n.moveChannelsAtBottom); |
428 |
mi.setIcon(null); |
mi.setIcon(null); |
429 |
cmenu.add(mi); |
cmenu.add(mi); |
430 |
|
|
432 |
|
|
433 |
cmenu.addSeparator(); |
cmenu.addSeparator(); |
434 |
|
|
435 |
mi = new JMenuItem(A4n.removeChannels); |
mi = new JMenuItem(a4n.removeChannels); |
436 |
mi.setIcon(null); |
mi.setIcon(null); |
437 |
cmenu.add(mi); |
cmenu.add(mi); |
438 |
} |
} |
439 |
|
|
440 |
|
@Override |
441 |
public void |
public void |
442 |
mousePressed(MouseEvent e) { |
mousePressed(MouseEvent e) { |
443 |
if(e.isPopupTrigger()) show(e); |
if(e.isPopupTrigger()) show(e); |
444 |
} |
} |
445 |
|
|
446 |
|
@Override |
447 |
public void |
public void |
448 |
mouseReleased(MouseEvent e) { |
mouseReleased(MouseEvent e) { |
449 |
if(e.isPopupTrigger()) show(e); |
if(e.isPopupTrigger()) show(e); |
471 |
submenu.add(new JMenuItem(new A4n.MoveChannelsTo(p))); |
submenu.add(new JMenuItem(new A4n.MoveChannelsTo(p))); |
472 |
} |
} |
473 |
} |
} |
474 |
|
|
475 |
|
public void |
476 |
|
processChannelSelection(JSChannel c, boolean controlDown, boolean shiftDown) { |
477 |
|
|
478 |
|
} |
479 |
} |
} |