/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/ChannelsPane.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/ChannelsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1776 - (show annotations) (download)
Thu Sep 11 18:48:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 7758 byte(s)
* Implemented virtual MIDI keyboard

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.fantasia;
24
25 import java.awt.BorderLayout;
26 import java.awt.Component;
27
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30
31 import javax.swing.BoxLayout;
32 import javax.swing.ListSelectionModel;
33
34 import javax.swing.event.ListSelectionEvent;
35 import javax.swing.event.ListSelectionListener;
36
37 import net.sf.juife.ComponentList;
38 import net.sf.juife.ComponentListModel;
39 import net.sf.juife.DefaultComponentListModel;
40
41 import org.jsampler.CC;
42 import org.jsampler.SamplerChannelModel;
43
44 import org.jsampler.view.JSChannel;
45 import org.jsampler.view.JSChannelsPane;
46
47
48 /**
49 *
50 * @author Grigor Iliev
51 */
52 public class ChannelsPane extends JSChannelsPane {
53 private final ChannelListPane chnList = new ChannelListPane();
54 private final DefaultComponentListModel listModel = new DefaultComponentListModel();
55
56 private ActionListener listener;
57
58 /**
59 * Creates a new instance of <code>ChannelsPane</code> with
60 * the specified <code>title</code>.
61 * @param title The title of this <code>ChannelsPane</code>
62 */
63 public
64 ChannelsPane(String title) {
65 this(title, null);
66 }
67
68 /**
69 * Creates a new instance of <code>ChannelsPane</code> with
70 * the specified <code>title</code>.
71 * @param title The title of this <code>ChannelsPane</code>
72 * @param l A listener which is notified when a newly created
73 * channel is fully expanded on the screen.
74 */
75 public
76 ChannelsPane(String title, ActionListener l) {
77 super(title);
78
79 listener = l;
80
81 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
82
83 chnList.setModel(listModel);
84 chnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
85
86 add(chnList);
87 }
88
89 class ChannelListPane extends ComponentList {
90 public java.awt.Dimension
91 getMaximumSize() { return getPreferredSize(); }
92 }
93
94 public void
95 setSelectedChannel(JSChannel channel) {
96 chnList.setSelectedComponent(channel, true);
97 }
98
99 /**
100 * Adds new channel to this channels pane.
101 * @param channelModel The sampler channel model to be used by the new channel.
102 */
103 public void
104 addChannel(SamplerChannelModel channelModel) {
105 Channel channel = new Channel(channelModel, listener);
106 listModel.add(channel);
107 if(channel.getChannelInfo().getEngine() == null) channel.expandChannel(false);
108 chnList.setSelectedComponent(channel, true);
109 }
110
111 /**
112 * Adds the specified channels to this channels pane.
113 * @param chns The channels to be added.
114 */
115 public void
116 addChannels(JSChannel[] chns) {
117 if(chns == null || chns.length == 0) return;
118
119 for(JSChannel c : chns) listModel.add(c);
120
121 chnList.setSelectedIndex(listModel.getSize() - 1);
122 }
123
124 /**
125 * Removes the specified channel from this channels pane.
126 * This method is invoked when a sampler channel is removed in the back-end.
127 * @param chn The channel to be removed from this channels pane.
128 */
129 public void
130 removeChannel(JSChannel chn) {
131 listModel.remove(chn);
132 }
133
134 /**
135 * Determines whether there is at least one selected channel.
136 * @return <code>true</code> if there is at least one selected channel,
137 * <code>false</code> otherwise.
138 */
139 public boolean
140 hasSelectedChannel() { return !chnList.isSelectionEmpty(); }
141
142 /**
143 * Gets the first channel in this channels pane.
144 * @return The first channel in this channels pane or <code>null</code> if
145 * the channels pane is empty.
146 */
147 public JSChannel
148 getFirstChannel() { return listModel.size() == 0 ? null : (JSChannel)listModel.get(0); }
149
150 /**
151 * Gets the last channel in this channels pane.
152 * @return The last channel in this channels pane or <code>null</code> if
153 * the channels pane is empty.
154 */
155 public JSChannel
156 getLastChannel() {
157 return listModel.size() == 0 ? null : (JSChannel)listModel.get(listModel.size()-1);
158 }
159
160 /**
161 * Gets the channel at the specified index.
162 * @return The channel at the specified index.
163 * @throws ArrayIndexOutOfBoundsException If the index is out of range.
164 */
165 public JSChannel
166 getChannel(int idx) { return (JSChannel)listModel.get(idx); }
167
168 /**
169 * Gets an array of all channels in this channels pane.
170 * @return An array of all channels in this channels pane.
171 */
172 public JSChannel[]
173 getChannels() {
174 JSChannel[] chns = new JSChannel[listModel.size()];
175 for(int i = 0; i < listModel.size(); i++) chns[i] = (JSChannel)listModel.get(i);
176 return chns;
177 }
178
179 /**
180 * Gets the number of channels in this channels pane.
181 * @return The number of channels in this channels pane.
182 */
183 public int
184 getChannelCount() { return listModel.size(); }
185
186 /**
187 * Gets an array of all selected channels.
188 * The channels are sorted in increasing index order.
189 * @return The selected channels or an empty array if nothing is selected.
190 */
191 public JSChannel[]
192 getSelectedChannels() {
193 Component[] cS = chnList.getSelectedComponents();
194 JSChannel[] chns = new JSChannel[cS.length];
195 for(int i = 0; i < cS.length; i++) chns[i] = (JSChannel)cS[i];
196 return chns;
197 }
198
199 /**
200 * Gets the number of the selected channels.
201 * @return The number of the selected channels.
202 */
203 public int
204 getSelectedChannelCount() { return chnList.getSelectedIndices().length; }
205
206 /**
207 * Removes all selected channels in this channels pane.
208 * Notice that this method does not remove any channels in the back-end.
209 * It is invoked after the channels are already removed in the back-end.
210 * @return The number of removed channels.
211 */
212 public int
213 removeSelectedChannels() {
214 int[] l = chnList.getSelectedIndices();
215 ComponentListModel model = chnList.getModel();
216
217 for(;;) {
218 int i = chnList.getMinSelectionIndex();
219 if(i == -1) break;
220 model.remove(i);
221 }
222
223 return l.length;
224 }
225
226 /**
227 * Registers the specified listener for receiving list selection events.
228 * @param listener The <code>ListSelectionListener</code> to register.
229 */
230 public void
231 addListSelectionListener(ListSelectionListener listener) {
232 listenerList.add(ListSelectionListener.class, listener); //TODO: Remove this?
233 chnList.addListSelectionListener(listener);
234 }
235
236 /**
237 * Removes the specified listener.
238 * @param listener The <code>ListSelectionListener</code> to remove.
239 */
240 public void
241 removeListSelectionListener(ListSelectionListener listener) {
242 listenerList.remove(ListSelectionListener.class, listener); //TODO: Remove this?
243 chnList.removeListSelectionListener(listener);
244 }
245
246 /**
247 * Determines whether the channel list UI should be automatically updated
248 * when channel is added/removed. The default value is <code>true</code>.
249 * @see updateChannelListUI
250 */
251 public boolean
252 getAutoUpdate() { return chnList.getAutoUpdate(); }
253
254 /**
255 * Determines whether the channel list UI should be automatically updated
256 * when channel is added/removed.
257 * @see updateChannelListUI
258 */
259 public void
260 setAutoUpdate(boolean b) { chnList.setAutoUpdate(b); }
261
262 /**
263 * Updates the channel list UI.
264 * @see setAutoUpdate
265 */
266 public void
267 updateChannelListUI() { chnList.updateList(); }
268 }

  ViewVC Help
Powered by ViewVC