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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1285 - (hide annotations) (download)
Fri Aug 10 19:55:03 2007 UTC (16 years, 9 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 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1285 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 787 *
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 iliev 1204 import java.awt.Dialog;
26 iliev 842 import java.awt.Dimension;
27 iliev 1204 import java.awt.Frame;
28 iliev 842
29 iliev 787 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 iliev 842 import org.jsampler.Prefs;
40 iliev 787
41     import org.jsampler.event.SamplerChannelListEvent;
42     import org.jsampler.event.SamplerChannelListListener;
43    
44 iliev 1204
45 iliev 787 /**
46 iliev 911 * Defines the skeleton of a JSampler's main frame.
47 iliev 787 * @author Grigor Iliev
48     */
49     public abstract class JSMainFrame extends JFrame {
50     private final Vector<JSChannelsPane> chnPaneList = new Vector<JSChannelsPane>();
51    
52 iliev 911 /** Creates a new instance of <code>JSMainFrame</code>. */
53 iliev 787 public
54     JSMainFrame() {
55     super(JSampler.NAME + ' ' + JSampler.VERSION);
56    
57     setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
58     addWindowListener(new WindowAdapter() {
59     public void
60 iliev 842 windowClosing(WindowEvent we) { onWindowClose(); }
61 iliev 787 });
62    
63     CC.getSamplerModel().addSamplerChannelListListener(new EventHandler());
64     }
65    
66 iliev 911 /**
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 iliev 842 onWindowClose() {
73     CC.cleanExit();
74     }
75    
76 iliev 911 /**
77 iliev 1143 * 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 iliev 1204 * 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 iliev 911 * 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 iliev 787 public Vector<JSChannelsPane>
104     getChannelsPaneList() { return chnPaneList; }
105    
106 iliev 911 /**
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 iliev 787 public JSChannelsPane
112     getChannelsPane(int idx) { return chnPaneList.get(idx); }
113    
114 iliev 911 /**
115     * Adds the specified <code>JSChannelsPane</code> to the view.
116     * @param chnPane The <code>JSChannelsPane</code> to be added.
117     */
118 iliev 787 public void
119     addChannelsPane(JSChannelsPane chnPane) { chnPaneList.add(chnPane); }
120    
121 iliev 911 /**
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 iliev 787 public boolean
130     removeChannelsPane(JSChannelsPane chnPane) { return chnPaneList.remove(chnPane); }
131    
132 iliev 911 /**
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 iliev 787 public int
137     getChannelsPaneCount() { return chnPaneList.size(); }
138    
139 iliev 911 /**
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 iliev 787 public abstract void insertChannelsPane(JSChannelsPane pane, int idx);
149 iliev 911
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 iliev 787 public abstract JSChannelsPane getSelectedChannelsPane();
159 iliev 911
160     /**
161     * Sets the <code>JSChannelsPane</code> to be selected.
162     * @param pane The <code>JSChannelsPane</code> to be shown.
163     */
164 iliev 787 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 iliev 1143 Integer id = e.getChannelModel().getChannelId();
175 iliev 787 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 iliev 1143 removeChannel(e.getChannelModel().getChannelId());
191 iliev 787 }
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 iliev 1143 for(JSChannel c : cp.getChannels()) if(c.getChannelId() == id) return c;
205 iliev 787 }
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 iliev 1143 if(c.getChannelId() == id) {
223 iliev 787 cp.removeChannel(c);
224     return c;
225     }
226     }
227     }
228    
229     return null;
230     }
231     }

  ViewVC Help
Powered by ViewVC