]> ruin.nu Git - moosique.git/blob - MooToolbar.java
vad sägs om bordern?
[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(120,27));
37                 panel.setLayout(new GridLayout(2,4));
38                 
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", 12);
55                 panel.add(measurevalue);
56                 
57                 beatsvalue = createProjIndLabel("1",12);
58                 panel.add(beatsvalue);
59                 
60                 ticksvalue = createProjIndLabel("1", 12);
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 fontstyle     the fontstyle of the text displayed on the label
86                  * @return titelvalue   the label that is a part of the progressindikator
87                  */
88                 private JLabel createProjIndLabel(String title, int fontsize){
89                         JLabel titelvalue = new JLabel(title,JLabel.CENTER);
90                         titelvalue.setFont(new Font("Times New Roman",
91                         Font.BOLD ,fontsize));
92                         titelvalue.setBorder(BorderFactory.createLineBorder(Color.black));
93                         return titelvalue;
94                 }
95                 // int pos = Moosique.getSequencer().getTickPosition();
96                 // int measures = pos / (4 * Moosique.getSequence.get)
97                 // int beats = (pos - measures * 4 * 96) / 96;
98                 // int ticks = (pos - measures*4*96 - beats*96);
99                 
100                         
101                 public void actionPerformed(ActionEvent e) {
102         
103                        if (((JButton)e.getSource()).getToolTipText() == "rewind") {
104                                 //få in rewindmetoden
105                         }       else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
106                                         ImageIcon playpauseIcon = ((ImageIcon)playpause.getIcon());
107                                         if (Moosique.getSequencer().isRunning()) {
108                                                 Moosique.pause();
109                                                 playpauseIcon.setImage(playimage);
110                                         } else {
111                                                 Moosique.play();
112                                                 playpauseIcon.setImage(pauseimage);
113                                         }
114                         
115                         }       else if (((JButton)e.getSource()).getToolTipText() == "stop") {
116                                         Moosique.stop();
117                                         
118                         }       else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
119                                         // få in fastforwardmetoden
120                         
121                         }
122                 }
123                 
124 }