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-2011 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; |
package org.jsampler.view; |
24 |
|
|
|
import javax.swing.JPanel; |
|
|
import javax.swing.event.ListSelectionListener; |
|
25 |
|
|
26 |
import org.jsampler.SamplerChannelModel; |
import org.jsampler.SamplerChannelModel; |
27 |
|
import org.jsampler.event.ListSelectionListener; |
28 |
import org.jsampler.view.SessionViewConfig.ChannelConfig; |
import org.jsampler.view.SessionViewConfig.ChannelConfig; |
29 |
|
|
30 |
|
|
32 |
* This class defines the skeleton of a pane containg sampler channels. |
* This class defines the skeleton of a pane containg sampler channels. |
33 |
* @author Grigor Iliev |
* @author Grigor Iliev |
34 |
*/ |
*/ |
35 |
public abstract class JSChannelsPane extends JPanel { |
public interface JSChannelsPane<C extends JSChannel> { |
36 |
/** The key used for reporting title's property change. */ |
/** The key used for reporting title's property change. */ |
37 |
public final static String TITLE = "ChannelsPaneTitle"; |
public final static String TITLE = "ChannelsPaneTitle"; |
38 |
|
|
|
private String title; |
|
|
|
|
|
/** Creates a new instance of <code>JSChannelsPane</code>. */ |
|
|
public |
|
|
JSChannelsPane(String title) { this.title = title; } |
|
|
|
|
39 |
/** |
/** |
40 |
* Returns the title of this <code>JSChannelsPane</code>. |
* Returns the title of this channels' pane. |
41 |
* @return The title of this <code>JSChannelsPane</code>. |
* @return The title of this channels' pane. |
42 |
*/ |
*/ |
43 |
public String |
public String getTitle(); |
|
getTitle() { return title; } |
|
44 |
|
|
45 |
/** |
/** |
46 |
* Sets the title of this <code>JSChannelsPane</code>. |
* Sets the title of this channels' pane. |
47 |
* @param title The new title of this <code>JSChannelsPane</code>. |
* @param title The new title of this channels' pane. |
48 |
*/ |
*/ |
49 |
public void |
public void setTitle(String title); |
|
setTitle(String title) { |
|
|
if(this.title.equals(title)) return; |
|
|
|
|
|
String oldTitle = this.title; |
|
|
this.title = title; |
|
|
firePropertyChange(TITLE, oldTitle, title); |
|
|
} |
|
50 |
|
|
51 |
/** |
//public void firePropertyChange(String propertyName, Object oldValue, Object newValue); |
|
* Returns the title of this <code>JSChannelsPane</code>. |
|
|
* @return The title of this <code>JSChannelsPane</code>. |
|
|
*/ |
|
|
@Override |
|
|
public String |
|
|
toString() { return getTitle(); } |
|
52 |
|
|
53 |
/** |
/** |
54 |
* Adds new channel to this channels pane. |
* Adds new channel to this channels pane. |
55 |
* @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. |
56 |
*/ |
*/ |
57 |
public abstract void addChannel(SamplerChannelModel channelModel); |
public void addChannel(SamplerChannelModel channelModel); |
58 |
|
|
59 |
/** |
/** |
60 |
* Adds new channel to this channels pane. |
* Adds new channel to this channels pane. |
61 |
* @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. |
62 |
* @param config The view config of the sampler channel. |
* @param config The view config of the sampler channel. |
63 |
*/ |
*/ |
64 |
public void |
public void addChannel(SamplerChannelModel channelModel, ChannelConfig config); |
|
addChannel(SamplerChannelModel channelModel, ChannelConfig config) { |
|
|
addChannel(channelModel); |
|
|
} |
|
65 |
|
|
66 |
/** |
/** |
67 |
* Adds the specified channels to this channels pane. |
* Adds the specified channels to this channels pane. |
68 |
* @param chns The channels to be added. |
* @param chns The channels to be added. |
69 |
*/ |
*/ |
70 |
public abstract void addChannels(JSChannel[] chns); |
public void addChannels(C[] chns); |
71 |
|
|
72 |
/** |
/** |
73 |
* Removes the specified channel from this channels pane. |
* Removes the specified channel from this channels pane. |
74 |
* 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. |
75 |
* @param chn The channel to be removed from this channels pane. |
* @param chn The channel to be removed from this channels pane. |
76 |
*/ |
*/ |
77 |
public abstract void removeChannel(JSChannel chn); |
public void removeChannel(C chn); |
78 |
|
|
79 |
/** |
/** |
80 |
* Determines whether there is at least one selected channel. |
* Determines whether there is at least one selected channel. |
81 |
* @return <code>true</code> if there is at least one selected channel, |
* @return <code>true</code> if there is at least one selected channel, |
82 |
* <code>false</code> otherwise. |
* <code>false</code> otherwise. |
83 |
*/ |
*/ |
84 |
public abstract boolean hasSelectedChannel(); |
public boolean hasSelectedChannel(); |
85 |
|
|
86 |
/** |
/** |
87 |
* Gets the first channel in this channels pane. |
* Gets the first channel in this channels pane. |
88 |
* @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 |
89 |
* the channels pane is empty. |
* the channels pane is empty. |
90 |
*/ |
*/ |
91 |
public abstract JSChannel getFirstChannel(); |
public C getFirstChannel(); |
92 |
|
|
93 |
/** |
/** |
94 |
* Gets the last channel in this channels pane. |
* Gets the last channel in this channels pane. |
95 |
* @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 |
96 |
* the channels pane is empty. |
* the channels pane is empty. |
97 |
*/ |
*/ |
98 |
public abstract JSChannel getLastChannel(); |
public C getLastChannel(); |
99 |
|
|
100 |
/** |
/** |
101 |
* Gets the channel at the specified index. |
* Gets the channel at the specified index. |
102 |
* @return The channel at the specified index. |
* @return The channel at the specified index. |
103 |
* @throws ArrayIndexOutOfBoundsException If the index is out of range. |
* @throws ArrayIndexOutOfBoundsException If the index is out of range. |
104 |
*/ |
*/ |
105 |
public abstract JSChannel getChannel(int idx); |
public C getChannel(int idx); |
106 |
|
|
107 |
/** |
/** |
108 |
* Gets an array of all channels in this channels pane. |
* Gets an array of all channels in this channels pane. |
109 |
* @return An array of all channels in this channels pane. |
* @return An array of all channels in this channels pane. |
110 |
*/ |
*/ |
111 |
public abstract JSChannel[] getChannels(); |
public C[] getChannels(); |
112 |
|
|
113 |
/** |
/** |
114 |
* Gets the number of channels in this channels pane. |
* Gets the number of channels in this channels pane. |
115 |
* @return The number of channels in this channels pane. |
* @return The number of channels in this channels pane. |
116 |
*/ |
*/ |
117 |
public abstract int getChannelCount(); |
public int getChannelCount(); |
118 |
|
|
119 |
/** |
/** |
120 |
* Gets an array of all selected channels. |
* Gets an array of all selected channels. |
121 |
* The channels are sorted in increasing index order. |
* The channels are sorted in increasing index order. |
122 |
* @return The selected channels or an empty array if nothing is selected. |
* @return The selected channels or an empty array if nothing is selected. |
123 |
*/ |
*/ |
124 |
public abstract JSChannel[] getSelectedChannels(); |
public C[] getSelectedChannels(); |
125 |
|
|
126 |
/** |
/** |
127 |
* Gets the number of the selected channels. |
* Gets the number of the selected channels. |
128 |
* @return The number of the selected channels. |
* @return The number of the selected channels. |
129 |
*/ |
*/ |
130 |
public abstract int getSelectedChannelCount(); |
public int getSelectedChannelCount(); |
131 |
|
|
132 |
/** |
/** |
133 |
* Selects the specified channel. |
* Selects the specified channel. |
134 |
*/ |
*/ |
135 |
public abstract void setSelectedChannel(JSChannel channel); |
public void setSelectedChannel(C channel); |
136 |
|
|
137 |
/** Selects all channels. */ |
/** Selects all channels. */ |
138 |
public abstract void selectAll(); |
public void selectAll(); |
139 |
|
|
140 |
/** Deselects all selected channels. */ |
/** Deselects all selected channels. */ |
141 |
public abstract void clearSelection(); |
public void clearSelection(); |
142 |
|
|
143 |
/** |
/** |
144 |
* Removes all selected channels in this channels pane. |
* Removes all selected channels in this channels pane. |
146 |
* 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. |
147 |
* @return The number of removed channels. |
* @return The number of removed channels. |
148 |
*/ |
*/ |
149 |
public abstract int removeSelectedChannels(); |
public int removeSelectedChannels(); |
150 |
|
|
151 |
public abstract void moveSelectedChannelsOnTop(); |
public void moveSelectedChannelsOnTop(); |
152 |
|
|
153 |
public abstract void moveSelectedChannelsUp(); |
public void moveSelectedChannelsUp(); |
154 |
|
|
155 |
public abstract void moveSelectedChannelsDown(); |
public void moveSelectedChannelsDown(); |
156 |
|
|
157 |
public abstract void moveSelectedChannelsAtBottom(); |
public void moveSelectedChannelsAtBottom(); |
158 |
|
|
159 |
/** |
/** |
160 |
* Registers the specified listener for receiving list selection events. |
* Registers the specified listener for receiving list selection events. |
161 |
* @param listener The <code>ListSelectionListener</code> to register. |
* @param listener The <code>ListSelectionListener</code> to register. |
162 |
*/ |
*/ |
163 |
public abstract void addListSelectionListener(ListSelectionListener listener); |
public void addListSelectionListener(ListSelectionListener listener); |
164 |
|
|
165 |
/** |
/** |
166 |
* Removes the specified listener. |
* Removes the specified listener. |
167 |
* @param listener The <code>ListSelectionListener</code> to remove. |
* @param listener The <code>ListSelectionListener</code> to remove. |
168 |
*/ |
*/ |
169 |
public abstract void removeListSelectionListener(ListSelectionListener listener); |
public void removeListSelectionListener(ListSelectionListener listener); |
170 |
|
|
171 |
/** |
/** |
172 |
* Process a selection event. |
* Process a selection event. |
174 |
* @param controlDown Specifies whether the control key is held down during selection. |
* @param controlDown Specifies whether the control key is held down during selection. |
175 |
* @param shiftDown Specifies whether the shift key is held down during selection. |
* @param shiftDown Specifies whether the shift key is held down during selection. |
176 |
*/ |
*/ |
177 |
public abstract void processChannelSelection(JSChannel c, boolean controlDown, boolean shiftDown); |
public void processChannelSelection(C c, boolean controlDown, boolean shiftDown); |
178 |
|
|
179 |
/** |
/** |
180 |
* Determines whether the channel list UI should be automatically updated |
* Determines whether the channel list UI should be automatically updated |
181 |
* when channel is added/removed. The default value is <code>true</code>. |
* when channel is added/removed. The default value is <code>true</code>. |
182 |
* @see updateChannelListUI |
* @see updateChannelListUI |
183 |
*/ |
*/ |
184 |
public abstract boolean getAutoUpdate(); |
public boolean getAutoUpdate(); |
185 |
|
|
186 |
/** |
/** |
187 |
* Determines whether the channel list UI should be automatically updated |
* Determines whether the channel list UI should be automatically updated |
188 |
* when channel is added/removed. |
* when channel is added/removed. |
189 |
* @see updateChannelListUI |
* @see updateChannelListUI |
190 |
*/ |
*/ |
191 |
public abstract void setAutoUpdate(boolean b); |
public void setAutoUpdate(boolean b); |
192 |
|
|
193 |
/** |
/** |
194 |
* Updates the channel list UI. |
* Updates the channel list UI. |
195 |
* @see setAutoUpdate |
* @see setAutoUpdate |
196 |
*/ |
*/ |
197 |
public abstract void updateChannelListUI(); |
public void updateChannelListUI(); |
198 |
} |
} |