]> ruin.nu Git - moosique.git/blobdiff - MooDialog.java
*** empty log message ***
[moosique.git] / MooDialog.java
index 54d6fdfb71308c4683c8a4fcdb77ba281d8d4a25..860b91edc83ac8951e043b3fc5a6aa14c2618875 100644 (file)
@@ -6,25 +6,28 @@ import java.io.*;
 import java.beans.*;
 
 /**
- * The GUI-class representing the popupdialogs in the Track menu.
+ * A generator class for the application's dialogs.
  *
  * @author Björn Lanneskog
  */
  
 public class MooDialog extends JDialog {
 
-       private JLabel labelA, labelB, labelC;
-       private JTextField textFieldA, textFieldB, textFieldC;
+       private JLabel labelA, labelB, labelC, labelD, labelE, labelF;
+       private JTextField textFieldA, textFieldB, textFieldC, textFieldD, textFieldE, textFieldF;
+       private JTextField textFieldG, textFieldH, textFieldI, textFieldJ, textFieldK;
        private JComboBox trackListA, trackListB; 
        private JButton okButton, cancelButton;
        public static final int ADD_TRACK = 1,
                                DELETE_TRACK = 2,
                                COPY_TRACK = 3,
                                MOVE_TRACK = 4,
-                               JUMP = 5,
-                               CONTENTS = 6,
+                               SET_POSITION = 5,
+                               MANUAL = 6,
                                INSERT_MEASURE = 7,
-                               DELETE_MEASURE = 8;
+                               DELETE_MEASURE = 8,
+                               SET_TEMPO = 9,
+                               PREFERENCES = 10;
        
        /**
         * Constructor of the dialogs.
@@ -42,10 +45,12 @@ public class MooDialog extends JDialog {
                        case DELETE_TRACK:      makeDelDialog(pane, tracks); break;
                        case COPY_TRACK:        makeCopyDialog(pane, tracks); break;
                        case MOVE_TRACK:        makeMoveDialog(pane, tracks); break;
-                       case JUMP:              makeJumpDialog(pane); break;
-                       case CONTENTS:          makeTextDialog(pane, "Manual.txt"); break;
+                       case SET_POSITION:      makeSetPositionDialog(pane); break;
+                       case MANUAL:            makeTextDialog(pane, "Manual.txt"); break;
                        case INSERT_MEASURE:    makeInsertMeasureDialog(pane); break;
                        case DELETE_MEASURE:    makeDeleteMeasureDialog(pane); break;
+                       case SET_TEMPO:         makeSetTempoDialog(pane); break;
+                       case PREFERENCES:       makePrefsDialog(pane); break;
                }
         }
        
@@ -78,11 +83,10 @@ public class MooDialog extends JDialog {
                cancelButton.setBounds(10, 150, 80, 30);
                okButton.setBounds(120, 150, 60, 30);
        
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(200,220);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
@@ -109,11 +113,10 @@ public class MooDialog extends JDialog {
                cancelButton.setBounds(10, 90, 80, 30);
                okButton.setBounds(120, 90, 60, 30);
        
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(200,165);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
@@ -147,11 +150,10 @@ public class MooDialog extends JDialog {
                cancelButton.setBounds(10, 150, 80, 30);
                okButton.setBounds(120, 150, 60, 30);
        
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(200,220);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
@@ -185,23 +187,22 @@ public class MooDialog extends JDialog {
                cancelButton.setBounds(10, 150, 80, 30);
                okButton.setBounds(120, 150, 60, 30);
        
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(200,220);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
        /**
-        * Builds the jump popupdialog.
+        * Builds the set position dialog.
         * @param pane          The container to put the dialog in.
         * @param tracks        A array containing miditracks.
         */
-       private void makeJumpDialog(Container pane) {
+       private void makeSetPositionDialog(Container pane) {
                
-               setTitle("Jump");
-               labelA = new JLabel("Msr", JLabel.CENTER);
+               setTitle("Set edit position");
+               labelA = new JLabel("Measure", JLabel.CENTER);
                pane.add(labelA);
                labelB = new JLabel("Beat", JLabel.CENTER);
                pane.add(labelB);
@@ -218,20 +219,19 @@ public class MooDialog extends JDialog {
                okButton = new JButton("OK");
                pane.add(okButton);
                
-               labelA.setBounds(30, 25, 50, 20);
+               labelA.setBounds(40, 25, 50, 20);
                labelB.setBounds(105, 25, 50, 20);
-               labelC.setBounds(180, 25, 50, 20);
-               textFieldA.setBounds(30, 45, 50, 20);
+               labelC.setBounds(170, 25, 50, 20);
+               textFieldA.setBounds(40, 45, 50, 20);
                textFieldB.setBounds(105, 45, 50, 20);
-               textFieldC.setBounds(180, 45, 50, 20);
+               textFieldC.setBounds(170, 45, 50, 20);
                cancelButton.setBounds(35, 90, 80, 30);
                okButton.setBounds(155, 90, 60, 30);
                
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(260,165);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
@@ -262,11 +262,10 @@ public class MooDialog extends JDialog {
                cancelButton.setBounds(20 ,95 , 80, 30);
                okButton.setBounds(120, 95, 60, 30);
                
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(210,175);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
@@ -297,16 +296,125 @@ public class MooDialog extends JDialog {
                cancelButton.setBounds(20 ,95 , 80, 30);
                okButton.setBounds(120, 95, 60, 30);
                
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
                setResizable(false);
                pack();
                setSize(210,175);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
        
+       /**
+        * Builds the set tempo dialog.
+        * @param pane          The container to put the dialog in.
+        * @param tracks        A array containing miditracks.
+        */
+       private void makeSetTempoDialog(Container pane) {
+               
+               setTitle("Set tempo");
+               // creating labels and adding them to a container
+               labelA = new JLabel("Measure", JLabel.CENTER);
+               pane.add(labelA);
+               labelB = new JLabel("Beat", JLabel.CENTER);
+               pane.add(labelB);
+               labelC = new JLabel("Tick", JLabel.CENTER);
+               pane.add(labelC);
+               labelD = new JLabel("Start at:", JLabel.RIGHT);
+               pane.add(labelD);
+               labelE = new JLabel("End at:", JLabel.RIGHT);
+               pane.add(labelE);
+               labelF = new JLabel("to", JLabel.CENTER);
+               pane.add(labelF);
+                
+               // the starting textfields and adding them to the container
+               textFieldA = new JTextField();
+               pane.add(textFieldA);
+               textFieldB = new JTextField();
+               pane.add(textFieldB);
+               textFieldC = new JTextField();
+               pane.add(textFieldC);
+               // ending textfields and adding them to the container
+               textFieldD = new JTextField();
+               pane.add(textFieldD);
+               textFieldE = new JTextField();
+               pane.add(textFieldE);
+               textFieldF = new JTextField();
+               pane.add(textFieldF);
+               // the amount to edit textfields and adding them to a container
+               textFieldG = new JTextField();
+               pane.add(textFieldG);
+               textFieldH = new JTextField();
+               pane.add(textFieldH);
+               textFieldI = new JTextField();
+               pane.add(textFieldI);
+               textFieldJ = new JTextField();
+               pane.add(textFieldJ);
+               textFieldK = new JTextField();
+               pane.add(textFieldK);
+
+               // creating the buttons and adding them to the container
+               JRadioButton constant = new JRadioButton("Set constant tempo of:");
+               constant.setSelected(true);
+               pane.add(constant);
+               JRadioButton change = new JRadioButton("Gradually change tempo:");
+               pane.add(change);
+               JRadioButton scale = new JRadioButton("Scale tempo in %:");
+               pane.add(scale);
+               JRadioButton add = new JRadioButton("Add to current tempo:");
+               pane.add(add);
+               
+               // creating a buttongroup and adding the buttons above
+               ButtonGroup group = new ButtonGroup();
+               group.add(constant);
+               group.add(change);
+               group.add(scale);
+               group.add(add);
+               
+               // creating the cancel and ok button
+               cancelButton = new JButton("Cancel");
+               pane.add(cancelButton);
+               okButton = new JButton("OK");
+               pane.add(okButton);
+               
+               
+               labelA.setBounds(80, 25, 50, 20);
+               labelB.setBounds(145, 25, 50, 20);
+               labelC.setBounds(210, 25, 50, 20);
+               labelD.setBounds(20, 45, 60, 20);
+               labelE.setBounds(20, 65, 60, 20);
+               labelF.setBounds(255, 125, 20 ,20);
+      
+               textFieldA.setBounds(80, 45, 50, 20);
+               textFieldB.setBounds(145, 45, 50, 20);
+               textFieldC.setBounds(210, 45, 50, 20);
+               textFieldD.setBounds(80, 65, 50, 20);
+               textFieldE.setBounds(145, 65, 50, 20);
+               textFieldF.setBounds(210, 65, 50, 20);
+               
+               textFieldG.setBounds(205, 100, 35, 20);
+               textFieldH.setBounds(220, 125, 35, 20);
+               textFieldI.setBounds(280, 125, 35, 20);
+               textFieldJ.setBounds(170, 150, 35, 20);
+               textFieldK.setBounds(200, 175, 35, 20);
+               
+               constant.setBounds(20, 100, 180, 20);
+               change.setBounds(20, 125, 200, 20);
+               scale.setBounds(20, 150, 150, 20);
+               add.setBounds(20, 175, 175, 20);
+               
+               cancelButton.setBounds(75, 215, 80, 30);
+               okButton.setBounds(195, 215, 60, 30);
+               
+               setResizable(false);
+               pack();
+               setSize(340,300);
+               setLocationRelativeTo(Moosique.getGUI());
+               setVisible(true);
+       }
+       
+       
        private void makeTextDialog(Container pane, String filename) {
-               setTitle("Contents");
+               setTitle("User Manual");
+               pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
                File manual = new File(filename);
                String s;
                try {
@@ -317,18 +425,39 @@ public class MooDialog extends JDialog {
                } catch (Exception ex) {
                        s = "Manual not found";
                }
-               JTextArea contents = new JTextArea(s, 30, 40);
-               contents.setAutoscrolls(true);
-               pane.add(contents);
-               contents.setBounds(10, 10, 500, 350);
+               pane.add(new JScrollPane(new JTextArea(s, 30, 95)));
+               Action close = new AbstractAction("Close") {
+                       public void actionPerformed(ActionEvent ae) {
+                               setVisible(false);
+                       }};
+               JButton closeButton = new JButton(close);
+               closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+               pane.add(closeButton);
                setResizable(false);
                pack();
-               setSize(600,400);
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
-               (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
+               setLocationRelativeTo(Moosique.getGUI());
                setVisible(true);
        }
 
+       private void makePrefsDialog(Container pane) {
+               /*              
+               MidiDevice.Info[] devInfo = MidiSystem.getMidiDeviceInfo();
+               for (int i = 0; i < devInfo.length; i++) {
+                       if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Sequencer) {
+                       
+                       } else if (MidiSystem.getMidiDevice(devInfo[i]) instanceof Synthesizer) {
+                       
+                       }
+               }
+               String[] seqNames, synthNames;
+               JPanel pane = (JPanel) this.getContentPane();
+               pane.add(new JLabel("Sequencer"));
+               JComboBox seqBox = new JComboBox(seqNames);
+               pane.add(new JLabel("Synthesizer"));
+               JComboBox synthBox = new JComboBox(synthNames);
+               */
+       }
+
        private MooNote note;
        private JOptionPane optionPane;
        private JTextField pitch;
@@ -340,30 +469,26 @@ public class MooDialog extends JDialog {
         * @param mn    the note that will be graphically represented
         */
        public MooDialog(MooNote mn) {
-               super(Moosique.getGUI(), "Note properties", false);
+               super(Moosique.getGUI(), "Note properties", true);
+               JPanel panel = new JPanel();
+               panel.setLayout(new GridLayout(3,2));
                note = mn;
                pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
-               JPanel pitchpanel = new JPanel();
-               pitchpanel.add(new Label("Pitch: "));
-               pitchpanel.add(pitch);
-
+               panel.add(new Label("Pitch: "));
+               panel.add(pitch);
 
                velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
-               JPanel velocitypanel = new JPanel();
-               velocitypanel.add(new Label("Velocity: "));
-               velocitypanel.add(velocity);
+               panel.add(new Label("Velocity: "));
+               panel.add(velocity);
 
                length = new JTextField(new Integer(note.getDuration()).toString(),5);
-               JPanel lengthpanel = new JPanel();
-               lengthpanel.add(new Label("Length: "));
-               lengthpanel.add(length);
+               panel.add(new Label("Length: "));
+               panel.add(length);
 
                Object[] array = {"Set the note properties",
-                               pitchpanel,
-                               velocitypanel,
-                               lengthpanel};
+                               panel};
        
-               final String btnString1 = "Enter";
+               final String btnString1 = "Apply changes";
                final String btnString2 = "Cancel";
                Object[] options = {btnString1, btnString2};
        
@@ -419,14 +544,15 @@ public class MooDialog extends JDialog {
                                                        note.setPitch(Integer.parseInt(pitch.getText()));
                                                        note.setVelocity(Integer.parseInt(velocity.getText()));
                                                        note.setDuration(Integer.parseInt(length.getText()));
-       
-                               setVisible(false);
+                                                       Moosique.setEdited();
+                                                       setVisible(false);
                            } else { // user closed dialog or clicked cancel
-                               setVisible(false);
+                               setVisible(false);
                            }
                        }
                    }
                });
                pack();
+               setVisible(true);
        }
 }