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