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.classic; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.ButtonGroup; |
37 |
import javax.swing.JButton; |
38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JComboBox; |
40 |
import javax.swing.JFileChooser; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JRadioButton; |
44 |
import javax.swing.JSlider; |
45 |
import javax.swing.JSpinner; |
46 |
import javax.swing.JTextField; |
47 |
import javax.swing.SpinnerNumberModel; |
48 |
|
49 |
import javax.swing.event.DocumentEvent; |
50 |
import javax.swing.event.DocumentListener; |
51 |
|
52 |
import net.sf.juife.Wizard; |
53 |
|
54 |
import net.sf.juife.wizard.DefaultWizardModel; |
55 |
import net.sf.juife.wizard.UserInputPage; |
56 |
import net.sf.juife.wizard.WizardPage; |
57 |
|
58 |
import org.jsampler.CC; |
59 |
import org.jsampler.Instrument; |
60 |
import org.jsampler.MidiInstrumentMap; |
61 |
import org.jsampler.OrchestraModel; |
62 |
|
63 |
import org.linuxsampler.lscp.MidiInstrumentInfo; |
64 |
import org.linuxsampler.lscp.SamplerEngine; |
65 |
|
66 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
67 |
|
68 |
|
69 |
/** |
70 |
* A wizard for mapping new MIDI instrument. |
71 |
* @author Grigor Iliev |
72 |
*/ |
73 |
public class NewMidiInstrumentWizard extends Wizard { |
74 |
|
75 |
/** Creates a new instance of <code>NewMidiInstrumentWizard</code>. */ |
76 |
public |
77 |
NewMidiInstrumentWizard() { |
78 |
super(CC.getMainFrame(), i18n.getLabel("NewMidiInstrumentWizard.title")); |
79 |
setModel(new NewMidiInstrumentWizardModel()); |
80 |
} |
81 |
|
82 |
} |
83 |
|
84 |
class NewMidiInstrumentWizardModel extends DefaultWizardModel { |
85 |
private final InstrLocationMethodWizardPage instrLocationMethodWizardPage = |
86 |
new InstrLocationMethodWizardPage(); |
87 |
|
88 |
private final OrchestraSelectWizardPage orchestraSelectWizardPage = |
89 |
new OrchestraSelectWizardPage(); |
90 |
|
91 |
private final ManualSelectWizardPage manualSelectWizardPage = new ManualSelectWizardPage(); |
92 |
|
93 |
private final InstrumentMappingWizardPage instrumentMappingWizardPage = |
94 |
new InstrumentMappingWizardPage(); |
95 |
|
96 |
NewMidiInstrumentWizardModel() { |
97 |
addPage(instrLocationMethodWizardPage); |
98 |
addStep(i18n.getLabel("NewMidiInstrumentWizard.step1")); |
99 |
|
100 |
addPage(manualSelectWizardPage); |
101 |
addPage(orchestraSelectWizardPage); |
102 |
addStep(i18n.getLabel("NewMidiInstrumentWizard.step2"), 2); |
103 |
|
104 |
addPage(instrumentMappingWizardPage); |
105 |
addStep(i18n.getLabel("NewMidiInstrumentWizard.step3")); |
106 |
} |
107 |
|
108 |
/** |
109 |
* Moves to the next page in the wizard. |
110 |
* @return The next page in the wizard. |
111 |
*/ |
112 |
public WizardPage |
113 |
next() { |
114 |
InstrLocationMethodWizardPage p1 = instrLocationMethodWizardPage; |
115 |
WizardPage p2 = manualSelectWizardPage; |
116 |
|
117 |
if(getCurrentPage() == p1 && p1.isOrchestraMethodSelected()) { |
118 |
super.next(); |
119 |
} else if(getCurrentPage() == manualSelectWizardPage) { |
120 |
super.next(); |
121 |
} |
122 |
|
123 |
return super.next(); |
124 |
} |
125 |
|
126 |
/** |
127 |
* Moves to the previous page in the wizard. |
128 |
* @return The previous page in the wizard. |
129 |
* @see #hasPrevious |
130 |
*/ |
131 |
public WizardPage |
132 |
previous() { |
133 |
InstrLocationMethodWizardPage p1 = instrLocationMethodWizardPage; |
134 |
WizardPage p2 = instrumentMappingWizardPage; |
135 |
|
136 |
if(getCurrentPage() == orchestraSelectWizardPage) { |
137 |
super.previous(); |
138 |
} else if(getCurrentPage() == p2 && !p1.isOrchestraMethodSelected()) { |
139 |
super.previous(); |
140 |
} |
141 |
|
142 |
return super.previous(); |
143 |
} |
144 |
|
145 |
public void |
146 |
mapInstrument() { |
147 |
MidiInstrumentInfo instr = new MidiInstrumentInfo(); |
148 |
if(instrLocationMethodWizardPage.isOrchestraMethodSelected()) { |
149 |
Instrument i = orchestraSelectWizardPage.getInstrument(); |
150 |
instr.setFileName(i.getPath()); |
151 |
instr.setInstrumentIndex(i.getInstrumentIndex()); |
152 |
instr.setEngine(i.getEngine()); |
153 |
instr.setLoadMode(orchestraSelectWizardPage.getLoadMode()); |
154 |
} else { |
155 |
instr.setFileName(manualSelectWizardPage.getSelectedFile()); |
156 |
instr.setInstrumentIndex(manualSelectWizardPage.getInstrumentIndex()); |
157 |
instr.setEngine(manualSelectWizardPage.getEngine()); |
158 |
instr.setLoadMode(manualSelectWizardPage.getLoadMode()); |
159 |
} |
160 |
|
161 |
int map = instrumentMappingWizardPage.getMapId(); |
162 |
int bank = instrumentMappingWizardPage.getMidiBank(); |
163 |
int prog = instrumentMappingWizardPage.getMidiProgram(); |
164 |
|
165 |
instr.setName(instrumentMappingWizardPage.getInstrumentName()); |
166 |
instr.setVolume(instrumentMappingWizardPage.getVolume()); |
167 |
|
168 |
CC.getSamplerModel().mapBackendMidiInstrument(map, bank, prog, instr); |
169 |
} |
170 |
} |
171 |
|
172 |
class InstrLocationMethodWizardPage extends UserInputPage { |
173 |
private final JRadioButton rbManual = |
174 |
new JRadioButton(i18n.getLabel("InstrLocationMethodWizardPage.rbManual")); |
175 |
|
176 |
private final JRadioButton rbOrchestra = |
177 |
new JRadioButton(i18n.getLabel("InstrLocationMethodWizardPage.rbOrchestra")); |
178 |
|
179 |
private final JCheckBox checkSkip = |
180 |
new JCheckBox(i18n.getLabel("InstrLocationMethodWizardPage.checkSkip")); |
181 |
|
182 |
InstrLocationMethodWizardPage() { |
183 |
super(i18n.getLabel("InstrLocationMethodWizardPage.subtitle")); |
184 |
|
185 |
String s = i18n.getLabel("InstrLocationMethodWizardPage.mainInstructions"); |
186 |
setMainInstructions(s); |
187 |
|
188 |
JPanel p = new JPanel(); |
189 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
190 |
|
191 |
ButtonGroup group = new ButtonGroup(); |
192 |
group.add(rbManual); |
193 |
group.add(rbOrchestra); |
194 |
rbManual.setSelected(true); |
195 |
|
196 |
p.add(rbManual); |
197 |
p.add(rbOrchestra); |
198 |
|
199 |
JPanel p2 = new JPanel(); |
200 |
p2.setLayout(new BorderLayout()); |
201 |
p2.add(p, BorderLayout.NORTH); |
202 |
p2.add(checkSkip, BorderLayout.SOUTH); |
203 |
setMainPane(p2); |
204 |
|
205 |
switch(ClassicPrefs.getInstrLocationMethod()) { |
206 |
case 0: |
207 |
rbManual.setSelected(true); |
208 |
break; |
209 |
case 1: |
210 |
rbOrchestra.setSelected(true); |
211 |
} |
212 |
|
213 |
checkSkip.setSelected(ClassicPrefs.getNewMidiInstrWizardSkip1()); |
214 |
|
215 |
rbManual.addActionListener(new ActionListener() { |
216 |
public void |
217 |
actionPerformed(ActionEvent e) { |
218 |
if(rbManual.isSelected()) ClassicPrefs.setInstrLocationMethod(0); |
219 |
} |
220 |
}); |
221 |
|
222 |
rbOrchestra.addActionListener(new ActionListener() { |
223 |
public void |
224 |
actionPerformed(ActionEvent e) { |
225 |
if(rbOrchestra.isSelected()) ClassicPrefs.setInstrLocationMethod(1); |
226 |
} |
227 |
}); |
228 |
|
229 |
checkSkip.addActionListener(new ActionListener() { |
230 |
public void |
231 |
actionPerformed(ActionEvent e) { |
232 |
ClassicPrefs.setNewMidiInstrWizardSkip1(checkSkip.isSelected()); |
233 |
} |
234 |
}); |
235 |
} |
236 |
|
237 |
/** |
238 |
* Determines whether the user selected an orchestra location method. |
239 |
*/ |
240 |
public boolean |
241 |
isOrchestraMethodSelected() { return rbOrchestra.isSelected(); } |
242 |
} |
243 |
|
244 |
class OrchestraSelectWizardPage extends UserInputPage { |
245 |
private final JLabel lOrchestras = |
246 |
new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lOrchestras")); |
247 |
|
248 |
private final JLabel lInstruments = |
249 |
new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lInstruments")); |
250 |
|
251 |
private final JLabel lLoadMode = |
252 |
new JLabel(i18n.getLabel("OrchestraSelectWizardPage.lLoadMode")); |
253 |
|
254 |
private final JComboBox cbOrchestras = new JComboBox(); |
255 |
private final JComboBox cbInstruments = new JComboBox(); |
256 |
private final JComboBox cbLoadMode = new JComboBox(); |
257 |
|
258 |
OrchestraSelectWizardPage() { |
259 |
super(i18n.getLabel("OrchestraSelectWizardPage.subtitle")); |
260 |
setMainInstructions(i18n.getLabel("OrchestraSelectWizardPage.mainInstructions")); |
261 |
|
262 |
GridBagLayout gridbag = new GridBagLayout(); |
263 |
GridBagConstraints c = new GridBagConstraints(); |
264 |
|
265 |
JPanel p = new JPanel(); |
266 |
|
267 |
p.setLayout(gridbag); |
268 |
|
269 |
c.fill = GridBagConstraints.NONE; |
270 |
|
271 |
c.gridx = 0; |
272 |
c.gridy = 0; |
273 |
c.anchor = GridBagConstraints.EAST; |
274 |
c.insets = new Insets(0, 0, 6, 16); |
275 |
gridbag.setConstraints(lOrchestras, c); |
276 |
p.add(lOrchestras); |
277 |
|
278 |
c.gridx = 0; |
279 |
c.gridy = 1; |
280 |
gridbag.setConstraints(lInstruments, c); |
281 |
p.add(lInstruments); |
282 |
|
283 |
c.gridx = 0; |
284 |
c.gridy = 2; |
285 |
c.insets = new Insets(12, 0, 6, 16); |
286 |
gridbag.setConstraints(lLoadMode, c); |
287 |
p.add(lLoadMode); |
288 |
|
289 |
c.gridx = 1; |
290 |
c.gridy = 0; |
291 |
c.weightx = 1.0; |
292 |
c.insets = new Insets(0, 0, 6, 48); |
293 |
c.fill = GridBagConstraints.HORIZONTAL; |
294 |
c.anchor = GridBagConstraints.NORTH; |
295 |
gridbag.setConstraints(cbOrchestras, c); |
296 |
p.add(cbOrchestras); |
297 |
|
298 |
c.gridx = 1; |
299 |
c.gridy = 1; |
300 |
gridbag.setConstraints(cbInstruments, c); |
301 |
p.add(cbInstruments); |
302 |
|
303 |
c.gridx = 1; |
304 |
c.gridy = 2; |
305 |
c.insets = new Insets(12, 0, 6, 48); |
306 |
gridbag.setConstraints(cbLoadMode, c); |
307 |
p.add(cbLoadMode); |
308 |
|
309 |
JPanel p2 = new JPanel(); |
310 |
p2.setOpaque(false); |
311 |
c.gridx = 0; |
312 |
c.gridy = 3; |
313 |
c.fill = GridBagConstraints.VERTICAL; |
314 |
c.weightx = 0.0; |
315 |
c.weighty = 1.0; |
316 |
gridbag.setConstraints(p2, c); |
317 |
p.add(p2); |
318 |
|
319 |
setMainPane(p); |
320 |
|
321 |
cbOrchestras.addActionListener(new ActionListener() { |
322 |
public void |
323 |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
324 |
}); |
325 |
|
326 |
for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) { |
327 |
cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i)); |
328 |
} |
329 |
|
330 |
cbInstruments.addActionListener(new ActionListener() { |
331 |
public void |
332 |
actionPerformed(ActionEvent e) { instrumentChanged(); } |
333 |
}); |
334 |
|
335 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT); |
336 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
337 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
338 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
339 |
} |
340 |
|
341 |
private void |
342 |
orchestraChanged() { |
343 |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
344 |
String s = om == null ? null : om.getDescription(); |
345 |
if(s != null && s.length() == 0) s = null; |
346 |
cbOrchestras.setToolTipText(s); |
347 |
|
348 |
cbInstruments.removeAllItems(); |
349 |
if(om == null || om.getInstrumentCount() == 0) { |
350 |
cbInstruments.setEnabled(false); |
351 |
return; |
352 |
} |
353 |
|
354 |
cbInstruments.setEnabled(true); |
355 |
|
356 |
for(int i = 0; i < om.getInstrumentCount(); i++) { |
357 |
cbInstruments.addItem(om.getInstrument(i)); |
358 |
} |
359 |
} |
360 |
|
361 |
private void |
362 |
instrumentChanged() { |
363 |
Instrument instr = (Instrument)cbInstruments.getSelectedItem(); |
364 |
String s = instr == null ? null : instr.getDescription(); |
365 |
if(s != null && s.length() == 0) s = null; |
366 |
cbInstruments.setToolTipText(s); |
367 |
|
368 |
getWizard().enableNextButton(instr != null); |
369 |
} |
370 |
|
371 |
public void |
372 |
postinitPage() { |
373 |
getWizard().enableNextButton(cbInstruments.getSelectedItem() != null); |
374 |
} |
375 |
|
376 |
/** |
377 |
* Gets the selected instrument. |
378 |
*/ |
379 |
public Instrument |
380 |
getInstrument() { return (Instrument)cbInstruments.getSelectedItem(); } |
381 |
|
382 |
/** |
383 |
* Gets the selected load mode. |
384 |
*/ |
385 |
public MidiInstrumentInfo.LoadMode |
386 |
getLoadMode() { return (MidiInstrumentInfo.LoadMode) cbLoadMode.getSelectedItem(); } |
387 |
} |
388 |
|
389 |
class ManualSelectWizardPage extends UserInputPage { |
390 |
private final JLabel lFilename = |
391 |
new JLabel(i18n.getLabel("ManualSelectWizardPage.lFilename")); |
392 |
|
393 |
private final JLabel lIndex = new JLabel(i18n.getLabel("ManualSelectWizardPage.lIndex")); |
394 |
|
395 |
private final JLabel lEngine = new JLabel(i18n.getLabel("ManualSelectWizardPage.lEngine")); |
396 |
|
397 |
private final JLabel lLoadMode = |
398 |
new JLabel(i18n.getLabel("ManualSelectWizardPage.lLoadMode")); |
399 |
|
400 |
private final JTextField tfFilename = new JTextField(); |
401 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
402 |
|
403 |
private final JButton btnBrowse = |
404 |
new JButton(Res.iconFolderOpen16); |
405 |
|
406 |
private final JComboBox cbEngine = new JComboBox(); |
407 |
private final JComboBox cbLoadMode = new JComboBox(); |
408 |
|
409 |
ManualSelectWizardPage() { |
410 |
super(i18n.getLabel("ManualSelectWizardPage.subtitle")); |
411 |
setMainInstructions(i18n.getLabel("ManualSelectWizardPage.mainInstructions")); |
412 |
|
413 |
GridBagLayout gridbag = new GridBagLayout(); |
414 |
GridBagConstraints c = new GridBagConstraints(); |
415 |
|
416 |
JPanel mainPane = new JPanel(); |
417 |
|
418 |
mainPane.setLayout(gridbag); |
419 |
|
420 |
c.fill = GridBagConstraints.NONE; |
421 |
|
422 |
c.gridx = 0; |
423 |
c.gridy = 0; |
424 |
c.anchor = GridBagConstraints.EAST; |
425 |
c.insets = new Insets(3, 3, 3, 3); |
426 |
gridbag.setConstraints(lFilename, c); |
427 |
mainPane.add(lFilename); |
428 |
|
429 |
c.gridx = 0; |
430 |
c.gridy = 1; |
431 |
gridbag.setConstraints(lIndex, c); |
432 |
mainPane.add(lIndex); |
433 |
|
434 |
c.gridx = 0; |
435 |
c.gridy = 2; |
436 |
c.insets = new Insets(12, 3, 3, 3); |
437 |
gridbag.setConstraints(lEngine, c); |
438 |
mainPane.add(lEngine); |
439 |
|
440 |
c.gridx = 0; |
441 |
c.gridy = 3; |
442 |
c.insets = new Insets(3, 3, 3, 3); |
443 |
gridbag.setConstraints(lLoadMode, c); |
444 |
mainPane.add(lLoadMode); |
445 |
|
446 |
btnBrowse.setMargin(new Insets(0, 0, 0, 0)); |
447 |
btnBrowse.setToolTipText(i18n.getLabel("ManualSelectWizardPage.btnBrowse")); |
448 |
c.gridx = 2; |
449 |
c.gridy = 0; |
450 |
gridbag.setConstraints(btnBrowse, c); |
451 |
mainPane.add(btnBrowse); |
452 |
|
453 |
c.fill = GridBagConstraints.HORIZONTAL; |
454 |
c.gridx = 1; |
455 |
c.gridy = 0; |
456 |
c.weightx = 1.0; |
457 |
c.anchor = GridBagConstraints.WEST; |
458 |
gridbag.setConstraints(tfFilename, c); |
459 |
mainPane.add(tfFilename); |
460 |
|
461 |
c.gridx = 1; |
462 |
c.gridy = 1; |
463 |
gridbag.setConstraints(spinnerIndex, c); |
464 |
mainPane.add(spinnerIndex); |
465 |
|
466 |
c.gridx = 1; |
467 |
c.gridy = 2; |
468 |
c.insets = new Insets(12, 3, 3, 64); |
469 |
gridbag.setConstraints(cbEngine, c); |
470 |
mainPane.add(cbEngine); |
471 |
|
472 |
c.gridx = 1; |
473 |
c.gridy = 3; |
474 |
c.insets = new Insets(3, 3, 3, 64); |
475 |
gridbag.setConstraints(cbLoadMode, c); |
476 |
mainPane.add(cbLoadMode); |
477 |
|
478 |
JPanel p2 = new JPanel(); |
479 |
p2.setOpaque(false); |
480 |
c.gridx = 0; |
481 |
c.gridy = 4; |
482 |
c.fill = GridBagConstraints.VERTICAL; |
483 |
c.weightx = 0.0; |
484 |
c.weighty = 1.0; |
485 |
gridbag.setConstraints(p2, c); |
486 |
mainPane.add(p2); |
487 |
|
488 |
setMainPane(mainPane); |
489 |
|
490 |
tfFilename.getDocument().addDocumentListener(getHandler()); |
491 |
|
492 |
btnBrowse.addActionListener(new ActionListener() { |
493 |
public void |
494 |
actionPerformed(ActionEvent e) { onBrowse(); } |
495 |
}); |
496 |
|
497 |
for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e); |
498 |
|
499 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT); |
500 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
501 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
502 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
503 |
} |
504 |
|
505 |
private void |
506 |
onBrowse() { |
507 |
JFileChooser fc = new JFileChooser(); |
508 |
int result = fc.showOpenDialog(this); |
509 |
if(result == JFileChooser.APPROVE_OPTION) { |
510 |
tfFilename.setText(fc.getSelectedFile().getPath()); |
511 |
} |
512 |
} |
513 |
|
514 |
private void |
515 |
updateState() { getWizard().enableNextButton(tfFilename.getText().length() != 0); } |
516 |
|
517 |
public void |
518 |
postinitPage() { |
519 |
updateState(); |
520 |
} |
521 |
|
522 |
/** |
523 |
* Gets the name of the instrument file. |
524 |
* @return The name of the instrument file. |
525 |
*/ |
526 |
public String |
527 |
getSelectedFile() { return tfFilename.getText(); } |
528 |
|
529 |
/** |
530 |
* Gets the index of the instrument in the instrument file. |
531 |
* @return The index of the instrument in the instrument file. |
532 |
*/ |
533 |
public int |
534 |
getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); } |
535 |
|
536 |
/** |
537 |
* Gets the selected engine. |
538 |
*/ |
539 |
public String |
540 |
getEngine() { return ((SamplerEngine)cbEngine.getSelectedItem()).getName(); } |
541 |
|
542 |
/** |
543 |
* Gets the selected load mode. |
544 |
*/ |
545 |
public MidiInstrumentInfo.LoadMode |
546 |
getLoadMode() { return (MidiInstrumentInfo.LoadMode)cbLoadMode.getSelectedItem(); } |
547 |
|
548 |
private final Handler eventHandler = new Handler(); |
549 |
|
550 |
private Handler |
551 |
getHandler() { return eventHandler; } |
552 |
|
553 |
private class Handler implements DocumentListener { |
554 |
// DocumentListener |
555 |
public void |
556 |
insertUpdate(DocumentEvent e) { updateState(); } |
557 |
|
558 |
public void |
559 |
removeUpdate(DocumentEvent e) { updateState(); } |
560 |
|
561 |
public void |
562 |
changedUpdate(DocumentEvent e) { updateState(); } |
563 |
} |
564 |
} |
565 |
|
566 |
class InstrumentMappingWizardPage extends WizardPage { |
567 |
private final JLabel lName = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lName")); |
568 |
private final JLabel lMap = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lMap")); |
569 |
private final JLabel lBank = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lBank")); |
570 |
private final JLabel lProgram = |
571 |
new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lProgram")); |
572 |
|
573 |
private final JLabel lVolume = |
574 |
new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lVolume")); |
575 |
|
576 |
private final JTextField tfName = new JTextField(); |
577 |
private final JComboBox cbMap = new JComboBox(); |
578 |
private final JSpinner spinnerBank = new JSpinner(new SpinnerNumberModel(0, 0, 16383, 1)); |
579 |
private final JComboBox cbProgram = new JComboBox(); |
580 |
private final JSlider slVolume = new JSlider(0, 100, 100); |
581 |
|
582 |
InstrumentMappingWizardPage() { |
583 |
super(i18n.getLabel("InstrumentMappingWizardPage.subtitle")); |
584 |
setPageType(Type.CONFIRMATION_PAGE); |
585 |
|
586 |
GridBagLayout gridbag = new GridBagLayout(); |
587 |
GridBagConstraints c = new GridBagConstraints(); |
588 |
|
589 |
setLayout(gridbag); |
590 |
|
591 |
c.fill = GridBagConstraints.NONE; |
592 |
|
593 |
c.gridx = 0; |
594 |
c.gridy = 0; |
595 |
c.anchor = GridBagConstraints.EAST; |
596 |
c.insets = new Insets(24, 3, 3, 0); |
597 |
gridbag.setConstraints(lName, c); |
598 |
add(lName); |
599 |
|
600 |
c.gridx = 0; |
601 |
c.gridy = 2; |
602 |
c.insets = new Insets(3, 3, 3, 0); |
603 |
gridbag.setConstraints(lMap, c); |
604 |
add(lMap); |
605 |
|
606 |
c.gridx = 0; |
607 |
c.gridy = 3; |
608 |
gridbag.setConstraints(lBank, c); |
609 |
add(lBank); |
610 |
|
611 |
c.gridx = 0; |
612 |
c.gridy = 4; |
613 |
gridbag.setConstraints(lProgram, c); |
614 |
add(lProgram); |
615 |
|
616 |
c.gridx = 0; |
617 |
c.gridy = 1; |
618 |
c.insets = new Insets(3, 3, 24, 0); |
619 |
gridbag.setConstraints(lVolume, c); |
620 |
add(lVolume); |
621 |
|
622 |
c.fill = GridBagConstraints.HORIZONTAL; |
623 |
c.gridx = 1; |
624 |
c.gridy = 0; |
625 |
c.weightx = 1.0; |
626 |
c.insets = new Insets(24, 12, 3, 36); |
627 |
c.anchor = GridBagConstraints.WEST; |
628 |
gridbag.setConstraints(tfName, c); |
629 |
add(tfName); |
630 |
|
631 |
c.gridx = 1; |
632 |
c.gridy = 2; |
633 |
c.insets = new Insets(3, 12, 3, 36); |
634 |
gridbag.setConstraints(cbMap, c); |
635 |
add(cbMap); |
636 |
|
637 |
c.gridx = 1; |
638 |
c.gridy = 3; |
639 |
gridbag.setConstraints(spinnerBank, c); |
640 |
add(spinnerBank); |
641 |
|
642 |
c.gridx = 1; |
643 |
c.gridy = 4; |
644 |
gridbag.setConstraints(cbProgram, c); |
645 |
add(cbProgram); |
646 |
|
647 |
c.gridx = 1; |
648 |
c.gridy = 1; |
649 |
c.insets = new Insets(3, 12, 24, 36); |
650 |
gridbag.setConstraints(slVolume, c); |
651 |
add(slVolume); |
652 |
|
653 |
JPanel p2 = new JPanel(); |
654 |
p2.setOpaque(false); |
655 |
c.gridx = 0; |
656 |
c.gridy = 5; |
657 |
c.insets = new Insets(0, 0, 0, 0); |
658 |
c.fill = GridBagConstraints.VERTICAL; |
659 |
c.weightx = 0.0; |
660 |
c.weighty = 1.0; |
661 |
gridbag.setConstraints(p2, c); |
662 |
add(p2); |
663 |
|
664 |
cbMap.addActionListener(new ActionListener() { |
665 |
public void |
666 |
actionPerformed(ActionEvent e) { updateState(); } |
667 |
}); |
668 |
|
669 |
for(MidiInstrumentMap m : CC.getSamplerModel().getMidiInstrumentMaps()) { |
670 |
cbMap.addItem(m); |
671 |
} |
672 |
|
673 |
tfName.getDocument().addDocumentListener(getHandler()); |
674 |
|
675 |
cbMap.setEnabled(cbMap.getItemCount() > 0); |
676 |
|
677 |
|
678 |
for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i)); |
679 |
} |
680 |
|
681 |
private void |
682 |
updateState() { |
683 |
cbMap.setEnabled(cbMap.getItemCount() > 0); |
684 |
boolean b = cbMap.getSelectedItem() != null; |
685 |
spinnerBank.setEnabled(b); |
686 |
cbProgram.setEnabled(b); |
687 |
|
688 |
b = tfName.getText().length() > 0 && cbMap.getSelectedItem() != null; |
689 |
b = b && cbProgram.getSelectedItem() != null; |
690 |
if(getWizard() != null) getWizard().enableFinishButton(b); |
691 |
} |
692 |
|
693 |
public void |
694 |
postinitPage() { |
695 |
updateState(); |
696 |
} |
697 |
|
698 |
/** |
699 |
* Invoked when the user clicks the 'Finish' button |
700 |
* while this page is the current page of the wizard. |
701 |
* @return <code>true</code> |
702 |
*/ |
703 |
public boolean |
704 |
mayFinish() { |
705 |
((NewMidiInstrumentWizardModel)getWizardModel()).mapInstrument(); |
706 |
return true; |
707 |
} |
708 |
|
709 |
/** |
710 |
* Gets the ID of the selected MIDI instrument map. |
711 |
*/ |
712 |
public int |
713 |
getMapId() { return ((MidiInstrumentMap)cbMap.getSelectedItem()).getMapId(); } |
714 |
|
715 |
/** |
716 |
* Gets the selected MIDI bank. |
717 |
*/ |
718 |
public int |
719 |
getMidiBank() { return Integer.parseInt(spinnerBank.getValue().toString()); } |
720 |
|
721 |
/** |
722 |
* Gets the selected MIDI program. |
723 |
*/ |
724 |
public int |
725 |
getMidiProgram() { return cbProgram.getSelectedIndex(); } |
726 |
|
727 |
/** |
728 |
* Gets the chosen name for the new MIDI instrument. |
729 |
* @return The chosen name for the new MIDI instrument. |
730 |
*/ |
731 |
public String |
732 |
getInstrumentName() { return tfName.getText(); } |
733 |
|
734 |
/** |
735 |
* Returns the volume level of the new MIDI instrument. |
736 |
* @return The volume level of the new MIDI instrument. |
737 |
*/ |
738 |
public float |
739 |
getVolume() { |
740 |
float f = slVolume.getValue(); |
741 |
f /= 100; |
742 |
return f; |
743 |
} |
744 |
|
745 |
private final Handler eventHandler = new Handler(); |
746 |
|
747 |
private Handler |
748 |
getHandler() { return eventHandler; } |
749 |
|
750 |
private class Handler implements DocumentListener { |
751 |
// DocumentListener |
752 |
public void |
753 |
insertUpdate(DocumentEvent e) { updateState(); } |
754 |
|
755 |
public void |
756 |
removeUpdate(DocumentEvent e) { updateState(); } |
757 |
|
758 |
public void |
759 |
changedUpdate(DocumentEvent e) { updateState(); } |
760 |
} |
761 |
} |