+ /**
+ * Creates a menu item with a keyboard accelerator.
+ * @param menu the menu to which the item is being added to
+ * @param name the name of this menuitem
+ * @param key the shortcut to activate the command
+ * @return item the item to add to the menu
+ */
+ private JMenuItem addItem(JMenu menu, String name, int key) {
+ JMenuItem item = new JMenuItem(name);
+ item.setAccelerator(KeyStroke.getKeyStroke(key, ActionEvent.CTRL_MASK));
+ item.addActionListener(this);
+ menu.add(item);
+ return item;
+ }
+
+ /**
+ * checks if the fileformat is compatible with our program
+ * @param f the file to check
+ * @return true or false
+ */
+ private boolean isMidiFile(File f) {
+ if(f != null) {
+ String extension = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase().trim();
+ if (extension.equals("mid")) return true;
+ }
+ return false;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ String command = e.getActionCommand();
+ Sequence seq;
+
+ if(command == "New") {
+ Moosique.clearSequence();
+ } else if (command == "Open...") {
+ JFileChooser chooser = new JFileChooser();
+ chooser.addChoosableFileFilter(new MidiFileFilter());
+ int returnVal = chooser.showOpenDialog(this);
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
+ Moosique.load(chooser.getSelectedFile().getAbsolutePath());
+ }
+ } else if (command == "Save") {
+ Moosique.save();
+ } else if (command == "Save as...") {
+ JFileChooser chooser = new JFileChooser();
+ chooser.addChoosableFileFilter(new MidiFileFilter());
+ int returnVal = chooser.showSaveDialog(this);
+ if(returnVal == JFileChooser.APPROVE_OPTION && isMidiFile(chooser.getSelectedFile())) {
+ Moosique.saveAs(chooser.getSelectedFile().getAbsolutePath());
+ }
+ } else if (command == "Exit") {
+ Moosique.quit();
+ } else if (command == "Copy") {
+
+ } else if (command == "Cut") {
+
+ } else if (command == "Paste") {
+
+ } else if (command == "Select all") {
+
+ } else if (command == "Invert selection") {
+
+ } else if (command == "Preferences...") {
+
+ } else if (command == "Play") {
+ if (!Moosique.getSequencer().isRunning()) Moosique.play();
+ } else if (command == "Pause") {
+ if (Moosique.getSequencer().isRunning()) Moosique.pause();
+ } else if (command == "Stop") {
+ Moosique.stop();
+ } else if (command == "Jump...") {
+
+ } else if (command == "Add track...") {
+ Moosique.getSequence().createTrack();
+ } else if (command == "Delete track...") {
+ /* Let the user select a track from a list.
+ seq = Moosique.getSequence();
+ seq.deleteTrack(seq.getTracks()[NUMBER]);
+ */
+ } else if (command == "Copy track...") {
+
+ } else if (command == "Move track...") {
+
+ } else if (command == "Insert measure...") {
+
+ } else if (command == "Delete measure...") {
+
+ } else if (command == "Set time signature...") {
+
+ } else if (command == "Set tempo...") {
+
+ } else if (command == "Scale velocity...") {
+
+ } else if (command == "Transpose...") {
+
+ } else if (command == "Contents") {
+ // contents to be filled in
+ JOptionPane.showMessageDialog(this, "här kommer contents komma");
+
+ } 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");
+ }
+ }
+
+ class MidiFileFilter extends javax.swing.filechooser.FileFilter {
+ public boolean accept(File f) {
+ if(f != null) {
+ if (f.isDirectory() || isMidiFile(f)) return true;
+ }
+ return false;
+ }
+
+ /*
+ * gets the description of the filetype
+ * @return "Midifiles the only filetyp compatibel with the program
+ */
+ public String getDescription() {
+ return "MIDI files";
+ }