1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2008 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.setExpanded(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.isExpanded(); |
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.getWizardDialog().setResizable(false); |
231 |
wizard.putClientProperty(Wizard.BACK_BUTTON_ICON, Res.iconBack16); |
232 |
wizard.putClientProperty(Wizard.NEXT_BUTTON_ICON, Res.iconNext16); |
233 |
Color c = new Color(0x626262); |
234 |
wizard.putClientProperty(Wizard.LEFT_PANE_BACKGROUND_COLOR, c); |
235 |
//c = new Color(0x4b4b4b); |
236 |
//wizard.putClientProperty(Wizard.LEFT_PANE_FOREGROUND_COLOR, c); |
237 |
|
238 |
if(preferences().getBoolProperty("NewMidiInstrumentWizard.skip1")) { |
239 |
if(wizard.getModel().getCurrentPage() == null) { |
240 |
wizard.getModel().next(); |
241 |
} |
242 |
wizard.getModel().next(); |
243 |
} |
244 |
|
245 |
wizard.showWizard(); |
246 |
} |
247 |
} |
248 |
|
249 |
private final Handler eventHandler = new Handler(); |
250 |
|
251 |
private Handler |
252 |
getHandler() { return eventHandler; } |
253 |
|
254 |
private class Handler implements ListListener<MidiInstrumentMap> { |
255 |
/** Invoked when an orchestra is added to the orchestra list. */ |
256 |
@Override |
257 |
public void |
258 |
entryAdded(ListEvent<MidiInstrumentMap> e) { |
259 |
if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(true); |
260 |
cbMaps.addItem(e.getEntry()); |
261 |
} |
262 |
|
263 |
/** Invoked when an orchestra is removed from the orchestra list. */ |
264 |
@Override |
265 |
public void |
266 |
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
267 |
cbMaps.removeItem(e.getEntry()); |
268 |
if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(false); |
269 |
} |
270 |
} |
271 |
} |