3 import java.awt.event.*;
4 import javax.sound.midi.*;
9 * A generator class for the application's dialogs.
11 * @author Björn Lanneskog
14 public class MooDialog extends JDialog {
16 private JLabel labelA, labelB, labelC, labelD, labelE, labelF, labelG, labelH;
17 private JTextField textFieldA, textFieldB, textFieldC, textFieldD, textFieldE,
18 textFieldF, textFieldG, textFieldH, textFieldI, textFieldJ,
20 private JComboBox trackListA, trackListB;
21 private JButton okButton, cancelButton;
22 public static final int ADD_TRACK = 1,
36 * Constructor of the dialogs.
38 public MooDialog(int type) {
39 super(Moosique.getGUI(), false);
41 Container pane = getContentPane();
44 Track[] tracks = Moosique.getSequence().getTracks();
47 case ADD_TRACK: makeAddDialog(pane, tracks); break;
48 case DELETE_TRACK: makeDelDialog(pane, tracks); break;
49 case COPY_TRACK: makeCopyDialog(pane, tracks); break;
50 case MOVE_TRACK: makeMoveDialog(pane, tracks); break;
51 case SET_POSITION: makeSetPositionDialog(pane); break;
52 case MANUAL: makeTextDialog(pane, "Manual.txt"); break;
53 case INSERT_MEASURE: makeInsertMeasureDialog(pane); break;
54 case DELETE_MEASURE: makeDeleteMeasureDialog(pane); break;
55 case SET_TEMPO: makeSetTempoDialog(pane); break;
56 case PREFERENCES: makePrefsDialog(pane); break;
57 case TRANSPOSE: makeTransposeDialog(pane, tracks); break;
58 case SCALE_VELOCITY: makeScaleVelocityDialog(pane, tracks); break;
63 * Builds the add track popupdialog.
64 * @param pane The container to put the dialog in.
65 * @param tracks A array containing miditracks.
67 private void makeAddDialog(Container pane, Track[] tracks) {
68 setTitle("Add track");
69 // create the contents of the dialog and add to container
70 labelA = new JLabel("Name of track", JLabel.CENTER);
72 // textfield for naming track
73 textFieldA = new JTextField();
75 labelB = new JLabel("Add after", JLabel.CENTER);
77 // list of where to add track
78 trackListA = new JComboBox();
79 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
81 // ok and cancel button
82 cancelButton = new JButton("Cancel");
83 pane.add(cancelButton);
84 okButton = new JButton("OK");
87 labelA.setBounds(50, 10, 100, 20);
88 textFieldA.setBounds(40, 35, 120, 20);
89 labelB.setBounds(50, 70, 100, 20);
90 trackListA.setBounds(40, 95, 120, 20);
91 cancelButton.setBounds(10, 150, 80, 30);
92 okButton.setBounds(120, 150, 60, 30);
96 setLocationRelativeTo(Moosique.getGUI());
101 * Builds the delete track popupdialog.
102 * @param pane The container to put the dialog in.
103 * @param tracks A array containing miditracks.
105 private void makeDelDialog(Container pane, Track[] tracks) {
106 setTitle("Delete track");
107 // create the contents of the dialog and add to container
108 labelB = new JLabel("Delete track", JLabel.CENTER);
110 // list of what track to delete
111 trackListA = new JComboBox();
112 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
113 pane.add(trackListA);
114 // ok and cancelbutton
115 cancelButton = new JButton("Cancel");
116 pane.add(cancelButton);
117 okButton = new JButton("OK");
120 labelB.setBounds(50, 10, 100, 20);
121 trackListA.setBounds(40, 35, 120, 20);
122 cancelButton.setBounds(10, 90, 80, 30);
123 okButton.setBounds(120, 90, 60, 30);
127 setLocationRelativeTo(Moosique.getGUI());
132 * Builds the copy track popupdialog.
133 * @param pane The container to put the dialog in.
134 * @param tracks A array containing miditracks.
136 private void makeCopyDialog(Container pane, Track[] tracks) {
137 setTitle("Copy Track");
138 // create the contents of the dialog and add to container
139 labelA = new JLabel("Track to copy", JLabel.CENTER);
141 // list of what track to copy
142 trackListA = new JComboBox();
143 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
144 pane.add(trackListA);
145 labelB = new JLabel("Insert after", JLabel.CENTER);
147 // list of where to put copied track
148 trackListB = new JComboBox();
149 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
150 pane.add(trackListB);
151 cancelButton = new JButton("Cancel");
152 pane.add(cancelButton);
153 okButton = new JButton("OK");
156 labelA.setBounds(50, 10, 100, 20);
157 trackListA.setBounds(40, 35, 120, 20);
158 labelB.setBounds(50, 70, 100, 20);
159 trackListB.setBounds(40, 95, 120, 20);
160 cancelButton.setBounds(10, 150, 80, 30);
161 okButton.setBounds(120, 150, 60, 30);
165 setLocationRelativeTo(Moosique.getGUI());
170 * Builds the move track popupdialog
171 * @param pane The container to put the dialog in.
172 * @param tracks A array containing miditracks.
174 private void makeMoveDialog(Container pane, Track[] tracks) {
175 setTitle("Move track");
176 // create the contents of the dialog and add to container
177 labelA = new JLabel("Track to move", JLabel.CENTER);
179 // list of track to move
180 trackListA = new JComboBox();
181 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
182 pane.add(trackListA);
183 labelB = new JLabel("Insert after", JLabel.CENTER);
185 // list of where to put moved track
186 trackListB = new JComboBox();
187 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
188 pane.add(trackListB);
189 // ok and cancelbuttons
190 cancelButton = new JButton("Cancel");
191 pane.add(cancelButton);
192 okButton = new JButton("OK");
195 labelA.setBounds(40, 10, 120, 20);
196 trackListA.setBounds(40, 35, 120, 20);
197 labelB.setBounds(50, 70, 100, 20);
198 trackListB.setBounds(40, 95, 120, 20);
199 cancelButton.setBounds(10, 150, 80, 30);
200 okButton.setBounds(120, 150, 60, 30);
204 setLocationRelativeTo(Moosique.getGUI());
209 * Builds the set position dialog.
210 * @param pane The container to put the dialog in.
211 * @param tracks A array containing miditracks.
213 private void makeSetPositionDialog(Container pane) {
215 setTitle("Set edit position");
216 // create the contents of the dialog and add to container
217 labelA = new JLabel("Measure", JLabel.CENTER);
219 labelB = new JLabel("Beat", JLabel.CENTER);
221 labelC = new JLabel("Tick", JLabel.CENTER);
223 textFieldA = new JTextField();
224 pane.add(textFieldA);
225 textFieldB = new JTextField();
226 pane.add(textFieldB);
227 textFieldC = new JTextField();
228 pane.add(textFieldC);
229 // ok and cancel buttons
230 cancelButton = new JButton("Cancel");
231 pane.add(cancelButton);
232 okButton = new JButton("OK");
235 labelA.setBounds(40, 25, 50, 20);
236 labelB.setBounds(105, 25, 50, 20);
237 labelC.setBounds(170, 25, 50, 20);
238 textFieldA.setBounds(40, 45, 50, 20);
239 textFieldB.setBounds(105, 45, 50, 20);
240 textFieldC.setBounds(170, 45, 50, 20);
241 cancelButton.setBounds(35, 90, 80, 30);
242 okButton.setBounds(155, 90, 60, 30);
246 setLocationRelativeTo(Moosique.getGUI());
251 * Builds the insert measure popupdialog.
252 * @param pane The container to put the dialog in.
254 private void makeInsertMeasureDialog(Container pane){
255 setTitle("Insert Measure");
256 // create the contents of the dialog and add to container
257 labelA = new JLabel("Insert at:", JLabel.RIGHT);
259 labelB = new JLabel("Measure count:", JLabel.RIGHT);
261 textFieldA = new JTextField();
262 pane.add(textFieldA);
263 textFieldB = new JTextField();
264 pane.add(textFieldB);
265 // ok and cancelbutton
266 cancelButton = new JButton("Cancel");
267 pane.add(cancelButton);
268 okButton = new JButton("OK");
271 labelA.setBounds(20, 20, 110 ,20);
272 labelB.setBounds(20, 50, 110, 20);
273 textFieldA.setBounds(140 ,20 , 40, 20);
274 textFieldB.setBounds(140,50, 40, 20);
275 cancelButton.setBounds(20 ,95 , 80, 30);
276 okButton.setBounds(120, 95, 60, 30);
280 setLocationRelativeTo(Moosique.getGUI());
285 * Builds the delete measure popupdialog.
286 * @param pane The container to put the dialog in.
288 private void makeDeleteMeasureDialog(Container pane) {
289 setTitle("Delete Measure");
290 // create the contents of the dialog and add to container
291 labelA = new JLabel("Delete at:", JLabel.RIGHT);
293 labelB = new JLabel("Measure count:", JLabel.RIGHT);
295 textFieldA = new JTextField();
296 pane.add(textFieldA);
297 textFieldB = new JTextField();
298 pane.add(textFieldB);
299 // ok and cancelbutton
300 cancelButton = new JButton("Cancel");
301 pane.add(cancelButton);
302 okButton = new JButton("OK");
305 labelA.setBounds(20, 20, 110 ,20);
306 labelB.setBounds(20, 50, 110, 20);
307 textFieldA.setBounds(140 ,20 , 40, 20);
308 textFieldB.setBounds(140,50, 40, 20);
309 cancelButton.setBounds(20 ,95 , 80, 30);
310 okButton.setBounds(120, 95, 60, 30);
314 setLocationRelativeTo(Moosique.getGUI());
319 * Builds the set tempo dialog.
320 * @param pane The container to put the dialog in.
322 private void makeSetTempoDialog(Container pane) {
323 setTitle("Set tempo");
324 // create contents of dialog and add to container
325 // track edit-intervall labels
326 labelA = new JLabel("Measure", JLabel.CENTER);
328 labelB = new JLabel("Beat", JLabel.CENTER);
330 labelC = new JLabel("Tick", JLabel.CENTER);
332 // start and end labels
333 labelD = new JLabel("Start at:", JLabel.RIGHT);
335 labelE = new JLabel("End at:", JLabel.RIGHT);
338 labelF = new JLabel("to", JLabel.CENTER);
340 // start inputvaluefields
341 textFieldA = new JTextField();
342 pane.add(textFieldA);
343 textFieldB = new JTextField();
344 pane.add(textFieldB);
345 textFieldC = new JTextField();
346 pane.add(textFieldC);
347 // end inputvaluefield
348 textFieldD = new JTextField();
349 pane.add(textFieldD);
350 textFieldE = new JTextField();
351 pane.add(textFieldE);
352 textFieldF = new JTextField();
353 pane.add(textFieldF);
354 // the radiobuttonlists inputvaluefields
355 textFieldG = new JTextField();
356 pane.add(textFieldG);
357 textFieldH = new JTextField();
358 pane.add(textFieldH);
359 textFieldI = new JTextField();
360 pane.add(textFieldI);
361 textFieldJ = new JTextField();
362 pane.add(textFieldJ);
363 textFieldK = new JTextField();
364 pane.add(textFieldK);
365 // the radiobuttonlist with associating titles
366 JRadioButton constant = new JRadioButton("Set constant tempo of:");
367 constant.setSelected(true);
369 JRadioButton change = new JRadioButton("Gradually change tempo:");
371 JRadioButton scale = new JRadioButton("Scale tempo in %:");
373 JRadioButton add = new JRadioButton("Add to current tempo:");
375 // a buttongroup for the radiobuttons
376 ButtonGroup group = new ButtonGroup();
381 // ok and cancelbutton
382 cancelButton = new JButton("Cancel");
383 pane.add(cancelButton);
384 okButton = new JButton("OK");
387 // set bounds of track edit-intervall labels
388 labelA.setBounds(80, 25, 50, 20);
389 labelB.setBounds(145, 25, 50, 20);
390 labelC.setBounds(210, 25, 50, 20);
391 // set bounds of start and end labels
392 labelD.setBounds(20, 45, 60, 20);
393 labelE.setBounds(20, 65, 60, 20);
394 // set bounds of from-to label
395 labelF.setBounds(255, 125, 20 ,20);
396 // set bounds of start inputvaluefields
397 textFieldA.setBounds(80, 45, 50, 20);
398 textFieldB.setBounds(145, 45, 50, 20);
399 textFieldC.setBounds(210, 45, 50, 20);
400 // set bounds of end inputvaluefield
401 textFieldD.setBounds(80, 65, 50, 20);
402 textFieldE.setBounds(145, 65, 50, 20);
403 textFieldF.setBounds(210, 65, 50, 20);
404 // set bounds of radiobuttonlists inputvaluefields
405 textFieldG.setBounds(220, 100, 35, 20);
406 textFieldH.setBounds(220, 125, 35, 20);
407 textFieldI.setBounds(280, 125, 35, 20);
408 textFieldJ.setBounds(220, 150, 35, 20);
409 textFieldK.setBounds(220, 175, 35, 20);
410 // set bounds of radiobuttonlist items
411 constant.setBounds(20, 100, 180, 20);
412 change.setBounds(20, 125, 200, 20);
413 scale.setBounds(20, 150, 150, 20);
414 add.setBounds(20, 175, 175, 20);
415 // set bounds of ok and cancelbutton
416 cancelButton.setBounds(75, 215, 80, 30);
417 okButton.setBounds(195, 215, 60, 30);
422 setLocationRelativeTo(Moosique.getGUI());
427 * Builds the transpose dialog.
428 * @param pane The container to put the dialog in.
429 * @param tracks A array containing miditracks.
431 private void makeTransposeDialog(Container pane, Track[] tracks) {
432 setTitle("Transpose");
433 // create contents of dialog and add to container
434 // track edit-intervall labels
435 labelA = new JLabel("Measure", JLabel.CENTER);
437 labelB = new JLabel("Beat", JLabel.CENTER);
439 labelC = new JLabel("Tick", JLabel.CENTER);
441 // start and end labels
442 labelD = new JLabel("Start at:", JLabel.RIGHT);
444 labelE = new JLabel("End at:", JLabel.RIGHT);
446 // oktave inputvalue labels
447 labelF = new JLabel("Octaves", JLabel.LEFT);
449 labelG = new JLabel("1/2 octaves", JLabel.LEFT);
451 // what track to edit label
452 labelH = new JLabel("Track to edit:", JLabel.CENTER);
454 // combobox representing the tracks
455 trackListA = new JComboBox();
456 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
457 pane.add(trackListA);
458 // start inputvaluefields
459 textFieldA = new JTextField();
460 pane.add(textFieldA);
461 textFieldB = new JTextField();
462 pane.add(textFieldB);
463 textFieldC = new JTextField();
464 pane.add(textFieldC);
465 // end inputvaluefield
466 textFieldD = new JTextField();
467 pane.add(textFieldD);
468 textFieldE = new JTextField();
469 pane.add(textFieldE);
470 textFieldF = new JTextField();
471 pane.add(textFieldF);
472 // the radiobuttonlists inputvaluefields
473 textFieldG = new JTextField();
474 pane.add(textFieldG);
475 textFieldH = new JTextField();
476 pane.add(textFieldH);
477 // the radiobuttonlist with associating titles
478 JRadioButton up = new JRadioButton("Change up");
479 up.setSelected(true);
481 JRadioButton down = new JRadioButton("Change down");
483 // a buttongroup for the radiobuttons
484 ButtonGroup group = new ButtonGroup();
487 // ok and cancelbutton
488 cancelButton = new JButton("Cancel");
489 pane.add(cancelButton);
490 okButton = new JButton("OK");
493 // set bounds of track edit-intervall labels
494 labelA.setBounds(90, 70, 50, 20);
495 labelB.setBounds(155, 70, 50, 20);
496 labelC.setBounds(220, 70, 50, 20);
497 // set bounds of start and end labels
498 labelD.setBounds(30, 90, 60, 20);
499 labelE.setBounds(30, 110, 60, 20);
500 // set bounds of octave inputvaluefields
501 labelF.setBounds(210, 150, 80, 20);
502 labelG.setBounds(210, 175, 100, 20);
503 // set bounds of trackslist label
504 labelH.setBounds(30, 30, 100, 20);
505 // set bounds of start inputvaluefields
506 textFieldA.setBounds(90, 90, 50, 20);
507 textFieldB.setBounds(155, 90, 50, 20);
508 textFieldC.setBounds(220, 90, 50, 20);
509 // set bounds of end inputvaluefield
510 textFieldD.setBounds(90, 110, 50, 20);
511 textFieldE.setBounds(155, 110, 50, 20);
512 textFieldF.setBounds(220, 110, 50, 20);
513 // set bounds of octave inputvaluefields
514 textFieldG.setBounds(170, 150, 35, 20);
515 textFieldH.setBounds(170, 175, 35, 20);
516 // set bounds of radiobuttonlist items
517 up.setBounds(30, 150, 100, 20);
518 down.setBounds(30, 175, 120, 20);
519 // set bounds of tracklist
520 trackListA.setBounds(145, 30, 120, 20);
521 // set bounds of ok and cancelbutton
522 cancelButton.setBounds(75, 215, 80, 30);
523 okButton.setBounds(195, 215, 60, 30);
528 setLocationRelativeTo(Moosique.getGUI());
533 * Builds the scale velocity dialog.
534 * @param pane The container to put the dialog in.
535 * @param tracks A array containing miditracks.
537 private void makeScaleVelocityDialog(Container pane, Track[] tracks) {
538 setTitle("Scale velocity");
539 // create contents of dialog and add to container
540 // track edit-intervall labels
541 labelA = new JLabel("Measure", JLabel.CENTER);
543 labelB = new JLabel("Beat", JLabel.CENTER);
545 labelC = new JLabel("Tick", JLabel.CENTER);
547 // start and end labels
548 labelD = new JLabel("Start at:", JLabel.RIGHT);
550 labelE = new JLabel("End at:", JLabel.RIGHT);
553 labelF = new JLabel("to", JLabel.CENTER);
555 // what track to edit label
556 labelG = new JLabel("Track to edit:", JLabel.CENTER);
558 // combobox representing the tracks
559 trackListA = new JComboBox();
560 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
561 pane.add(trackListA);
562 // start inputvaluefields
563 textFieldA = new JTextField();
564 pane.add(textFieldA);
565 textFieldB = new JTextField();
566 pane.add(textFieldB);
567 textFieldC = new JTextField();
568 pane.add(textFieldC);
569 // end inputvaluefield
570 textFieldD = new JTextField();
571 pane.add(textFieldD);
572 textFieldE = new JTextField();
573 pane.add(textFieldE);
574 textFieldF = new JTextField();
575 pane.add(textFieldF);
576 // the radiobuttonlists inputvaluefields
577 textFieldG = new JTextField();
578 pane.add(textFieldG);
579 textFieldH = new JTextField();
580 pane.add(textFieldH);
581 textFieldI = new JTextField();
582 pane.add(textFieldI);
583 textFieldJ = new JTextField();
584 pane.add(textFieldJ);
585 textFieldK = new JTextField();
586 pane.add(textFieldK);
587 // the radiobuttonlist with associating titles
588 JRadioButton constant = new JRadioButton("Change all values to:");
589 constant.setSelected(true);
591 JRadioButton change = new JRadioButton("Gradually change value:");
593 JRadioButton scale = new JRadioButton("Scale values to %:");
595 JRadioButton add = new JRadioButton("Add to current value:");
597 // a buttongroup for the radiobuttons
598 ButtonGroup group = new ButtonGroup();
603 // ok and cancelbutton
604 cancelButton = new JButton("Cancel");
605 pane.add(cancelButton);
606 okButton = new JButton("OK");
609 // set bounds of track edit-intervall labels
610 labelA.setBounds(80, 75, 50, 20);
611 labelB.setBounds(145, 75, 50, 20);
612 labelC.setBounds(210, 75, 50, 20);
613 // set bounds of start and end labels
614 labelD.setBounds(20, 95, 60, 20);
615 labelE.setBounds(20, 115, 60, 20);
616 // set bounds of from-to label
617 labelF.setBounds(255, 175, 20 ,20);
618 // set bounds of trackslist label
619 labelG.setBounds(30, 30, 100, 20);
620 // set bounds of start inputvaluefields
621 textFieldA.setBounds(80, 95, 50, 20);
622 textFieldB.setBounds(145, 95, 50, 20);
623 textFieldC.setBounds(210, 95, 50, 20);
624 // set bounds of end inputvaluefield
625 textFieldD.setBounds(80, 115, 50, 20);
626 textFieldE.setBounds(145,115, 50, 20);
627 textFieldF.setBounds(210, 115, 50, 20);
628 // set bounds of radiobuttonlists inputvaluefields
629 textFieldG.setBounds(220, 150, 35, 20);
630 textFieldH.setBounds(220, 175, 35, 20);
631 textFieldI.setBounds(280, 175, 35, 20);
632 textFieldJ.setBounds(220, 200, 35, 20);
633 textFieldK.setBounds(220, 225, 35, 20);
634 // set bounds of radiobuttonlist items
635 constant.setBounds(20, 150, 180, 20);
636 change.setBounds(20, 175, 200, 20);
637 scale.setBounds(20, 200, 150, 20);
638 add.setBounds(20, 225, 175, 20);
639 // set bounds of tracklist
640 trackListA.setBounds(145, 30, 120, 20);
641 // set bounds of ok and cancelbutton
642 cancelButton.setBounds(75, 265, 80, 30);
643 okButton.setBounds(195, 265, 60, 30);
648 setLocationRelativeTo(Moosique.getGUI());
651 /** creates the "User manual dialog" that displays a textfile
653 private void makeTextDialog(Container pane, String filename) {
654 setTitle("User Manual");
655 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
656 File manual = new File(filename);
659 BufferedReader br = new BufferedReader(new FileReader(manual));
660 char[] chars = new char[(int)manual.length()];
661 br.read(chars, 0, (int)manual.length());
662 s = new String(chars);
663 } catch (Exception ex) {
664 s = "Manual not found";
666 JTextArea text = new JTextArea(s, 30, 95);
667 text.setLineWrap(true);
668 text.setWrapStyleWord(true);
669 text.setEnabled(false);
670 text.setDisabledTextColor(Color.black);
671 pane.add(new JScrollPane(text));
672 Action close = new AbstractAction("Close") {
673 public void actionPerformed(ActionEvent ae) {
676 JButton closeButton = new JButton(close);
677 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
678 pane.add(closeButton);
681 setLocationRelativeTo(Moosique.getGUI());
685 private void makePrefsDialog(Container pane) {
687 MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo();
688 for (int i = 0; i < devInfo.length; i++) {
689 if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Sequencer) {
691 } else if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Synthesizer) {
695 String[] seqNames, synthNames;
696 JPanel pane = (JPanel) this.getContentPane();
697 pane.add(new JLabel("Sequencer"));
698 JComboBox seqBox = new JComboBox(seqNames);
699 pane.add(new JLabel("Synthesizer"));
700 JComboBox synthBox = new JComboBox(synthNames);
704 private MooNote note;
705 private JOptionPane optionPane;
706 private JTextField pitch;
707 private JTextField velocity;
708 private JTextField length;
711 * Creates a new note preference dialog.
712 * @param mn the note that will be graphically represented
714 public MooDialog(MooNote mn) {
715 super(Moosique.getGUI(), "Note properties", true);
716 JPanel panel = new JPanel();
717 panel.setLayout(new GridLayout(3,2));
719 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
720 panel.add(new Label("Pitch: "));
723 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
724 panel.add(new Label("Velocity: "));
727 length = new JTextField(new Integer(note.getDuration()).toString(),5);
728 panel.add(new Label("Length: "));
731 Object[] array = {"Set the note properties",
734 final String btnString1 = "Apply changes";
735 final String btnString2 = "Cancel";
736 Object[] options = {btnString1, btnString2};
738 optionPane = new JOptionPane(array,
739 JOptionPane.QUESTION_MESSAGE,
740 JOptionPane.YES_NO_OPTION,
744 setContentPane(optionPane);
745 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
747 ActionListener intValidator = new ActionListener() {
748 public void actionPerformed(ActionEvent e) {
749 if (e.getSource() instanceof JTextField){
750 JTextField s = (JTextField)e.getSource();
751 int num = Integer.parseInt(s.getText());
754 else if (num > 127 && s != length)
756 s.setText(new Integer(num).toString());
760 pitch.addActionListener(intValidator);
761 velocity.addActionListener(intValidator);
762 length.addActionListener(intValidator);
764 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
765 public void propertyChange(PropertyChangeEvent e) {
766 String prop = e.getPropertyName();
769 && (e.getSource() == optionPane)
770 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
771 prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
772 Object value = optionPane.getValue();
774 if (value == JOptionPane.UNINITIALIZED_VALUE) {
779 // Reset the JOptionPane's value.
780 // If you don't do this, then if the user
781 // presses the same button next time, no
782 // property change event will be fired.
784 JOptionPane.UNINITIALIZED_VALUE);
786 if (value.equals(btnString1)) {
787 note.setPitch(Integer.parseInt(pitch.getText()));
788 note.setVelocity(Integer.parseInt(velocity.getText()));
789 note.setDuration(Integer.parseInt(length.getText()));
790 Moosique.setEdited();
792 } else { // user closed dialog or clicked cancel