]> ruin.nu Git - moosique.git/blobdiff - MooToolbar.java
some changes
[moosique.git] / MooToolbar.java
index 3045118d7cbe573f14105a6cf8c286ded0bbae6a..3574d2bb6ba8b8d7867ef5f408fa9114f228d37d 100644 (file)
 import javax.swing.*;
-import java.awt.event.*;
 import java.awt.*;
-import java.awt.Color;
+import java.awt.event.*;
+import javax.sound.midi.*;
 
-public class MooToolbar extends JToolBar implements ActionListener     {
+/**
+ * The application's toolbar, with the most frequently used commands.
+ * 
+ * @author  Björn Lanneskog
+ */
+public class MooToolbar extends JToolBar {
 
-       public MooToolbar()     {
+       private JButton rewind, playpause, stop, fastforward;
+       private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
+       private ImageIcon playIcon, pauseIcon;
+       private MooMouseAdapter mouseAdapter;
        
-               rewind = createButton("images/rewind.gif", "rewind");
-               add(rewind);
+       /**
+        * Creates the toolbar.
+        */
+       
+       public MooToolbar() {
+               setFloatable(false);
+               mouseAdapter = new MooMouseAdapter();
 
-               playpause = createButton("images/play.gif", "play");
+               // 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");
+               playIcon = new ImageIcon("images/play.gif");
+               pauseIcon = new ImageIcon("images/pause.gif");
+               stop = createButton("images/stop.gif", "Stop");
                add(stop);
-               
-               fastforward = createButton("images/forward.gif", "fast forward");
+               fastforward = createButton("images/forward.gif", "Fast forward");
                add(fastforward);
                
-               meas = createLabel("Measure");
-               add(meas);
-               
-               beat = createLabel("Beats");
-               add(beat);
+               // Creates progress indicator
+               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);
+               progIndPanel.add(new JPanel());
+               progIndPanel.add(measure);
+               progIndPanel.add(beats);
+               progIndPanel.add(ticks);
+               progIndPanel.add(new JPanel());
+               progIndPanel.add(measurevalue);
+               progIndPanel.add(beatsvalue);
+               progIndPanel.add(ticksvalue);
+               add(progIndPanel);
+       }
                
-               ticks = createLabel("Ticks");
-               add(ticks);
-               
-               }
-               
-               private JButton createButton(String imageLocation, String toolTip) {
-                       JButton button = new JButton (new ImageIcon(imageLocation));
-                       button.setToolTipText(toolTip);
-                       button.addActionListener(this);
-                       return button;
-               }
-               
-               private JLabel createLabel(String name) {
-                       JLabel label = new JLabel(name);
-                       return label;
-                       
+       /**
+        * Creates a button with the specified image and tooltip.
+        * @param imagelocation         the imagelacation of the the image displayed in the button
+        * @param tooltip               the tooltip associated with this button
+        * @return button               the button to be attached to the toolbar
+        */
+       private JButton createButton(String imagelocation, String tooltip) {
+               JButton button = new JButton (new ImageIcon(imagelocation));
+               button.setToolTipText(tooltip);
+               button.addMouseListener(mouseAdapter);
+               return button;
+       }
+       
+       /**
+        * Creates labels with the specified text and font size. 
+        * @param title         the titel displayed on the label
+        * @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;
+       }
+       
+       // 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") {
+                                       Moosique.play();
+                                       playpause.setIcon(pauseIcon);
+                                       playpause.setToolTipText("Pause");
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
+                                       Moosique.pause();
+                                       playpause.setIcon(playIcon);
+                                       playpause.setToolTipText("Resume");
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
+                                       Moosique.resume();
+                                       playpause.setIcon(pauseIcon);
+                                       playpause.setToolTipText("Pause");
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
+                               Moosique.stop();
+                               playpause.setIcon(playIcon);
+                               playpause.setToolTipText("Play");
+                       }
                }
-               
-               public void actionPerformed(ActionEvent e) {
-                       
-                       
-                       /*if () {
-                       
-                       } else if () {
-                               
-                       
-                       } else if () {
-                       
-                       } else if () {
-                       
-                       }*/
+
+               public void mousePressed(MouseEvent e) {
+                       if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
+                               Moosique.rewind(96);
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Fast forward") {
+                               Moosique.forward(96);
+                       }
                }
-               private JButton rewind;
-               private JButton playpause;
-               private JButton stop;
-               private JButton fastforward;
-               private JLabel meas;
-               private JLabel beat;
-               private JLabel ticks;
+
+               public void mouseReleased(MouseEvent e) {}
+       }
 }