]> ruin.nu Git - moosique.git/blobdiff - MooToolbar.java
Fixed some bugs
[moosique.git] / MooToolbar.java
index a2f55712fac336c7e0df85fbc0ae85e190b9f55d..c1244f575e81b717e8db764427727b2d0362fd06 100644 (file)
@@ -11,7 +11,7 @@ import javax.sound.midi.*;
 public class MooToolbar extends JToolBar {
 
        private JButton rewind, playpause, stop, fastforward;
-       private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
+       private JLabel measure, beats, ticks, measureValue, beatsValue, ticksValue;
        private ImageIcon playIcon, pauseIcon;
        private MooMouseAdapter mouseAdapter;
        public static final Color bgColor = new Color(192, 224, 255);
@@ -21,50 +21,64 @@ public class MooToolbar extends JToolBar {
         */
        
        public MooToolbar() {
+               // setAlignmentX(LEFT_ALIGNMENT);
                setFloatable(false);
                mouseAdapter = new MooMouseAdapter();
 
                // Creates playback buttons
                rewind = createButton("images/rewind.gif", "Rewind");
-               add(rewind);
                playpause = createButton("images/play.gif", "Play");
-               add(playpause);
+               stop = createButton("images/stop.gif", "Stop");
+               fastforward = createButton("images/forward.gif", "Fast forward");
                playIcon = new ImageIcon("images/play.gif");
                pauseIcon = new ImageIcon("images/pause.gif");
-               stop = createButton("images/stop.gif", "Stop");
+
+               // Adds playback buttons
+               add(rewind);
+               add(playpause);
                add(stop);
-               fastforward = createButton("images/forward.gif", "Fast forward");
                add(fastforward);
                
                // Creates progress indicator
+               measure = createLabel("Msr", 10);
+               beats = createLabel("Beat", 10);
+               ticks = createLabel("Tick", 10);
+               measureValue = createLabel("1", 16);
+               beatsValue = createLabel("1", 16);
+               ticksValue = createLabel("1", 16);
+               JPanel spacenorth = new JPanel();
+               spacenorth.setBackground(bgColor);
+               JPanel spacesouth = new JPanel();
+               spacesouth.setBackground(bgColor);
+
+               // Creates progress indicator panel and adds components
                JPanel progIndPanel = new JPanel();
                progIndPanel.setMaximumSize(new Dimension(120,27));
                progIndPanel.setLayout(new GridLayout(2,4));
-               measure = createLabel("Mrs",10);
-               beats = createLabel("Beat",10);
-               ticks = createLabel("Tick",10);
-               measurevalue = createLabel("1", 16);
-               beatsvalue = createLabel("1",16);
-               ticksvalue = createLabel("1",16);
-               
-               JPanel spacenorth = new JPanel();
-               spacenorth.setBackground(bgColor);
                progIndPanel.add(spacenorth);
-               
                progIndPanel.add(measure);
                progIndPanel.add(beats);
                progIndPanel.add(ticks);
-               
-               JPanel spacesouth = new JPanel();
-               spacesouth.setBackground(bgColor);
                progIndPanel.add(spacesouth);
-               
-               progIndPanel.add(measurevalue);
-               progIndPanel.add(beatsvalue);
-               progIndPanel.add(ticksvalue);
+               progIndPanel.add(measureValue);
+               progIndPanel.add(beatsValue);
+               progIndPanel.add(ticksValue);
                add(progIndPanel);
+
        }
-               
+
+       /**
+        * Updates the progress indicator.
+        */
+       public void updateProgInd() {
+               int pos = Moosique.getSequencer().getTickPosition();
+               int ticksPerBeat = Moosique.getSequencer().getResolution();
+               int beatsPerMeasure = 4;
+               measureValue.setText(pos / (beatsPerMeasure * ticksPerBeat));
+               beatsValue.setText((pos - measures * beatsPerMeasure * ticksPerBeat) / ticksPerBeat);
+               ticksValue.setText(pos - measures * beatsPerMeasure * ticksPerBeat - beats * ticksPerBeat);
+       }
+
        /**
         * Creates a button with the specified image and tooltip.
         * @param imagelocation         the imagelacation of the the image displayed in the button
@@ -84,17 +98,12 @@ public class MooToolbar extends JToolBar {
         * @param fontsize      the fontzise of the text displayed on the label
         */
        private JLabel createLabel(String title, int fontSize){
-               JLabel value = new JLabel(title,JLabel.CENTER);
-               value.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
-               value.setBorder(BorderFactory.createLineBorder(Color.black));
-               return value;
+               JLabel label = new JLabel(title,JLabel.CENTER);
+               label.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
+               label.setBorder(BorderFactory.createLineBorder(Color.black));
+               return label;
        }
-       
-       // int pos = Moosique.getSequencer().getTickPosition();
-       // int measures = pos / (4 * Moosique.getSequence.get)
-       // int beats = (pos - measures * 4 * 96) / 96;
-       // int ticks = (pos - measures*4*96 - beats*96);
-       
+
        class MooMouseAdapter extends MouseAdapter {
                public void mouseClicked(MouseEvent e) {
                        if (((JButton)e.getSource()).getToolTipText() == "Play") {
@@ -126,4 +135,4 @@ public class MooToolbar extends JToolBar {
 
                public void mouseReleased(MouseEvent e) {}
        }
-}
+}
\ No newline at end of file