]> ruin.nu Git - moosique.git/blob - MooToolbar.java
Fixed some errors, updated the menu and toolbar.
[moosique.git] / MooToolbar.java
1 import javax.swing.*;
2 import java.awt.event.*;
3 import java.awt.*;
4 import javax.sound.midi.*;
5
6 /**
7  * Moosiques GUI representing a toolbar, with the most frequently used commands.
8  * 
9  * @author  Björn Lanneskog
10  */
11 public class MooToolbar extends JToolBar implements ActionListener      {
12
13         private JButton rewind, playpause, stop, fastforward;
14         private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
15         private Image pauseimage, playimage;
16         
17         /**
18          * Constructs a toolbar
19          */
20         
21         public MooToolbar()     {
22         
23                 rewind = createButton("images/rewind.gif", "rewind");
24                 add(rewind);
25
26                 playpause = createButton("images/play.gif", "play/pause");
27                 add(playpause);
28                 
29                 stop = createButton("images/stop.gif", "stop");
30                 add(stop);
31                 
32                 fastforward = createButton("images/forward.gif", "fast forward");
33                 add(fastforward);
34                 
35                 JPanel panel = new JPanel();
36                 panel.setMaximumSize(new Dimension(100,22));
37                 panel.setLayout(new GridLayout(2,4));
38                 add(panel);
39                 
40                 panel.add(new JPanel());
41                 
42                 measure = createProjIndLabel("Mrs",10);
43                 panel.add(measure);
44                 
45                 beats = createProjIndLabel("Beat",10);
46                 panel.add(beats);
47                 
48                 ticks = createProjIndLabel("Tick",10);
49                 panel.add(ticks);
50                 
51                 panel.add(new JPanel());
52                 
53                 measurevalue = createProjIndLabel("1",10);
54                 panel.add(measurevalue);
55                 
56                 beatsvalue = createProjIndLabel("1",10);
57                 panel.add(beatsvalue);
58                 
59                 ticksvalue = createProjIndLabel("1",10);
60                 panel.add(ticksvalue);
61                 
62                 playimage = Toolkit.getDefaultToolkit().getImage("images/play.gif");
63                 pauseimage = Toolkit.getDefaultToolkit().getImage("images/pause.gif");
64                 
65                 }
66                 
67                 /**
68                  * creates a JButton for the toolbar
69                  * @param imagelocation         the imagelacation of the the image displayed in the button
70                  * @param tooltip               the tooltip associated with this button
71                  * @return button               the button to be attached to the toolbar
72                  */
73                 private JButton createButton(String imagelocation, String tooltip) {
74                         JButton button = new JButton (new ImageIcon(imagelocation));
75                         button.setToolTipText(tooltip);
76                         button.addActionListener(this);
77                         return button;
78                 }
79                 
80                 /**
81                  * creates JLabels for the progressindikator, attached to the toolbar
82                  * @param title         the titel displayed on the label
83                  * @param fontsize      the fontzise of the text displayed on the label
84                  * @param titelvalue    the label that is a part of the progressindikator
85                  */
86                 private JLabel createProjIndLabel(String title, int fontsize){
87                         JLabel titelvalue = new JLabel(title,JLabel.CENTER);
88                         titelvalue.setFont(new Font("Times New Roman",
89                         Font.PLAIN ,fontsize));
90                         return titelvalue;
91                 }
92                 
93                 // int pos = Moosique.getSequencer().getTickPosition();
94                 // int measures = pos / (4 * Moosique.getSequence.get)
95                 // int beats = (pos - measures * 4 * 96) / 96;
96                 // int ticks = (pos - measures*4*96 - beats*96);
97                 
98                         
99                 public void actionPerformed(ActionEvent e) {
100         
101                        if (((JButton)e.getSource()).getToolTipText() == "rewind") {
102                                 //få in rewindmetoden
103                         }       else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
104                                         ImageIcon playpauseIcon = ((ImageIcon)playpause.getIcon());
105                                         if (Moosique.getSequencer().isRunning()) {
106                                                 Moosique.pause();
107                                                 playpauseIcon.setImage(playimage);
108                                         } else {
109                                                 Moosique.play();
110                                                 playpauseIcon.setImage(pauseimage);
111                                         }
112                         
113                         }       else if (((JButton)e.getSource()).getToolTipText() == "stop") {
114                                         Moosique.stop();
115                                         
116                         }       else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
117                                         // få in fastforwardmetoden
118                         
119                         }
120                 }
121                 
122 }