+
+
+ 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 MooDialog(MooNote mn) {
+ super(Moosique.getGUI(), "Note properties", false);
+ note = mn;
+ 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(DISPOSE_ON_CLOSE);
+
+ ActionListener intValidator = new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() instanceof JTextField){
+ JTextField s = (JTextField)e.getSource();
+ int num = Integer.parseInt(s.getText());
+ if (num < 0)
+ num = 0;
+ else if (num > 127 && s != length)
+ num = 127;
+ s.setText(new Integer(num).toString());
+ }
+ }
+ };
+ pitch.addActionListener(intValidator);
+ velocity.addActionListener(intValidator);
+ length.addActionListener(intValidator);