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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1286 - (hide annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 8 months ago) by iliev
File size: 8788 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

1 iliev 1286 /*
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.fantasia;
24    
25     import java.awt.BorderLayout;
26     import java.awt.Color;
27     import java.awt.Dimension;
28     import java.awt.Graphics;
29     import java.awt.Insets;
30    
31     import java.awt.event.ActionEvent;
32     import java.awt.event.ActionListener;
33    
34     import java.beans.PropertyChangeEvent;
35     import java.beans.PropertyChangeListener;
36    
37     import javax.swing.Action;
38     import javax.swing.BorderFactory;
39     import javax.swing.Box;
40     import javax.swing.BoxLayout;
41     import javax.swing.JButton;
42     import javax.swing.JComboBox;
43     import javax.swing.JPanel;
44     import javax.swing.JScrollPane;
45     import javax.swing.JToolBar;
46    
47     import net.sf.juife.Wizard;
48    
49     import org.jsampler.CC;
50     import org.jsampler.MidiInstrumentMap;
51    
52     import org.jsampler.event.ListEvent;
53     import org.jsampler.event.ListListener;
54    
55     import org.jsampler.view.std.JSManageMidiMapsPane;
56     import org.jsampler.view.std.JSMidiInstrumentsPane;
57     import org.jsampler.view.std.JSNewMidiInstrumentWizard;
58    
59     import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
60     import static org.jsampler.view.fantasia.FantasiaPrefs.*;
61    
62     /**
63     *
64     * @author Grigor Iliev
65     */
66     public class MidiInstrumentsPane extends JPanel {
67     private final JPanel taskPaneContainer = new JPanel();
68     private final TaskPane mapsTaskPane = new TaskPane();
69    
70     private ManageMapsPane manageMapsPane = new ManageMapsPane();
71     private final InstrumentsPane instrumentsPane = new InstrumentsPane();
72    
73     private final JComboBox cbMaps = new JComboBox();
74     //private final InstrumentsPane instrumentsPane = new InstrumentsPane();
75    
76     /** Creates a new instance of <code>MidiInstrumentsPane</code> */
77     public
78     MidiInstrumentsPane() {
79     setLayout(new BorderLayout());
80     setOpaque(false);
81    
82     mapsTaskPane.setTitle(i18n.getLabel("MidiInstrumentsPane.mapsTaskPane"));
83     mapsTaskPane.add(manageMapsPane);
84     boolean b;
85     mapsTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
86     b = preferences().getBoolProperty("MidiInstrumentsPane.mapsTaskPane.expanded");
87     mapsTaskPane.setExpanded(b);
88    
89     preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
90     public void
91     propertyChange(PropertyChangeEvent e) {
92     mapsTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
93     }
94     });
95    
96     taskPaneContainer.setOpaque(false);
97     taskPaneContainer.setLayout(new BorderLayout());
98     taskPaneContainer.add(mapsTaskPane);
99     taskPaneContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
100    
101     add(taskPaneContainer, BorderLayout.NORTH);
102     add(new MapsPane());
103    
104     cbMaps.addActionListener(new ActionListener() {
105     public void
106     actionPerformed(ActionEvent e) { mapChanged(); }
107     });
108    
109     for(Object o : CC.getSamplerModel().getMidiInstrumentMaps()) {
110     cbMaps.addItem(o);
111     }
112    
113     CC.getSamplerModel().addMidiInstrumentMapListListener(getHandler());
114     cbMaps.setEnabled(cbMaps.getItemCount() != 0);
115     }
116    
117     private void
118     mapChanged() {
119     MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
120     instrumentsPane.setMidiInstrumentMap(map);
121     }
122    
123     public void
124     savePreferences() {
125     boolean b = mapsTaskPane.isExpanded();
126     preferences().setBoolProperty("MidiInstrumentsPane.mapsTaskPane.expanded", b);
127     }
128    
129     static class ToolBar extends JToolBar {
130     private static Insets pixmapInsets = new Insets(1, 1, 1, 1);
131    
132     ToolBar() {
133     setFloatable(false);
134     setOpaque(false);
135     setPreferredSize(new Dimension(77, 29));
136     setMinimumSize(getPreferredSize());
137     }
138    
139     protected void
140     paintComponent(Graphics g) {
141     super.paintComponent(g);
142    
143     PixmapPane.paintComponent(this, g, Res.gfxCreateChannel, pixmapInsets);
144     }
145     }
146    
147     class ManageMapsPane extends JSManageMidiMapsPane {
148     ManageMapsPane() {
149     actionAddMap.putValue(Action.SMALL_ICON, Res.iconNew16);
150     actionEditMap.putValue(Action.SMALL_ICON, Res.iconEdit16);
151     actionRemoveMap.putValue(Action.SMALL_ICON, Res.iconDelete16);
152    
153     removeAll();
154    
155     ToolBar toolBar = new ToolBar();
156     toolBar.add(new ToolbarButton(actionAddMap));
157     toolBar.add(new ToolbarButton(actionEditMap));
158     toolBar.add(new ToolbarButton(actionRemoveMap));
159     add(toolBar, BorderLayout.NORTH);
160    
161     JScrollPane sp = new JScrollPane(midiMapTable);
162     sp.setPreferredSize(new Dimension(120, 130));
163    
164     PixmapPane p = new PixmapPane(Res.gfxChannelOptions);
165     p.setPixmapInsets(new Insets(1, 1, 1, 1));
166     p.setLayout(new BorderLayout());
167     p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
168    
169     PixmapPane p2 = new PixmapPane(Res.gfxBorder);
170     p2.setPixmapInsets(new Insets(1, 1, 1, 1));
171     p2.setLayout(new BorderLayout());
172     p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
173     p2.add(sp);
174     p.add(p2);
175    
176     add(p);
177     }
178     }
179    
180     class MapsPane extends JPanel {
181     MapsPane() {
182     setOpaque(false);
183     setLayout(new BorderLayout());
184     setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
185    
186     PixmapPane p = new PixmapPane(Res.gfxChannelOptions);
187     p.setPixmapInsets(new Insets(1, 1, 1, 1));
188     p.setLayout(new BorderLayout());
189     p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
190    
191     PixmapPane p2 = new PixmapPane(Res.gfxRoundBg7);
192     p2.setPixmapInsets(new Insets(3, 3, 3, 3));
193     p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
194     p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
195     p2.add(cbMaps);
196     p2.add(Box.createRigidArea(new Dimension(0, 5)));
197     p2.add(instrumentsPane);
198    
199     add(p2);
200     }
201     }
202    
203     class InstrumentsPane extends JSMidiInstrumentsPane {
204     InstrumentsPane() {
205     actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16);
206     actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16);
207     actionRemove.putValue(Action.SMALL_ICON, Res.iconDelete16);
208    
209     removeAll();
210    
211     ToolBar toolBar = new ToolBar();
212     toolBar.add(new ToolbarButton(actionAddInstrument));
213     toolBar.add(new ToolbarButton(actionEditInstrument));
214     toolBar.add(new ToolbarButton(actionRemove));
215    
216     toolBar.setFloatable(false);
217     add(toolBar, java.awt.BorderLayout.NORTH);
218    
219     JScrollPane sp = new JScrollPane(midiInstrumentTree);
220     Dimension d;
221     d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height);
222     sp.setPreferredSize(d);
223    
224     PixmapPane p = new PixmapPane(Res.gfxChannelOptions);
225     p.setPixmapInsets(new Insets(1, 1, 1, 1));
226     p.setLayout(new BorderLayout());
227     p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
228    
229     PixmapPane p2 = new PixmapPane(Res.gfxBorder);
230     p2.setPixmapInsets(new Insets(1, 1, 1, 1));
231     p2.setLayout(new BorderLayout());
232     p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
233     p2.add(sp);
234     p.add(p2);
235    
236     add(p);
237     }
238    
239     public void
240     addInstrument() {
241     JSNewMidiInstrumentWizard wizard =
242     new JSNewMidiInstrumentWizard(preferences(), Res.iconBrowse16);
243     wizard.getWizardDialog().setResizable(false);
244     wizard.putClientProperty(Wizard.BACK_BUTTON_ICON, Res.iconBack16);
245     wizard.putClientProperty(Wizard.NEXT_BUTTON_ICON, Res.iconNext16);
246     Color c = new Color(0x626262);
247     wizard.putClientProperty(Wizard.LEFT_PANE_BACKGROUND_COLOR, c);
248     //c = new Color(0x4b4b4b);
249     //wizard.putClientProperty(Wizard.LEFT_PANE_FOREGROUND_COLOR, c);
250    
251     if(preferences().getBoolProperty("NewMidiInstrumentWizard.skip1")) {
252     if(wizard.getModel().getCurrentPage() == null) {
253     wizard.getModel().next();
254     }
255     wizard.getModel().next();
256     }
257    
258     wizard.showWizard();
259     }
260     }
261    
262     private final Handler eventHandler = new Handler();
263    
264     private Handler
265     getHandler() { return eventHandler; }
266    
267     private class Handler implements ListListener<MidiInstrumentMap> {
268     /** Invoked when an orchestra is added to the orchestra list. */
269     public void
270     entryAdded(ListEvent<MidiInstrumentMap> e) {
271     if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(true);
272     cbMaps.addItem(e.getEntry());
273     }
274    
275     /** Invoked when an orchestra is removed from the orchestra list. */
276     public void
277     entryRemoved(ListEvent<MidiInstrumentMap> e) {
278     cbMaps.removeItem(e.getEntry());
279     if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(false);
280     }
281     }
282     }

  ViewVC Help
Powered by ViewVC