]> ruin.nu Git - moosique.git/blob - MooDialog.java
no message
[moosique.git] / MooDialog.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.*;
4 import javax.sound.midi.*;
5 import java.io.*;
6 import java.beans.*;
7
8 /**
9  * A generator class for the application's dialogs.
10  *
11  * @author Björn Lanneskog
12  */
13  
14 public class MooDialog extends JDialog {
15
16         private Container pane;
17         private Track[] tracks;
18
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,
22                            textFieldK;
23         private JComboBox trackListA, trackListB; 
24         private JButton okButton, cancelButton;
25         public static final int ADD_TRACK = 1,
26                                 DELETE_TRACK = 2,
27                                 COPY_TRACK = 3,
28                                 MOVE_TRACK = 4,
29                                 SET_POSITION = 5,
30                                 MANUAL = 6,
31                                 INSERT_MEASURE = 7,
32                                 DELETE_MEASURE = 8,
33                                 SET_TEMPO = 9,
34                                 PREFERENCES = 10,
35                                 TRANSPOSE = 11,
36                                 SCALE_VELOCITY = 12, 
37                                 RECORD = 13;
38         public static final String[] noteSizes = {"Whole", "Half", "Quarter", "Eighth", "Sixteenth"};
39         
40         /**
41          * Constructor of the dialogs.
42          */
43          public MooDialog(int type) {
44                 super(Moosique.getGUI(), false);
45                         
46                 pane = getContentPane();
47                 pane.setLayout(null);
48                 
49                 tracks = Moosique.getSequence().getTracks();
50
51                 switch (type) {
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;
65                 }
66          }
67         
68         /**
69          * Builds the add track popupdialog.
70          * @param pane          The container to put the dialog in.
71          * @param tracks        A array containing miditracks.
72          */
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);
77                 pane.add(labelA);
78                 // textfield for naming track
79                 textFieldA = new JTextField();  
80                 pane.add(textFieldA);
81                 labelB = new JLabel("Add after", JLabel.CENTER);
82                 pane.add(labelB);
83                 // list of where to add track
84                 trackListA = new JComboBox();
85                 for (int i = 1; i < tracks.length; i++) trackListA.addItem("Track " + i);
86                 pane.add(trackListA);
87                 // ok and cancel button
88                 cancelButton = new JButton("Cancel");
89                 pane.add(cancelButton);
90                 okButton = new JButton("OK");
91                 pane.add(okButton);
92                 // set layout prop
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);
99                 setResizable(false);
100                 pack();
101                 setSize(200,220);
102                 setLocationRelativeTo(Moosique.getGUI());
103                 setVisible(true);
104         }
105         
106         /**
107          * Builds the delete track popupdialog.
108          * @param pane          The container to put the dialog in.
109          * @param tracks        A array containing miditracks.
110          */
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);
115                 pane.add(labelB);
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");
124                 pane.add(okButton);
125                 // set layout prop      
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);
130                 setResizable(false);
131                 pack();
132                 setSize(200,165);
133                 setLocationRelativeTo(Moosique.getGUI());
134                 setVisible(true);
135         }
136         
137         /**
138          * Builds the copy track popupdialog.
139          * @param pane          The container to put the dialog in.
140          * @param tracks        A array containing miditracks.
141          */
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);
146                 pane.add(labelA);
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);
152                 pane.add(labelB);
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");
160                 pane.add(okButton);
161                 // set layout prop
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);
168                 setResizable(false);
169                 pack();
170                 setSize(200,220);
171                 setLocationRelativeTo(Moosique.getGUI());
172                 setVisible(true);
173         }
174         
175         /**
176          * Builds the move track popupdialog
177          * @param pane          The container to put the dialog in.
178          * @param tracks        A array containing miditracks.
179          */
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);
184                 pane.add(labelA);
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);
190                 pane.add(labelB);
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");
199                 pane.add(okButton);
200                 // set layoutprop
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);
207                 setResizable(false);
208                 pack();
209                 setSize(200,220);
210                 setLocationRelativeTo(Moosique.getGUI());
211                 setVisible(true);
212         }
213         
214         /**
215          * Builds the set position dialog.
216          * @param pane          The container to put the dialog in.
217          * @param tracks        A array containing miditracks.
218          */
219         private void makeSetPositionDialog() {
220                 
221                 setTitle("Set edit position");
222                 // create the contents of the dialog and add to container
223                 labelA = new JLabel("Measure", JLabel.CENTER);
224                 pane.add(labelA);
225                 labelB = new JLabel("Beat", JLabel.CENTER);
226                 pane.add(labelB);
227                 labelC = new JLabel("Tick", JLabel.CENTER);
228                 pane.add(labelC);
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");
239                 pane.add(okButton);
240                 // set layoutprop
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);
249                 setResizable(false);
250                 pack();
251                 setSize(260,165);
252                 setLocationRelativeTo(Moosique.getGUI());
253                 setVisible(true);
254         }
255         
256         /**
257          * Builds the insert measure popupdialog.
258          * @param pane          The container to put the dialog in.
259          */
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);
264                 pane.add(labelA);
265                 labelB = new JLabel("Measure count:", JLabel.RIGHT);
266                 pane.add(labelB);
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");
275                 pane.add(okButton);
276                 // set layout prop
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);
283                 setResizable(false);
284                 pack();
285                 setSize(210,175);
286                 setLocationRelativeTo(Moosique.getGUI());
287                 setVisible(true);
288         }
289         
290         /**
291          * Builds the delete measure popupdialog.
292          * @param pane          The container to put the dialog in.
293          */
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);
298                 pane.add(labelA);
299                 labelB = new JLabel("Measure count:", JLabel.RIGHT);
300                 pane.add(labelB);
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");
309                 pane.add(okButton);
310                 // set layout prop
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);
317                 setResizable(false);
318                 pack();
319                 setSize(210,175);
320                 setLocationRelativeTo(Moosique.getGUI());
321                 setVisible(true);
322         }
323         
324         /**
325          * Builds the set tempo dialog.
326          * @param pane          The container to put the dialog in.
327          */
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);
333                 pane.add(labelA);
334                 labelB = new JLabel("Beat", JLabel.CENTER);
335                 pane.add(labelB);
336                 labelC = new JLabel("Tick", JLabel.CENTER);
337                 pane.add(labelC);
338                 // start and end labels
339                 labelD = new JLabel("Start at:", JLabel.RIGHT);
340                 pane.add(labelD);
341                 labelE = new JLabel("End at:", JLabel.RIGHT);
342                 pane.add(labelE);
343                 // from-to label
344                 labelF = new JLabel("to", JLabel.CENTER);
345                 pane.add(labelF);
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);
374                 pane.add(constant);
375                 JRadioButton change = new JRadioButton("Gradually change tempo:");
376                 pane.add(change);
377                 JRadioButton scale = new JRadioButton("Scale tempo in %:");
378                 pane.add(scale);
379                 JRadioButton add = new JRadioButton("Add to current tempo:");
380                 pane.add(add);
381                 // a buttongroup for the radiobuttons
382                 ButtonGroup group = new ButtonGroup();
383                 group.add(constant);
384                 group.add(change);
385                 group.add(scale);
386                 group.add(add);
387                 // ok and cancelbutton
388                 cancelButton = new JButton("Cancel");
389                 pane.add(cancelButton);
390                 okButton = new JButton("OK");
391                 pane.add(okButton);
392                 
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);
424                 // set layout prop
425                 setResizable(false);
426                 pack();
427                 setSize(340,300);
428                 setLocationRelativeTo(Moosique.getGUI());
429                 setVisible(true);
430         }
431         
432         /**
433          * Builds the transpose dialog.
434          * @param pane          The container to put the dialog in.
435          * @param tracks        A array containing miditracks.
436          */
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);
442                 pane.add(labelA);
443                 labelB = new JLabel("Beat", JLabel.CENTER);
444                 pane.add(labelB);
445                 labelC = new JLabel("Tick", JLabel.CENTER);
446                 pane.add(labelC);
447                 // start and end labels
448                 labelD = new JLabel("Start at:", JLabel.RIGHT);
449                 pane.add(labelD);
450                 labelE = new JLabel("End at:", JLabel.RIGHT);
451                 pane.add(labelE);
452                 // oktave inputvalue labels
453                 labelF = new JLabel("Octaves", JLabel.LEFT);
454                 pane.add(labelF);
455                 labelG = new JLabel("1/2 octaves", JLabel.LEFT);
456                 pane.add(labelG);
457                 // what track to edit label
458                 labelH = new JLabel("Track to edit:", JLabel.CENTER);
459                 pane.add(labelH);
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);
486                 pane.add(up);
487                 JRadioButton down = new JRadioButton("Change down");
488                 pane.add(down);
489                 // a buttongroup for the radiobuttons
490                 ButtonGroup group = new ButtonGroup();
491                 group.add(up);
492                 group.add(down);
493                 // ok and cancelbutton
494                 cancelButton = new JButton("Cancel");
495                 pane.add(cancelButton);
496                 okButton = new JButton("OK");
497                 pane.add(okButton);
498                 
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);
530                 // set layoutprop
531                 setResizable(false);
532                 pack();
533                 setSize(340,300);
534                 setLocationRelativeTo(Moosique.getGUI());
535                 setVisible(true);
536         }
537         
538         /**
539          * Builds the scale velocity dialog.
540          * @param pane  The container to put the dialog in.
541          * @param tracks        A array containing miditracks.
542          */
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);
548                 pane.add(labelA);
549                 labelB = new JLabel("Beat", JLabel.CENTER);
550                 pane.add(labelB);
551                 labelC = new JLabel("Tick", JLabel.CENTER);
552                 pane.add(labelC);
553                 // start and end labels
554                 labelD = new JLabel("Start at:", JLabel.RIGHT);
555                 pane.add(labelD);
556                 labelE = new JLabel("End at:", JLabel.RIGHT);
557                 pane.add(labelE);
558                 // from-to label
559                 labelF = new JLabel("to", JLabel.CENTER);
560                 pane.add(labelF);
561                 // what track to edit label
562                 labelG = new JLabel("Track to edit:", JLabel.CENTER);
563                 pane.add(labelG);
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);
596                 pane.add(constant);
597                 JRadioButton change = new JRadioButton("Gradually  change value:");
598                 pane.add(change);
599                 JRadioButton scale = new JRadioButton("Scale values to %:");
600                 pane.add(scale);
601                 JRadioButton add = new JRadioButton("Add to current value:");
602                 pane.add(add);
603                 // a buttongroup for the radiobuttons
604                 ButtonGroup group = new ButtonGroup();
605                 group.add(constant);
606                 group.add(change);
607                 group.add(scale);
608                 group.add(add);
609                 // ok and cancelbutton
610                 cancelButton = new JButton("Cancel");
611                 pane.add(cancelButton);
612                 okButton = new JButton("OK");
613                 pane.add(okButton);
614                 
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);
650                 // set layout prop
651                 setResizable(false);
652                 pack();
653                 setSize(340,350);
654                 setLocationRelativeTo(Moosique.getGUI());
655                 setVisible(true);
656         }
657         /** creates the "User manual dialog" that displays a  textfile
658         */
659         private void makeTextDialog(String title, String filename, int rows, int columns) {
660                 setTitle(title);
661                 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
662                 File manual = new File(filename);
663                 String s;
664                 try {
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";
671                 }
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) {
680                                 setVisible(false);
681                         }};
682                 JButton closeButton = new JButton(close);
683                 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
684                 pane.add(closeButton);
685                 setResizable(false);
686                 pack();
687                 setLocationRelativeTo(Moosique.getGUI());
688                 setVisible(true);
689         }
690
691         private void makePrefsDialog() {
692                 /*              
693                 MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo();
694                 for (int i = 0; i < devInfo.length; i++) {
695                         if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Sequencer) {
696                         
697                         } else if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Synthesizer) {
698                         
699                         }
700                 }
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);
707                 */
708         }
709
710         private void makeRecordDialog() {
711                 setTitle("Record");
712
713                 JPanel panel = new JPanel();
714                 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
715
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);
722
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);
729
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);
750
751                 // Creating buttons
752                 final String btnString1 = "Record!";
753                 final String btnString2 = "Cancel";
754                 Object[] options = {btnString1, btnString2};
755
756                 // Creating option pane
757                 optionPane = new JOptionPane(panel, 
758                                             JOptionPane.QUESTION_MESSAGE,
759                                             JOptionPane.YES_NO_OPTION,
760                                             null,
761                                             options,
762                                             options[0]);
763                 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
764                     public void propertyChange(PropertyChangeEvent e) {
765                         String prop = e.getPropertyName();
766         
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);
772                                 
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);
780                                 }
781                                 setVisible(false);
782                         }
783                     }
784                 });
785                 setContentPane(optionPane);
786                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
787
788                 setResizable(false);
789                 pack();
790                 setLocationRelativeTo(Moosique.getGUI());
791                 setVisible(true);
792         }
793
794         private MooNote note;
795         private JOptionPane optionPane;
796         private JTextField pitch;
797         private JTextField velocity;
798         private JTextField length;
799         
800         /** 
801          * Creates a new note preference dialog.
802          * @param mn    the note that will be graphically represented
803          */
804         public MooDialog(MooNote mn) {
805                 super(Moosique.getGUI(), "Note properties", true);
806
807                 note = mn;
808
809                 JPanel panel = new JPanel();
810                 panel.setLayout(new GridLayout(3,2));
811
812                 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
813                 panel.add(new Label("Pitch: "));
814                 panel.add(pitch);
815
816                 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
817                 panel.add(new Label("Velocity: "));
818                 panel.add(velocity);
819
820                 length = new JTextField(new Integer(note.getDuration()).toString(),5);
821                 panel.add(new Label("Length: "));
822                 panel.add(length);
823
824                 Object[] array = {"Set the note properties",
825                                 panel};
826         
827                 final String btnString1 = "Apply changes";
828                 final String btnString2 = "Cancel";
829                 Object[] options = {btnString1, btnString2};
830         
831                 optionPane = new JOptionPane(array, 
832                                             JOptionPane.QUESTION_MESSAGE,
833                                             JOptionPane.YES_NO_OPTION,
834                                             null,
835                                             options,
836                                             options[0]);
837                 setContentPane(optionPane);
838                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
839         
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());
845                                                 if (num < 0)
846                                                         num = 0;
847                                                 else if (num > 127 && s != length)
848                                                         num = 127;
849                                                 s.setText(new Integer(num).toString());
850                                         }
851                     }
852                 };
853                 pitch.addActionListener(intValidator);
854                 velocity.addActionListener(intValidator);
855                 length.addActionListener(intValidator);
856
857                 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
858                     public void propertyChange(PropertyChangeEvent e) {
859                         String prop = e.getPropertyName();
860         
861                         if (isVisible() 
862                          && (e.getSource() == optionPane)
863                          && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
864                              prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
865                             Object value = optionPane.getValue();
866         
867                             if (value == JOptionPane.UNINITIALIZED_VALUE) {
868                                 //ignore reset
869                                 return;
870                             }
871         
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.
876                             optionPane.setValue(
877                                     JOptionPane.UNINITIALIZED_VALUE);
878         
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();
884                                                         setVisible(false);
885                             } else { // user closed dialog or clicked cancel
886                                 setVisible(false);
887                             }
888                         }
889                     }
890                 });
891                 pack();
892                 setLocationRelativeTo(Moosique.getGUI());
893                 setVisible(true);
894         }
895 }