]> ruin.nu Git - moosique.git/blobdiff - MooMenu.java
*** empty log message ***
[moosique.git] / MooMenu.java
index ab055a9a1959046e361f0f16b219b6596023070d..9abc407a9a4222b2a83305737958725c992807b8 100644 (file)
@@ -12,7 +12,7 @@ import java.awt.*;
  */
 public class MooMenu extends JMenuBar implements ActionListener {
        
-       private JMenu file, edit, playback, music, help;
+       private JMenu file, edit, keyboard, playback, music, help;
        private JFileChooser chooser;
        private File directory;
 
@@ -23,57 +23,66 @@ public class MooMenu extends JMenuBar implements ActionListener {
                file = createMenu("File", KeyEvent.VK_F);
                add(file);
                                
-               addItem(file, "New", KeyEvent.VK_N);
-               addItem(file, "Open...", KeyEvent.VK_O);
-               addItem(file, "Save", KeyEvent.VK_S);
-               addItem(file, "Save as...");
-               addItem(file, "Exit", KeyEvent.VK_Q);
+               addItem(file, "New", KeyEvent.VK_N, ActionEvent.CTRL_MASK);
+               addItem(file, "Open...", KeyEvent.VK_O, ActionEvent.CTRL_MASK);
+               addItem(file, "Save", KeyEvent.VK_S, ActionEvent.CTRL_MASK);
+               addItem(file, "Save as...", KeyEvent.VK_A);
+               file.addSeparator();
+               addItem(file, "Exit", KeyEvent.VK_Q, ActionEvent.CTRL_MASK);
                
                edit = createMenu("Edit", KeyEvent.VK_E);
                add(edit);
                
-               addItem(edit, "Copy", KeyEvent.VK_C);
-               addItem(edit, "Cut", KeyEvent.VK_X);
-               addItem(edit, "Paste", KeyEvent.VK_V);
-               addItem(edit, "Select all", KeyEvent.VK_E);
-               addItem(edit, "Invert selection", KeyEvent.VK_I);
-               addItem(edit, "Preferences...", KeyEvent.VK_P);
+               addItem(edit, "Copy", KeyEvent.VK_C, ActionEvent.CTRL_MASK);
+               addItem(edit, "Cut", KeyEvent.VK_X, ActionEvent.CTRL_MASK);
+               addItem(edit, "Paste", KeyEvent.VK_V, ActionEvent.CTRL_MASK);
+               edit.addSeparator();
+               addItem(edit, "Select all", KeyEvent.VK_E, ActionEvent.CTRL_MASK);
+               addItem(edit, "Invert selection", KeyEvent.VK_I, ActionEvent.CTRL_MASK);
+               edit.addSeparator();
+               addItem(edit, "Preferences...", KeyEvent.VK_P, ActionEvent.CTRL_MASK);
                
                playback = createMenu("Playback", KeyEvent.VK_P);
                add(playback);
                
-               addItem(playback, "Play", KeyEvent.VK_SPACE);
-               addItem(playback, "Pause");
-               addItem(playback, "Stop");
-               addItem(playback, "Jump...");
+               addItem(playback, "Play", "F5", KeyEvent.VK_P);
+               addItem(playback, "Pause", "F7", KeyEvent.VK_A);
+               addItem(playback, "Stop", "F6", KeyEvent.VK_S);
+               playback.addSeparator();
+               addItem(playback, "Set position...", KeyEvent.VK_E);
+               playback.addSeparator();
+               keyboard = createMenu("Set keyboard octave", KeyEvent.VK_K);
+               edit.add(keyboard);
+               for (int i = 9; i >= 0; i--) addItem(keyboard, "Octave " + i, i + 48);
                
                music = createMenu("Music", KeyEvent.VK_M);
                add(music);
                
-               addItem(music, "Add track...", KeyEvent.VK_A);
-               addItem(music, "Delete track...", KeyEvent.VK_D);
-               addItem(music, "Copy track...", KeyEvent.VK_Y);
-               addItem(music, "Move track...", KeyEvent.VK_M);
-               addItem(music, "Insert measure...");
-               addItem(music, "Delete measure...");
-               addItem(music, "Set time signature...");
-               addItem(music, "Set tempo...");
-               addItem(music, "Scale velocity...");
-               addItem(music, "Transpose...");
+               addItem(music, "Add track...", KeyEvent.VK_A, ActionEvent.CTRL_MASK);
+               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);
+               music.addSeparator();
+               addItem(music, "Insert measure...", KeyEvent.VK_I);
+               addItem(music, "Delete measure...", KeyEvent.VK_E);
+               music.addSeparator();
+               addItem(music, "Set time signature...", KeyEvent.VK_S);
+               addItem(music, "Set tempo...", KeyEvent.VK_M);
+               addItem(music, "Scale velocity...", KeyEvent.VK_V);
+               addItem(music, "Transpose...", KeyEvent.VK_T);
                
                help = createMenu("Help", KeyEvent.VK_L);
                add(help);
                
-               addItem(help, "Contents");
-               addItem(help, "Getting started");
-               addItem(help, "About");
+               addItem(help, "User manual", "F1", KeyEvent.VK_M);
+               help.addSeparator();
+               addItem(help, "About", KeyEvent.VK_A);
        }
