]> ruin.nu Git - moosique.git/blobdiff - MooToolbar.java
no message
[moosique.git] / MooToolbar.java
index 08e4a0d2f580622ffd20587ab17d0fa31f552322..1ea47ab08f5e3af9becb759089bc58889cdda5ef 100644 (file)
@@ -24,6 +24,7 @@ public class MooToolbar extends JToolBar {
         */
        
        public MooToolbar() {
+               setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
                // setAlignmentX(LEFT_ALIGNMENT);
                setFloatable(false);
                mouseAdapter = new MAdapter();
@@ -74,6 +75,7 @@ public class MooToolbar extends JToolBar {
         * @param tickPosition  the tick position to visualize
         */
        public void updateProgInd(long tickPosition) {
+               ticksPerBeat = Moosique.getSequence().getResolution();
                if (tickPosition == 0) {
                        resetProgInd();
                } else {
@@ -99,17 +101,18 @@ public class MooToolbar extends JToolBar {
                        ticksPerBeat = Moosique.getSequence().getResolution();
        }
 
-       /*
-        * Creates a button with the specified image and tooltip.
+       /**
+        * Creates a button with the specified image and action command / tooltip.
         */
-       private JButton createButton(String imagelocation, String tooltip) {
+       private JButton createButton(String imagelocation, String command) {
                JButton button = new JButton (new ImageIcon(imagelocation));
-               button.setToolTipText(tooltip);
+               button.setToolTipText(command);
+               button.setActionCommand(command);
                button.addMouseListener(mouseAdapter);
                return button;
        }
        
-       /*
+       /**
         * Creates labels with the specified text and font size. 
         */
        private JLabel createLabel(String title, int fontSize){
@@ -118,7 +121,7 @@ public class MooToolbar extends JToolBar {
                return label;
        }
 
-       /*
+       /**
         * Formats the given label for the progress indicator.
         */
        private JLabel formatProgInd(JLabel label){
@@ -131,51 +134,53 @@ public class MooToolbar extends JToolBar {
        class MAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (e.getSource() instanceof JButton) {
-                               String toolTip = ((JButton)e.getSource()).getToolTipText();
-                               if (toolTip == "Play") {
+                               String command = ((JButton)e.getSource()).getActionCommand();
+                               if (command == "Play") {
                                        playpause.setIcon(pauseIcon);
+                                       playpause.setActionCommand("Pause");
                                        playpause.setToolTipText("Pause");
                                        Moosique.play();
-                               } else if (toolTip == "Pause") {
+                               } else if (command == "Pause") {
                                        playpause.setIcon(playIcon);
+                                       playpause.setActionCommand("Resume");
                                        playpause.setToolTipText("Resume");
                                        Moosique.pause();
-                               } else if (toolTip == "Resume") {
+                               } else if (command == "Resume") {
                                        playpause.setIcon(pauseIcon);
+                                       playpause.setActionCommand("Pause");
                                        playpause.setToolTipText("Pause");
                                        Moosique.resume();
-                               } else if (toolTip == "Stop") {
-                                       resetProgInd();
+                               } else if (command == "Rewind") {
+                                       // Different implementation, perhaps?
+                                       Moosique.setEditPosition(0);
+                                       Moosique.stop();
+                               } else if (command == "Fast forward") {
+
+                               } else if (command == "Stop") {
                                        Moosique.stop();
                                }
                        } else if (e.getSource() instanceof JLabel) {
-                               long position = Moosique.getSequencer().getTickPosition();
+                               long position = Moosique.getEditPosition();
                                if (e.getSource().equals(measuresValue)) {
                                        if (SwingUtilities.isRightMouseButton(e)) {
-                                               System.out.println("IncM");
                                                position += beatsPerMeasure * ticksPerBeat;
                                        } else if (SwingUtilities.isLeftMouseButton(e) && Integer.parseInt(measuresValue.getText()) > 1) {
-                                               System.out.println("DecM");
                                                position -= beatsPerMeasure * ticksPerBeat;
                                        }
                                } else if (e.getSource().equals(beatsValue)) {
                                        if (SwingUtilities.isRightMouseButton(e)) {
-                                               System.out.println("IncB");
                                                position += ticksPerBeat;
                                        } else if (SwingUtilities.isLeftMouseButton(e) && Integer.parseInt(beatsValue.getText()) > 1) {
-                                               System.out.println("DecB");
                                                position -= ticksPerBeat;
                                        }
                                } else if (e.getSource().equals(ticksValue)) {
                                        if (SwingUtilities.isRightMouseButton(e)) {
-                                               System.out.println("IncT");
                                                position += 1;
                                        } else if (SwingUtilities.isLeftMouseButton(e) && Integer.parseInt(ticksValue.getText()) > 1) {
-                                               System.out.println("DecT");
                                                position -= 1;
                                        }
                                }
-                               Moosique.getSequencer().setTickPosition(position);
+                               Moosique.setEditPosition(position);
                                Moosique.getGUI().update(position);
                        }
                }
@@ -192,4 +197,4 @@ public class MooToolbar extends JToolBar {
 
                public void mouseReleased(MouseEvent e) {}
        }
-}
\ No newline at end of file
+}