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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 912 - (hide annotations) (download)
Mon Aug 7 18:34:40 2006 UTC (17 years, 8 months ago) by iliev
File size: 6426 byte(s)
* updating to JSampler 0.3a

1 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005, 2006 Grigor Kirilov Iliev
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 javax.swing.ListSelectionModel;
29    
30     import javax.swing.event.ListSelectionEvent;
31     import javax.swing.event.ListSelectionListener;
32    
33     import net.sf.juife.ComponentList;
34     import net.sf.juife.ComponentListModel;
35     import net.sf.juife.DefaultComponentListModel;
36    
37     import org.jsampler.CC;
38     import org.jsampler.SamplerChannelModel;
39    
40     import org.jsampler.view.JSChannel;
41     import org.jsampler.view.JSChannelsPane;
42    
43    
44     /**
45     *
46     * @author Grigor Iliev
47     */
48     public class ChannelsPane extends JSChannelsPane {
49     private final ComponentList chnList = new ComponentList();
50     private final DefaultComponentListModel listModel = new DefaultComponentListModel();
51    
52    
53     /**
54     * Creates a new instance of <code>ChannelsPane</code> with
55     * the specified <code>title</code>.
56     * @param title The title of this <code>ChannelsPane</code>
57     */
58     public
59     ChannelsPane(String title) {
60     super(title);
61    
62     setLayout(new BorderLayout());
63    
64     chnList.setOpaque(false);
65     chnList.setModel(listModel);
66     chnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
67    
68     add(chnList);
69    
70     setOpaque(true);
71     }
72    
73     /**
74     * Adds new channel to this channels pane.
75     * @param channelModel The sampler channel model to be used by the new channel.
76     */
77     public void
78     addChannel(SamplerChannelModel channelModel) {
79     Channel channel = new Channel(channelModel);
80     listModel.add(channel);
81     if(channel.getChannelInfo().getEngine() == null) channel.expandChannel();
82     chnList.setSelectedComponent(channel, true);
83    
84     MainFrame.repack(CC.getMainFrame());
85     }
86    
87     /**
88     * Adds the specified channels to this channels pane.
89     * @param chns The channels to be added.
90     */
91     public void
92     addChannels(JSChannel[] chns) {
93     if(chns == null || chns.length == 0) return;
94    
95     for(JSChannel c : chns) listModel.add(c);
96    
97     chnList.setSelectedIndex(listModel.getSize() - 1);
98    
99     MainFrame.repack(CC.getMainFrame());
100     }
101    
102     /**
103     * Removes the specified channel from this channels pane.
104     * This method is invoked when a sampler channel is removed in the back-end.
105     * @param chn The channel to be removed from this channels pane.
106     */
107     public void
108     removeChannel(JSChannel chn) {
109     listModel.remove(chn);
110    
111     MainFrame.repack(CC.getMainFrame());
112     }
113    
114     /**
115     * Determines whether there is at least one selected channel.
116     * @return <code>true</code> if there is at least one selected channel,
117     * <code>false</code> otherwise.
118     */
119     public boolean
120     hasSelectedChannel() { return !chnList.isSelectionEmpty(); }
121    
122     /**
123     * Gets the first channel in this channels pane.
124     * @return The first channel in this channels pane or <code>null</code> if
125     * the channels pane is empty.
126     */
127     public JSChannel
128     getFirstChannel() { return listModel.size() == 0 ? null : (JSChannel)listModel.get(0); }
129    
130     /**
131     * Gets the last channel in this channels pane.
132     * @return The last channel in this channels pane or <code>null</code> if
133     * the channels pane is empty.
134     */
135     public JSChannel
136     getLastChannel() {
137     return listModel.size() == 0 ? null : (JSChannel)listModel.get(listModel.size()-1);
138     }
139    
140     /**
141     * Gets the channel at the specified index.
142     * @return The channel at the specified index.
143     * @throws ArrayIndexOutOfBoundsException If the index is out of range.
144     */
145     public JSChannel
146     getChannel(int idx) { return (JSChannel)listModel.get(idx); }
147    
148     /**
149     * Gets an array of all channels in this channels pane.
150     * @return An array of all channels in this channels pane.
151     */
152     public JSChannel[]
153     getChannels() {
154     JSChannel[] chns = new JSChannel[listModel.size()];
155     for(int i = 0; i < listModel.size(); i++) chns[i] = (JSChannel)listModel.get(i);
156     return chns;
157     }
158    
159     /**
160     * Gets the number of channels in this channels pane.
161     * @return The number of channels in this channels pane.
162     */
163     public int
164     getChannelCount() { return listModel.size(); }
165    
166     /**
167     * Gets an array of all selected channels.
168     * The channels are sorted in increasing index order.
169     * @return The selected channels or an empty array if nothing is selected.
170     */
171     public JSChannel[]
172     getSelectedChannels() {
173     Component[] cS = chnList.getSelectedComponents();
174     JSChannel[] chns = new JSChannel[cS.length];
175     for(int i = 0; i < cS.length; i++) chns[i] = (JSChannel)cS[i];
176     return chns;
177     }
178    
179     /**
180     * Gets the number of the selected channels.
181     * @return The number of the selected channels.
182     */
183     public int
184     getSelectedChannelCount() { return chnList.getSelectedIndices().length; }
185    
186     /**
187     * Removes all selected channels in this channels pane.
188     * Notice that this method does not remove any channels in the back-end.
189     * It is invoked after the channels are already removed in the back-end.
190     * @return The number of removed channels.
191     */
192     public int
193     removeSelectedChannels() {
194     int[] l = chnList.getSelectedIndices();
195     ComponentListModel model = chnList.getModel();
196    
197     for(;;) {
198     int i = chnList.getMinSelectionIndex();
199     if(i == -1) break;
200     model.remove(i);
201     }
202    
203    
204     MainFrame.repack(CC.getMainFrame());
205    
206     return l.length;
207     }
208    
209     /**
210     * Registers the specified listener for receiving list selection events.
211     * @param listener The <code>ListSelectionListener</code> to register.
212     */
213     public void
214     addListSelectionListener(ListSelectionListener listener) {
215     listenerList.add(ListSelectionListener.class, listener);
216     }
217    
218     /**
219     * Removes the specified listener.
220     * @param listener The <code>ListSelectionListener</code> to remove.
221     */
222     public void
223     removeListSelectionListener(ListSelectionListener listener) {
224     listenerList.remove(ListSelectionListener.class, listener);
225     }
226     }

  ViewVC Help
Powered by ViewVC