/[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 1285 - (show annotations) (download)
Fri Aug 10 19:55:03 2007 UTC (16 years, 8 months ago) by iliev
File size: 7584 byte(s)
* Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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

  ViewVC Help
Powered by ViewVC