/[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 1688 - (show annotations) (download)
Thu Feb 14 16:52:36 2008 UTC (16 years, 2 months ago) by iliev
File size: 8121 byte(s)
* Implemented a backend list with option to manually choose a backend
  to connect on startup(Edit/Preferences, then click the `Backend' tab)
  and option to change the backend without restarting JSampler
  (Actions/Change Backend or Ctrl + B)

* Added confirmation messages for removing sampler channels and
  audio/MIDI devices (Edit/Preferences, then click the `View' tab)

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

  ViewVC Help
Powered by ViewVC