]> ruin.nu Git - moosique.git/commitdiff
mostly done
authorMichael Andreen <harv@ruin.nu>
Sun, 11 May 2003 23:36:04 +0000 (23:36 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 11 May 2003 23:36:04 +0000 (23:36 +0000)
MooNoteProp.java

index e2a8ed22fa9a5bf404daa23ebd866d03ededa443..cc3c192855c5a7a7aa42e3039c6bc6900bbeb1b7 100644 (file)
@@ -1,6 +1,7 @@
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
+import java.beans.*;
 
 /**
  * Graphical representation of a MIDI note.
@@ -8,19 +9,108 @@ import java.awt.event.*;
  * @author  Andersson, Andreen, Lanneskog, Pehrson
  * @version 1
  */
+
 public class MooNoteProp extends JDialog{
 
        private MooNote note;
+    private JOptionPane optionPane;
+       private JTextField pitch;
+       private JTextField velocity;
+       private JTextField length;
+
        /** 
         * Creates a new note preference dialog.
         * @param mn The note that will be graphically represented
         */
-       public MooNoteProp (MooNote mn) {
+    public MooNoteProp(MooNote mn) {
+        super((JFrame)null, true);
                note = mn;
+        setTitle("Note properties");
+
+               pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
+               JPanel pitchpanel = new JPanel();
+               pitchpanel.add(new Label("Pitch: "));
+               pitchpanel.add(pitch);
+
+
+               velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
+               JPanel velocitypanel = new JPanel();
+               velocitypanel.add(new Label("Velocity: "));
+               velocitypanel.add(velocity);
+
+               length = new JTextField(new Integer(note.getDuration()).toString(),5);
+               JPanel lengthpanel = new JPanel();
+               lengthpanel.add(new Label("Length: "));
+               lengthpanel.add(length);
+
+        Object[] array = {"Set the note properties",
+                       pitchpanel,
+                       velocitypanel,
+                       lengthpanel};
+
+        final String btnString1 = "Enter";
+        final String btnString2 = "Cancel";
+        Object[] options = {btnString1, btnString2};
+
+        optionPane = new JOptionPane(array, 
+                                    JOptionPane.QUESTION_MESSAGE,
+                                    JOptionPane.YES_NO_OPTION,
+                                    null,
+                                    options,
+                                    options[0]);
+        setContentPane(optionPane);
+        setDefaultCloseOperation(EXIT_ON_CLOSE);
+/*
+        textField.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                optionPane.setValue(btnString1);
+            }
+        });
+*/
+        optionPane.addPropertyChangeListener(new PropertyChangeListener() {
+            public void propertyChange(PropertyChangeEvent e) {
+                String prop = e.getPropertyName();
 
+                if (isVisible() 
+                 && (e.getSource() == optionPane)
+                 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
+                     prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
+                    Object value = optionPane.getValue();
+
+                    if (value == JOptionPane.UNINITIALIZED_VALUE) {
+                        //ignore reset
+                        return;
+                    }
+
+                    // Reset the JOptionPane's value.
+                    // If you don't do this, then if the user
+                    // presses the same button next time, no
+                    // property change event will be fired.
+                    optionPane.setValue(
+                            JOptionPane.UNINITIALIZED_VALUE);
+
+                    if (value.equals(btnString1)) {
+                                               note.setPitch(Integer.parseInt(pitch.getText()));
+                                               note.setVelocity(Integer.parseInt(velocity.getText()));
+                                               note.setDuration(Integer.parseInt(length.getText()));
+
+                        setVisible(false);
+                    } else { // user closed dialog or clicked cancel
+                        setVisible(false);
+                    }
+                }
+            }
+        });
                pack();
-       }
+    }
+
+       public static void main(String[] args){
 
-                       
+               MooNote n = new MooNote(0,0,10,20,0,30);
+               MooNoteProp prop = new MooNoteProp(n);
+               prop.setVisible(true);
+               prop = new MooNoteProp(n);
+               prop.setVisible(true);
+
+       }
 }