]> ruin.nu Git - moosique.git/blobdiff - MooToolbar.java
Fixed "Reopen"-menu.
[moosique.git] / MooToolbar.java
index e5e46da50e7a17cb39a362cf256cf4be315e0cef..bca50efba950d727f80be24e97136d40795fcb17 100644 (file)
@@ -1,7 +1,7 @@
+import javax.sound.midi.*;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
-import javax.sound.midi.*;
 
 /**
  * The application's toolbar, with the most frequently used commands.
@@ -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,16 +75,16 @@ public class MooToolbar extends JToolBar {
         * @param tickPosition  the tick position to visualize
         */
        public void updateProgInd(long tickPosition) {
+               System.out.print("Updating to " + tickPosition + " = ");
                if (tickPosition == 0) {
                        resetProgInd();
+                       System.out.println("1:1:1");
                } else {
-                       // Otherwise, calculates the current song position in measures, beats and ticks.
-                       long measures = tickPosition / (beatsPerMeasure * ticksPerBeat);
-                       long beats = (tickPosition - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat;
-                       long ticks = tickPosition - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat;
-                       measuresValue.setText(Long.toString(1 + measures));
-                       beatsValue.setText(Long.toString(1 + beats));
-                       ticksValue.setText(Long.toString(1 + ticks));
+                       int[] position = Moosique.getPositionForTicks(tickPosition);
+                       System.out.println("" + position[0] + ":" + position[1] + ":" + position[2]);
+                       measuresValue.setText(Integer.toString(position[0]));
+                       beatsValue.setText(Long.toString(position[1]));
+                       ticksValue.setText(Long.toString(position[2]));
                }
        }
 
@@ -91,25 +92,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){
@@ -118,7 +119,7 @@ public class MooToolbar extends JToolBar {
                return label;
        }
 
-       /*
+       /**
         * Formats the given label for the progress indicator.
         */
        private JLabel formatProgInd(JLabel label){
@@ -128,27 +129,41 @@ 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) {
-                               long position = Moosique.getPosition();
+                               long position = Moosique.getEditPosition();
                                if (e.getSource().equals(measuresValue)) {
                                        if (SwingUtilities.isRightMouseButton(e)) {
                                                position += beatsPerMeasure * ticksPerBeat;
@@ -168,12 +183,12 @@ public class MooToolbar extends JToolBar {
                                                position -= 1;
                                        }
                                }
-                               Moosique.setPosition(position);
+                               Moosique.setEditPosition(position);
                                Moosique.getGUI().update(position);
                        }
                }
 
-               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);
@@ -184,5 +199,5 @@ public class MooToolbar extends JToolBar {
                }
 
                public void mouseReleased(MouseEvent e) {}
-       }
+*/     }
 }