1 |
/* |
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 |
MidiInstrumentMap map = (MidiInstrumentMap)cbMaps.getSelectedItem(); |
242 |
|
243 |
JSNewMidiInstrumentWizard wizard = |
244 |
new JSNewMidiInstrumentWizard(Res.iconBrowse16, map); |
245 |
wizard.getWizardDialog().setResizable(false); |
246 |
wizard.putClientProperty(Wizard.BACK_BUTTON_ICON, Res.iconBack16); |
247 |
wizard.putClientProperty(Wizard.NEXT_BUTTON_ICON, Res.iconNext16); |
248 |
Color c = new Color(0x626262); |
249 |
wizard.putClientProperty(Wizard.LEFT_PANE_BACKGROUND_COLOR, c); |
250 |
//c = new Color(0x4b4b4b); |
251 |
//wizard.putClientProperty(Wizard.LEFT_PANE_FOREGROUND_COLOR, c); |
252 |
|
253 |
if(preferences().getBoolProperty("NewMidiInstrumentWizard.skip1")) { |
254 |
if(wizard.getModel().getCurrentPage() == null) { |
255 |
wizard.getModel().next(); |
256 |
} |
257 |
wizard.getModel().next(); |
258 |
} |
259 |
|
260 |
wizard.showWizard(); |
261 |
} |
262 |
} |
263 |
|
264 |
private final Handler eventHandler = new Handler(); |
265 |
|
266 |
private Handler |
267 |
getHandler() { return eventHandler; } |
268 |
|
269 |
private class Handler implements ListListener<MidiInstrumentMap> { |
270 |
/** Invoked when an orchestra is added to the orchestra list. */ |
271 |
public void |
272 |
entryAdded(ListEvent<MidiInstrumentMap> e) { |
273 |
if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(true); |
274 |
cbMaps.addItem(e.getEntry()); |
275 |
} |
276 |
|
277 |
/** Invoked when an orchestra is removed from the orchestra list. */ |
278 |
public void |
279 |
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
280 |
cbMaps.removeItem(e.getEntry()); |
281 |
if(cbMaps.getItemCount() == 0) cbMaps.setEnabled(false); |
282 |
} |
283 |
} |
284 |
} |