]> ruin.nu Git - moosique.git/blobdiff - MooMenu.java
varså god einar
[moosique.git] / MooMenu.java
index d1794d2f5faf4b37978832436d15c4b541bb9b1f..eeb1b218ce4f8ac4c18ddc420e9b60bc8415bbcf 100644 (file)
 import javax.swing.*;
+import javax.swing.filechooser.*;
+import java.awt.event.*;
+import java.io.*;
 
-/*
- * 
- * 
- * @author  Andersson, Andreen, Lanneskog, Pehrson
- * @version 1
+/**
+ * Moosiques GUI representing a menubar, menus and menuitems
+ *
+ * @author Björn Lanneskog
  */
-public class MooMenu {
+public class MooMenu extends JMenuBar implements ActionListener {
+       
+/*
+
+Musikrelaterade menyer i Midisoft Recording Session:
+
+Track          Insert New...           Har vi
+               Delete...               Har vi
+               Move...                 Har vi
+               Copy...                 Har vi
+               Combine...              Onödig
+               Rechannel...            Kanske
+               Split by Pitch...       Onödig
+               
+Music          Insert Measure...       Lagt till
+               Delete Measure...       Lagt till
+               Clef...                 Onödig
+               Time Signature...       Lagt till
+               Key Signature...        Onödig
+               Tempo...                Lagt till
+               Scale Velocity...       Lagt till
+               Transpose...            Lagt till
+               Quantize...             Onödig
+
+Kanske också:  Reset Solo / Mute
+
+*/
+       private JMenu file, edit, playback, track, help, music;
+
+       /**
+        * contructs a menubar
+        */
+       public MooMenu() {
+               file = makeMenu("File", KeyEvent.VK_F);
+               add(file);
+                               
+               file.add(makeItem(file, "New", KeyEvent.VK_N));
+               file.add(makeItem(file, "Open...", KeyEvent.VK_O));
+               file.add(makeItem(file, "Save", KeyEvent.VK_S));
+               file.add(makeItem(file, "Save as..."));
+               file.add(makeItem(file, "Exit", KeyEvent.VK_Q));
+               
+               edit = makeMenu("Edit", KeyEvent.VK_E);
+               add(edit);
+               
+               edit.add(makeItem(edit, "Copy", KeyEvent.VK_C));
+               edit.add(makeItem(edit, "Cut", KeyEvent.VK_X));
+               edit.add(makeItem(edit, "Paste", KeyEvent.VK_V));
+               edit.add(makeItem(edit, "Select all", KeyEvent.VK_E));
+               edit.add(makeItem(edit, "Invert selection", KeyEvent.VK_I));
+               edit.add(makeItem(edit, "Preferences", KeyEvent.VK_P));
+               
+               playback = makeMenu("Playback", KeyEvent.VK_P);
+               add(playback);
+               
+               playback.add(makeItem(playback, "Play", KeyEvent.VK_SPACE));
+               playback.add(makeItem(playback, "Pause", KeyEvent.VK_SPACE));
+               playback.add(makeItem(playback, "Stop"));
+               playback.add(makeItem(playback, "Jump..."));
+               
+               track = makeMenu("Track", KeyEvent.VK_T);
+               add(track);
+               
+               track.add(makeItem(track, "Add", KeyEvent.VK_A));
+               track.add(makeItem(track, "Delete", KeyEvent.VK_D));
+               track.add(makeItem(track, "Copy track", KeyEvent.VK_Y));
+               track.add(makeItem(track, "Move", KeyEvent.VK_M));
+               
+               music = makeMenu("Music", KeyEvent.VK_M);
+               add(music);
+               
+               music.add(makeItem(track, "Insert measure..."));
+               music.add(makeItem(track, "Delete measure..."));
+               music.add(makeItem(track, "Time signature..."));
+               music.add(makeItem(track, "Tempo..."));
+               music.add(makeItem(track, "Scale velocity..."));
+               music.add(makeItem(track, "Transpose..."));
+               
+               help = makeMenu("Help", KeyEvent.VK_L);
+               add(help);
+               
+               help.add(makeItem(help, "Contents"));
+               help.add(makeItem(help, "Getting started"));
+               help.add(makeItem(help, "About"));
+       }
 
-       /* 
-        * Creates the menus.
+       /**
+        * creates a menu for the menubar
+        * @param name          the name of the menu
+        * @param mnemonic      the shortcut to activate the menu
+        * @return menu         the menu to be added to the menubar
         */
-       public MooMenu () {
+       private JMenu makeMenu(String name, int mnemonic) {
+               JMenu menu = new JMenu(name);
+               menu.setMnemonic(mnemonic);
+               return menu;
+       }
+       
+       /**
+        * creates a menuitem
+        * @param menu          the menu to which the item is being added to
+        * @param name          the name of this menuitem
+        * @return item         the item to add to the menu
+        */
+       private JMenuItem makeItem(JMenu menu, String name) {
+               JMenuItem item = new JMenuItem(name);
+               item.addActionListener(this);
+               menu.add(item);
+               return item;
+       }
+       
+       /**
+        * creates a menuitem
+        * @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 makeItem(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();
+               
+               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 / Resume") {
+                       //if (Moosique.getSequence().isRunning()) {
+                               //Moosique.pause();
+                       //} else Moosique.play();
+               
+               } else if (command == "Pause") {
+                       // koda för resume också
+                       Moosique.pause();
+               } else if (command == "Stop") {
+                       Moosique.stop();
+               } else if (command == "Jump...") {
+               
+               } else if (command == "Add") {
+               
+               } else if (command == "Delete") {
+               
+               } else if (command == "Copy track") {
+               
+               } else if (command == "Move") {
+               
+               } else if (command == "Insert Measure...") {
+               
+               } else if (command == "Delete Measure...") {
+               
+               } else if (command == "Time Signature...") {
+               
+               } else if (command == "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";
+               }
        }
 }