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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1778 - (hide annotations) (download)
Sun Sep 28 20:38:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 8605 byte(s)
* Fantasia: Improved look and feel
* Fantasia: Added buttons for increasing/decreasing the key number
  of the MIDI keyboard (Ctrl+Up Arrow/Ctrl+Down Arrow)
* Fantasia: Added buttons for scrolling left/right on the MIDI keyboard
  (Ctrl+Left Arrow/Ctrl+Right Arrow)
* Added key bindings for triggering MIDI notes using the computer keyboard
  (from a to ' for the white keys and from 0 to 7 for changing the octaves)
* Notes are now triggered when dragging the mouse over the MIDI keyboard

1 iliev 1286 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1778 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 1286 *
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.Dimension;
27     import java.awt.Graphics;
28     import java.awt.Insets;
29    
30     import java.awt.event.ActionEvent;
31     import java.awt.event.ActionListener;
32    
33     import java.beans.PropertyChangeEvent;
34     import java.beans.PropertyChangeListener;
35    
36     import javax.swing.Action;
37     import javax.swing.BorderFactory;
38     import javax.swing.Box;
39     import javax.swing.BoxLayout;
40     import javax.swing.JComboBox;
41     import javax.swing.JPanel;
42     import javax.swing.JScrollPane;
43     import javax.swing.JToolBar;
44    
45     import org.jsampler.CC;
46     import org.jsampler.OrchestraModel;
47    
48     import org.jsampler.event.OrchestraAdapter;
49     import org.jsampler.event.OrchestraEvent;
50     import org.jsampler.event.ListEvent;
51     import org.jsampler.event.ListListener;
52    
53     import org.jsampler.view.std.JSManageOrchestrasPane;
54     import org.jsampler.view.std.JSOrchestraPane;
55    
56     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
57     import static org.jsampler.view.fantasia.FantasiaPrefs.*;
58    
59    
60     /**
61     *
62     * @author Grigor Iliev
63     */
64     public class OrchestrasPane extends JPanel {
65     private final JPanel taskPaneContainer = new JPanel();
66 iliev 1778 private final FantasiaTaskPane orchestrasTaskPane = new FantasiaTaskPane();
67 iliev 1286
68     private ManageOrchestrasPane manageOrchestrasPane = new ManageOrchestrasPane();
69    
70     private final JComboBox cbOrchestras = new JComboBox();
71     private final OrchestraPane orchestraPane = new OrchestraPane();
72    
73 iliev 1329 /**
74     * Because the orchestras are added after the view is created,
75     * we need to remember the orchestra used in the previous session.
76     */
77     private int orchIdx;
78    
79 iliev 1286 /** Creates a new instance of <code>OrchestrasPane</code> */
80     public
81     OrchestrasPane() {
82     setLayout(new BorderLayout());
83     setOpaque(false);
84    
85     orchestrasTaskPane.setTitle(i18n.getLabel("OrchestrasPane.orchestrasTaskPane"));
86 iliev 1778
87     FantasiaSubPanel fsp = new FantasiaSubPanel(false, true, false);
88     fsp.add(manageOrchestrasPane);
89     orchestrasTaskPane.add(fsp);
90 iliev 1286 boolean b;
91     orchestrasTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
92     b = preferences().getBoolProperty("OrchestrasPane.orchestrasTaskPane.expanded");
93     orchestrasTaskPane.setExpanded(b);
94    
95     preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
96     public void
97     propertyChange(PropertyChangeEvent e) {
98     boolean b = preferences().getBoolProperty(ANIMATED);
99     orchestrasTaskPane.setAnimated(b);
100     }
101     });
102    
103     taskPaneContainer.setOpaque(false);
104     taskPaneContainer.setLayout(new BorderLayout());
105     taskPaneContainer.add(orchestrasTaskPane);
106     taskPaneContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
107    
108     add(taskPaneContainer, BorderLayout.NORTH);
109     add(new InstrumentsPane());
110    
111 iliev 1329 orchIdx = preferences().getIntProperty("OrchestrasPane.OrchestraIndex", 0);
112    
113 iliev 1286 cbOrchestras.addActionListener(new ActionListener() {
114     public void
115     actionPerformed(ActionEvent e) { orchestraChanged(); }
116     });
117    
118     for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) {
119     cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i));
120     }
121    
122     CC.getOrchestras().addOrchestraListListener(getHandler());
123     cbOrchestras.setEnabled(cbOrchestras.getItemCount() != 0);
124 iliev 1329
125    
126     if(CC.getOrchestras().getOrchestraCount() > orchIdx) {
127     cbOrchestras.setSelectedIndex(orchIdx);
128     orchIdx = -1;
129     }
130 iliev 1286 }
131    
132     public void
133     savePreferences() {
134     boolean b = orchestrasTaskPane.isExpanded();
135     preferences().setBoolProperty("OrchestrasPane.orchestrasTaskPane.expanded", b);
136     }
137    
138     private void
139     orchestraChanged() {
140     OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem();
141     orchestraPane.setOrchestra(om);
142    
143     if(om != null) {
144     String s = om.getDescription();
145     if(s != null && s.length() == 0) s = null;
146     cbOrchestras.setToolTipText(s);
147     }
148 iliev 1329
149     int i = cbOrchestras.getSelectedIndex();
150     if(i >= 0) preferences().setIntProperty("OrchestrasPane.OrchestraIndex", i);
151 iliev 1286 }
152    
153     class InstrumentsPane extends JPanel {
154     InstrumentsPane() {
155     setOpaque(false);
156     setLayout(new BorderLayout());
157 iliev 1778 setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
158 iliev 1286
159 iliev 1778 FantasiaSubPanel p2 = new FantasiaSubPanel(true, false);
160 iliev 1286 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
161     p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
162 iliev 1778 JPanel p = new FantasiaPanel();
163     p.setOpaque(false);
164     p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
165     p.add(cbOrchestras);
166     p.setBorder(BorderFactory.createEmptyBorder(3, 1, 5, 1));
167     p2.add(p);
168 iliev 1286
169 iliev 1778 FantasiaSubPanel fsp = new FantasiaSubPanel(false, true, false);
170     fsp.add(orchestraPane);
171    
172     p2.add(fsp);
173    
174 iliev 1286 add(p2);
175     }
176     }
177    
178     class ManageOrchestrasPane extends JSManageOrchestrasPane {
179     ManageOrchestrasPane() {
180     actionAddOrchestra.putValue(Action.SMALL_ICON, Res.iconNew16);
181     actionEditOrchestra.putValue(Action.SMALL_ICON, Res.iconEdit16);
182     actionDeleteOrchestra.putValue(Action.SMALL_ICON, Res.iconDelete16);
183    
184     removeAll();
185    
186 iliev 1778 JToolBar toolBar = FantasiaUtils.createSubToolBar();
187 iliev 1286 toolBar.add(new ToolbarButton(actionAddOrchestra));
188     toolBar.add(new ToolbarButton(actionEditOrchestra));
189     toolBar.add(new ToolbarButton(actionDeleteOrchestra));
190     add(toolBar, BorderLayout.NORTH);
191    
192     JScrollPane sp = new JScrollPane(orchestraTable);
193     sp.setPreferredSize(new Dimension(120, 130));
194    
195 iliev 1778 JPanel p = FantasiaUtils.createBottomSubPane();
196     p.add(sp);
197 iliev 1286
198     add(p);
199     }
200     }
201    
202     class OrchestraPane extends JSOrchestraPane {
203     OrchestraPane() {
204     actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16);
205     actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16);
206     actionDeleteInstrument.putValue(Action.SMALL_ICON, Res.iconDelete16);
207     //actionInstrumentUp.putValue(Action.SMALL_ICON, Res.iconUp16);
208     //actionInstrumentDown.putValue(Action.SMALL_ICON, Res.iconDown16);
209    
210     removeAll();
211    
212 iliev 1778 JToolBar toolBar = FantasiaUtils.createSubToolBar();
213 iliev 1286 toolBar.add(new ToolbarButton(actionAddInstrument));
214     toolBar.add(new ToolbarButton(actionEditInstrument));
215     toolBar.add(new ToolbarButton(actionDeleteInstrument));
216    
217     //toolBar.addSeparator();
218    
219     //toolBar.add(new ToolbarButton(actionInstrumentUp));
220     //toolBar.add(new ToolbarButton(actionInstrumentDown));
221    
222     toolBar.setFloatable(false);
223     add(toolBar, java.awt.BorderLayout.NORTH);
224    
225     JScrollPane sp = new JScrollPane(instrumentTable);
226     Dimension d;
227     d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height);
228     sp.setPreferredSize(d);
229    
230 iliev 1778 JPanel p = FantasiaUtils.createBottomSubPane();
231     p.add(sp);
232 iliev 1286
233     add(p);
234     }
235     }
236    
237     private final Handler eventHandler = new Handler();
238    
239     private Handler
240     getHandler() { return eventHandler; }
241    
242     private class Handler extends OrchestraAdapter implements ListListener<OrchestraModel> {
243     /** Invoked when an orchestra is added to the orchestra list. */
244 iliev 1778 @Override
245 iliev 1286 public void
246     entryAdded(ListEvent<OrchestraModel> e) {
247     if(cbOrchestras.getItemCount() == 0) cbOrchestras.setEnabled(true);
248     cbOrchestras.addItem(e.getEntry());
249 iliev 1329
250     // we do this because the orchestras are added after creation of the view.
251     if(orchIdx != -1 && cbOrchestras.getItemCount() > orchIdx) {
252     cbOrchestras.setSelectedIndex(orchIdx);
253     orchIdx = -1;
254     }
255 iliev 1286 }
256    
257     /** Invoked when an orchestra is removed from the orchestra list. */
258 iliev 1778 @Override
259 iliev 1286 public void
260     entryRemoved(ListEvent<OrchestraModel> e) {
261     cbOrchestras.removeItem(e.getEntry());
262     if(cbOrchestras.getItemCount() == 0) cbOrchestras.setEnabled(false);
263 iliev 1329
264     if(orchIdx != -1) orchIdx = -1;
265 iliev 1286 }
266    
267     /** Invoked when the name of orchestra is changed. */
268 iliev 1778 @Override
269 iliev 1286 public void
270     nameChanged(OrchestraEvent e) {
271    
272     }
273    
274     /** Invoked when the description of orchestra is changed. */
275 iliev 1778 @Override
276 iliev 1286 public void
277     descriptionChanged(OrchestraEvent e) { }
278    
279    
280     }
281     }

  ViewVC Help
Powered by ViewVC