]> ruin.nu Git - moosique.git/blobdiff - MooToolbar.java
vad sägs om bordern?
[moosique.git] / MooToolbar.java
index 5eae4772a3b12120f0a4ea6777c500a4af00ae37..ebb626e9ed06db1569251158e6fa0363f246ffa5 100644 (file)
 import javax.swing.*;
+import java.awt.event.*;
+import java.awt.*;
+import javax.sound.midi.*;
 
 /**
+ * Moosiques GUI representing a toolbar, with the most frequently used commands.
  * 
- * 
- * @author  Andersson, Andreen, Lanneskog, Pehrson
- * @version 1
+ * @author  Björn Lanneskog
  */
-public class MooToolbar {
+public class MooToolbar extends JToolBar implements ActionListener     {
 
-       /** 
-        * Creates the toolbar.
+       private JButton rewind, playpause, stop, fastforward;
+       private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
+       private Image pauseimage, playimage;
+       
+       /**
+        * Constructs a toolbar
         */
-       public MooToolbar () {
+       
+       public MooToolbar()     {
+       
+               rewind = createButton("images/rewind.gif", "rewind");
+               add(rewind);
 
-       }
+               playpause = createButton("images/play.gif", "play/pause");
+               add(playpause);
+               
+               stop = createButton("images/stop.gif", "stop");
+               add(stop);
+               
+               fastforward = createButton("images/forward.gif", "fast forward");
+               add(fastforward);
+               
+               JPanel panel = new JPanel();
+               panel.setMaximumSize(new Dimension(120,27));
+               panel.setLayout(new GridLayout(2,4));
+               
+               add(panel);
+               
+               panel.add(new JPanel());
+               
+               measure = createProjIndLabel("Mrs", 10);
+               panel.add(measure);
+               
+               beats = createProjIndLabel("Beat", 10);
+               panel.add(beats);
+               
+               ticks = createProjIndLabel("Tick", 10);
+               panel.add(ticks);
+               
+               panel.add(new JPanel());
+               
+               measurevalue = createProjIndLabel("1", 12);
+               panel.add(measurevalue);
+               
+               beatsvalue = createProjIndLabel("1",12);
+               panel.add(beatsvalue);
+               
+               ticksvalue = createProjIndLabel("1", 12);
+               panel.add(ticksvalue);
+               
+               playimage = Toolkit.getDefaultToolkit().getImage("images/play.gif");
+               pauseimage = Toolkit.getDefaultToolkit().getImage("images/pause.gif");
+               
+               }
+               
+               /**
+                * creates a JButton for the toolbar
+                * @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.addActionListener(this);
+                       return button;
+               }
+               
+               /**
+                * creates JLabels for the progressindikator, attached to the toolbar
+                * @param title         the titel displayed on the label
+                * @param fontsize      the fontzise of the text displayed on the label
+                * @param fontstyle     the fontstyle of the text displayed on the label
+                * @return titelvalue   the label that is a part of the progressindikator
+                */
+               private JLabel createProjIndLabel(String title, int fontsize){
+                       JLabel titelvalue = new JLabel(title,JLabel.CENTER);
+                       titelvalue.setFont(new Font("Times New Roman",
+                       Font.BOLD ,fontsize));
+                       titelvalue.setBorder(BorderFactory.createLineBorder(Color.black));
+                       return titelvalue;
+               }
+               // 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);
+               
+                       
+               public void actionPerformed(ActionEvent e) {
+       
+                      if (((JButton)e.getSource()).getToolTipText() == "rewind") {
+                               //få in rewindmetoden
+                       }       else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
+                                       ImageIcon playpauseIcon = ((ImageIcon)playpause.getIcon());
+                                       if (Moosique.getSequencer().isRunning()) {
+                                               Moosique.pause();
+                                               playpauseIcon.setImage(playimage);
+                                       } else {
+                                               Moosique.play();
+                                               playpauseIcon.setImage(pauseimage);
+                                       }
+                       
+                       }       else if (((JButton)e.getSource()).getToolTipText() == "stop") {
+                                       Moosique.stop();
+                                       
+                       }       else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
+                                       // få in fastforwardmetoden
+                       
+                       }
+               }
+               
 }