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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2148 - (show annotations) (download)
Thu Oct 14 14:45:42 2010 UTC (13 years, 6 months ago) by iliev
File size: 8387 byte(s)
* Add/Edit Instrument dialog and New MIDI Instrument wizard
  are now resizable
* Using multicolumn menus for loading instruments from
  Instruments Database and selecting values in string list parameters

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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.Graphics2D;
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.BoxLayout;
40 import javax.swing.JComboBox;
41 import javax.swing.JPanel;
42 import javax.swing.JScrollPane;
43 import javax.swing.JToolBar;
44
45 import net.sf.juife.Wizard;
46
47 import org.jsampler.CC;
48 import org.jsampler.MidiInstrumentMap;
49
50 import org.jsampler.event.ListEvent;
51 import org.jsampler.event.ListListener;
52
53 import org.jsampler.view.fantasia.basic.*;
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 FantasiaTaskPane mapsTaskPane = new FantasiaTaskPane();
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
84 FantasiaSubPanel fsp = new FantasiaSubPanel(false, true, false);
85 fsp.add(manageMapsPane);
86 mapsTaskPane.add(fsp);
87 boolean b;
88 mapsTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
89 b = preferences().getBoolProperty("MidiInstrumentsPane.mapsTaskPane.expanded");
90 mapsTaskPane.setCollapsed(!b);
91
92 preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() {
93 public void
94 propertyChange(PropertyChangeEvent e) {
95 mapsTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED));
96 }
97 });
98
99 taskPaneContainer.setOpaque(false);
100 taskPaneContainer.setLayout(new BorderLayout());
101 taskPaneContainer.add(mapsTaskPane);
102 taskPaneContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
103
104 add(taskPaneContainer, BorderLayout.NORTH);
105 add(new MapsPane());
106
107 cbMaps.addActionListener(new ActionListener() {
108 public void
109 actionPerformed(ActionEvent e) { mapChanged(); }
110 });
111
112 for(Object o : CC.getSamplerModel().getMidiInstrumentMaps()) {
113 cbMaps.addItem(o);
114 }
115
116 CC.getSamplerModel().addMidiInstrumentMapListListener(getHandler());
117 cbMaps.setEnabled(cbMaps.getItemCount() != 0);
118 }
119
120 private void
121 mapChanged() {
122 MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
123 instrumentsPane.setMidiInstrumentMap(map);
124 }
125
126 public void
127 savePreferences() {
128 boolean b = !mapsTaskPane.isCollapsed();
129 preferences().setBoolProperty("MidiInstrumentsPane.mapsTaskPane.expanded", b);
130 }
131
132 class ManageMapsPane extends JSManageMidiMapsPane {
133 ManageMapsPane() {
134 actionAddMap.putValue(Action.SMALL_ICON, Res.iconNew16);
135 actionEditMap.putValue(Action.SMALL_ICON, Res.iconEdit16);
136 actionRemoveMap.putValue(Action.SMALL_ICON, Res.iconDelete16);
137
138 removeAll();
139
140 JToolBar toolBar = FantasiaUtils.createSubToolBar();
141 toolBar.add(new ToolbarButton(actionAddMap));
142 toolBar.add(new ToolbarButton(actionEditMap));
143 toolBar.add(new ToolbarButton(actionRemoveMap));
144 add(toolBar, BorderLayout.NORTH);
145
146 JScrollPane sp = new JScrollPane(midiMapTable);
147 sp.setPreferredSize(new Dimension(120, 130));
148
149 JPanel p = FantasiaUtils.createBottomSubPane();
150 p.add(sp);
151 add(p);
152 }
153
154 @Override
155 protected void
156 paintComponent(Graphics g) {
157 super.paintComponent(g);
158
159 double h = getSize().getHeight();
160 double w = getSize().getWidth();
161
162 FantasiaPainter.paintGradient((Graphics2D)g, 0, 0, w - 1, h - 1);
163
164 FantasiaPainter.RoundCorners rc =
165 new FantasiaPainter.RoundCorners(true, false, false, true);
166
167 FantasiaPainter.paintOuterBorder((Graphics2D)g, 0, 0, w - 1, h - 1, rc);
168 }
169 }
170
171 class MapsPane extends JPanel {
172 MapsPane() {
173 setOpaque(false);
174 setLayout(new BorderLayout());
175 setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
176
177 FantasiaSubPanel p2 = new FantasiaSubPanel(true, false);
178 p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
179 p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS));
180
181 JPanel p = new FantasiaPanel();
182 p.setOpaque(false);
183 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
184 p.add(cbMaps);
185 p.setBorder(BorderFactory.createEmptyBorder(3, 1, 5, 1));
186 p2.add(p);
187
188 FantasiaSubPanel fsp = new FantasiaSubPanel(false, true, false);
189 fsp.add(instrumentsPane);
190
191 p2.add(fsp);
192
193 add(p2);
194 }
195 }
196
197 class InstrumentsPane extends JSMidiInstrumentsPane {
198 InstrumentsPane() {
199 actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16);
200 actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16);
201 actionRemove.putValue(Action.SMALL_ICON, Res.iconDelete16);
202
203 removeAll();
204
205 JToolBar toolBar = FantasiaUtils.createSubToolBar();
206 toolBar.add(new ToolbarButton(actionAddInstrument));
207 toolBar.add(new ToolbarButton(actionEditInstrument));
208 toolBar.add(new ToolbarButton(actionRemove));
209
210 add(toolBar, java.awt.BorderLayout.NORTH);
211
212 JScrollPane sp = new JScrollPane(midiInstrumentTree);
213 Dimension d;
214 d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height);
215 sp.setPreferredSize(d);
216
217 JPanel p = FantasiaUtils.createBottomSubPane();
218 p.add(sp);
219
220 add(p);
221 }
222
223 @Override
224 public void
225 addInstrument() {
226 MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem();
227
228 JSNewMidiInstrumentWizard wizard =
229 new JSNewMidiInstrumentWizard(Res.iconBrowse16, map);
230 wizard.setMinimumSize(wizard.getPreferredSize());
231 javax.swing.JDialog wizardDlg = wizard.getWizardDialog();
232 wizardDlg.setMinimumSize(wizardDlg.getPreferredSize());
233 wizard.putClientProperty(Wizard.BACK_BUTTON_ICON, Res.iconBack16);
234 wizard.putClientProperty(Wizard.NEXT_BUTTON_ICON, Res.iconNext16);
235 Color c = new Color(0x626262);
236 wizard.putClientProperty(Wizard.LEFT_PANE_BACKGROUND_COLOR, c);
237 //c = new Color(0x4b4b4b);
238 //wizard.putClientProperty(Wizard.LEFT_PANE_FOREGROUND_COLOR, c);
239
240 if(preferences().getBoolProperty("NewMidiInstrumentWizard.skip1")) {
241 if(wizard.getModel().getCurrentPage() == null) {
242 wizard.getModel().next();
243 }
244 wizard.getModel().next();
245 }
246
247 wizard.showWizard();
248 }
249 }
250
251 private final Handler eventHandler = new Handler();
252
253 private Handler
254 getHandler() { return eventHandler; }
255
256 private class Handler implements ListListener<MidiInstrumentMap> {
257 /** Invoked when an orchestra is added to the orchestra list. */
258 @Override
259 public void
260 entryAdded(ListEvent<MidiInstrumentMap> e) {
261 if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(true);
262 cbMaps.addItem(e.getEntry());
263 }
264
265 /** Invoked when an orchestra is removed from the orchestra list. */
266 @Override
267 public void
268 entryRemoved(ListEvent<MidiInstrumentMap> e) {
269 cbMaps.removeItem(e.getEntry());
270 if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(false);
271 }
272 }
273 }

  ViewVC Help
Powered by ViewVC