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

Diff of /jsampler/trunk/src/org/jsampler/view/classic/NewChannelWizard.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 841 by iliev, Mon Oct 10 16:03:12 2005 UTC revision 842 by iliev, Thu Mar 16 18:08:34 2006 UTC
# Line 23  Line 23 
23  package org.jsampler.view.classic;  package org.jsampler.view.classic;
24    
25  import java.awt.Dimension;  import java.awt.Dimension;
26    import java.awt.GridBagConstraints;
27    import java.awt.GridBagLayout;
28    import java.awt.Insets;
29    
30    import java.awt.event.ActionEvent;
31    import java.awt.event.ActionListener;
32    
33  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
34  import javax.swing.Box;  import javax.swing.Box;
35  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
36    import javax.swing.JButton;
37  import javax.swing.JComboBox;  import javax.swing.JComboBox;
38    import javax.swing.JFileChooser;
39  import javax.swing.JLabel;  import javax.swing.JLabel;
40  import javax.swing.JPanel;  import javax.swing.JPanel;
41    import javax.swing.JRadioButton;
42    import javax.swing.ButtonGroup;
43    import javax.swing.JSpinner;
44    import javax.swing.JTextField;
45    import javax.swing.SpinnerNumberModel;
46    
47    import net.sf.juife.JuifeUtils;
48  import net.sf.juife.Wizard;  import net.sf.juife.Wizard;
49    
50  import net.sf.juife.wizard.ConfirmationPage;  import net.sf.juife.event.TaskEvent;
51    import net.sf.juife.event.TaskListener;
52    
53  import net.sf.juife.wizard.DefaultWizardModel;  import net.sf.juife.wizard.DefaultWizardModel;
54  import net.sf.juife.wizard.UserInputPage;  import net.sf.juife.wizard.UserInputPage;
55  import net.sf.juife.wizard.WizardPage;  import net.sf.juife.wizard.WizardPage;
56    
57  import org.jsampler.AudioDeviceModel;  import org.jsampler.AudioDeviceModel;
58  import org.jsampler.CC;  import org.jsampler.CC;
59    import org.jsampler.HF;
60  import org.jsampler.MidiDeviceModel;  import org.jsampler.MidiDeviceModel;
61    
62    import org.jsampler.event.AudioDeviceListEvent;
63    import org.jsampler.event.AudioDeviceListListener;
64    import org.jsampler.event.MidiDeviceListEvent;
65    import org.jsampler.event.MidiDeviceListListener;
66    
67  import org.jsampler.task.AddChannel;  import org.jsampler.task.AddChannel;
68    import org.jsampler.task.LoadEngine;
69    import org.jsampler.task.LoadInstrument;
70    import org.jsampler.task.SetChannelAudioOutputDevice;
71    import org.jsampler.task.SetChannelMidiInputChannel;
72    import org.jsampler.task.SetChannelMidiInputDevice;
73    import org.jsampler.task.SetChannelMidiInputPort;
74    
75    import org.linuxsampler.lscp.AudioOutputDevice;
76    import org.linuxsampler.lscp.MidiInputDevice;
77    import org.linuxsampler.lscp.MidiPort;
78    import org.linuxsampler.lscp.SamplerEngine;
79    
80  import static org.jsampler.view.classic.ClassicI18n.i18n;  import static org.jsampler.view.classic.ClassicI18n.i18n;
81    
# Line 64  public class NewChannelWizard extends Wi Line 97  public class NewChannelWizard extends Wi
97  }  }
98    
99  class NewChannelWizardModel extends DefaultWizardModel {  class NewChannelWizardModel extends DefaultWizardModel {
100          private MidiDeviceWizardPage midiDevicePage = new MidiDeviceWizardPage();          private final MidiDeviceWizardPage midiDevicePage = new MidiDeviceWizardPage();
101          private MidiPortWizardPage midiPortPage = new MidiPortWizardPage();          private final MidiPortWizardPage midiPortPage = new MidiPortWizardPage();
102          private AudioDeviceWizardPage audioDevicePage = new AudioDeviceWizardPage();          private final MidiChannelWizardPage midiChannelPage = new MidiChannelWizardPage();
103          private EngineWizardPage enginePage = new EngineWizardPage();          private final AudioDeviceWizardPage audioDevicePage = new AudioDeviceWizardPage();
104          private InstrumentWizardPage instrumentPage = new InstrumentWizardPage();          private final EngineWizardPage enginePage = new EngineWizardPage();
105          private ConfirmationWizardPage confirmationPage = new ConfirmationWizardPage();          private final InstrumentWizardPage instrumentPage = new InstrumentWizardPage();
106            private final ConfirmationWizardPage confirmationPage = new ConfirmationWizardPage();
107                                                    
108          NewChannelWizardModel() {          NewChannelWizardModel() {
109                  addPage(midiDevicePage);                  addPage(midiDevicePage);
110                  addPage(midiPortPage);                  addPage(midiPortPage);
111                  addStep(i18n.getLabel("NewChannelWizard.step1"), 2);                  addPage(midiChannelPage);
112                    addStep(i18n.getLabel("NewChannelWizard.step1"), 3);
113                                    
114                  addPage(audioDevicePage);                  addPage(audioDevicePage);
115                  addStep(i18n.getLabel("NewChannelWizard.step2"));                  addStep(i18n.getLabel("NewChannelWizard.step2"));
# Line 90  class NewChannelWizardModel extends Defa Line 125  class NewChannelWizardModel extends Defa
125                                    
126                  setLast(confirmationPage);                  setLast(confirmationPage);
127          }          }
128            
129            /**
130             * Moves to the next page in the wizard.
131             * @return The next page in the wizard.
132             */
133            public WizardPage
134            next() {
135                    if(getCurrentPage() == midiDevicePage && !midiDevicePage.getCustomSettings()) {
136                            super.next(); super.next();
137                    }
138                    
139                    return super.next();
140            }
141            
142            /**
143             * Moves to the previous page in the wizard.
144             * @return The previous page in the wizard.
145             * @see #hasPrevious
146             */
147            public WizardPage
148            previous() {
149                    if(getCurrentPage() == audioDevicePage && !midiDevicePage.getCustomSettings()) {
150                            super.previous(); super.previous();
151                    }
152                    
153                    return super.previous();
154            }
155            
156            /**
157             * Gets the selected MIDI device.
158             * @return The selected MIDI device or <code>null</code>
159             * if there is no MIDI device selected.
160             */
161            public MidiInputDevice
162            getSelectedMidiDevice() { return midiDevicePage.getSelectedDevice(); }
163            
164            /**
165             * Determines whether the user chooses to specify custom MIDI device settings.
166             * @return <code>true</code> if the user chooses to specify custom MIDI device settings,
167             * <code>false</code> otherwise.
168             */
169            public boolean
170            getCustomMidiSettings() { return midiDevicePage.getCustomSettings(); }
171            
172            /**
173             * Gets the selected MIDI input port.
174             * @return The selected MIDI input port.
175             */
176            public MidiPort
177            getSelectedMidiPort() { return midiPortPage.getSelectedPort(); }
178            
179            /**
180             * Gets the selected MIDI channel.
181             * @return The number of the selected MIDI channel or -1 which means all channels.
182             */
183            public int
184            getSelectedMidiChannel() { return midiChannelPage.getSelectedChannel(); }
185            
186            /**
187             * Gets the selected audio device.
188             * @return The selected audio device or <code>null</code> if there is no device selected.
189             */
190            public AudioOutputDevice
191            getSelectedAudioDevice() { return audioDevicePage.getSelectedDevice(); }
192            
193            /**
194             * Gets the selected sampler engine to be used.
195             * @return The selected sampler engine to be used.
196             */
197            public SamplerEngine
198            getSelectedEngine() { return enginePage.getSelectedEngine(); }
199            
200            /**
201             * Gets the name of the selected instrument file.
202             * @return The name of the selected instrument file.
203             */
204            public String
205            getSelectedFile() { return instrumentPage.getSelectedFile(); }
206            
207            /**
208             * Gets the index of the instrument in the instrument file.
209             * @return The index of the instrument in the instrument file.
210             */
211            public int
212            getInstrumentIndex() { return instrumentPage.getInstrumentIndex(); }
213  }  }
214    
215  class MidiDeviceWizardPage extends UserInputPage {  class MidiDeviceWizardPage extends UserInputPage {
216          private final JLabel lDevice = new JLabel(i18n.getLabel("MidiDeviceWizardPage.lDevice"));          private final JLabel lDevice = new JLabel(i18n.getLabel("MidiDeviceWizardPage.lDevice"));
217          private final JComboBox cbDevices = new JComboBox();          private final JComboBox cbDevices = new JComboBox();
218            private final JButton btnNewDevice =
219                    new JButton(i18n.getButtonLabel("MidiDeviceWizardPage.btnNewDevice"));
220            private final JRadioButton rbDefaultSettings =
221                    new JRadioButton(i18n.getButtonLabel("MidiDeviceWizardPage.rbDefaultSettings"));
222            private final JRadioButton rbCustomSettings =
223                    new JRadioButton(i18n.getButtonLabel("MidiDeviceWizardPage.rbCustomSettings"));
224                    
225          MidiDeviceWizardPage() {          MidiDeviceWizardPage() {
226                  super(i18n.getLabel("MidiDeviceWizardPage.subtitle"));                  super(i18n.getLabel("MidiDeviceWizardPage.subtitle"));
# Line 113  class MidiDeviceWizardPage extends UserI Line 239  class MidiDeviceWizardPage extends UserI
239                  }                  }
240                                    
241                  cbDevices.setMaximumSize(cbDevices.getPreferredSize());                  cbDevices.setMaximumSize(cbDevices.getPreferredSize());
242                    if(cbDevices.getItemCount() == 0) enableDevComp(false);
243                                    
244                  p.add(cbDevices);                  p.add(cbDevices);
245                                    
246                  setMainPane(p);                  CC.getSamplerModel().addMidiDeviceListListener(getHandler());
247                    
248                    p.add(Box.createRigidArea(new Dimension(12, 0)));
249                    p.add(btnNewDevice);
250                    p.setAlignmentX(JPanel.LEFT_ALIGNMENT);
251                    
252                    JPanel mainPane = new JPanel();
253                    mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
254                    mainPane.add(p);
255                    
256                    mainPane.add(Box.createRigidArea(new Dimension(0, 6)));
257                    
258                    rbDefaultSettings.setAlignmentX(JPanel.LEFT_ALIGNMENT);
259                    mainPane.add(rbDefaultSettings);
260                    rbCustomSettings.setAlignmentX(JPanel.LEFT_ALIGNMENT);
261                    mainPane.add(rbCustomSettings);
262                    
263                    ButtonGroup btnGroup = new ButtonGroup();
264                    btnGroup.add(rbDefaultSettings);
265                    btnGroup.add(rbCustomSettings);
266                    rbDefaultSettings.setSelected(true);
267                    
268                    setMainPane(mainPane);
269                    
270                    btnNewDevice.addActionListener(new ActionListener() {
271                            public void
272                            actionPerformed(ActionEvent e) {
273                                    new NewMidiDeviceDlg(getWizardDialog()).setVisible(true);
274                            }
275                    });
276            }
277            
278            /**
279             * Gets the selected device.
280             * @return The selected device or <code>null</code> if there is no device selected.
281             */
282            public MidiInputDevice
283            getSelectedDevice() { return (MidiInputDevice)cbDevices.getSelectedItem(); }
284            
285            private void
286            enableDevComp(boolean b) {
287                    cbDevices.setEnabled(b);
288                    rbDefaultSettings.setEnabled(b);
289                    rbCustomSettings.setEnabled(b);
290            }
291            
292            /**
293             * Determines whether the user chooses to specify custom device settings.
294             * @return <code>true</code> if the user chooses to specify custom device settings,
295             * <code>false</code> otherwise.
296             */
297            public boolean
298            getCustomSettings() { return rbCustomSettings.isSelected(); }
299            
300            private final Handler handler = new Handler();
301            
302            private Handler
303            getHandler() { return handler; }
304            
305            private class Handler implements MidiDeviceListListener {
306                    public void
307                    deviceAdded(MidiDeviceListEvent e) {
308                            updateDeviceList(e.getMidiDeviceModel().getDeviceInfo());
309                    }
310            
311                    public void
312                    deviceRemoved(MidiDeviceListEvent e) { updateDeviceList(null); }
313                            
314                    private void
315                    updateDeviceList(MidiInputDevice dev) {
316                            cbDevices.removeAllItems();
317                            
318                            for(MidiDeviceModel m : CC.getSamplerModel().getMidiDeviceModels()) {
319                                    cbDevices.addItem(m.getDeviceInfo());
320                            }
321                            
322                            if(cbDevices.getItemCount() == 0) enableDevComp(false);
323                            else {
324                                    enableDevComp(true);
325                                    cbDevices.setSelectedItem(dev);
326                            }
327                            cbDevices.setMaximumSize(cbDevices.getPreferredSize());
328                    }
329          }          }
330  }  }
331    
# Line 142  class MidiPortWizardPage extends UserInp Line 351  class MidiPortWizardPage extends UserInp
351                                    
352                  setMainPane(p);                  setMainPane(p);
353          }          }
354            
355            public void
356            initPage() {
357                    updatePorts(((NewChannelWizardModel)getWizardModel()).getSelectedMidiDevice());
358            }
359            
360            /**
361             * Gets the selected MIDI input port.
362             * @return The selected MIDI input port.
363             */
364            public MidiPort
365            getSelectedPort() { return (MidiPort)cbPorts.getSelectedItem(); }
366            
367            public void
368            updatePorts(MidiInputDevice dev) {
369                    Object current = cbPorts.getSelectedItem();
370                    cbPorts.removeAllItems();
371                    
372                    if(dev != null) for(MidiPort p : dev.getMidiPorts()) cbPorts.addItem(p);
373                    if(current != null) cbPorts.setSelectedItem(current);
374                    cbPorts.setEnabled(cbPorts.getItemCount() > 0);
375                    cbPorts.setMaximumSize(cbPorts.getPreferredSize());
376            }
377    }
378    
379    class MidiChannelWizardPage extends UserInputPage {
380            private final JLabel lChannel = new JLabel(i18n.getLabel("MidiChannelWizardPage.lChannel"));
381            private final JComboBox cbChannels = new JComboBox();
382            
383            MidiChannelWizardPage() {
384                    super(i18n.getLabel("MidiChannelWizardPage.subtitle"));
385                    
386                    setMainInstructions(i18n.getLabel("MidiChannelWizardPage.mainInstructions"));
387                    
388                    JPanel p = new JPanel();
389                    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
390                    
391                    p.add(lChannel);
392                    
393                    p.add(Box.createRigidArea(new Dimension(6, 0)));
394                    
395                    cbChannels.addItem("All");
396                    for(int i = 1; i <= 16; i++) cbChannels.addItem(String.valueOf(i));
397                    cbChannels.setMaximumSize(cbChannels.getPreferredSize());
398                    
399                    p.add(cbChannels);
400                    
401                    setMainPane(p);
402            }
403            
404            /**
405             * Gets the selected MIDI channel.
406             * @return The number of the selected MIDI channel or -1 which means all channels.
407             */
408            public int
409            getSelectedChannel() {
410                    Object o = cbChannels.getSelectedItem();
411                    if(o == null) return -1;
412                    
413                    return o.toString().equals("All") ? -1 : Integer.parseInt(o.toString());
414            }
415  }  }
416    
417  class AudioDeviceWizardPage extends UserInputPage {  class AudioDeviceWizardPage extends UserInputPage {
418          private final JLabel lDevice = new JLabel(i18n.getLabel("AudioDeviceWizardPage.lDevice"));          private final JLabel lDevice = new JLabel(i18n.getLabel("AudioDeviceWizardPage.lDevice"));
419          private final JComboBox cbDevices = new JComboBox();          private final JComboBox cbDevices = new JComboBox();
420            private final JButton btnNewDevice =
421                    new JButton(i18n.getButtonLabel("AudioDeviceWizardPage.btnNewDevice"));
422                    
423          AudioDeviceWizardPage() {          AudioDeviceWizardPage() {
424                  super(i18n.getLabel("AudioDeviceWizardPage.subtitle"));                  super(i18n.getLabel("AudioDeviceWizardPage.subtitle"));
425                                    
426                  setMainInstructions(i18n.getLabel("AudioDeviceWizardPage.mainInstructions"));                  setMainInstructions(i18n.getLabel("AudioDeviceWizardPage.mainInstructions"));
427                    setAdditionalInstructions (
428                            i18n.getLabel("AudioDeviceWizardPage.additionalInstructions")
429                    );
430                                    
431                  JPanel p = new JPanel();                  JPanel p = new JPanel();
432                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                  p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
# Line 165  class AudioDeviceWizardPage extends User Line 440  class AudioDeviceWizardPage extends User
440                  }                  }
441                                    
442                  cbDevices.setMaximumSize(cbDevices.getPreferredSize());                  cbDevices.setMaximumSize(cbDevices.getPreferredSize());
443                    if(cbDevices.getItemCount() == 0) cbDevices.setEnabled(false);
444                                    
445                  p.add(cbDevices);                  p.add(cbDevices);
446                                    
447                    CC.getSamplerModel().addAudioDeviceListListener(getHandler());
448                    
449                    p.add(Box.createRigidArea(new Dimension(12, 0)));
450                    p.add(btnNewDevice);
451                    
452                  setMainPane(p);                  setMainPane(p);
453                    
454                    btnNewDevice.addActionListener(new ActionListener() {
455                            public void
456                            actionPerformed(ActionEvent e) {
457                                    new NewAudioDeviceDlg(getWizardDialog()).setVisible(true);
458                            }
459                    });
460            }
461            
462            /**
463             * Gets the selected device.
464             * @return The selected device or <code>null</code> if there is no device selected.
465             */
466            public AudioOutputDevice
467            getSelectedDevice() { return (AudioOutputDevice)cbDevices.getSelectedItem(); }
468            
469            private final Handler handler = new Handler();
470            
471            private Handler
472            getHandler() { return handler; }
473            
474            private class Handler implements AudioDeviceListListener {
475                    public void
476                    deviceAdded(AudioDeviceListEvent e) {
477                            updateDeviceList(e.getAudioDeviceModel().getDeviceInfo());
478                    }
479            
480                    public void
481                    deviceRemoved(AudioDeviceListEvent e) { updateDeviceList(null); }
482                            
483                    private void
484                    updateDeviceList(AudioOutputDevice dev) {
485                            cbDevices.removeAllItems();
486                            
487                            for(AudioDeviceModel m : CC.getSamplerModel().getAudioDeviceModels()) {
488                                    cbDevices.addItem(m.getDeviceInfo());
489                            }
490                            
491                            if(cbDevices.getItemCount() == 0) cbDevices.setEnabled(false);
492                            else {
493                                    cbDevices.setEnabled(true);
494                                    cbDevices.setSelectedItem(dev);
495                            }
496                            cbDevices.setMaximumSize(cbDevices.getPreferredSize());
497                    }
498          }          }
499  }  }
500    
# Line 179  class EngineWizardPage extends UserInput Line 505  class EngineWizardPage extends UserInput
505          EngineWizardPage() {          EngineWizardPage() {
506                  super(i18n.getLabel("EngineWizardPage.subtitle"));                  super(i18n.getLabel("EngineWizardPage.subtitle"));
507                                    
                 setOptionalButtons(OptionalButtons.LAST);  
                   
508                  setMainInstructions(i18n.getLabel("EngineWizardPage.mainInstructions"));                  setMainInstructions(i18n.getLabel("EngineWizardPage.mainInstructions"));
509                                    
510                  JPanel p = new JPanel();                  JPanel p = new JPanel();
# Line 200  class EngineWizardPage extends UserInput Line 524  class EngineWizardPage extends UserInput
524                                    
525                  setMainPane(p);                  setMainPane(p);
526          }          }
527            
528            /**
529             * Gets the selected sampler engine to be used.
530             * @return The selected sampler engine to be used.
531             */
532            public SamplerEngine
533            getSelectedEngine() { return (SamplerEngine)cbEngines.getSelectedItem(); }
534  }  }
535    
536  class InstrumentWizardPage extends UserInputPage {  class InstrumentWizardPage extends UserInputPage {
537            private final JLabel lFilename = new JLabel(i18n.getLabel("InstrumentChooser.lFilename"));
538            private final JLabel lIndex = new JLabel(i18n.getLabel("InstrumentChooser.lIndex"));
539            
540            private final JTextField tfFilename = new JTextField();
541            private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1));
542            
543            private final JButton btnBrowse =
544                    new JButton(i18n.getLabel("InstrumentChooser.btnBrowse"));
545            
546                    
547          InstrumentWizardPage() {          InstrumentWizardPage() {
548                  super(i18n.getLabel("InstrumentWizardPage.subtitle"));                  super(i18n.getLabel("InstrumentWizardPage.subtitle"));
549                                    
550                  setMainInstructions(i18n.getLabel("InstrumentWizardPage.mainInstructions"));                  setMainInstructions(i18n.getLabel("InstrumentWizardPage.mainInstructions"));
551                    
552                    JPanel p = new JPanel();
553                    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
554                    
555                    p.add(lFilename);
556                    
557                    p.add(Box.createRigidArea(new Dimension(6, 0)));
558                    
559                    tfFilename.setPreferredSize (
560                            new Dimension(200, tfFilename.getPreferredSize().height)
561                    );
562                    tfFilename.setMaximumSize(tfFilename.getPreferredSize());
563                    p.add(tfFilename);
564                    
565                    p.add(Box.createRigidArea(new Dimension(6, 0)));
566                    
567                    spinnerIndex.setMaximumSize(spinnerIndex.getPreferredSize());
568                    p.add(spinnerIndex);
569                    
570                    p.add(Box.createRigidArea(new Dimension(6, 0)));
571                    
572                    p.add(btnBrowse);
573                    
574                    p.setMaximumSize(p.getPreferredSize());
575                    setMainPane(p);
576                    
577                    btnBrowse.addActionListener(new ActionListener() {
578                            public void
579                            actionPerformed(ActionEvent e) { onBrowse(); }
580                    });
581                    
582                    btnBrowse.requestFocusInWindow();
583            }
584            
585            public void
586            initPage() {
587                    NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel();
588                    if(model.getSelectedAudioDevice() == null) {
589                            String s = i18n.getLabel("InstrumentWizardPage.additionalInstructions");
590                            setAdditionalInstructions(s);
591                    } else {
592                            System.out.println("Exo");
593                            setAdditionalInstructions("");
594                    }
595            }
596            
597            public boolean
598            mayGoToNext() {
599                    NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel();
600                    if(model.getSelectedAudioDevice() == null && getSelectedFile().length() > 0) {
601                            String s = i18n.getError("InstrumentWizardPage.selectAODevice!");
602                            HF.showErrorMessage(s, getWizardDialog());
603                            return false;
604                    } else {
605                            return true;
606                    }
607            }
608            
609            /**
610             * Gets the name of the instrument file.
611             * @return The name of the instrument file.
612             */
613            public String
614            getSelectedFile() { return tfFilename.getText(); }
615            
616            /**
617             * Gets the index of the instrument in the instrument file.
618             * @return The index of the instrument in the instrument file.
619             */
620            public int
621            getInstrumentIndex() { return Integer.parseInt(spinnerIndex.getValue().toString()); }
622            
623            private void
624            onBrowse() {
625                    JFileChooser fc = new JFileChooser();
626                    int result = fc.showOpenDialog(this);
627                    if(result == JFileChooser.APPROVE_OPTION) {
628                            tfFilename.setText(fc.getSelectedFile().getPath());
629                    }
630          }          }
631  }  }
632    
633  class ConfirmationWizardPage extends ConfirmationPage {  class ConfirmationWizardPage extends WizardPage {
634            private MidiInputDevice midiDev = null;
635            private MidiPort midiPort = null;
636            private int midiChannel = -1;
637            private AudioOutputDevice audioDev = null;
638            private SamplerEngine engine = null;
639            private String instrFile = null;
640            private int instrIndex;
641            
642            private final JLabel lInfo = new JLabel(i18n.getLabel("ConfirmationWizardPage.lInfo"));
643            
644            private final JLabel lMidiDevice =
645                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiDevice"));
646            private final JLabel lMidiPort =
647                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiPort"));
648            private final JLabel lMidiChannel =
649                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lMidiChannel"));
650            private final JLabel lEngine =
651                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lEngine"));
652            private final JLabel lInstrFile =
653                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lInstrFile"));
654            private final JLabel lInstrIndex =
655                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lInstrIndex"));
656            private final JLabel lAudioDevice =
657                    new JLabel(i18n.getLabel("ConfirmationWizardPage.lAudioDevice"));
658            
659            private final JTextField tfMidiDevice = new EnhancedTextField();
660            private final JTextField tfMidiPort = new EnhancedTextField();
661            private final JTextField tfMidiChannel = new EnhancedTextField();
662            private final JTextField tfEngine = new EnhancedTextField();
663            private final JTextField tfInstrFile = new EnhancedTextField();
664            private final JTextField tfInstrIndex = new EnhancedTextField();
665            private final JTextField tfAudioDevice = new EnhancedTextField();
666                    
667          ConfirmationWizardPage() {          ConfirmationWizardPage() {
668                  //super(i18n.getLabel("ConfirmationWizardPage.subtitle"));                  super(i18n.getLabel("ConfirmationWizardPage.subtitle"), "", Type.CONFIRMATION_PAGE);
669                    
670                    GridBagLayout gridbag = new GridBagLayout();
671                    GridBagConstraints c = new GridBagConstraints();
672                    
673                    //JPanel mainPane = new JPanel();
674                    
675                    setLayout(gridbag);
676                    
677                    c.fill = GridBagConstraints.NONE;
678                    
679                    c.gridx = 0;
680                    c.gridy = 1;
681                    c.anchor = GridBagConstraints.EAST;
682                    c.insets = new Insets(3, 3, 3, 3);
683                    gridbag.setConstraints(lMidiDevice, c);
684                    add(lMidiDevice);
685                    
686                    c.gridx = 0;
687                    c.gridy = 2;
688                    gridbag.setConstraints(lMidiPort, c);
689                    add(lMidiPort);
690                    
691                    c.gridx = 0;
692                    c.gridy = 3;
693                    gridbag.setConstraints(lMidiChannel, c);
694                    add(lMidiChannel);
695                    
696                    c.gridx = 0;
697                    c.gridy = 4;
698                    gridbag.setConstraints(lEngine, c);
699                    add(lEngine);
700                    
701                    c.gridx = 0;
702                    c.gridy = 5;
703                    gridbag.setConstraints(lInstrFile, c);
704                    add(lInstrFile);
705                    
706                    c.gridx = 0;
707                    c.gridy = 6;
708                    gridbag.setConstraints(lInstrIndex, c);
709                    add(lInstrIndex);
710                    
711                    c.gridx = 0;
712                    c.gridy = 7;
713                    gridbag.setConstraints(lAudioDevice, c);
714                    add(lAudioDevice);
715                    
716                    c.fill = GridBagConstraints.HORIZONTAL;
717                    c.gridx = 1;
718                    c.gridy = 1;
719                    c.weightx = 1.0;
720                    c.anchor = GridBagConstraints.WEST;
721                    gridbag.setConstraints(tfMidiDevice, c);
722                    add(tfMidiDevice);
723                            
724                    c.gridx = 1;
725                    c.gridy = 2;
726                    gridbag.setConstraints(tfMidiPort, c);
727                    add(tfMidiPort);
728                    
729                    c.gridx = 1;
730                    c.gridy = 3;
731                    gridbag.setConstraints(tfMidiChannel, c);
732                    add(tfMidiChannel);
733                    
734                    c.gridx = 1;
735                    c.gridy = 4;
736                    gridbag.setConstraints(tfEngine, c);
737                    add(tfEngine);
738                    
739                    c.gridx = 1;
740                    c.gridy = 5;
741                    gridbag.setConstraints(tfInstrFile, c);
742                    add(tfInstrFile);
743                    
744                    c.gridx = 1;
745                    c.gridy = 6;
746                    gridbag.setConstraints(tfInstrIndex, c);
747                    add(tfInstrIndex);
748                    
749                    c.gridx = 1;
750                    c.gridy = 7;
751                    gridbag.setConstraints(tfAudioDevice, c);
752                    add(tfAudioDevice);
753                    
754                    lInfo.setFont(lInfo.getFont().deriveFont(java.awt.Font.PLAIN));
755                    
756                    c.gridx = 0;
757                    c.gridy = 0;
758                    c.gridwidth = 2;
759                    c.insets = new Insets(12, 3, 17, 3);
760                    c.anchor = GridBagConstraints.NORTH;
761                    gridbag.setConstraints(lInfo, c);
762                    add(lInfo);
763                    
764                    JPanel p = new JPanel();
765                    p.setOpaque(false);
766                    c.gridx = 0;
767                    c.gridy = 8;
768                    c.weightx = 1.0;
769                    c.weighty = 1.0;
770                    c.insets = new Insets(0, 0, 0, 0);
771                    gridbag.setConstraints(p, c);
772                    add(p);
773                                    
774                  setPageType(Type.CONFIRMATION_PAGE);          }
775            
776            public void
777            initPage() {
778                    NewChannelWizardModel model = (NewChannelWizardModel)getWizardModel();
779                    setMidiDevice(model.getSelectedMidiDevice());
780                    
781                    
782                    if(model.getCustomMidiSettings()) {
783                            setMidiPort(model.getSelectedMidiPort());
784                            setMidiChannel(model.getSelectedMidiChannel());
785                    } else {
786                            MidiInputDevice mdev = model.getSelectedMidiDevice();
787                            if(mdev == null) setMidiPort(null);
788                            else if(mdev.getMidiPorts().length < 1) setMidiPort(null);
789                            else setMidiPort(mdev.getMidiPort(0));
790                            
791                            setMidiChannel(-1);
792                    }
793                    
794                    setEngine(model.getSelectedEngine());
795                    setAudioDevice(model.getSelectedAudioDevice());
796                    setInstrumentFile(model.getSelectedFile());
797                    setInstrumentIndex(model.getInstrumentIndex());
798          }          }
799                    
800          /**          /**
# Line 226  class ConfirmationWizardPage extends Con Line 804  class ConfirmationWizardPage extends Con
804           */           */
805          public boolean          public boolean
806          mayFinish() {          mayFinish() {
807                  CC.getTaskQueue().add(new AddChannel());                  final AddChannel ac = new AddChannel();
808                    
809                    ac.addTaskListener(new TaskListener() {
810                            public void
811                            taskPerformed(TaskEvent e) {
812                                    if(ac.doneWithErrors()) return;
813                                    doIt(ac.getResult());
814                            }
815                    });
816                    
817                    CC.getTaskQueue().add(ac);
818                                    
819                  return true;                  return true;
820          }          }
821            
822            private void
823            doIt(int chn) {
824                    if(getEngine() != null)
825                            CC.getTaskQueue().add(new LoadEngine(getEngine().getName(), chn));
826                    
827                    /*if(getMidiDPort() != null) CC.getTaskQueue().add (
828                            new SetChannelMidiInputPort(chn, getMidiPort().)
829                    );*/
830                    
831                    MidiInputDevice d = getMidiDevice();
832                    if(d != null) {
833                            CC.getTaskQueue().add(new SetChannelMidiInputDevice(chn, d.getDeviceID()));
834                            
835                            if(getMidiPort() != null) {
836                                    int port = -1;
837                                    for(int i = 0; i < d.getMidiPortCount(); i++) {
838                                            if(d.getMidiPort(i) == getMidiPort()) {
839                                                    port = i;
840                                                    break;
841                                            }
842                                    }
843                                    
844                                    if(port != -1) CC.getTaskQueue().add (
845                                            new SetChannelMidiInputPort(chn, port)
846                                    );
847                            }
848                            
849                    
850                            int mc = (getMidiChannel() == -1 ? -1 : getMidiChannel() - 1);
851                            CC.getTaskQueue().add(new SetChannelMidiInputChannel(chn, mc));
852                    }
853                            
854                            
855                    
856                    if(getAudioDevice() != null) CC.getTaskQueue().add (
857                            new SetChannelAudioOutputDevice(chn, getAudioDevice().getDeviceID())
858                    );
859                    
860                    if(getInstrumentFile().length() > 0) CC.getTaskQueue().add (
861                            new LoadInstrument(getInstrumentFile(), getInstrumentIndex(), chn)
862                    );
863            }
864            
865            /**
866             * Gets the audio output device to be used by this sampler channel.
867             * @return The audio output device to be used by this sampler channel.
868             */
869            public AudioOutputDevice
870            getAudioDevice() { return audioDev; }
871            
872            /**
873             * Sets the audio output device to be used by this sampler channel.
874             * @param dev The audio output device to be used by this sampler channel.
875             */
876            public void
877            setAudioDevice(AudioOutputDevice dev) {
878                    audioDev = dev;
879                    if(dev == null) {
880                            tfAudioDevice.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified"));
881                    } else {
882                            tfAudioDevice.setText(dev.getDeviceID() + " (" + dev.getDriverName() + ")");
883                    }
884            }
885            
886            /**
887             * Gets the sampler engine to be used.
888             * @return The sampler engine to be used.
889             */
890            public SamplerEngine
891            getEngine() { return engine; }
892            
893            /**
894             * Sets the sampler engine to be used.
895             * @param engine The sampler engine to be used.
896             */
897            public void
898            setEngine(SamplerEngine engine) {
899                    this.engine = engine;
900                    if(engine == null) {
901                            tfEngine.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified"));
902                    } else {
903                            tfEngine.setText(engine.getName() + " (" + engine.getDescription() + ")");
904                    }
905            }
906            
907            /**
908             * Gets the name of the instrument file.
909             * @return The name of the instrument file.
910             */
911            public String
912            getInstrumentFile() { return instrFile; }
913            
914            /**
915             * Sets the name of the instrument file.
916             * @param file The name of the instrument file.
917             */
918            public void
919            setInstrumentFile(String file) {
920                    instrFile = file;
921                    
922                    if(file.length() == 0)  {
923                            tfInstrFile.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified"));
924                    } else {
925                            tfInstrFile.setText(file);
926                    }
927            }
928            
929            /**
930             * Gets the index of the instrument in the instrument file.
931             * @return The index of the instrument in the instrument file.
932             */
933            public int
934            getInstrumentIndex() { return instrIndex; }
935            
936            /**
937             * Sets the index of the instrument in the instrument file.
938             * @param idx The index of the instrument in the instrument file.
939             */
940            public void
941            setInstrumentIndex(int idx) {
942                    instrIndex = idx;
943                    tfInstrIndex.setText(String.valueOf(idx));
944            }
945            
946            /**
947             * Gets the MIDI channel to which this sampler channel will listen to.
948             * @return The MIDI channel to which this sampler channel will listen to
949             * (-1 means all channels).
950             * .
951             */
952            public int
953            getMidiChannel() { return midiChannel; }
954            
955            /**
956             * Sets the MIDI channel to which this sampler channel will listen to.
957             * @param chn The MIDI channel to which this sampler channel will listen to
958             * (-1 means all channels).
959             * .
960             */
961            public void
962            setMidiChannel(int chn) {
963                    midiChannel = chn;
964                    tfMidiChannel.setText(chn == -1 ? "All" : String.valueOf(chn));
965            }
966            
967            /**
968             * Gets the MIDI input device to which this sampler channel will be connected to.
969             * @return The MIDI input device to which this sampler channel will be connected to.
970             */
971            public MidiInputDevice
972            getMidiDevice() { return midiDev; }
973            
974            /**
975             * Sets the MIDI input device to which this sampler channel will be connected to.
976             * @param dev The numerical id of the MIDI input device to which
977             * this sampler channel will be connected to.
978             */
979            public void
980            setMidiDevice(MidiInputDevice dev) {
981                    midiDev = dev;
982                    
983                    if(dev == null) {
984                            tfMidiDevice.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified"));
985                    } else {
986                            tfMidiDevice.setText(dev.getDeviceID() + " (" + dev.getDriverName() + ")");
987                    }
988            }
989            
990            /**
991             * Gets the MIDI input port.
992             * @return The MIDI input port.
993             */
994            public MidiPort
995            getMidiPort() { return midiPort; }
996            
997            /**
998             * Sets the MIDI input port.
999             * @param port The MIDI input port.
1000             */
1001            public void
1002            setMidiPort(MidiPort port) {
1003                    midiPort = port;
1004                    
1005                    if(port == null) {
1006                            tfMidiPort.setText(i18n.getLabel("ConfirmationWizardPage.notSpecified"));
1007                    } else {
1008                            tfMidiPort.setText(port.getName());
1009                    }
1010            }
1011            
1012            private class EnhancedTextField extends JTextField {
1013                    EnhancedTextField() {
1014                            setEditable(false);
1015                            setBorder(BorderFactory.createEmptyBorder());
1016                    }
1017            }
1018  }  }

Legend:
Removed from v.841  
changed lines
  Added in v.842

  ViewVC Help
Powered by ViewVC