3 import java.awt.event.*;
4 import javax.sound.midi.*;
8 * The add dialog that pops up if the user clicks on the add track menuitem
10 * @author Björn Lanneskog
13 public class MooDialog extends JDialog {
15 private JLabel name, whichtoedit;
16 private JTextField textfield;
17 private JComboBox trackList, trackLust;
18 private JButton okbutton, cancelbutton;
19 public static final int ADD_TRACK = 1,
25 * Creates the add dialog
27 public MooDialog(int type) {
28 super(Moosique.getGUI(), "Add track", false);
30 Container pane = getContentPane();
33 Track[] tracks = Moosique.getSequence().getTracks();
38 name = new JLabel("Name of track", JLabel.CENTER);
40 textfield = new JTextField();
42 whichtoedit = new JLabel("Add after", JLabel.CENTER);
43 pane.add(whichtoedit);
44 trackList = new JComboBox();
45 for (int i = 1; i <= tracks.length; i++) trackList.addItem("Track " + i);
47 cancelbutton = new JButton("Cancel");
48 pane.add(cancelbutton);
49 okbutton = new JButton("OK");
52 name.setBounds(50, 10, 100, 20);
53 textfield.setBounds(40, 35, 120, 20);
54 whichtoedit.setBounds(50, 70, 100, 20);
55 trackList.setBounds(40, 95, 120, 20);
56 cancelbutton.setBounds(10, 150, 80, 30);
57 okbutton.setBounds(120, 150, 60, 30);
59 setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
60 (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
69 whichtoedit = new JLabel("Delete track", JLabel.CENTER);
70 pane.add(whichtoedit);
71 trackList = new JComboBox();
72 for (int i = 1; i <= tracks.length; i++) trackList.addItem("Track " + i);
74 cancelbutton = new JButton("Cancel");
75 pane.add(cancelbutton);
76 okbutton = new JButton("OK");
79 whichtoedit.setBounds(50, 10, 100, 20);
80 trackList.setBounds(40, 35, 120, 20);
81 cancelbutton.setBounds(10, 90, 80, 30);
82 okbutton.setBounds(120, 90, 60, 30);
84 setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
85 (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
94 name = new JLabel("Track to copy", JLabel.CENTER);
96 trackLust = new JComboBox();
97 for (int i = 1; i <= tracks.length; i++) trackLust.addItem("Track " + i);
99 whichtoedit = new JLabel("Insert after", JLabel.CENTER);
100 pane.add(whichtoedit);
101 trackList = new JComboBox();
102 for (int i = 1; i <= tracks.length; i++) trackList.addItem("Track " + i);
104 cancelbutton = new JButton("Cancel");
105 pane.add(cancelbutton);
106 okbutton = new JButton("OK");
109 name.setBounds(50, 10, 100, 20);
110 trackLust.setBounds(40, 35, 120, 20);
111 whichtoedit.setBounds(50, 70, 100, 20);
112 trackList.setBounds(40, 95, 120, 20);
113 cancelbutton.setBounds(10, 150, 80, 30);
114 okbutton.setBounds(120, 150, 60, 30);
116 setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
117 (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
126 name = new JLabel("Track to move", JLabel.CENTER);
128 trackLust = new JComboBox();
129 for (int i = 1; i <= tracks.length; i++) trackLust.addItem("Track " + i);
131 whichtoedit = new JLabel("Insert after", JLabel.CENTER);
132 pane.add(whichtoedit);
133 trackList = new JComboBox();
134 for (int i = 1; i <= tracks.length; i++) trackList.addItem("Track " + i);
136 cancelbutton = new JButton("Cancel");
137 pane.add(cancelbutton);
138 okbutton = new JButton("OK");
141 name.setBounds(40, 10, 120, 20);
142 trackLust.setBounds(40, 35, 120, 20);
143 whichtoedit.setBounds(50, 70, 100, 20);
144 trackList.setBounds(40, 95, 120, 20);
145 cancelbutton.setBounds(10, 150, 80, 30);
146 okbutton.setBounds(120, 150, 60, 30);
148 setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getWidth()) / 2,
149 (Toolkit.getDefaultToolkit().getScreenSize().height - this.getHeight()) / 2);
158 private MooNote note;
159 private JOptionPane optionPane;
160 private JTextField pitch;
161 private JTextField velocity;
162 private JTextField length;
165 * Creates a new note preference dialog.
166 * @param mn the note that will be graphically represented
168 public MooDialog(MooNote mn) {
169 super(Moosique.getGUI(), "Note properties", false);
171 pitch = new JTextField(new Integer(note.getPitch()).toString(),3);
172 JPanel pitchpanel = new JPanel();
173 pitchpanel.add(new Label("Pitch: "));
174 pitchpanel.add(pitch);
177 velocity = new JTextField(new Integer(note.getVelocity()).toString(),3);
178 JPanel velocitypanel = new JPanel();
179 velocitypanel.add(new Label("Velocity: "));
180 velocitypanel.add(velocity);
182 length = new JTextField(new Integer(note.getDuration()).toString(),5);
183 JPanel lengthpanel = new JPanel();
184 lengthpanel.add(new Label("Length: "));
185 lengthpanel.add(length);
187 Object[] array = {"Set the note properties",
192 final String btnString1 = "Enter";
193 final String btnString2 = "Cancel";
194 Object[] options = {btnString1, btnString2};
196 optionPane = new JOptionPane(array,
197 JOptionPane.QUESTION_MESSAGE,
198 JOptionPane.YES_NO_OPTION,
202 setContentPane(optionPane);
203 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
205 ActionListener intValidator = new ActionListener() {
206 public void actionPerformed(ActionEvent e) {
207 if (e.getSource() instanceof JTextField){
208 JTextField s = (JTextField)e.getSource();
209 int num = Integer.parseInt(s.getText());
212 else if (num > 127 && s != length)
214 s.setText(new Integer(num).toString());
218 pitch.addActionListener(intValidator);
219 velocity.addActionListener(intValidator);
220 length.addActionListener(intValidator);
222 optionPane.addPropertyChangeListener(new PropertyChangeListener() {
223 public void propertyChange(PropertyChangeEvent e) {
224 String prop = e.getPropertyName();
227 && (e.getSource() == optionPane)
228 && (prop.equals(JOptionPane.VALUE_PROPERTY) ||
229 prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) {
230 Object value = optionPane.getValue();
232 if (value == JOptionPane.UNINITIALIZED_VALUE) {
237 // Reset the JOptionPane's value.
238 // If you don't do this, then if the user
239 // presses the same button next time, no
240 // property change event will be fired.
242 JOptionPane.UNINITIALIZED_VALUE);
244 if (value.equals(btnString1)) {
245 note.setPitch(Integer.parseInt(pitch.getText()));
246 note.setVelocity(Integer.parseInt(velocity.getText()));
247 note.setDuration(Integer.parseInt(length.getText()));
250 } else { // user closed dialog or clicked cancel