/[svn]/jsampler/trunk/src/org/jsampler/view/classic/NewMidiInstrumentWizard.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/NewMidiInstrumentWizard.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1204 - (show annotations) (download)
Thu May 24 21:43:45 2007 UTC (16 years, 10 months ago) by iliev
File size: 20884 byte(s)
upgrading to version 0.5a

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.setFilePath(i.getPath());
151 instr.setInstrumentIndex(i.getInstrumentIndex());
152 instr.setEngine(i.getEngine());
153 instr.setLoadMode(orchestraSelectWizardPage.getLoadMode());
154 } else {
155 instr.setFilePath(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 = new JButton(Res.iconFolderOpen16);
404
405 private final JComboBox cbEngine = new JComboBox();
406 private final JComboBox cbLoadMode = new JComboBox();
407
408 ManualSelectWizardPage() {
409 super(i18n.getLabel("ManualSelectWizardPage.subtitle"));
410 setMainInstructions(i18n.getLabel("ManualSelectWizardPage.mainInstructions"));
411
412 GridBagLayout gridbag = new GridBagLayout();
413 GridBagConstraints c = new GridBagConstraints();
414
415 JPanel mainPane = new JPanel();
416
417 mainPane.setLayout(gridbag);
418
419 c.fill = GridBagConstraints.NONE;
420
421 c.gridx = 0;
422 c.gridy = 0;
423 c.anchor = GridBagConstraints.EAST;
424 c.insets = new Insets(3, 3, 3, 3);
425 gridbag.setConstraints(lFilename, c);
426 mainPane.add(lFilename);
427
428 c.gridx = 0;
429 c.gridy = 1;
430 gridbag.setConstraints(lIndex, c);
431 mainPane.add(lIndex);
432
433 c.gridx = 0;
434 c.gridy = 2;
435 c.insets = new Insets(12, 3, 3, 3);
436 gridbag.setConstraints(lEngine, c);
437 mainPane.add(lEngine);
438
439 c.gridx = 0;
440 c.gridy = 3;
441 c.insets = new Insets(3, 3, 3, 3);
442 gridbag.setConstraints(lLoadMode, c);
443 mainPane.add(lLoadMode);
444
445 btnBrowse.setMargin(new Insets(0, 0, 0, 0));
446 btnBrowse.setToolTipText(i18n.getLabel("ManualSelectWizardPage.btnBrowse"));
447 c.gridx = 2;
448 c.gridy = 0;
449 gridbag.setConstraints(btnBrowse, c);
450 mainPane.add(btnBrowse);
451
452 c.fill = GridBagConstraints.HORIZONTAL;
453 c.gridx = 1;
454 c.gridy = 0;
455 c.weightx = 1.0;
456 c.anchor = GridBagConstraints.WEST;
457 gridbag.setConstraints(tfFilename, c);
458 mainPane.add(tfFilename);
459
460 c.gridx = 1;
461 c.gridy = 1;
462 gridbag.setConstraints(spinnerIndex, c);
463 mainPane.add(spinnerIndex);
464
465 c.gridx = 1;
466 c.gridy = 2;
467 c.insets = new Insets(12, 3, 3, 64);
468 gridbag.setConstraints(cbEngine, c);
469 mainPane.add(cbEngine);
470
471 c.gridx = 1;
472 c.gridy = 3;
473 c.insets = new Insets(3, 3, 3, 64);
474 gridbag.setConstraints(cbLoadMode, c);
475 mainPane.add(cbLoadMode);
476
477 JPanel p2 = new JPanel();
478 p2.setOpaque(false);
479 c.gridx = 0;
480 c.gridy = 4;
481 c.fill = GridBagConstraints.VERTICAL;
482 c.weightx = 0.0;
483 c.weighty = 1.0;
484 gridbag.setConstraints(p2, c);
485 mainPane.add(p2);
486
487 setMainPane(mainPane);
488
489 tfFilename.getDocument().addDocumentListener(getHandler());
490
491 btnBrowse.addActionListener(new ActionListener() {
492 public void
493 actionPerformed(ActionEvent e) { onBrowse(); }
494 });
495
496 for(SamplerEngine e : CC.getSamplerModel().getEngines()) cbEngine.addItem(e);
497
498 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT);
499 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND);
500 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD);
501 cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT);
502 }
503
504 private void
505 onBrowse() {
506 JFileChooser fc = new JFileChooser();
507 int result = fc.showOpenDialog(this);
508 if(result == JFileChooser.APPROVE_OPTION) {
509 tfFilename.setText(fc.getSelectedFile().getPath());
510 }
511 }
512
513 private void
514 updateState() { getWizard().enableNextButton(tfFilename.getText().length() != 0); }
515
516 public void
517 postinitPage() {
518 updateState();
519 }
520
521 /**
522 * Gets the name of the instrument file.
523 * @return The name of the instrument file.
524 */
525 public String
526 getSelectedFile() { return tfFilename.getText(); }
527
528 /**
529 * Gets the index of the instrument in the instrument file.
530 * @return The index of the instrument in the instrument file.
531 */
532 public int
533 getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); }
534
535 /**
536 * Gets the selected engine.
537 */
538 public String
539 getEngine() { return ((SamplerEngine)cbEngine.getSelectedItem()).getName(); }
540
541 /**
542 * Gets the selected load mode.
543 */
544 public MidiInstrumentInfo.LoadMode
545 getLoadMode() { return (MidiInstrumentInfo.LoadMode)cbLoadMode.getSelectedItem(); }
546
547 private final Handler eventHandler = new Handler();
548
549 private Handler
550 getHandler() { return eventHandler; }
551
552 private class Handler implements DocumentListener {
553 // DocumentListener
554 public void
555 insertUpdate(DocumentEvent e) { updateState(); }
556
557 public void
558 removeUpdate(DocumentEvent e) { updateState(); }
559
560 public void
561 changedUpdate(DocumentEvent e) { updateState(); }
562 }
563 }
564
565 class InstrumentMappingWizardPage extends WizardPage {
566 private final JLabel lName = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lName"));
567 private final JLabel lMap = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lMap"));
568 private final JLabel lBank = new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lBank"));
569 private final JLabel lProgram =
570 new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lProgram"));
571
572 private final JLabel lVolume =
573 new JLabel(i18n.getLabel("InstrumentMappingWizardPage.lVolume"));
574
575 private final JTextField tfName = new JTextField();
576 private final JComboBox cbMap = new JComboBox();
577 private final JSpinner spinnerBank = new JSpinner(new SpinnerNumberModel(0, 0, 16383, 1));
578 private final JComboBox cbProgram = new JComboBox();
579 private final JSlider slVolume = new JSlider(0, 100, 100);
580
581 InstrumentMappingWizardPage() {
582 super(i18n.getLabel("InstrumentMappingWizardPage.subtitle"));
583 setPageType(Type.CONFIRMATION_PAGE);
584
585 GridBagLayout gridbag = new GridBagLayout();
586 GridBagConstraints c = new GridBagConstraints();
587
588 setLayout(gridbag);
589
590 c.fill = GridBagConstraints.NONE;
591
592 c.gridx = 0;
593 c.gridy = 0;
594 c.anchor = GridBagConstraints.EAST;
595 c.insets = new Insets(24, 3, 3, 0);
596 gridbag.setConstraints(lName, c);
597 add(lName);
598
599 c.gridx = 0;
600 c.gridy = 2;
601 c.insets = new Insets(3, 3, 3, 0);
602 gridbag.setConstraints(lMap, c);
603 add(lMap);
604
605 c.gridx = 0;
606 c.gridy = 3;
607 gridbag.setConstraints(lBank, c);
608 add(lBank);
609
610 c.gridx = 0;
611 c.gridy = 4;
612 gridbag.setConstraints(lProgram, c);
613 add(lProgram);
614
615 c.gridx = 0;
616 c.gridy = 1;
617 c.insets = new Insets(3, 3, 24, 0);
618 gridbag.setConstraints(lVolume, c);
619 add(lVolume);
620
621 c.fill = GridBagConstraints.HORIZONTAL;
622 c.gridx = 1;
623 c.gridy = 0;
624 c.weightx = 1.0;
625 c.insets = new Insets(24, 12, 3, 36);
626 c.anchor = GridBagConstraints.WEST;
627 gridbag.setConstraints(tfName, c);
628 add(tfName);
629
630 c.gridx = 1;
631 c.gridy = 2;
632 c.insets = new Insets(3, 12, 3, 36);
633 gridbag.setConstraints(cbMap, c);
634 add(cbMap);
635
636 c.gridx = 1;
637 c.gridy = 3;
638 gridbag.setConstraints(spinnerBank, c);
639 add(spinnerBank);
640
641 c.gridx = 1;
642 c.gridy = 4;
643 gridbag.setConstraints(cbProgram, c);
644 add(cbProgram);
645
646 c.gridx = 1;
647 c.gridy = 1;
648 c.insets = new Insets(3, 12, 24, 36);
649 gridbag.setConstraints(slVolume, c);
650 add(slVolume);
651
652 JPanel p2 = new JPanel();
653 p2.setOpaque(false);
654 c.gridx = 0;
655 c.gridy = 5;
656 c.insets = new Insets(0, 0, 0, 0);
657 c.fill = GridBagConstraints.VERTICAL;
658 c.weightx = 0.0;
659 c.weighty = 1.0;
660 gridbag.setConstraints(p2, c);
661 add(p2);
662
663 cbMap.addActionListener(new ActionListener() {
664 public void
665 actionPerformed(ActionEvent e) { updateState(); }
666 });
667
668 for(MidiInstrumentMap m : CC.getSamplerModel().getMidiInstrumentMaps()) {
669 cbMap.addItem(m);
670 }
671
672 tfName.getDocument().addDocumentListener(getHandler());
673
674 cbMap.setEnabled(cbMap.getItemCount() > 0);
675
676
677 for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i));
678 }
679
680 private void
681 updateState() {
682 cbMap.setEnabled(cbMap.getItemCount() > 0);
683 boolean b = cbMap.getSelectedItem() != null;
684 spinnerBank.setEnabled(b);
685 cbProgram.setEnabled(b);
686
687 b = tfName.getText().length() > 0 && cbMap.getSelectedItem() != null;
688 b = b && cbProgram.getSelectedItem() != null;
689 if(getWizard() != null) getWizard().enableFinishButton(b);
690 }
691
692 public void
693 postinitPage() {
694 updateState();
695 }
696
697 /**
698 * Invoked when the user clicks the 'Finish' button
699 * while this page is the current page of the wizard.
700 * @return <code>true</code>
701 */
702 public boolean
703 mayFinish() {
704 ((NewMidiInstrumentWizardModel)getWizardModel()).mapInstrument();
705 return true;
706 }
707
708 /**
709 * Gets the ID of the selected MIDI instrument map.
710 */
711 public int
712 getMapId() { return ((MidiInstrumentMap)cbMap.getSelectedItem()).getMapId(); }
713
714 /**
715 * Gets the selected MIDI bank.
716 */
717 public int
718 getMidiBank() { return Integer.parseInt(spinnerBank.getValue().toString()); }
719
720 /**
721 * Gets the selected MIDI program.
722 */
723 public int
724 getMidiProgram() { return cbProgram.getSelectedIndex(); }
725
726 /**
727 * Gets the chosen name for the new MIDI instrument.
728 * @return The chosen name for the new MIDI instrument.
729 */
730 public String
731 getInstrumentName() { return tfName.getText(); }
732
733 /**
734 * Returns the volume level of the new MIDI instrument.
735 * @return The volume level of the new MIDI instrument.
736 */
737 public float
738 getVolume() {
739 float f = slVolume.getValue();
740 f /= 100;
741 return f;
742 }
743
744 private final Handler eventHandler = new Handler();
745
746 private Handler
747 getHandler() { return eventHandler; }
748
749 private class Handler implements DocumentListener {
750 // DocumentListener
751 public void
752 insertUpdate(DocumentEvent e) { updateState(); }
753
754 public void
755 removeUpdate(DocumentEvent e) { updateState(); }
756
757 public void
758 changedUpdate(DocumentEvent e) { updateState(); }
759 }
760 }

  ViewVC Help
Powered by ViewVC