addItem(music, "Delete track...", KeyEvent.VK_D, ActionEvent.CTRL_MASK);
addItem(music, "Copy track...", KeyEvent.VK_Y, ActionEvent.CTRL_MASK);
addItem(music, "Move track...", KeyEvent.VK_M, ActionEvent.CTRL_MASK);
- edit.addSeparator();
+ music.addSeparator();
addItem(music, "Insert measure...");
addItem(music, "Delete measure...");
- edit.addSeparator();
+ music.addSeparator();
addItem(music, "Set time signature...");
addItem(music, "Set tempo...");
addItem(music, "Scale velocity...");
addItem(help, "Getting started");
addItem(help, "About");
}
-
+ /**
+ * Creats a menu in the menubar.
+ * @param name The name of the menu.
+ * @param mnemnic The shortcut-key to access the menu.
+ * @return menu The menu created.
+ */
private JMenu createMenu(String name, int mnemonic) {
JMenu menu = new JMenu(name);
menu.setMnemonic(mnemonic);
return menu;
}
+ /**
+ * Creats a menuitem in the menu.
+ * @param menu The menu where to add the menuitem.
+ * @param name The name of the menuitem.
+ * @return item The menuitem created.
+ */
private JMenuItem addItem(JMenu menu, String name) {
JMenuItem item = new JMenuItem(name);
item.addActionListener(this);
return item;
}
+ /**
+ * Creats a menuitem in the menu.
+ * @param menu The menu to where to add the menuitem.
+ * @param name The name of the menuitem.
+ * @param key The keystroke to access this menuitem.
+ * @return item The menuitem created.
+ */
private JMenuItem addItem(JMenu menu, String name, String key) {
JMenuItem item = new JMenuItem(name);
item.setAccelerator(KeyStroke.getKeyStroke(key));
return item;
}
+ /**
+ * Creats a menuitem in the menu.
+ * @param menu The menu to where to add the menuitem.
+ * @param name The name of the menuitem.
+ * @param key The keystroke to access this menuitem.
+ * @param mask The keyboard mask.
+ * @return item The menuitem created.
+ */
private JMenuItem addItem(JMenu menu, String name, int key, int mask) {
JMenuItem item = new JMenuItem(name);
item.setAccelerator(KeyStroke.getKeyStroke(key, mask));
}
return false;
}
-
+ /**
+ * Gets the users command of takes and properiate action
+ * @param e The action perfomed.
+ */
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
Sequence seq;
Moosique.load(chooser.getSelectedFile().getAbsolutePath());
}
} else if (command == "Save") {
- Moosique.save();
+ if (!Moosique.save()) showSaveAsDialog();
} else if (command == "Save as...") {
- // Shows a file chooser. If shown previously, starts in the current directory.
- if (directory != null) {
- chooser = new JFileChooser(directory);
- } else {
- chooser = new JFileChooser();
- }
- chooser.addChoosableFileFilter(new MidiFileFilter());
- int returnVal = chooser.showSaveDialog(this);
-
- // Stores the current directory and loads the selected file.
- File file = chooser.getSelectedFile();
- if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
- directory = file.getParentFile();
- Moosique.saveAs(file.getAbsolutePath());
- }
+ showSaveAsDialog();
} else if (command == "Exit") {
Moosique.quit();
} else if (command == "Copy") {
} else if (command == "Stop") {
Moosique.stop();
} else if (command == "Jump...") {
- MooDialog what = new MooDialog(MooDialog.JUMP);
+ MooDialog newDialog = new MooDialog(MooDialog.JUMP);
// Moosique.setPosition(???); Räkna ut från msr, beats, ticks, time sig.
} else if (command == "Add track...") {
- MooDialog what = new MooDialog(MooDialog.ADD_TRACK);
+ MooDialog newDialog = new MooDialog(MooDialog.ADD_TRACK);
Moosique.getSequence().createTrack();
} else if (command == "Delete track...") {
- MooDialog what = new MooDialog(MooDialog.DELETE_TRACK);
+ MooDialog newDialog = new MooDialog(MooDialog.DELETE_TRACK);
/* Let the user select a track from a list.
seq = Moosique.getSequence();
seq.deleteTrack(seq.getTracks()[NUMBER]);
*/
} else if (command == "Copy track...") {
-
- MooDialog what = new MooDialog(MooDialog.COPY_TRACK);
-
+ MooDialog newDialog = new MooDialog(MooDialog.COPY_TRACK);
} else if (command == "Move track...") {
-
- MooDialog what = new MooDialog(MooDialog.MOVE_TRACK);
-
+ MooDialog newDialog = new MooDialog(MooDialog.MOVE_TRACK);
} else if (command == "Insert measure...") {
-
+ MooDialog newDialog = new MooDialog(MooDialog.INSERT_MEASURE);
} else if (command == "Delete measure...") {
-
+ MooDialog newDialog = new MooDialog(MooDialog.DELETE_MEASURE);
} else if (command == "Set time signature...") {
} else if (command == "Set tempo...") {
} else if (command == "Transpose...") {
} else if (command == "Contents") {
- // contents to be filled in
- JOptionPane.showMessageDialog(this, "här kommer contents komma");
-
+ MooDialog contents = new MooDialog(MooDialog.CONTENTS);
} else if (command == "Getting started") {
- // getting started to be filled in
+
JOptionPane.showMessageDialog(null, "här kommer getting started komma");
} else if (command == "About") {
- // about to be filled in
+
JOptionPane.showMessageDialog(null, "här kommer about att komma");
}
}
+ private void showSaveAsDialog() {
+ // Shows a file chooser. If shown previously, starts in the current directory.
+ if (directory != null) {
+ chooser = new JFileChooser(directory);
+ } else {
+ chooser = new JFileChooser();
+ }
+ chooser.addChoosableFileFilter(new MidiFileFilter());
+ int returnVal = chooser.showSaveDialog(this);
+
+ // Stores the current directory and loads the selected file.
+ File file = chooser.getSelectedFile();
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(file)) {
+ directory = file.getParentFile();
+ Moosique.saveAs(file.getAbsolutePath());
+ }
+ }
+
class MidiFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File f) {
if(f != null) {
return false;
}
- /*
+ /**
* gets the description of the filetype
* @return "Midifiles the only filetyp compatibel with the program
*/