-
        /**
-        * 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
+        * 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);
@@ -82,12 +91,12 @@ public class MooMenu extends JMenuBar implements ActionListener {
        }
        
        /**
-        * Creates a menu item.
-        * @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
+        * 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) {
+       private JMenuItem addItem(JMenu menu, String name, int mnemonic) {
                JMenuItem item = new JMenuItem(name);
                item.addActionListener(this);
                menu.add(item);
@@ -95,35 +104,38 @@ public class MooMenu extends JMenuBar implements ActionListener {
        }
        
        /**
-        * 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
+        * 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, int key) {
+       private JMenuItem addItem(JMenu menu, String name, String key, int mnemonic) {
                JMenuItem item = new JMenuItem(name);
-               item.setAccelerator(KeyStroke.getKeyStroke(key, ActionEvent.CTRL_MASK));
+               item.setAccelerator(KeyStroke.getKeyStroke(key));
+               item.setMnemonic(mnemonic);
                item.addActionListener(this);
                menu.add(item);
                return item;
        }
        
        /**
-       * creates a JFrame popupmenu, containing diffrent choices
-       * @param title  the title of the JFrame
-       * @param labelone       the first label of two
-       * @param labeltwo       the second label of two
-       * @return trackframe    the JFrame to popup....ffaaaaaaaaaaaaaaaan!
-       */
-       
-               
-       
-       /**
-        * checks if the fileformat is compatible with our program
-        * @param f     the file to check
-        * @return true or false
+        * 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));
+               item.setMnemonic(key);
+               item.addActionListener(this);
+               menu.add(item);
+               return item;
+       }
+       
        private boolean isMidiFile(File f) {
                if(f != null) {
                        String extension = f.getName().substring(f.getName().lastIndexOf('.') + 1).toLowerCase().trim();
@@ -131,7 +143,10 @@ public class MooMenu extends JMenuBar implements ActionListener {
                }
                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;
@@ -155,23 +170,9 @@ public class MooMenu extends JMenuBar implements ActionListener {
                                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") {
@@ -192,98 +193,68 @@ public class MooMenu extends JMenuBar implements ActionListener {
                        if (Moosique.getSequencer().isRunning()) Moosique.pause();
                } else if (command == "Stop") {
                        Moosique.stop();
-               } else if (command == "Jump...") {
-                       
+               } else if (command == "Set position...") {
+                       MooDialog newDialog = new MooDialog(MooDialog.SET_POSITION);
+                       // Moosique.setPosition(???); Räkna ut från msr, beats, ticks, time sig.
+               } else if (command.startsWith("Octave")) {
+                       MooKeyboard.setOctave(Integer.parseInt(command.substring(7,8)));
                } else if (command == "Add track...") {
-               
-                       JFrame frame = new JFrame("Add track");
-                       JPanel panel = new JPanel();
-                       //panel.setPreferredSize(new Dimension(250,400));
-                       panel.setLayout(new GridLayout(2,2));
-                       frame.setContentPane(panel);
-                       
-                       JLabel top = new JLabel("Name of track", JLabel.CENTER);
-                       top.setFont(new Font("Times new Roman", Font.BOLD, 10));
-                       panel.add(top);
-                       
-                       JTextField field = new JTextField(5);
-                       panel.add(field);
-                      
-                       JLabel bottom = new JLabel("Add it after",JLabel.CENTER);
-                       bottom.setFont(new Font("Times new Roman", Font.BOLD, 10));
-                       panel.add(bottom);
-                       
-                       JComboBox tracklist = new JComboBox();
-                       panel.add(tracklist);
-                       
-                       
-                       frame.pack();
-                       frame.show();
-                       
+                       MooDialog newDialog = new MooDialog(MooDialog.ADD_TRACK);
                        Moosique.getSequence().createTrack();
-                       
                } else if (command == "Delete track...") {
-                       
-                       JFrame frame = new JFrame("Delete track");
-                       JPanel panel = new JPanel();
-                       panel.setPreferredSize(new Dimension(250,400));
-                       frame.setContentPane(panel);
-                       
-                       frame.pack();
-                       frame.show();
+               
+                       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...") {
-               
-                       JFrame frame = new JFrame("Copy track");
-                       JPanel panel = new JPanel();
-                       panel.setPreferredSize(new Dimension(250,400));
-                       frame.setContentPane(panel);
-                       
-                       frame.pack();
-                       frame.show();
-               
+                       MooDialog newDialog = new MooDialog(MooDialog.COPY_TRACK);
                } else if (command == "Move track...") {
-               
-                       JFrame frame = new JFrame("Move track");
-                       JPanel panel = new JPanel();
-                       panel.setPreferredSize(new Dimension(250,400));
-                       panel.setLayout(new GridLayout(2,2));
-                       frame.setContentPane(panel);
-                       
-                       frame.pack();
-                       frame.show();
-               
-
+                       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...") {
+                       MooDialog newDialog = new MooDialog(MooDialog.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 == "User manual") {
+                       MooDialog manual = new MooDialog(MooDialog.MANUAL);
                } else if (command == "About") {
-                       // about to be filled in
-                       JOptionPane.showMessageDialog(null, "här kommer about att komma");
+                       JOptionPane.showMessageDialog(null,
+                               "Moosique\nversion 1.0\n\nby\n\nRoland Andersson\nMichael Andreen\nBjörn Lanneskog\nEinar Pehrson",
+                               "About Moosique",
+                               JOptionPane.INFORMATION_MESSAGE,
+                               new ImageIcon(Moosique.getGUI().logo));
                }
        }
 
+       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) {
@@ -292,7 +263,7 @@ public class MooMenu extends JMenuBar implements ActionListener {
                        return false;
                }
                
-               /*
+               /**
                 * gets the description of the filetype
                 * @return "Midifiles   the only filetyp compatibel with the program
                 */