]> ruin.nu Git - moosique.git/blobdiff - MooToolbar.java
Fixed accessors, encoders and decoders for tempo and time signature.
[moosique.git] / MooToolbar.java
index a94aabdf8ef0138af880d5592a39c830c6fbd0fd..5be8fdb77a29d0ddfd251bce0fd60433c9c79333 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();
@@ -92,25 +93,25 @@ public class MooToolbar extends JToolBar {
         * Resets the progress indicator.
         */
        public void resetProgInd() {
-                       measuresValue.setText("1");
-                       beatsValue.setText("1");
-                       ticksValue.setText("1");
-                       playpause.setIcon(playIcon);
-                       playpause.setToolTipText("Play");
-                       ticksPerBeat = Moosique.getSequence().getResolution();
+               measuresValue.setText("1");
+               beatsValue.setText("1");
+               ticksValue.setText("1");
+               updatePlayButton("Play", playIcon);
+               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){
@@ -119,7 +120,7 @@ public class MooToolbar extends JToolBar {
                return label;
        }
 
-       /*
+       /**
         * Formats the given label for the progress indicator.
         */
        private JLabel formatProgInd(JLabel label){
@@ -129,23 +130,37 @@ public class MooToolbar extends JToolBar {
                return label;
        }
 
+       /**
+        * Updates the play button with the given command and icon.
+        */
+       private void updatePlayButton(String command, Icon icon) {
+               playpause.setIcon(icon);
+               playpause.setActionCommand(command);
+               playpause.setToolTipText(command);
+       }
+
        class MAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (e.getSource() instanceof JButton) {
-                               String toolTip = ((JButton)e.getSource()).getToolTipText();
-                               if (toolTip == "Play") {
-                                       playpause.setIcon(pauseIcon);
-                                       playpause.setToolTipText("Pause");
+                               String command = ((JButton)e.getSource()).getActionCommand();
+                               if (command == "Play") {
+                                       updatePlayButton("Pause", pauseIcon);
                                        Moosique.play();
-                               } else if (toolTip == "Pause") {
-                                       playpause.setIcon(playIcon);
-                                       playpause.setToolTipText("Resume");
+                               } else if (command == "Pause") {
+                                       updatePlayButton("Resume", playIcon);
                                        Moosique.pause();
-                               } else if (toolTip == "Resume") {
-                                       playpause.setIcon(pauseIcon);
-                                       playpause.setToolTipText("Pause");
+                               } else if (command == "Resume") {
+                                       updatePlayButton("Pause", pauseIcon);
                                        Moosique.resume();
-                               } else if (toolTip == "Stop") {
+                               } else if (command == "Rewind") {
+                                       System.out.println("Rewound!");
+                                       // Different implementation, perhaps?
+                                       updatePlayButton("Play", playIcon);
+                                       Moosique.setEditPosition(0);
+                                       Moosique.stop();
+                               } else if (command == "Fast forward") {
+                               } else if (command == "Stop") {
+                                       updatePlayButton("Play", playIcon);
                                        Moosique.stop();
                                }
                        } else if (e.getSource() instanceof JLabel) {
@@ -174,7 +189,7 @@ public class MooToolbar extends JToolBar {
                        }
                }
 
-               public void mousePressed(MouseEvent e) {
+/*             public void mousePressed(MouseEvent e) {
                        if (e.getSource() instanceof JButton) {
                                if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
                                        Moosique.rewind(beatsPerMeasure * ticksPerBeat);
@@ -185,5 +200,5 @@ public class MooToolbar extends JToolBar {
                }
 
                public void mouseReleased(MouseEvent e) {}
-       }
+*/     }
 }