/[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 1866 - (hide annotations) (download)
Sun Mar 15 19:40:29 2009 UTC (15 years, 2 months ago) by iliev
File size: 8578 byte(s)
* show controller names in fx sends dialogs
* save send levels when exporting sampler configuration
* ask when removing nonempty map
* fixed compilation error

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

  ViewVC Help
Powered by ViewVC