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,
37 * Constructor of the dialogs.
39 public MooDialog(int type) {
40 super(Moosique.getGUI(), false);
42 Container pane = getContentPane();
45 Track[] tracks = Moosique.getSequence().getTracks();
48 case ADD_TRACK: makeAddDialog(pane, tracks); break;
49 case DELETE_TRACK: makeDelDialog(pane, tracks); break;
50 case COPY_TRACK: makeCopyDialog(pane, tracks); break;
51 case MOVE_TRACK: makeMoveDialog(pane, tracks); break;
52 case SET_POSITION: makeSetPositionDialog(pane); break;
53 case MANUAL: makeTextDialog(pane, "Manual.txt"); break;
54 case INSERT_MEASURE: makeInsertMeasureDialog(pane); break;
55 case DELETE_MEASURE: makeDeleteMeasureDialog(pane); break;
56 case SET_TEMPO: makeSetTempoDialog(pane); break;
57 case PREFERENCES: makePrefsDialog(pane); break;
58 case TRANSPOSE: makeTransposeDialog(pane, tracks); break;
59 case SCALE_VELOCITY: makeScaleVelocityDialog(pane, tracks); break;
64 * Builds the add track popupdialog.
65 * @param pane The container to put the dialog in.
66 * @param tracks A array containing miditracks.
68 private void makeAddDialog(Container pane, Track[] tracks) {
69 setTitle("Add track");
70 // create the contents of the dialog and add to container
71 labelA = new JLabel("Name of track", JLabel.CENTER);
73 // textfield for naming track
74 textFieldA = new JTextField();
76 labelB = new JLabel("Add after", JLabel.CENTER);
78 // list of where to add track
79 trackListA = new JComboBox();
80 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
82 // ok and cancel button
83 cancelButton = new JButton("Cancel");
84 pane.add(cancelButton);
85 okButton = new JButton("OK");
88 labelA.setBounds(50, 10, 100, 20);
89 textFieldA.setBounds(40, 35, 120, 20);
90 labelB.setBounds(50, 70, 100, 20);
91 trackListA.setBounds(40, 95, 120, 20);
92 cancelButton.setBounds(10, 150, 80, 30);
93 okButton.setBounds(120, 150, 60, 30);
97 setLocationRelativeTo(Moosique.getGUI());
102 * Builds the delete track popupdialog.
103 * @param pane The container to put the dialog in.
104 * @param tracks A array containing miditracks.
106 private void makeDelDialog(Container pane, Track[] tracks) {
107 setTitle("Delete track");
108 // create the contents of the dialog and add to container
109 labelB = new JLabel("Delete track", JLabel.CENTER);
111 // list of what track to delete
112 trackListA = new JComboBox();
113 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
114 pane.add(trackListA);
115 // ok and cancelbutton
116 cancelButton = new JButton("Cancel");
117 pane.add(cancelButton);
118 okButton = new JButton("OK");
121 labelB.setBounds(50, 10, 100, 20);
122 trackListA.setBounds(40, 35, 120, 20);
123 cancelButton.setBounds(10, 90, 80, 30);
124 okButton.setBounds(120, 90, 60, 30);
128 setLocationRelativeTo(Moosique.getGUI());
133 * Builds the copy track popupdialog.
134 * @param pane The container to put the dialog in.
135 * @param tracks A array containing miditracks.
137 private void makeCopyDialog(Container pane, Track[] tracks) {
138 setTitle("Copy Track");
139 // create the contents of the dialog and add to container
140 labelA = new JLabel("Track to copy", JLabel.CENTER);
142 // list of what track to copy
143 trackListA = new JComboBox();
144 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
145 pane.add(trackListA);
146 labelB = new JLabel("Insert after", JLabel.CENTER);
148 // list of where to put copied track
149 trackListB = new JComboBox();
150 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
151 pane.add(trackListB);
152 cancelButton = new JButton("Cancel");
153 pane.add(cancelButton);
154 okButton = new JButton("OK");
157 labelA.setBounds(50, 10, 100, 20);
158 trackListA.setBounds(40, 35, 120, 20);
159 labelB.setBounds(50, 70, 100, 20);
160 trackListB.setBounds(40, 95, 120, 20);
161 cancelButton.setBounds(10, 150, 80, 30);
162 okButton.setBounds(120, 150, 60, 30);
166 setLocationRelativeTo(Moosique.getGUI());
171 * Builds the move track popupdialog
172 * @param pane The container to put the dialog in.
173 * @param tracks A array containing miditracks.
175 private void makeMoveDialog(Container pane, Track[] tracks) {
176 setTitle("Move track");
177 // create the contents of the dialog and add to container
178 labelA = new JLabel("Track to move", JLabel.CENTER);
180 // list of track to move
181 trackListA = new JComboBox();
182 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
183 pane.add(trackListA);
184 labelB = new JLabel("Insert after", JLabel.CENTER);
186 // list of where to put moved track
187 trackListB = new JComboBox();
188 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
189 pane.add(trackListB);
190 // ok and cancelbuttons
191 cancelButton = new JButton("Cancel");
192 pane.add(cancelButton);
193 okButton = new JButton("OK");
196 labelA.setBounds(40, 10, 120, 20);
197 trackListA.setBounds(40, 35, 120, 20);
198 labelB.setBounds(50, 70, 100, 20);
199 trackListB.setBounds(40, 95, 120, 20);
200 cancelButton.setBounds(10, 150, 80, 30);
201 okButton.setBounds(120, 150, 60, 30);
205 setLocationRelativeTo(Moosique.getGUI());
210 * Builds the set position dialog.
211 * @param pane The container to put the dialog in.
212 * @param tracks A array containing miditracks.
214 private void makeSetPositionDialog(Container pane) {
216 setTitle("Set edit position");
217 // create the contents of the dialog and add to container
218 labelA = new JLabel("Measure", JLabel.CENTER);
220 labelB = new JLabel("Beat", JLabel.CENTER);
222 labelC = new JLabel("Tick", JLabel.CENTER);
224 textFieldA = new JTextField();
225 pane.add(textFieldA);
226 textFieldB = new JTextField();
227 pane.add(textFieldB);
228 textFieldC = new JTextField();
229 pane.add(textFieldC);
230 // ok and cancel buttons
231 cancelButton = new JButton("Cancel");
232 pane.add(cancelButton);
233 okButton = new JButton("OK");
236 labelA.setBounds(40, 25, 50, 20);
237 labelB.setBounds(105, 25, 50, 20);
238 labelC.setBounds(170, 25, 50, 20);
239 textFieldA.setBounds(40, 45, 50, 20);
240 textFieldB.setBounds(105, 45, 50, 20);
241 textFieldC.setBounds(170, 45, 50, 20);
242 cancelButton.setBounds(35, 90, 80, 30);
243 okButton.setBounds(155, 90, 60, 30);
247 setLocationRelativeTo(Moosique.getGUI());
252 * Builds the insert measure popupdialog.
253 * @param pane The container to put the dialog in.
255 private void makeInsertMeasureDialog(Container pane){
256 setTitle("Insert Measure");
257 // create the contents of the dialog and add to container
258 labelA = new JLabel("Insert at:", JLabel.RIGHT);
260 labelB = new JLabel("Measure count:", JLabel.RIGHT);
262 textFieldA = new JTextField();
263 pane.add(textFieldA);
264 textFieldB = new JTextField();
265 pane.add(textFieldB);
266 // ok and cancelbutton
267 cancelButton = new JButton("Cancel");
268 pane.add(cancelButton);
269 okButton = new JButton("OK");
272 labelA.setBounds(20, 20, 110 ,20);
273 labelB.setBounds(20, 50, 110, 20);
274 textFieldA.setBounds(140 ,20 , 40, 20);
275 textFieldB.setBounds(140,50, 40, 20);
276 cancelButton.setBounds(20 ,95 , 80, 30);
277 okButton.setBounds(120, 95, 60, 30);
281 setLocationRelativeTo(Moosique.getGUI());
286 * Builds the delete measure popupdialog.
287 * @param pane The container to put the dialog in.
289 private void makeDeleteMeasureDialog(Container pane) {
290 setTitle("Delete Measure");
291 // create the contents of the dialog and add to container
292 labelA = new JLabel("Delete at:", JLabel.RIGHT);
294 labelB = new JLabel("Measure count:", JLabel.RIGHT);
296 textFieldA = new JTextField();
297 pane.add(textFieldA);
298 textFieldB = new JTextField();
299 pane.add(textFieldB);
300 // ok and cancelbutton
301 cancelButton = new JButton("Cancel");
302 pane.add(cancelButton);
303 okButton = new JButton("OK");
306 labelA.setBounds(20, 20, 110 ,20);
307 labelB.setBounds(20, 50, 110, 20);
308 textFieldA.setBounds(140 ,20 , 40, 20);
309 textFieldB.setBounds(140,50, 40, 20);
310 cancelButton.setBounds(20 ,95 , 80, 30);
311 okButton.setBounds(120, 95, 60, 30);
315 setLocationRelativeTo(Moosique.getGUI());
320 * Builds the set tempo dialog.
321 * @param pane The container to put the dialog in.
323 private void makeSetTempoDialog(Container pane) {
324 setTitle("Set tempo");
325 // create contents of dialog and add to container
326 // track edit-intervall labels
327 labelA = new JLabel("Measure", JLabel.CENTER);
329 labelB = new JLabel("Beat", JLabel.CENTER);
331 labelC = new JLabel("Tick", JLabel.CENTER);
333 // start and end labels
334 labelD = new JLabel("Start at:", JLabel.RIGHT);
336 labelE = new JLabel("End at:", JLabel.RIGHT);
339 labelF = new JLabel("to", JLabel.CENTER);
341 // start inputvaluefields
342 textFieldA = new JTextField();
343 pane.add(textFieldA);
344 textFieldB = new JTextField();
345 pane.add(textFieldB);
346 textFieldC = new JTextField();
347 pane.add(textFieldC);
348 // end inputvaluefield
349 textFieldD = new JTextField();
350 pane.add(textFieldD);
351 textFieldE = new JTextField();
352 pane.add(textFieldE);
353 textFieldF = new JTextField();
354 pane.add(textFieldF);
355 // the radiobuttonlists inputvaluefields
356 textFieldG = new JTextField();
357 pane.add(textFieldG);
358 textFieldH = new JTextField();
359 pane.add(textFieldH);
360 textFieldI = new JTextField();
361 pane.add(textFieldI);
362 textFieldJ = new JTextField();
363 pane.add(textFieldJ);
364 textFieldK = new JTextField();
365 pane.add(textFieldK);
366 // the radiobuttonlist with associating titles
367 JRadioButton constant = new JRadioButton("Set constant tempo of:");
368 constant.setSelected(true);
370 JRadioButton change = new JRadioButton("Gradually change tempo:");
372 JRadioButton scale = new JRadioButton("Scale tempo in %:");
374 JRadioButton add = new JRadioButton("Add to current tempo:");
376 // a buttongroup for the radiobuttons
377 ButtonGroup group = new ButtonGroup();
382 // ok and cancelbutton
383 cancelButton = new JButton("Cancel");
384 pane.add(cancelButton);
385 okButton = new JButton("OK");
388 // set bounds of track edit-intervall labels
389 labelA.setBounds(80, 25, 50, 20);
390 labelB.setBounds(145, 25, 50, 20);
391 labelC.setBounds(210, 25, 50, 20);
392 // set bounds of start and end labels
393 labelD.setBounds(20, 45, 60, 20);
394 labelE.setBounds(20, 65, 60, 20);
395 // set bounds of from-to label
396 labelF.setBounds(255, 125, 20 ,20);
397 // set bounds of start inputvaluefields
398 textFieldA.setBounds(80, 45, 50, 20);
399 textFieldB.setBounds(145, 45, 50, 20);
400 textFieldC.setBounds(210, 45, 50, 20);
401 // set bounds of end inputvaluefield
402 textFieldD.setBounds(80, 65, 50, 20);
403 textFieldE.setBounds(145, 65, 50, 20);
404 textFieldF.setBounds(210, 65, 50, 20);
405 // set bounds of radiobuttonlists inputvaluefields
406 textFieldG.setBounds(220, 100, 35, 20);
407 textFieldH.setBounds(220, 125, 35, 20);
408 textFieldI.setBounds(280, 125, 35, 20);
409 textFieldJ.setBounds(220, 150, 35, 20);
410 textFieldK.setBounds(220, 175, 35, 20);
411 // set bounds of radiobuttonlist items
412 constant.setBounds(20, 100, 180, 20);
413 change.setBounds(20, 125, 200, 20);
414 scale.setBounds(20, 150, 150, 20);
415 add.setBounds(20, 175, 175, 20);
416 // set bounds of ok and cancelbutton
417 cancelButton.setBounds(75, 215, 80, 30);
418 okButton.setBounds(195, 215, 60, 30);
423 setLocationRelativeTo(Moosique.getGUI());
428 * Builds the transpose dialog.
429 * @param pane The container to put the dialog in.
430 * @param tracks A array containing miditracks.
432 private void makeTransposeDialog(Container pane, Track[] tracks) {
433 setTitle("Transpose");
434 // create contents of dialog and add to container
435 // track edit-intervall labels
436 labelA = new JLabel("Measure", JLabel.CENTER);
438 labelB = new JLabel("Beat", JLabel.CENTER);
440 labelC = new JLabel("Tick", JLabel.CENTER);
442 // start and end labels
443 labelD = new JLabel("Start at:", JLabel.RIGHT);
445 labelE = new JLabel("End at:", JLabel.RIGHT);
447 // oktave inputvalue labels
448 labelF = new JLabel("Octaves", JLabel.LEFT);
450 labelG = new JLabel("1/2 octaves", JLabel.LEFT);
452 // what track to edit label
453 labelH = new JLabel("Track to edit:", JLabel.CENTER);
455 // combobox representing the tracks
456 trackListA = new JComboBox();
457 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
458 pane.add(trackListA);
459 // start inputvaluefields
460 textFieldA = new JTextField();
461 pane.add(textFieldA);
462 textFieldB = new JTextField();
463 pane.add(textFieldB);
464 textFieldC = new JTextField();
465 pane.add(textFieldC);
466 // end inputvaluefield
467 textFieldD = new JTextField();
468 pane.add(textFieldD);
469 textFieldE = new JTextField();
470 pane.add(textFieldE);
471 textFieldF = new JTextField();
472 pane.add(textFieldF);
473 // the radiobuttonlists inputvaluefields
474 textFieldG = new JTextField();
475 pane.add(textFieldG);
476 textFieldH = new JTextField();
477 pane.add(textFieldH);
478 // the radiobuttonlist with associating titles
479 JRadioButton up = new JRadioButton("Change up");
480 up.setSelected(true);
482 JRadioButton down = new JRadioButton("Change down");
484 // a buttongroup for the radiobuttons
485 ButtonGroup group = new ButtonGroup();
488 // ok and cancelbutton
489 cancelButton = new JButton("Cancel");
490 pane.add(cancelButton);
491 okButton = new JButton("OK");
494 // set bounds of track edit-intervall labels
495 labelA.setBounds(90, 70, 50, 20);
496 labelB.setBounds(155, 70, 50, 20);
497 labelC.setBounds(220, 70, 50, 20);
498 // set bounds of start and end labels
499 labelD.setBounds(30, 90, 60, 20);
500 labelE.setBounds(30, 110, 60, 20);
501 // set bounds of octave inputvaluefields
502 labelF.setBounds(210, 150, 80, 20);
503 labelG.setBounds(210, 175, 100, 20);
504 // set bounds of trackslist label
505 labelH.setBounds(30, 30, 100, 20);
506 // set bounds of start inputvaluefields
507 textFieldA.setBounds(90, 90, 50, 20);
508 textFieldB.setBounds(155, 90, 50, 20);
509 textFieldC.setBounds(220, 90, 50, 20);
510 // set bounds of end inputvaluefield
511 textFieldD.setBounds(90, 110, 50, 20);
512 textFieldE.setBounds(155, 110, 50, 20);
513 textFieldF.setBounds(220, 110, 50, 20);
514 // set bounds of octave inputvaluefields
515 textFieldG.setBounds(170, 150, 35, 20);
516 textFieldH.setBounds(170, 175, 35, 20);
517 // set bounds of radiobuttonlist items
518 up.setBounds(30, 150, 100, 20);
519 down.setBounds(30, 175, 120, 20);
520 // set bounds of tracklist
521 trackListA.setBounds(145, 30, 120, 20);
522 // set bounds of ok and cancelbutton
523 cancelButton.setBounds(75, 215, 80, 30);
524 okButton.setBounds(195, 215, 60, 30);
529 setLocationRelativeTo(Moosique.getGUI());
534 * Builds the scale velocity dialog.
535 * @param pane The container to put the dialog in.
536 * @param tracks A array containing miditracks.
538 private void makeScaleVelocityDialog(Container pane, Track[] tracks) {
539 setTitle("Scale velocity");
540 // create contents of dialog and add to container
541 // track edit-intervall labels
542 labelA = new JLabel("Measure", JLabel.CENTER);
544 labelB = new JLabel("Beat", JLabel.CENTER);
546 labelC = new JLabel("Tick", JLabel.CENTER);
548 // start and end labels
549 labelD = new JLabel("Start at:", JLabel.RIGHT);
551 labelE = new JLabel("End at:", JLabel.RIGHT);
554 labelF = new JLabel("to", JLabel.CENTER);
556 // what track to edit label
557 labelG = new JLabel("Track to edit:", JLabel.CENTER);
559 // combobox representing the tracks
560 trackListA = new JComboBox();
561 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
562 pane.add(trackListA);
563 // start inputvaluefields
564 textFieldA = new JTextField();
565 pane.add(textFieldA);
566 textFieldB = new JTextField();
567 pane.add(textFieldB);
568 textFieldC = new JTextField();
569 pane.add(textFieldC);
570 // end inputvaluefield
571 textFieldD = new JTextField();
572 pane.add(textFieldD);
573 textFieldE = new JTextField();
574 pane.add(textFieldE);
575 textFieldF = new JTextField();
576 pane.add(textFieldF);
577 // the radiobuttonlists inputvaluefields
578 textFieldG = new JTextField();
579 pane.add(textFieldG);
580 textFieldH = new JTextField();
581 pane.add(textFieldH);
582 textFieldI = new JTextField();
583 pane.add(textFieldI);
584 textFieldJ = new JTextField();
585 pane.add(textFieldJ);
586 textFieldK = new JTextField();
587 pane.add(textFieldK);
588 // the radiobuttonlist with associating titles
589 JRadioButton constant = new JRadioButton("Change all values to:");
590 constant.setSelected(true);
592 JRadioButton change = new JRadioButton("Gradually change value:");
594 JRadioButton scale = new JRadioButton("Scale values to %:");
596 JRadioButton add = new JRadioButton("Add to current value:");
598 // a buttongroup for the radiobuttons
599 ButtonGroup group = new ButtonGroup();
604 // ok and cancelbutton
605 cancelButton = new JButton("Cancel");
606 pane.add(cancelButton);
607 okButton = new JButton("OK");
610 // set bounds of track edit-intervall labels
611 labelA.setBounds(80, 75, 50, 20);
612 labelB.setBounds(145, 75, 50, 20);
613 labelC.setBounds(210, 75, 50, 20);
614 // set bounds of start and end labels
615 labelD.setBounds(20, 95, 60, 20);
616 labelE.setBounds(20, 115, 60, 20);
617 // set bounds of from-to label
618 labelF.setBounds(255, 175, 20 ,20);
619 // set bounds of trackslist label
620 labelG.setBounds(30, 30, 100, 20);
621 // set bounds of start inputvaluefields
622 textFieldA.setBounds(80, 95, 50, 20);
623 textFieldB.setBounds(145, 95, 50, 20);
624 textFieldC.setBounds(210, 95, 50, 20);
625 // set bounds of end inputvaluefield
626 textFieldD.setBounds(80, 115, 50, 20);
627 textFieldE.setBounds(145,115, 50, 20);
628 textFieldF.setBounds(210, 115, 50, 20);
629 // set bounds of radiobuttonlists inputvaluefields
630 textFieldG.setBounds(220, 150, 35, 20);
631 textFieldH.setBounds(220, 175, 35, 20);
632 textFieldI.setBounds(280, 175, 35, 20);
633 textFieldJ.setBounds(220, 200, 35, 20);
634 textFieldK.setBounds(220, 225, 35, 20);
635 // set bounds of radiobuttonlist items
636 constant.setBounds(20, 150, 180, 20);
637 change.setBounds(20, 175, 200, 20);
638 scale.setBounds(20, 200, 150, 20);
639 add.setBounds(20, 225, 175, 20);
640 // set bounds of tracklist
641 trackListA.setBounds(145, 30, 120, 20);
642 // set bounds of ok and cancelbutton
643 cancelButton.setBounds(75, 265, 80, 30);
644 okButton.setBounds(195, 265, 60, 30);
649 setLocationRelativeTo(Moosique.getGUI());
652 /** creates the "User manual dialog" that displays a textfile
654 private void makeTextDialog(Container pane, String filename) {
655 setTitle("User Manual");
656 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
657 File manual = new File(filename);
660 BufferedReader br = new BufferedReader(new FileReader(manual));
661 char[] chars = new char[(int)manual.length()];
662 br.read(chars, 0, (int)manual.length());
663 s = new String(chars);
664 } catch (Exception ex) {
665 s = "Manual not found";
667 JTextArea text = new JTextArea(s, 30, 95);
668 text.setLineWrap(true);
669 text.setWrapStyleWord(true);
670 text.setEnabled(false);
671 text.setDisabledTextColor(Color.black);
672 pane.add(new JScrollPane(text));
673 Action close = new AbstractAction("Close") {
674 public void actionPerformed(ActionEvent ae) {
677 JButton closeButton = new JButton(close);
678 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
679 pane.add(closeButton);
682 setLocationRelativeTo(Moosique.getGUI());
686 private void makePrefsDialog(Container pane) {
688 MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo();
689 for (int i = 0; i < devInfo.length; i++) {
690 if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Sequencer) {
692 } else if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Synthesizer) {
696 String[] seqNames, synthNames;
697 JPanel pane = (JPanel) this.getContentPane();
698 pane.add(new JLabel("Sequencer"));
699 JComboBox seqBox = new JComboBox(seqNames);
700 pane.add(new JLabel("Synthesizer"));
701 JComboBox synthBox = new JComboBox(synthNames);
705 private void makeRecordDialog(Container pane) {
706 /* Show a dialog with:
708 "Channel" field? (disabled?,
711 "Resolution" combo box,
712 "Location" checkboxes and
713 "Duration" checkboxes
714 "Start Recording" button.
716 Moosique.record(track);
720 private MooNote note;
721 private JOptionPane optionPane;
722 private JTextField pitch;
723 private JTextField velocity;
724 private JTextField length;
727 * Creates a new note preference dialog.
728 * @param mn the note that will be graphically represented
730 public MooDialog(MooNote mn) {
731 super(Moosique.getGUI(), "Note properties", true);
732 JPanel panel = new JPanel();
733 panel.setLayout(new GridLayout(3,2));
735 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
736 panel.add(new Label("Pitch: "));
739 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
740 panel.add(new Label("Velocity: "));
743 length = new JTextField(new Integer(note.getDuration()).toString(),5);
744 panel.add(new Label("Length: "));
747 Object[] array = {"Set the note properties",
750 final String btnString1 = "Apply changes";
751 final String btnString2 = "Cancel";
752 Object[] options = {btnString1, btnString2};
754 optionPane = new JOptionPane(array,
755 JOptionPane.QUESTION_MESSAGE,
756 JOptionPane.YES_NO_OPTION,
760 setContentPane(optionPane);
761 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
763 ActionListener intValidator = new ActionListener() {
764 public void actionPerformed(ActionEvent e) {
765 if (e.getSource() instanceof JTextField){
766 JTextField s = (JTextField)e.getSource();
767 int num = Integer.parseInt(s.getText());
770 else if (num > 127 && s != length)
772 s.setText(new Integer(num).toString());
776 pitch.addActionListener(intValidator);
777 velocity.addActionListener(intValidator);
778 length.addActionListener(intValidator);
780 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
781 public void propertyChange(PropertyChangeEvent e) {
782 String prop = e.getPropertyName();
785 && (e.getSource() == optionPane)
786 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
787 prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
788 Object value = optionPane.getValue();
790 if (value == JOptionPane.UNINITIALIZED_VALUE) {
795 // Reset the JOptionPane's value.
796 // If you don't do this, then if the user
797 // presses the same button next time, no
798 // property change event will be fired.
800 JOptionPane.UNINITIALIZED_VALUE);
802 if (value.equals(btnString1)) {
803 note.setPitch(Integer.parseInt(pitch.getText()));
804 note.setVelocity(Integer.parseInt(velocity.getText()));
805 note.setDuration(Integer.parseInt(length.getText()));
806 Moosique.setEdited();
808 } else { // user closed dialog or clicked cancel