]> ruin.nu Git - moosique.git/blob - MooDialog.java
nu är även den fina scale velocity dialogen färdig
[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 JLabel labelA, labelB, labelC, labelD, labelE, labelF, labelG, labelH;
17         private JTextField textFieldA, textFieldB, textFieldC, textFieldD, textFieldE, textFieldF,
18                            textFieldG, textFieldH, textFieldI, textFieldJ, textFieldK;
19         private JComboBox trackListA, trackListB; 
20         private JButton okButton, cancelButton;
21         public static final int ADD_TRACK = 1,
22                                 DELETE_TRACK = 2,
23                                 COPY_TRACK = 3,
24                                 MOVE_TRACK = 4,
25                                 SET_POSITION = 5,
26                                 MANUAL = 6,
27                                 INSERT_MEASURE = 7,
28                                 DELETE_MEASURE = 8,
29                                 SET_TEMPO = 9,
30                                 PREFERENCES = 10,
31                                 TRANSPOSE = 11,
32                                 SCALE_VELOCITY = 12;
33         
34         /**
35          * Constructor of the dialogs.
36          */
37          public MooDialog(int type) {
38                 super(Moosique.getGUI(), false);
39                         
40                 Container pane = getContentPane();
41                 pane.setLayout(null);
42                 
43                 Track[] tracks = Moosique.getSequence().getTracks();
44
45                 switch (type) {
46                         case ADD_TRACK:         makeAddDialog(pane, tracks); break;
47                         case DELETE_TRACK:      makeDelDialog(pane, tracks); break;
48                         case COPY_TRACK:        makeCopyDialog(pane, tracks); break;
49                         case MOVE_TRACK:        makeMoveDialog(pane, tracks); break;
50                         case SET_POSITION:      makeSetPositionDialog(pane); break;
51                         case MANUAL:            makeTextDialog(pane, "Manual.txt"); break;
52                         case INSERT_MEASURE:    makeInsertMeasureDialog(pane); break;
53                         case DELETE_MEASURE:    makeDeleteMeasureDialog(pane); break;
54                         case SET_TEMPO:         makeSetTempoDialog(pane); break;
55                         case PREFERENCES:       makePrefsDialog(pane); break;
56                         case TRANSPOSE:         makeTransposeDialog(pane, tracks); break;
57                         case SCALE_VELOCITY:    makeScaleVelocityDialog(pane, tracks); break;
58                 }
59          }
60         
61         /**
62          * Builds the add track popupdialog.
63          * @param pane          The container to put the dialog in.
64          * @param tracks        A array containing miditracks.
65          */
66         private void makeAddDialog(Container pane, Track[] tracks) {
67         
68                 setTitle("Add track");
69                 labelA = new JLabel("Name of track", JLabel.CENTER);
70                 pane.add(labelA);
71                 textFieldA = new JTextField();  
72                 pane.add(textFieldA);
73                 labelB = new JLabel("Add after", JLabel.CENTER);
74                 pane.add(labelB);
75                 trackListA = new JComboBox();
76                 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
77                 pane.add(trackListA);
78                 cancelButton = new JButton("Cancel");
79                 pane.add(cancelButton);
80                 okButton = new JButton("OK");
81                 pane.add(okButton);
82         
83                 labelA.setBounds(50, 10, 100, 20);
84                 textFieldA.setBounds(40, 35, 120, 20);
85                 labelB.setBounds(50, 70, 100, 20);
86                 trackListA.setBounds(40, 95, 120, 20);
87                 cancelButton.setBounds(10, 150, 80, 30);
88                 okButton.setBounds(120, 150, 60, 30);
89         
90                 setResizable(false);
91                 pack();
92                 setSize(200,220);
93                 setLocationRelativeTo(Moosique.getGUI());
94                 setVisible(true);
95         }
96         
97         /**
98          * Builds the delete track popupdialog.
99          * @param pane          The container to put the dialog in.
100          * @param tracks        A array containing miditracks.
101          */
102         private void makeDelDialog(Container pane, Track[] tracks) {
103         
104                 setTitle("Delete track");
105                 labelB = new JLabel("Delete track", JLabel.CENTER);
106                 pane.add(labelB);
107                 trackListA = new JComboBox();
108                 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
109                 pane.add(trackListA);
110                 cancelButton = new JButton("Cancel");
111                 pane.add(cancelButton);
112                 okButton = new JButton("OK");
113                 pane.add(okButton);
114                         
115                 labelB.setBounds(50, 10, 100, 20);
116                 trackListA.setBounds(40, 35, 120, 20);
117                 cancelButton.setBounds(10, 90, 80, 30);
118                 okButton.setBounds(120, 90, 60, 30);
119         
120                 setResizable(false);
121                 pack();
122                 setSize(200,165);
123                 setLocationRelativeTo(Moosique.getGUI());
124                 setVisible(true);
125         }
126         
127         /**
128          * Builds the copy track popupdialog.
129          * @param pane          The container to put the dialog in.
130          * @param tracks        A array containing miditracks.
131          */
132         private void makeCopyDialog(Container pane, Track[] tracks) {
133         
134                 setTitle("Copy Track");
135                 labelA = new JLabel("Track to copy", JLabel.CENTER);
136                 pane.add(labelA);
137                 trackListA = new JComboBox();
138                 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
139                 pane.add(trackListA);
140                 labelB = new JLabel("Insert after", JLabel.CENTER);
141                 pane.add(labelB);
142                 trackListB = new JComboBox();
143                 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
144                 pane.add(trackListB);
145                 cancelButton = new JButton("Cancel");
146                 pane.add(cancelButton);
147                 okButton = new JButton("OK");
148                 pane.add(okButton);
149                 
150                 labelA.setBounds(50, 10, 100, 20);
151                 trackListA.setBounds(40, 35, 120, 20);
152                 labelB.setBounds(50, 70, 100, 20);
153                 trackListB.setBounds(40, 95, 120, 20);
154                 cancelButton.setBounds(10, 150, 80, 30);
155                 okButton.setBounds(120, 150, 60, 30);
156         
157                 setResizable(false);
158                 pack();
159                 setSize(200,220);
160                 setLocationRelativeTo(Moosique.getGUI());
161                 setVisible(true);
162         }
163         
164         /**
165          * Builds the move track popupdialog
166          * @param pane          The container to put the dialog in.
167          * @param tracks        A array containing miditracks.
168          */
169         private void makeMoveDialog(Container pane, Track[] tracks) {
170         
171                 setTitle("Move track");
172                 labelA = new JLabel("Track to move", JLabel.CENTER);
173                 pane.add(labelA);
174                 trackListA = new JComboBox();
175                 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
176                 pane.add(trackListA);
177                 labelB = new JLabel("Insert after", JLabel.CENTER);
178                 pane.add(labelB);
179                 trackListB = new JComboBox();
180                 for (int i = 1; i <= tracks.length; i++) trackListB.addItem("Track " + i);
181                 pane.add(trackListB);
182                 cancelButton = new JButton("Cancel");
183                 pane.add(cancelButton);
184                 okButton = new JButton("OK");
185                 pane.add(okButton);
186                 
187                 labelA.setBounds(40, 10, 120, 20);
188                 trackListA.setBounds(40, 35, 120, 20);
189                 labelB.setBounds(50, 70, 100, 20);
190                 trackListB.setBounds(40, 95, 120, 20);
191                 cancelButton.setBounds(10, 150, 80, 30);
192                 okButton.setBounds(120, 150, 60, 30);
193         
194                 setResizable(false);
195                 pack();
196                 setSize(200,220);
197                 setLocationRelativeTo(Moosique.getGUI());
198                 setVisible(true);
199         }
200         
201         /**
202          * Builds the set position dialog.
203          * @param pane          The container to put the dialog in.
204          * @param tracks        A array containing miditracks.
205          */
206         private void makeSetPositionDialog(Container pane) {
207                 
208                 setTitle("Set edit position");
209                 labelA = new JLabel("Measure", JLabel.CENTER);
210                 pane.add(labelA);
211                 labelB = new JLabel("Beat", JLabel.CENTER);
212                 pane.add(labelB);
213                 labelC = new JLabel("Tick", JLabel.CENTER);
214                 pane.add(labelC);
215                 textFieldA = new JTextField();
216                 pane.add(textFieldA);
217                 textFieldB = new JTextField();
218                 pane.add(textFieldB);
219                 textFieldC = new JTextField();
220                 pane.add(textFieldC);
221                 cancelButton = new JButton("Cancel");
222                 pane.add(cancelButton);
223                 okButton = new JButton("OK");
224                 pane.add(okButton);
225                 
226                 labelA.setBounds(40, 25, 50, 20);
227                 labelB.setBounds(105, 25, 50, 20);
228                 labelC.setBounds(170, 25, 50, 20);
229                 textFieldA.setBounds(40, 45, 50, 20);
230                 textFieldB.setBounds(105, 45, 50, 20);
231                 textFieldC.setBounds(170, 45, 50, 20);
232                 cancelButton.setBounds(35, 90, 80, 30);
233                 okButton.setBounds(155, 90, 60, 30);
234                 
235                 setResizable(false);
236                 pack();
237                 setSize(260,165);
238                 setLocationRelativeTo(Moosique.getGUI());
239                 setVisible(true);
240         }
241         
242         /**
243          * Builds the insert measure popupdialog.
244          * @param pane          The container to put the dialog in.
245          */
246         private void makeInsertMeasureDialog(Container pane){
247         
248                 setTitle("Insert Measure");
249                 labelA = new JLabel("Insert at:", JLabel.RIGHT);
250                 pane.add(labelA);
251                 labelB = new JLabel("Measure count:", JLabel.RIGHT);
252                 pane.add(labelB);
253                 textFieldA = new JTextField();
254                 pane.add(textFieldA);
255                 textFieldB = new JTextField();
256                 pane.add(textFieldB);
257                 cancelButton = new JButton("Cancel");
258                 pane.add(cancelButton);
259                 okButton = new JButton("OK");
260                 pane.add(okButton);
261                 
262                 labelA.setBounds(20, 20, 110 ,20);
263                 labelB.setBounds(20, 50, 110, 20);
264                 textFieldA.setBounds(140 ,20 , 40, 20);
265                 textFieldB.setBounds(140,50, 40, 20);
266                 cancelButton.setBounds(20 ,95 , 80, 30);
267                 okButton.setBounds(120, 95, 60, 30);
268                 
269                 setResizable(false);
270                 pack();
271                 setSize(210,175);
272                 setLocationRelativeTo(Moosique.getGUI());
273                 setVisible(true);
274         }
275         
276         /**
277          * Builds the delete measure popupdialog.
278          * @param pane          The container to put the dialog in.
279          */
280         private void makeDeleteMeasureDialog(Container pane) {
281         
282                 setTitle("Delete Measure");
283                 labelA = new JLabel("Delete at:", JLabel.RIGHT);
284                 pane.add(labelA);
285                 labelB = new JLabel("Measure count:", JLabel.RIGHT);
286                 pane.add(labelB);
287                 textFieldA = new JTextField();
288                 pane.add(textFieldA);
289                 textFieldB = new JTextField();
290                 pane.add(textFieldB);
291                 cancelButton = new JButton("Cancel");
292                 pane.add(cancelButton);
293                 okButton = new JButton("OK");
294                 pane.add(okButton);
295                 
296                 labelA.setBounds(20, 20, 110 ,20);
297                 labelB.setBounds(20, 50, 110, 20);
298                 textFieldA.setBounds(140 ,20 , 40, 20);
299                 textFieldB.setBounds(140,50, 40, 20);
300                 cancelButton.setBounds(20 ,95 , 80, 30);
301                 okButton.setBounds(120, 95, 60, 30);
302                 
303                 setResizable(false);
304                 pack();
305                 setSize(210,175);
306                 setLocationRelativeTo(Moosique.getGUI());
307                 setVisible(true);
308         }
309         
310         /**
311          * Builds the set tempo dialog.
312          * @param pane          The container to put the dialog in.
313          */
314         private void makeSetTempoDialog(Container pane) {
315                 
316                 setTitle("Set tempo");
317                 
318                 // create contents of dialog and add to container
319                 // track edit-intervall labels
320                 labelA = new JLabel("Measure", JLabel.CENTER);
321                 pane.add(labelA);
322                 labelB = new JLabel("Beat", JLabel.CENTER);
323                 pane.add(labelB);
324                 labelC = new JLabel("Tick", JLabel.CENTER);
325                 pane.add(labelC);
326                 // start and end labels
327                 labelD = new JLabel("Start at:", JLabel.RIGHT);
328                 pane.add(labelD);
329                 labelE = new JLabel("End at:", JLabel.RIGHT);
330                 pane.add(labelE);
331                 // from-to label
332                 labelF = new JLabel("to", JLabel.CENTER);
333                 pane.add(labelF);
334                 // start inputvaluefields
335                 textFieldA = new JTextField();
336                 pane.add(textFieldA);
337                 textFieldB = new JTextField();
338                 pane.add(textFieldB);
339                 textFieldC = new JTextField();
340                 pane.add(textFieldC);
341                 // end inputvaluefield
342                 textFieldD = new JTextField();
343                 pane.add(textFieldD);
344                 textFieldE = new JTextField();
345                 pane.add(textFieldE);
346                 textFieldF = new JTextField();
347                 pane.add(textFieldF);
348                 // the radiobuttonlists inputvaluefields
349                 textFieldG = new JTextField();
350                 pane.add(textFieldG);
351                 textFieldH = new JTextField();
352                 pane.add(textFieldH);
353                 textFieldI = new JTextField();
354                 pane.add(textFieldI);
355                 textFieldJ = new JTextField();
356                 pane.add(textFieldJ);
357                 textFieldK = new JTextField();
358                 pane.add(textFieldK);
359                 // the radiobuttonlist with associating titles
360                 JRadioButton constant = new JRadioButton("Set constant tempo of:");
361                 constant.setSelected(true);
362                 pane.add(constant);
363                 JRadioButton change = new JRadioButton("Gradually change tempo:");
364                 pane.add(change);
365                 JRadioButton scale = new JRadioButton("Scale tempo in %:");
366                 pane.add(scale);
367                 JRadioButton add = new JRadioButton("Add to current tempo:");
368                 pane.add(add);
369                 // a buttongroup for the radiobuttons
370                 ButtonGroup group = new ButtonGroup();
371                 group.add(constant);
372                 group.add(change);
373                 group.add(scale);
374                 group.add(add);
375                 // ok and cancelbutton
376                 cancelButton = new JButton("Cancel");
377                 pane.add(cancelButton);
378                 okButton = new JButton("OK");
379                 pane.add(okButton);
380                 
381                 // set bounds of track edit-intervall labels
382                 labelA.setBounds(80, 25, 50, 20);
383                 labelB.setBounds(145, 25, 50, 20);
384                 labelC.setBounds(210, 25, 50, 20);
385                 // set bounds of start and end labels
386                 labelD.setBounds(20, 45, 60, 20);
387                 labelE.setBounds(20, 65, 60, 20);
388                 // set bounds of from-to label
389                 labelF.setBounds(255, 125, 20 ,20);
390                 // set bounds of start inputvaluefields
391                 textFieldA.setBounds(80, 45, 50, 20);
392                 textFieldB.setBounds(145, 45, 50, 20);
393                 textFieldC.setBounds(210, 45, 50, 20);
394                 // set bounds of end inputvaluefield
395                 textFieldD.setBounds(80, 65, 50, 20);
396                 textFieldE.setBounds(145, 65, 50, 20);
397                 textFieldF.setBounds(210, 65, 50, 20);
398                 // set bounds of radiobuttonlists inputvaluefields
399                 textFieldG.setBounds(220, 100, 35, 20);
400                 textFieldH.setBounds(220, 125, 35, 20);
401                 textFieldI.setBounds(280, 125, 35, 20);
402                 textFieldJ.setBounds(220, 150, 35, 20);
403                 textFieldK.setBounds(220, 175, 35, 20);
404                 // set bounds of radiobuttonlist items
405                 constant.setBounds(20, 100, 180, 20);
406                 change.setBounds(20, 125, 200, 20);
407                 scale.setBounds(20, 150, 150, 20);
408                 add.setBounds(20, 175, 175, 20);
409                 // set bounds of ok and cancelbutton
410                 cancelButton.setBounds(75, 215, 80, 30);
411                 okButton.setBounds(195, 215, 60, 30);
412                 
413                 setResizable(false);
414                 pack();
415                 setSize(340,300);
416                 setLocationRelativeTo(Moosique.getGUI());
417                 setVisible(true);
418         }
419         
420         /**
421          * Builds the transpose dialog.
422          * @param pane          The container to put the dialog in.
423          * @param tracks        A array containing miditracks.
424          */
425         private void makeTransposeDialog(Container pane, Track[] tracks) {
426                 
427                 setTitle("Transpose");
428                 // create contents of dialog and add to container
429                 // track edit-intervall labels
430                 labelA = new JLabel("Measure", JLabel.CENTER);
431                 pane.add(labelA);
432                 labelB = new JLabel("Beat", JLabel.CENTER);
433                 pane.add(labelB);
434                 labelC = new JLabel("Tick", JLabel.CENTER);
435                 pane.add(labelC);
436                 // start and end labels
437                 labelD = new JLabel("Start at:", JLabel.RIGHT);
438                 pane.add(labelD);
439                 labelE = new JLabel("End at:", JLabel.RIGHT);
440                 pane.add(labelE);
441                 // oktave inputvalue labels
442                 labelF = new JLabel("Octaves", JLabel.LEFT);
443                 pane.add(labelF);
444                 labelG = new JLabel("1/2 octaves", JLabel.LEFT);
445                 pane.add(labelG);
446                 // what track to edit label
447                 labelH = new JLabel("Track to edit:", JLabel.CENTER);
448                 pane.add(labelH);
449                 // combobox representing the tracks
450                 trackListA = new JComboBox();
451                 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
452                 pane.add(trackListA);
453                 // start inputvaluefields
454                 textFieldA = new JTextField();
455                 pane.add(textFieldA);
456                 textFieldB = new JTextField();
457                 pane.add(textFieldB);
458                 textFieldC = new JTextField();
459                 pane.add(textFieldC);
460                 // end inputvaluefield
461                 textFieldD = new JTextField();
462                 pane.add(textFieldD);
463                 textFieldE = new JTextField();
464                 pane.add(textFieldE);
465                 textFieldF = new JTextField();
466                 pane.add(textFieldF);
467                 // the radiobuttonlists inputvaluefields
468                 textFieldG = new JTextField();
469                 pane.add(textFieldG);
470                 textFieldH = new JTextField();
471                 pane.add(textFieldH);
472                 // the radiobuttonlist with associating titles
473                 JRadioButton up = new JRadioButton("Change up");
474                 up.setSelected(true);
475                 pane.add(up);
476                 JRadioButton down = new JRadioButton("Change down");
477                 pane.add(down);
478                 // a buttongroup for the radiobuttons
479                 ButtonGroup group = new ButtonGroup();
480                 group.add(up);
481                 group.add(down);
482                 // ok and cancelbutton
483                 cancelButton = new JButton("Cancel");
484                 pane.add(cancelButton);
485                 okButton = new JButton("OK");
486                 pane.add(okButton);
487                 
488                 // set bounds of track edit-intervall labels
489                 labelA.setBounds(90, 70, 50, 20);
490                 labelB.setBounds(155, 70, 50, 20);
491                 labelC.setBounds(220, 70, 50, 20);
492                 // set bounds of start and end labels
493                 labelD.setBounds(30, 90, 60, 20);
494                 labelE.setBounds(30, 110, 60, 20);
495                 // set bounds of octave inputvaluefields
496                 labelF.setBounds(210, 150, 80, 20);
497                 labelG.setBounds(210, 175, 100, 20);
498                 // set bounds of trackslist label
499                 labelH.setBounds(30, 30, 100, 20);
500                 // set bounds of start inputvaluefields
501                 textFieldA.setBounds(90, 90, 50, 20);
502                 textFieldB.setBounds(155, 90, 50, 20);
503                 textFieldC.setBounds(220, 90, 50, 20);
504                 // set bounds of end inputvaluefield
505                 textFieldD.setBounds(90, 110, 50, 20);
506                 textFieldE.setBounds(155, 110, 50, 20);
507                 textFieldF.setBounds(220, 110, 50, 20);
508                 // set bounds of octave inputvaluefields
509                 textFieldG.setBounds(170, 150, 35, 20);
510                 textFieldH.setBounds(170, 175, 35, 20);
511                 // set bounds of radiobuttonlist items
512                 up.setBounds(30, 150, 100, 20);
513                 down.setBounds(30, 175, 120, 20);
514                 // set bounds of tracklist
515                 trackListA.setBounds(145, 30, 120, 20);
516                 // set bounds of ok and cancelbutton
517                 cancelButton.setBounds(75, 215, 80, 30);
518                 okButton.setBounds(195, 215, 60, 30);
519                 
520                 setResizable(false);
521                 pack();
522                 setSize(340,300);
523                 setLocationRelativeTo(Moosique.getGUI());
524                 setVisible(true);
525         }
526         
527         /**
528          * Builds the scale velocity dialog.
529          * @param pane  The container to put the dialog in.
530          * @param tracks        A array containing miditracks.
531          */
532         private void makeScaleVelocityDialog(Container pane, Track[] tracks) {
533                 
534                 setTitle("Scale velocity");
535                 
536                 // create contents of dialog and add to container
537                 // track edit-intervall labels
538                 labelA = new JLabel("Measure", JLabel.CENTER);
539                 pane.add(labelA);
540                 labelB = new JLabel("Beat", JLabel.CENTER);
541                 pane.add(labelB);
542                 labelC = new JLabel("Tick", JLabel.CENTER);
543                 pane.add(labelC);
544                 // start and end labels
545                 labelD = new JLabel("Start at:", JLabel.RIGHT);
546                 pane.add(labelD);
547                 labelE = new JLabel("End at:", JLabel.RIGHT);
548                 pane.add(labelE);
549                 // from-to label
550                 labelF = new JLabel("to", JLabel.CENTER);
551                 pane.add(labelF);
552                 // what track to edit label
553                 labelG = new JLabel("Track to edit:", JLabel.CENTER);
554                 pane.add(labelG);
555                 // combobox representing the tracks
556                 trackListA = new JComboBox();
557                 for (int i = 1; i <= tracks.length; i++) trackListA.addItem("Track " + i);
558                 pane.add(trackListA);
559                 // start inputvaluefields
560                 textFieldA = new JTextField();
561                 pane.add(textFieldA);
562                 textFieldB = new JTextField();
563                 pane.add(textFieldB);
564                 textFieldC = new JTextField();
565                 pane.add(textFieldC);
566                 // end inputvaluefield
567                 textFieldD = new JTextField();
568                 pane.add(textFieldD);
569                 textFieldE = new JTextField();
570                 pane.add(textFieldE);
571                 textFieldF = new JTextField();
572                 pane.add(textFieldF);
573                 // the radiobuttonlists inputvaluefields
574                 textFieldG = new JTextField();
575                 pane.add(textFieldG);
576                 textFieldH = new JTextField();
577                 pane.add(textFieldH);
578                 textFieldI = new JTextField();
579                 pane.add(textFieldI);
580                 textFieldJ = new JTextField();
581                 pane.add(textFieldJ);
582                 textFieldK = new JTextField();
583                 pane.add(textFieldK);
584                 // the radiobuttonlist with associating titles
585                 JRadioButton constant = new JRadioButton("Change all values to:");
586                 constant.setSelected(true);
587                 pane.add(constant);
588                 JRadioButton change = new JRadioButton("Gradually  change value:");
589                 pane.add(change);
590                 JRadioButton scale = new JRadioButton("Scale values to %:");
591                 pane.add(scale);
592                 JRadioButton add = new JRadioButton("Add to current value:");
593                 pane.add(add);
594                 // a buttongroup for the radiobuttons
595                 ButtonGroup group = new ButtonGroup();
596                 group.add(constant);
597                 group.add(change);
598                 group.add(scale);
599                 group.add(add);
600                 // ok and cancelbutton
601                 cancelButton = new JButton("Cancel");
602                 pane.add(cancelButton);
603                 okButton = new JButton("OK");
604                 pane.add(okButton);
605                 
606                 // set bounds of track edit-intervall labels
607                 labelA.setBounds(80, 75, 50, 20);
608                 labelB.setBounds(145, 75, 50, 20);
609                 labelC.setBounds(210, 75, 50, 20);
610                 // set bounds of start and end labels
611                 labelD.setBounds(20, 95, 60, 20);
612                 labelE.setBounds(20, 115, 60, 20);
613                 // set bounds of from-to label
614                 labelF.setBounds(255, 175, 20 ,20);
615                 // set bounds of trackslist label
616                 labelG.setBounds(30, 30, 100, 20);
617                 // set bounds of start inputvaluefields
618                 textFieldA.setBounds(80, 95, 50, 20);
619                 textFieldB.setBounds(145, 95, 50, 20);
620                 textFieldC.setBounds(210, 95, 50, 20);
621                 // set bounds of end inputvaluefield
622                 textFieldD.setBounds(80, 115, 50, 20);
623                 textFieldE.setBounds(145,115, 50, 20);
624                 textFieldF.setBounds(210, 115, 50, 20);
625                 // set bounds of radiobuttonlists inputvaluefields
626                 textFieldG.setBounds(220, 150, 35, 20);
627                 textFieldH.setBounds(220, 175, 35, 20);
628                 textFieldI.setBounds(280, 175, 35, 20);
629                 textFieldJ.setBounds(220, 200, 35, 20);
630                 textFieldK.setBounds(220, 225, 35, 20);
631                 // set bounds of radiobuttonlist items
632                 constant.setBounds(20, 150, 180, 20);
633                 change.setBounds(20, 175, 200, 20);
634                 scale.setBounds(20, 200, 150, 20);
635                 add.setBounds(20, 225, 175, 20);
636                 // set bounds of tracklist
637                 trackListA.setBounds(145, 30, 120, 20);
638                 // set bounds of ok and cancelbutton
639                 cancelButton.setBounds(75, 265, 80, 30);
640                 okButton.setBounds(195, 265, 60, 30);
641                 
642                 setResizable(false);
643                 pack();
644                 setSize(340,350);
645                 setLocationRelativeTo(Moosique.getGUI());
646                 setVisible(true);
647         }
648         
649         private void makeTextDialog(Container pane, String filename) {
650                 setTitle("User Manual");
651                 pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
652                 File manual = new File(filename);
653                 String s;
654                 try {
655                         BufferedReader br = new BufferedReader(new FileReader(manual));
656                         char[] chars = new char[(int)manual.length()];
657                         br.read(chars, 0, (int)manual.length());
658                         s = new String(chars);
659                 } catch (Exception ex) {
660                         s = "Manual not found";
661                 }
662                 pane.add(new JScrollPane(new JTextArea(s, 30, 95)));
663                 Action close = new AbstractAction("Close") {
664                         public void actionPerformed(ActionEvent ae) {
665                                 setVisible(false);
666                         }};
667                 JButton closeButton = new JButton(close);
668                 closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
669                 pane.add(closeButton);
670                 setResizable(false);
671                 pack();
672                 setLocationRelativeTo(Moosique.getGUI());
673                 setVisible(true);
674         }
675
676         private void makePrefsDialog(Container pane) {
677                 /*              
678                 MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo();
679                 for (int i = 0; i < devInfo.length; i++) {
680                         if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Sequencer) {
681                         
682                         } else if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Synthesizer) {
683                         
684                         }
685                 }
686                 String[] seqNames, synthNames;
687                 JPanel pane = (JPanel) this.getContentPane();
688                 pane.add(new JLabel("Sequencer"));
689                 JComboBox seqBox = new JComboBox(seqNames);
690                 pane.add(new JLabel("Synthesizer"));
691                 JComboBox synthBox = new JComboBox(synthNames);
692                 */
693         }
694
695         private MooNote note;
696         private JOptionPane optionPane;
697         private JTextField pitch;
698         private JTextField velocity;
699         private JTextField length;
700         
701         /** 
702          * Creates a new note preference dialog.
703          * @param mn    the note that will be graphically represented
704          */
705         public MooDialog(MooNote mn) {
706                 super(Moosique.getGUI(), "Note properties", true);
707                 JPanel panel = new JPanel();
708                 panel.setLayout(new GridLayout(3,2));
709                 note = mn;
710                 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
711                 panel.add(new Label("Pitch: "));
712                 panel.add(pitch);
713
714                 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
715                 panel.add(new Label("Velocity: "));
716                 panel.add(velocity);
717
718                 length = new JTextField(new Integer(note.getDuration()).toString(),5);
719                 panel.add(new Label("Length: "));
720                 panel.add(length);
721
722                 Object[] array = {"Set the note properties",
723                                 panel};
724         
725                 final String btnString1 = "Apply changes";
726                 final String btnString2 = "Cancel";
727                 Object[] options = {btnString1, btnString2};
728         
729                 optionPane = new JOptionPane(array, 
730                                             JOptionPane.QUESTION_MESSAGE,
731                                             JOptionPane.YES_NO_OPTION,
732                                             null,
733                                             options,
734                                             options[0]);
735                 setContentPane(optionPane);
736                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
737         
738                 ActionListener intValidator = new ActionListener() {
739                     public void actionPerformed(ActionEvent e) {
740                                         if (e.getSource() instanceof JTextField){
741                                                 JTextField s = (JTextField)e.getSource();
742                                                 int num = Integer.parseInt(s.getText());
743                                                 if (num < 0)
744                                                         num = 0;
745                                                 else if (num > 127 && s != length)
746                                                         num = 127;
747                                                 s.setText(new Integer(num).toString());
748                                         }
749                     }
750                 };
751                 pitch.addActionListener(intValidator);
752                 velocity.addActionListener(intValidator);
753                 length.addActionListener(intValidator);
754
755                 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
756                     public void propertyChange(PropertyChangeEvent e) {
757                         String prop = e.getPropertyName();
758         
759                         if (isVisible() 
760                          && (e.getSource() == optionPane)
761                          && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
762                              prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
763                             Object value = optionPane.getValue();
764         
765                             if (value == JOptionPane.UNINITIALIZED_VALUE) {
766                                 //ignore reset
767                                 return;
768                             }
769         
770                             // Reset the JOptionPane's value.
771                             // If you don't do this, then if the user
772                             // presses the same button next time, no
773                             // property change event will be fired.
774                             optionPane.setValue(
775                                     JOptionPane.UNINITIALIZED_VALUE);
776         
777                             if (value.equals(btnString1)) {
778                                                         note.setPitch(Integer.parseInt(pitch.getText()));
779                                                         note.setVelocity(Integer.parseInt(velocity.getText()));
780                                                         note.setDuration(Integer.parseInt(length.getText()));
781                                                         Moosique.setEdited();
782                                                         setVisible(false);
783                             } else { // user closed dialog or clicked cancel
784                                 setVisible(false);
785                             }
786                         }
787                     }
788                 });
789                 pack();
790                 setVisible(true);
791         }
792 }