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 |
* |
* |
23 |
package org.jsampler.view; |
package org.jsampler.view; |
24 |
|
|
25 |
import java.awt.Dialog; |
import java.awt.Dialog; |
|
import java.awt.Dimension; |
|
26 |
import java.awt.Frame; |
import java.awt.Frame; |
27 |
|
|
28 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
38 |
import javax.swing.JFrame; |
import javax.swing.JFrame; |
39 |
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
40 |
|
|
41 |
|
import javax.swing.event.ListSelectionEvent; |
42 |
|
import javax.swing.event.ListSelectionListener; |
43 |
import org.jsampler.CC; |
import org.jsampler.CC; |
44 |
import org.jsampler.JSampler; |
import org.jsampler.JSampler; |
45 |
import org.jsampler.Prefs; |
import org.jsampler.SamplerChannelModel; |
46 |
import org.jsampler.Server; |
import org.jsampler.Server; |
47 |
|
|
48 |
import org.jsampler.event.SamplerChannelListEvent; |
import org.jsampler.event.SamplerChannelListEvent; |
114 |
*/ |
*/ |
115 |
public abstract void showDetailedErrorMessage(Dialog owner, String err, String details); |
public abstract void showDetailedErrorMessage(Dialog owner, String err, String details); |
116 |
|
|
117 |
|
protected Vector<ListSelectionListener> channelsPaneListeners = |
118 |
|
new Vector<ListSelectionListener>(); |
119 |
|
|
120 |
|
/** |
121 |
|
* Registers the specified listener for receiving event messages. |
122 |
|
* @param l The <code>ListSelectionListener</code> to register. |
123 |
|
*/ |
124 |
|
public void |
125 |
|
addChannelsPaneSelectionListener(ListSelectionListener l) { |
126 |
|
channelsPaneListeners.add(l); |
127 |
|
} |
128 |
|
|
129 |
|
/** |
130 |
|
* Removes the specified listener. |
131 |
|
* @param l The <code>ListSelectionListener</code> to remove. |
132 |
|
*/ |
133 |
|
public void |
134 |
|
removeChannelsPaneSelectionListener(ListSelectionListener l) { |
135 |
|
channelsPaneListeners.remove(l); |
136 |
|
} |
137 |
|
|
138 |
|
protected void |
139 |
|
fireChannelsPaneSelectionChanged() { |
140 |
|
int i = getChannelsPaneIndex(getSelectedChannelsPane()); |
141 |
|
ListSelectionEvent e = new ListSelectionEvent(this, i, i, false); |
142 |
|
for(ListSelectionListener l : channelsPaneListeners) l.valueChanged(e); |
143 |
|
} |
144 |
|
|
145 |
/** |
/** |
146 |
* Returns a list containing all <code>JSChannelsPane</code>s added to the view. |
* Returns a list containing all <code>JSChannelsPane</code>s added to the view. |
147 |
* @return A list containing all <code>JSChannelsPane</code>s added to the view. |
* @return A list containing all <code>JSChannelsPane</code>s added to the view. |
185 |
getChannelsPaneCount() { return chnPaneList.size(); } |
getChannelsPaneCount() { return chnPaneList.size(); } |
186 |
|
|
187 |
/** |
/** |
188 |
|
* Returns the index of the specified channels pane, or -1 if |
189 |
|
* the specified channels pane is not found. |
190 |
|
*/ |
191 |
|
public int |
192 |
|
getChannelsPaneIndex(JSChannelsPane chnPane) { |
193 |
|
return chnPaneList.indexOf(chnPane); |
194 |
|
} |
195 |
|
|
196 |
|
/** |
197 |
* Inserts the specified <code>JSChannelsPane</code> at the specified position |
* Inserts the specified <code>JSChannelsPane</code> at the specified position |
198 |
* in the view and in the code>JSChannelsPane</code> list. |
* in the view and in the code>JSChannelsPane</code> list. |
199 |
* Where and how this pane will be shown depends on the view/GUI implementation. |
* Where and how this pane will be shown depends on the view/GUI implementation. |
229 |
|
|
230 |
/** |
/** |
231 |
* Sets the <code>JSChannelsPane</code> to be selected. |
* Sets the <code>JSChannelsPane</code> to be selected. |
232 |
|
* Note that all registered listeners should be notified |
233 |
|
* when the selection is changed. |
234 |
* @param pane The <code>JSChannelsPane</code> to be shown. |
* @param pane The <code>JSChannelsPane</code> to be shown. |
235 |
|
* @see #fireChannelsPaneSelectionChanged |
236 |
*/ |
*/ |
237 |
public abstract void setSelectedChannelsPane(JSChannelsPane pane); |
public abstract void setSelectedChannelsPane(JSChannelsPane pane); |
238 |
|
|
242 |
* @param e A <code>SamplerChannelListEvent</code> |
* @param e A <code>SamplerChannelListEvent</code> |
243 |
* instance providing the event information. |
* instance providing the event information. |
244 |
*/ |
*/ |
245 |
|
@Override |
246 |
public void |
public void |
247 |
channelAdded(SamplerChannelListEvent e) { |
channelAdded(SamplerChannelListEvent e) { |
248 |
if(e.getChannelModel() == null) return; |
if(e.getChannelModel() == null) return; |
260 |
* @param e A <code>SamplerChannelListEvent</code> |
* @param e A <code>SamplerChannelListEvent</code> |
261 |
* instance providing the event information. |
* instance providing the event information. |
262 |
*/ |
*/ |
263 |
|
@Override |
264 |
public void |
public void |
265 |
channelRemoved(SamplerChannelListEvent e) { |
channelRemoved(SamplerChannelListEvent e) { |
266 |
removeChannel(e.getChannelModel().getChannelId()); |
removeChannel(e.getChannelModel().getChannelId()); |
306 |
} |
} |
307 |
|
|
308 |
/** |
/** |
309 |
|
* Gets the zero-based position of the specified sampler channel |
310 |
|
* in the channels pane, to which the channel is added. |
311 |
|
* Note that the position may change when adding/removing sampler channels. |
312 |
|
* @return The zero-based position of the specified sampler channel |
313 |
|
* in the channels pane, or -1 if the specified channels is not found. |
314 |
|
*/ |
315 |
|
public int |
316 |
|
getChannelNumber(SamplerChannelModel channel) { |
317 |
|
if(channel == null) return -1; |
318 |
|
|
319 |
|
for(int i = 0; i < getChannelsPaneCount(); i++) { |
320 |
|
JSChannelsPane chnPane = getChannelsPane(i); |
321 |
|
for(int j = 0; j < chnPane.getChannelCount(); j++) { |
322 |
|
if(chnPane.getChannel(j).getChannelId() == channel.getChannelId()) { |
323 |
|
return j; |
324 |
|
} |
325 |
|
} |
326 |
|
} |
327 |
|
|
328 |
|
return -1; |
329 |
|
} |
330 |
|
|
331 |
|
/** |
332 |
|
* Returns a string in the format <code>channelPaneNumber/channelNumber</code>, |
333 |
|
* where <code>channelPaneNumber</code> is the one-based number of the channels |
334 |
|
* pane containing the specified channel and <code>channelNumber</code> is the |
335 |
|
* one-based number of the channel's position in the channels pane. |
336 |
|
* Note that this path may change when adding/removing channels/channels panes. |
337 |
|
* @return The channels path, or <code>null</code> if the specified channels is not found. |
338 |
|
*/ |
339 |
|
public String |
340 |
|
getChannelPath(SamplerChannelModel channel) { |
341 |
|
if(channel == null) return null; |
342 |
|
|
343 |
|
for(int i = 0; i < getChannelsPaneCount(); i++) { |
344 |
|
JSChannelsPane chnPane = getChannelsPane(i); |
345 |
|
for(int j = 0; j < chnPane.getChannelCount(); j++) { |
346 |
|
if(chnPane.getChannel(j).getChannelId() == channel.getChannelId()) { |
347 |
|
return (i + 1) + "/" + (j + 1); |
348 |
|
} |
349 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
return null; |
353 |
|
} |
354 |
|
|
355 |
|
/** |
356 |
|
* Gets the zero-based number of the channels pane, |
357 |
|
* to which the specified sampler channel is added. |
358 |
|
* Note that the can be moved from one channels pane to another. |
359 |
|
* @return The zero-based index of the channels pane, |
360 |
|
* to which the specified sampler channel is added, or |
361 |
|
* -1 if the specified channels is not found. |
362 |
|
*/ |
363 |
|
public int |
364 |
|
getChannelsPaneNumber(SamplerChannelModel channel) { |
365 |
|
if(channel == null) return -1; |
366 |
|
|
367 |
|
for(int i = 0; i < getChannelsPaneCount(); i++) { |
368 |
|
JSChannelsPane chnPane = getChannelsPane(i); |
369 |
|
for(int j = 0; j < chnPane.getChannelCount(); j++) { |
370 |
|
if(chnPane.getChannel(j).getChannelId() == channel.getChannelId()) { |
371 |
|
return i; |
372 |
|
} |
373 |
|
} |
374 |
|
} |
375 |
|
|
376 |
|
return -1; |
377 |
|
} |
378 |
|
|
379 |
|
/** |
380 |
* Determines whether the channel list UI should be automatically updated |
* Determines whether the channel list UI should be automatically updated |
381 |
* when channel is added/removed. The default value is <code>true</code>. |
* when channel is added/removed. The default value is <code>true</code>. |
382 |
*/ |
*/ |