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 Container pane;
17 private Track[] tracks;
19 private JLabel labelA, labelB, labelC, labelD, labelE, labelF, labelG, labelH;
20 private JTextField textFieldA, textFieldB, textFieldC, textFieldD, textFieldE,
21 textFieldF, textFieldG, textFieldH, textFieldI, textFieldJ,
23 private JComboBox trackListA, trackListB;
24 private JButton okButton, cancelButton;
25 public static final int ADD_TRACK = 1,
38 public static final String[] noteSizes = {"Whole", "Half", "Quarter", "Eighth", "Sixteenth"};
41 * Constructor of the dialogs.
43 public MooDialog(int type) {
44 super(Moosique.getGUI(), false);
46 pane = getContentPane();
49 tracks = Moosique.getSequence().getTracks();
52 case ADD_TRACK: makeAddDialog(); break;
53 case DELETE_TRACK: makeDelDialog(); break;
54 case COPY_TRACK: makeCopyDialog(); break;
55 case MOVE_TRACK: makeMoveDialog(); break;
56 case SET_POSITION: makeSetPositionDialog(); break;
57 case MANUAL: makeTextDialog("User Manual", "Manual.txt", 30, 95); break;
58 case INSERT_MEASURE: makeInsertMeasureDialog(); break;
59 case DELETE_MEASURE: makeDeleteMeasureDialog(); break;
60 case SET_TEMPO: makeSetTempoDialog(); break;
61 case PREFERENCES: makePrefsDialog(); break;
62 case TRANSPOSE: makeTransposeDialog(); break;
63 case SCALE_VELOCITY: makeScaleVelocityDialog(); break;
64 case RECORD: makeRecordDialog(); break;
69 * Builds the add track popupdialog.
70 * @param pane The container to put the dialog in.
71 * @param tracks A array containing miditracks.
73 private void makeAddDialog() {
74 setTitle("Add track");
75 // create the contents of the dialog and add to container
76 labelA = new JLabel("Name of track", JLabel.CENTER);
78 // textfield for naming track
79 textFieldA = new JTextField();
81 labelB = new JLabel("Add after", JLabel.CENTER);
83 // list of where to add track
84 trackListA = new JComboBox();
85 for (int i = 1; i < tracks.length; i++) trackListA.addItem("Track " + i);
87 // ok and cancel button
88 cancelButton = new JButton("Cancel");
89 pane.add(cancelButton);
90 okButton = new JButton("OK");
93 labelA.setBounds(50, 10, 100, 20);
94 textFieldA.setBounds(40, 35, 120, 20);
95 labelB.setBounds(50, 70, 100, 20);
96 trackListA.setBounds(40, 95, 120, 20);
97 cancelButton.setBounds(10, 150, 80, 30);
98 okButton.setBounds(120, 150, 60, 30);
102 setLocationRelativeTo(Moosique.getGUI());
107 * Builds the delete track popupdialog.
108 * @param pane The container to put the dialog in.
109 * @param tracks A array containing miditracks.
111 private void makeDelDialog() {
112 setTitle("Delete track");
113 // create the contents of the dialog and add to container
114 labelB = new JLabel("Delete track", JLabel.CENTER);
116 // list of what track to delete
117 trackListA = new JComboBox();
118 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
119 pane.add(trackListA);
120 // ok and cancelbutton
121 cancelButton = new JButton("Cancel");
122 pane.add(cancelButton);
123 okButton = new JButton("OK");
126 labelB.setBounds(50, 10, 100, 20);
127 trackListA.setBounds(40, 35, 120, 20);
128 cancelButton.setBounds(10, 90, 80, 30);
129 okButton.setBounds(120, 90, 60, 30);
133 setLocationRelativeTo(Moosique.getGUI());
138 * Builds the copy track popupdialog.
139 * @param pane The container to put the dialog in.
140 * @param tracks A array containing miditracks.
142 private void makeCopyDialog() {
143 setTitle("Copy Track");
144 // create the contents of the dialog and add to container
145 labelA = new JLabel("Track to copy", JLabel.CENTER);
147 // list of what track to copy
148 trackListA = new JComboBox();
149 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
150 pane.add(trackListA);
151 labelB = new JLabel("Insert after", JLabel.CENTER);
153 // list of where to put copied track
154 trackListB = new JComboBox();
155 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
156 pane.add(trackListB);
157 cancelButton = new JButton("Cancel");
158 pane.add(cancelButton);
159 okButton = new JButton("OK");
162 labelA.setBounds(50, 10, 100, 20);
163 trackListA.setBounds(40, 35, 120, 20);
164 labelB.setBounds(50, 70, 100, 20);
165 trackListB.setBounds(40, 95, 120, 20);
166 cancelButton.setBounds(10, 150, 80, 30);
167 okButton.setBounds(120, 150, 60, 30);
171 setLocationRelativeTo(Moosique.getGUI());
176 * Builds the move track popupdialog
177 * @param pane The container to put the dialog in.
178 * @param tracks A array containing miditracks.
180 private void makeMoveDialog() {
181 setTitle("Move track");
182 // create the contents of the dialog and add to container
183 labelA = new JLabel("Track to move", JLabel.CENTER);
185 // list of track to move
186 trackListA = new JComboBox();
187 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
188 pane.add(trackListA);
189 labelB = new JLabel("Insert after", JLabel.CENTER);
191 // list of where to put moved track
192 trackListB = new JComboBox();
193 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
194 pane.add(trackListB);
195 // ok and cancelbuttons
196 cancelButton = new JButton("Cancel");
197 pane.add(cancelButton);
198 okButton = new JButton("OK");
201 labelA.setBounds(40, 10, 120, 20);
202 trackListA.setBounds(40, 35, 120, 20);
203 labelB.setBounds(50, 70, 100, 20);
204 trackListB.setBounds(40, 95, 120, 20);
205 cancelButton.setBounds(10, 150, 80, 30);
206 okButton.setBounds(120, 150, 60, 30);
210 setLocationRelativeTo(Moosique.getGUI());
215 * Builds the set position dialog.
216 * @param pane The container to put the dialog in.
217 * @param tracks A array containing miditracks.
219 private void makeSetPositionDialog() {
221 setTitle("Set edit position");
222 // create the contents of the dialog and add to container
223 labelA = new JLabel("Measure", JLabel.CENTER);
225 labelB = new JLabel("Beat", JLabel.CENTER);
227 labelC = new JLabel("Tick", JLabel.CENTER);
229 textFieldA = new JTextField();
230 pane.add(textFieldA);
231 textFieldB = new JTextField();
232 pane.add(textFieldB);
233 textFieldC = new JTextField();
234 pane.add(textFieldC);
235 // ok and cancel buttons
236 cancelButton = new JButton("Cancel");
237 pane.add(cancelButton);
238 okButton = new JButton("OK");
241 labelA.setBounds(40, 25, 50, 20);
242 labelB.setBounds(105, 25, 50, 20);
243 labelC.setBounds(170, 25, 50, 20);
244 textFieldA.setBounds(40, 45, 50, 20);
245 textFieldB.setBounds(105, 45, 50, 20);
246 textFieldC.setBounds(170, 45, 50, 20);
247 cancelButton.setBounds(35, 90, 80, 30);
248 okButton.setBounds(155, 90, 60, 30);
252 setLocationRelativeTo(Moosique.getGUI());
257 * Builds the insert measure popupdialog.
258 * @param pane The container to put the dialog in.
260 private void makeInsertMeasureDialog(){
261 setTitle("Insert Measure");
262 // create the contents of the dialog and add to container
263 labelA = new JLabel("Insert at:", JLabel.RIGHT);
265 labelB = new JLabel("Measure count:", JLabel.RIGHT);
267 textFieldA = new JTextField();
268 pane.add(textFieldA);
269 textFieldB = new JTextField();
270 pane.add(textFieldB);
271 // ok and cancelbutton
272 cancelButton = new JButton("Cancel");
273 pane.add(cancelButton);
274 okButton = new JButton("OK");
277 labelA.setBounds(20, 20, 110 ,20);
278 labelB.setBounds(20, 50, 110, 20);
279 textFieldA.setBounds(140 ,20 , 40, 20);
280 textFieldB.setBounds(140,50, 40, 20);
281 cancelButton.setBounds(20 ,95 , 80, 30);
282 okButton.setBounds(120, 95, 60, 30);
286 setLocationRelativeTo(Moosique.getGUI());
291 * Builds the delete measure popupdialog.
292 * @param pane The container to put the dialog in.
294 private void makeDeleteMeasureDialog() {
295 setTitle("Delete Measure");
296 // create the contents of the dialog and add to container
297 labelA = new JLabel("Delete at:", JLabel.RIGHT);
299 labelB = new JLabel("Measure count:", JLabel.RIGHT);
301 textFieldA = new JTextField();
302 pane.add(textFieldA);
303 textFieldB = new JTextField();
304 pane.add(textFieldB);
305 // ok and cancelbutton
306 cancelButton = new JButton("Cancel");
307 pane.add(cancelButton);
308 okButton = new JButton("OK");
311 labelA.setBounds(20, 20, 110 ,20);
312 labelB.setBounds(20, 50, 110, 20);
313 textFieldA.setBounds(140 ,20 , 40, 20);
314 textFieldB.setBounds(140,50, 40, 20);
315 cancelButton.setBounds(20 ,95 , 80, 30);
316 okButton.setBounds(120, 95, 60, 30);
320 setLocationRelativeTo(Moosique.getGUI());
325 * Builds the set tempo dialog.
326 * @param pane The container to put the dialog in.
328 private void makeSetTempoDialog() {
329 setTitle("Set tempo");
330 // create contents of dialog and add to container
331 // track edit-intervall labels
332 labelA = new JLabel("Measure", JLabel.CENTER);
334 labelB = new JLabel("Beat", JLabel.CENTER);
336 labelC = new JLabel("Tick", JLabel.CENTER);
338 // start and end labels
339 labelD = new JLabel("Start at:", JLabel.RIGHT);
341 labelE = new JLabel("End at:", JLabel.RIGHT);
344 labelF = new JLabel("to", JLabel.CENTER);
346 // start inputvaluefields
347 textFieldA = new JTextField();
348 pane.add(textFieldA);
349 textFieldB = new JTextField();
350 pane.add(textFieldB);
351 textFieldC = new JTextField();
352 pane.add(textFieldC);
353 // end inputvaluefield
354 textFieldD = new JTextField();
355 pane.add(textFieldD);
356 textFieldE = new JTextField();
357 pane.add(textFieldE);
358 textFieldF = new JTextField();
359 pane.add(textFieldF);
360 // the radiobuttonlists inputvaluefields
361 textFieldG = new JTextField();
362 pane.add(textFieldG);
363 textFieldH = new JTextField();
364 pane.add(textFieldH);
365 textFieldI = new JTextField();
366 pane.add(textFieldI);
367 textFieldJ = new JTextField();
368 pane.add(textFieldJ);
369 textFieldK = new JTextField();
370 pane.add(textFieldK);
371 // the radiobuttonlist with associating titles
372 JRadioButton constant = new JRadioButton("Set constant tempo of:");
373 constant.setSelected(true);
375 JRadioButton change = new JRadioButton("Gradually change tempo:");
377 JRadioButton scale = new JRadioButton("Scale tempo in %:");
379 JRadioButton add = new JRadioButton("Add to current tempo:");
381 // a buttongroup for the radiobuttons
382 ButtonGroup group = new ButtonGroup();
387 // ok and cancelbutton
388 cancelButton = new JButton("Cancel");
389 pane.add(cancelButton);
390 okButton = new JButton("OK");
393 // set bounds of track edit-intervall labels
394 labelA.setBounds(80, 25, 50, 20);
395 labelB.setBounds(145, 25, 50, 20);
396 labelC.setBounds(210, 25, 50, 20);
397 // set bounds of start and end labels
398 labelD.setBounds(20, 45, 60, 20);
399 labelE.setBounds(20, 65, 60, 20);
400 // set bounds of from-to label
401 labelF.setBounds(255, 125, 20 ,20);
402 // set bounds of start inputvaluefields
403 textFieldA.setBounds(80, 45, 50, 20);
404 textFieldB.setBounds(145, 45, 50, 20);
405 textFieldC.setBounds(210, 45, 50, 20);
406 // set bounds of end inputvaluefield
407 textFieldD.setBounds(80, 65, 50, 20);
408 textFieldE.setBounds(145, 65, 50, 20);
409 textFieldF.setBounds(210, 65, 50, 20);
410 // set bounds of radiobuttonlists inputvaluefields
411 textFieldG.setBounds(220, 100, 35, 20);
412 textFieldH.setBounds(220, 125, 35, 20);
413 textFieldI.setBounds(280, 125, 35, 20);
414 textFieldJ.setBounds(220, 150, 35, 20);
415 textFieldK.setBounds(220, 175, 35, 20);
416 // set bounds of radiobuttonlist items
417 constant.setBounds(20, 100, 180, 20);
418 change.setBounds(20, 125, 200, 20);
419 scale.setBounds(20, 150, 150, 20);
420 add.setBounds(20, 175, 175, 20);
421 // set bounds of ok and cancelbutton
422 cancelButton.setBounds(75, 215, 80, 30);
423 okButton.setBounds(195, 215, 60, 30);
428 setLocationRelativeTo(Moosique.getGUI());
433 * Builds the transpose dialog.
434 * @param pane The container to put the dialog in.
435 * @param tracks A array containing miditracks.
437 private void makeTransposeDialog() {
438 setTitle("Transpose");
439 // create contents of dialog and add to container
440 // track edit-intervall labels
441 labelA = new JLabel("Measure", JLabel.CENTER);
443 labelB = new JLabel("Beat", JLabel.CENTER);
445 labelC = new JLabel("Tick", JLabel.CENTER);
447 // start and end labels
448 labelD = new JLabel("Start at:", JLabel.RIGHT);
450 labelE = new JLabel("End at:", JLabel.RIGHT);
452 // oktave inputvalue labels
453 labelF = new JLabel("Octaves", JLabel.LEFT);
455 labelG = new JLabel("1/2 octaves", JLabel.LEFT);
457 // what track to edit label
458 labelH = new JLabel("Track to edit:", JLabel.CENTER);
460 // combobox representing the tracks
461 trackListA = new JComboBox();
462 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
463 pane.add(trackListA);
464 // start inputvaluefields
465 textFieldA = new JTextField();
466 pane.add(textFieldA);
467 textFieldB = new JTextField();
468 pane.add(textFieldB);
469 textFieldC = new JTextField();
470 pane.add(textFieldC);
471 // end inputvaluefield
472 textFieldD = new JTextField();
473 pane.add(textFieldD);
474 textFieldE = new JTextField();
475 pane.add(textFieldE);
476 textFieldF = new JTextField();
477 pane.add(textFieldF);
478 // the radiobuttonlists inputvaluefields
479 textFieldG = new JTextField();
480 pane.add(textFieldG);
481 textFieldH = new JTextField();
482 pane.add(textFieldH);
483 // the radiobuttonlist with associating titles
484 JRadioButton up = new JRadioButton("Change up");
485 up.setSelected(true);
487 JRadioButton down = new JRadioButton("Change down");
489 // a buttongroup for the radiobuttons
490 ButtonGroup group = new ButtonGroup();
493 // ok and cancelbutton
494 cancelButton = new JButton("Cancel");
495 pane.add(cancelButton);
496 okButton = new JButton("OK");
499 // set bounds of track edit-intervall labels
500 labelA.setBounds(90, 70, 50, 20);
501 labelB.setBounds(155, 70, 50, 20);
502 labelC.setBounds(220, 70, 50, 20);
503 // set bounds of start and end labels
504 labelD.setBounds(30, 90, 60, 20);
505 labelE.setBounds(30, 110, 60, 20);
506 // set bounds of octave inputvaluefields
507 labelF.setBounds(210, 150, 80, 20);
508 labelG.setBounds(210, 175, 100, 20);
509 // set bounds of trackslist label
510 labelH.setBounds(30, 30, 100, 20);
511 // set bounds of start inputvaluefields
512 textFieldA.setBounds(90, 90, 50, 20);
513 textFieldB.setBounds(155, 90, 50, 20);
514 textFieldC.setBounds(220, 90, 50, 20);
515 // set bounds of end inputvaluefield
516 textFieldD.setBounds(90, 110, 50, 20);
517 textFieldE.setBounds(155, 110, 50, 20);
518 textFieldF.setBounds(220, 110, 50, 20);
519 // set bounds of octave inputvaluefields
520 textFieldG.setBounds(170, 150, 35, 20);
521 textFieldH.setBounds(170, 175, 35, 20);
522 // set bounds of radiobuttonlist items
523 up.setBounds(30, 150, 100, 20);
524 down.setBounds(30, 175, 120, 20);
525 // set bounds of tracklist
526 trackListA.setBounds(145, 30, 120, 20);
527 // set bounds of ok and cancelbutton
528 cancelButton.setBounds(75, 215, 80, 30);
529 okButton.setBounds(195, 215, 60, 30);
534 setLocationRelativeTo(Moosique.getGUI());
539 * Builds the scale velocity dialog.
540 * @param pane The container to put the dialog in.
541 * @param tracks A array containing miditracks.
543 private void makeScaleVelocityDialog() {
544 setTitle("Scale velocity");
545 // create contents of dialog and add to container
546 // track edit-intervall labels
547 labelA = new JLabel("Measure", JLabel.CENTER);
549 labelB = new JLabel("Beat", JLabel.CENTER);
551 labelC = new JLabel("Tick", JLabel.CENTER);
553 // start and end labels
554 labelD = new JLabel("Start at:", JLabel.RIGHT);
556 labelE = new JLabel("End at:", JLabel.RIGHT);
559 labelF = new JLabel("to", JLabel.CENTER);
561 // what track to edit label
562 labelG = new JLabel("Track to edit:", JLabel.CENTER);
564 // combobox representing the tracks
565 trackListA = new JComboBox();
566 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
567 pane.add(trackListA);
568 // start inputvaluefields
569 textFieldA = new JTextField();
570 pane.add(textFieldA);
571 textFieldB = new JTextField();
572 pane.add(textFieldB);
573 textFieldC = new JTextField();
574 pane.add(textFieldC);
575 // end inputvaluefield
576 textFieldD = new JTextField();
577 pane.add(textFieldD);
578 textFieldE = new JTextField();
579 pane.add(textFieldE);
580 textFieldF = new JTextField();
581 pane.add(textFieldF);
582 // the radiobuttonlists inputvaluefields
583 textFieldG = new JTextField();
584 pane.add(textFieldG);
585 textFieldH = new JTextField();
586 pane.add(textFieldH);
587 textFieldI = new JTextField();
588 pane.add(textFieldI);
589 textFieldJ = new JTextField();
590 pane.add(textFieldJ);
591 textFieldK = new JTextField();
592 pane.add(textFieldK);
593 // the radiobuttonlist with associating titles
594 JRadioButton constant = new JRadioButton("Change all values to:");
595 constant.setSelected(true);
597 JRadioButton change = new JRadioButton("Gradually change value:");
599 JRadioButton scale = new JRadioButton("Scale values to %:");
601 JRadioButton add = new JRadioButton("Add to current value:");
603 // a buttongroup for the radiobuttons
604 ButtonGroup group = new ButtonGroup();
609 // ok and cancelbutton
610 cancelButton = new JButton("Cancel");
611 pane.add(cancelButton);
612 okButton = new JButton("OK");
615 // set bounds of track edit-intervall labels
616 labelA.setBounds(80, 75, 50, 20);
617 labelB.setBounds(145, 75, 50, 20);
618 labelC.setBounds(210, 75, 50, 20);
619 // set bounds of start and end labels
620 labelD.setBounds(20, 95, 60, 20);
621 labelE.setBounds(20, 115, 60, 20);
622 // set bounds of from-to label
623 labelF.setBounds(255, 175, 20 ,20);
624 // set bounds of trackslist label
625 labelG.setBounds(30, 30, 100, 20);
626 // set bounds of start inputvaluefields
627 textFieldA.setBounds(80, 95, 50, 20);
628 textFieldB.setBounds(145, 95, 50, 20);
629 textFieldC.setBounds(210, 95, 50, 20);
630 // set bounds of end inputvaluefield
631 textFieldD.setBounds(80, 115, 50, 20);
632 textFieldE.setBounds(145,115, 50, 20);
633 textFieldF.setBounds(210, 115, 50, 20);
634 // set bounds of radiobuttonlists inputvaluefields
635 textFieldG.setBounds(220, 150, 35, 20);
636 textFieldH.setBounds(220, 175, 35, 20);
637 textFieldI.setBounds(280, 175, 35, 20);
638 textFieldJ.setBounds(220, 200, 35, 20);
639 textFieldK.setBounds(220, 225, 35, 20);
640 // set bounds of radiobuttonlist items
641 constant.setBounds(20, 150, 180, 20);
642 change.setBounds(20, 175, 200, 20);
643 scale.setBounds(20, 200, 150, 20);
644 add.setBounds(20, 225, 175, 20);
645 // set bounds of tracklist
646 trackListA.setBounds(145, 30, 120, 20);
647 // set bounds of ok and cancelbutton
648 cancelButton.setBounds(75, 265, 80, 30);
649 okButton.setBounds(195, 265, 60, 30);
654 setLocationRelativeTo(Moosique.getGUI());
657 /** creates the "User manual dialog" that displays a textfile
659 private void makeTextDialog(String title, String filename, int rows, int columns) {
661 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
662 File manual = new File(filename);
665 BufferedReader br = new BufferedReader(new FileReader(manual));
666 char[] chars = new char[(int)manual.length()];
667 br.read(chars, 0, (int)manual.length());
668 s = new String(chars);
669 } catch (Exception ex) {
670 s = "File not found";
672 JTextArea text = new JTextArea(s, rows, columns);
673 text.setLineWrap(true);
674 text.setWrapStyleWord(true);
675 text.setEnabled(false);
676 text.setDisabledTextColor(Color.black);
677 pane.add(new JScrollPane(text));
678 Action close = new AbstractAction("Close") {
679 public void actionPerformed(ActionEvent ae) {
682 JButton closeButton = new JButton(close);
683 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
684 pane.add(closeButton);
687 setLocationRelativeTo(Moosique.getGUI());
691 private void makePrefsDialog() {
693 MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo();
694 for (int i = 0; i < devInfo.length; i++) {
695 if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Sequencer) {
697 } else if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Synthesizer) {
701 String[] seqNames, synthNames;
702 JPanel pane = (JPanel) this.getContentPane();
703 pane.add(new JLabel("Sequencer"));
704 JComboBox seqBox = new JComboBox(seqNames);
705 pane.add(new JLabel("Synthesizer"));
706 JComboBox synthBox = new JComboBox(synthNames);
710 private void makeRecordDialog() {
713 JPanel panel = new JPanel();
714 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
716 // Creating track combo box,
717 panel.add(new Label("Track: "));
718 trackListA = new JComboBox();
719 for (int i = 1; i < tracks.length; i++) trackListA.addItem("Track " + i);
720 trackListA.setFont(Moosique.getGUI().FONT);
721 panel.add(trackListA);
723 // Creating channel combo box
724 panel.add(new Label("Channel: "));
725 JComboBox channelList = new JComboBox();
726 for (int i = 1; i <= 16; i++) channelList.addItem("Channel " + i);
727 channelList.setFont(Moosique.getGUI().FONT);
728 panel.add(channelList);
730 // Creating quantize pane
731 JLayeredPane quantizePane = new JLayeredPane();
732 quantizePane.setBorder(BorderFactory.createTitledBorder("Quantize"));
733 JCheckBox quantizeBox = new JCheckBox("Quantize");
734 quantizePane.add(quantizeBox);
735 JLabel quantizeSizeLabel = new JLabel("Resolution");
736 JComboBox quantizeSize = new JComboBox(noteSizes);
737 quantizeSize.setSelectedIndex(4);
738 quantizeSize.setEnabled(false);
739 quantizeSize.setFont(Moosique.getGUI().FONT);
740 quantizeSizeLabel.setLabelFor(quantizeSize);
741 quantizePane.add(quantizeSizeLabel);
742 quantizePane.add(quantizeSize);
743 JCheckBox quantizeLocationBox = new JCheckBox("Affect location", true);
744 quantizeLocationBox.setEnabled(false);
745 quantizePane.add(quantizeLocationBox);
746 JCheckBox quantizeDurationBox = new JCheckBox("Affect duration", true);
747 quantizeDurationBox.setEnabled(false);
748 quantizePane.add(quantizeDurationBox);
749 panel.add(quantizePane);
752 final String btnString1 = "Record!";
753 final String btnString2 = "Cancel";
754 Object[] options = {btnString1, btnString2};
756 // Creating option pane
757 optionPane = new JOptionPane(panel,
758 JOptionPane.QUESTION_MESSAGE,
759 JOptionPane.YES_NO_OPTION,
763 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
764 public void propertyChange(PropertyChangeEvent e) {
765 String prop = e.getPropertyName();
767 if (isVisible() && (e.getSource() == optionPane) &&
768 (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
769 Object value = optionPane.getValue();
770 if (value == JOptionPane.UNINITIALIZED_VALUE) return;
771 optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);
773 if (value.equals(btnString1)) {
774 // boolean[] quantizers = {quantize, location, duration};
775 Track track = tracks[trackListA.getSelectedIndex() + 1];
776 int channel = Moosique.getGUI().getView().getTrackView(track).getTitle().getChannel();
777 boolean[] quantizers = {false, false, false};
778 int resolution = Moosique.SIXTEENTH_NOTE;
779 Moosique.record(track, channel, quantizers, resolution);
785 setContentPane(optionPane);
786 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
790 setLocationRelativeTo(Moosique.getGUI());
794 private MooNote note;
795 private JOptionPane optionPane;
796 private JTextField pitch;
797 private JTextField velocity;
798 private JTextField length;
801 * Creates a new note preference dialog.
802 * @param mn the note that will be graphically represented
804 public MooDialog(MooNote mn) {
805 super(Moosique.getGUI(), "Note properties", true);
809 JPanel panel = new JPanel();
810 panel.setLayout(new GridLayout(3,2));
812 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
813 panel.add(new Label("Pitch: "));
816 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
817 panel.add(new Label("Velocity: "));
820 length = new JTextField(new Integer(note.getDuration()).toString(),5);
821 panel.add(new Label("Length: "));
824 Object[] array = {"Set the note properties",
827 final String btnString1 = "Apply changes";
828 final String btnString2 = "Cancel";
829 Object[] options = {btnString1, btnString2};
831 optionPane = new JOptionPane(array,
832 JOptionPane.QUESTION_MESSAGE,
833 JOptionPane.YES_NO_OPTION,
837 setContentPane(optionPane);
838 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
840 ActionListener intValidator = new ActionListener() {
841 public void actionPerformed(ActionEvent e) {
842 if (e.getSource() instanceof JTextField){
843 JTextField s = (JTextField)e.getSource();
844 int num = Integer.parseInt(s.getText());
847 else if (num > 127 && s != length)
849 s.setText(new Integer(num).toString());
853 pitch.addActionListener(intValidator);
854 velocity.addActionListener(intValidator);
855 length.addActionListener(intValidator);
857 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
858 public void propertyChange(PropertyChangeEvent e) {
859 String prop = e.getPropertyName();
862 && (e.getSource() == optionPane)
863 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
864 prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
865 Object value = optionPane.getValue();
867 if (value == JOptionPane.UNINITIALIZED_VALUE) {
872 // Reset the JOptionPane's value.
873 // If you don't do this, then if the user
874 // presses the same button next time, no
875 // property change event will be fired.
877 JOptionPane.UNINITIALIZED_VALUE);
879 if (value.equals(btnString1)) {
880 note.setPitch(Integer.parseInt(pitch.getText()));
881 note.setVelocity(Integer.parseInt(velocity.getText()));
882 note.setDuration(Integer.parseInt(length.getText()));
883 Moosique.setEdited();
885 } else { // user closed dialog or clicked cancel
892 setLocationRelativeTo(Moosique.getGUI());