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

Contents of /jsampler/trunk/src/org/jsampler/view/JSMainFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1143 - (show annotations) (download)
Mon Apr 2 21:18:31 2007 UTC (17 years, 1 month ago) by iliev
File size: 7193 byte(s)
* upgrading to version 0.4a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 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;
24
25 import java.awt.Dimension;
26
27 import java.awt.event.WindowAdapter;
28 import java.awt.event.WindowEvent;
29
30 import java.util.Vector;
31 import java.util.logging.Level;
32
33 import javax.swing.JFrame;
34
35 import org.jsampler.CC;
36 import org.jsampler.JSampler;
37 import org.jsampler.Prefs;
38
39 import org.jsampler.event.SamplerChannelListEvent;
40 import org.jsampler.event.SamplerChannelListListener;
41
42 /**
43 * Defines the skeleton of a JSampler's main frame.
44 * @author Grigor Iliev
45 */
46 public abstract class JSMainFrame extends JFrame {
47 private final Vector<JSChannelsPane> chnPaneList = new Vector<JSChannelsPane>();
48
49 /** Creates a new instance of <code>JSMainFrame</code>. */
50 public
51 JSMainFrame() {
52 super(JSampler.NAME + ' ' + JSampler.VERSION);
53
54 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
55 addWindowListener(new WindowAdapter() {
56 public void
57 windowClosing(WindowEvent we) { onWindowClose(); }
58 });
59
60 CC.getSamplerModel().addSamplerChannelListListener(new EventHandler());
61 }
62
63 /**
64 * Invoked when this window is about to close.
65 * Don't forget to call <code>super.onWindowClose()</code> at the end,
66 * when override this method.
67 */
68 protected void
69 onWindowClose() {
70 CC.cleanExit();
71 }
72
73 /**
74 * Invoked on startup when no JSampler home directory is specified
75 * or the specified JSampler home directory doesn't exist.
76 * This method should ask the user to specify a JSampler
77 * home directory and then set the specified JSampler home directory using
78 * {@link org.jsampler.CC#setJSamplerHome} method.
79 * @see org.jsampler.CC#getJSamplerHome
80 * @see org.jsampler.CC#setJSamplerHome
81 */
82 public abstract void installJSamplerHome();
83
84 /**
85 * Returns a list containing all <code>JSChannelsPane</code>s added to the view.
86 * @return A list containing all <code>JSChannelsPane</code>s added to the view.
87 * @see #addChannelsPane
88 * @see #removeChannelsPane
89 */
90 public Vector<JSChannelsPane>
91 getChannelsPaneList() { return chnPaneList; }
92
93 /**
94 * Return the <code>JSChannelsPane</code> at the specified position.
95 * @param idx The position of the <code>JSChannelsPane</code> to be returned.
96 * @return The <code>JSChannelsPane</code> at the specified position.
97 */
98 public JSChannelsPane
99 getChannelsPane(int idx) { return chnPaneList.get(idx); }
100
101 /**
102 * Adds the specified <code>JSChannelsPane</code> to the view.
103 * @param chnPane The <code>JSChannelsPane</code> to be added.
104 */
105 public void
106 addChannelsPane(JSChannelsPane chnPane) { chnPaneList.add(chnPane); }
107
108 /**
109 * Removes the specified <code>JSChannelsPane</code> from the view.
110 * Override this method to remove <code>chnPane</code> from the view,
111 * and don't forget to call <code>super.removeChannelsPane(chnPane);</code>.
112 * @param chnPane The <code>JSChannelsPane</code> to be removed.
113 * @return <code>true</code> if the specified code>JSChannelsPane</code>
114 * is actually removed from the view, <code>false</code> otherwise.
115 */
116 public boolean
117 removeChannelsPane(JSChannelsPane chnPane) { return chnPaneList.remove(chnPane); }
118
119 /**
120 * Gets the current number of <code>JSChannelsPane</code>s added to the view.
121 * @return The current number of <code>JSChannelsPane</code>s added to the view.
122 */
123 public int
124 getChannelsPaneCount() { return chnPaneList.size(); }
125
126 /**
127 * Inserts the specified <code>JSChannelsPane</code> at the specified position
128 * in the view and in the code>JSChannelsPane</code> list.
129 * Where and how this pane will be shown depends on the view/GUI implementation.
130 * Note that some GUI implementation may have only one pane containing sampler channels.
131 * @param pane The <code>JSChannelsPane</code> to be inserted.
132 * @param idx Specifies the position of the <code>JSChannelsPane</code>.
133 * @see #getChannelsPaneList
134 */
135 public abstract void insertChannelsPane(JSChannelsPane pane, int idx);
136
137 /**
138 * Gets the <code>JSChannelsPane</code> that is currently shown,
139 * or has the focus if more than one channels' panes are shown.
140 * If the GUI implementation has only one pane containing sampler channels,
141 * than this method should always return that pane (the <code>JSChannelsPane</code>
142 * with index 0).
143 * @return The selected <code>JSChannelsPane</code>.
144 */
145 public abstract JSChannelsPane getSelectedChannelsPane();
146
147 /**
148 * Sets the <code>JSChannelsPane</code> to be selected.
149 * @param pane The <code>JSChannelsPane</code> to be shown.
150 */
151 public abstract void setSelectedChannelsPane(JSChannelsPane pane);
152
153 private class EventHandler implements SamplerChannelListListener {
154 /**
155 * Invoked when a new sampler channel is created.
156 * @param e A <code>SamplerChannelListEvent</code>
157 * instance providing the event information.
158 */
159 public void
160 channelAdded(SamplerChannelListEvent e) {
161 Integer id = e.getChannelModel().getChannelId();
162 if(findChannel(id) != null) {
163 CC.getLogger().log(Level.WARNING, "JSMainFrame.channelExist!", id);
164 return;
165 }
166
167 getSelectedChannelsPane().addChannel(e.getChannelModel());
168 }
169
170 /**
171 * Invoked when a sampler channel is removed.
172 * @param e A <code>SamplerChannelListEvent</code>
173 * instance providing the event information.
174 */
175 public void
176 channelRemoved(SamplerChannelListEvent e) {
177 removeChannel(e.getChannelModel().getChannelId());
178 }
179 }
180
181 /**
182 * Searches for the first occurence of a channel with numerical ID <code>id</code>.
183 * @return The first occurence of a channel with numerical ID <code>id</code> or
184 * <code>null</code> if there is no channel with numerical ID <code>id</code>.
185 */
186 public JSChannel
187 findChannel(int id) {
188 if(id < 0) return null;
189
190 for(JSChannelsPane cp : getChannelsPaneList()) {
191 for(JSChannel c : cp.getChannels()) if(c.getChannelId() == id) return c;
192 }
193
194 return null;
195 }
196
197 /**
198 * Removes the first occurence of a channel with numerical ID <code>id</code>.
199 * This method is invoked when a sampler channel is removed in the back-end.
200 * @return The removed channel or <code>null</code>
201 * if there is no channel with numerical ID <code>id</code>.
202 */
203 public JSChannel
204 removeChannel(int id) {
205 if(id < 0) return null;
206
207 for(JSChannelsPane cp : getChannelsPaneList()) {
208 for(JSChannel c : cp.getChannels()) {
209 if(c.getChannelId() == id) {
210 cp.removeChannel(c);
211 return c;
212 }
213 }
214 }
215
216 return null;
217 }
218 }

  ViewVC Help
Powered by ViewVC