]> ruin.nu Git - moosique.git/blob - MooToolbar.java
Changed window size and TrackView generation. Updated Toolbar listeners, and cleaned...
[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  * The application's toolbar, with the most frequently used commands.
8  * 
9  * @author  Björn Lanneskog
10  */
11 public class MooToolbar extends JToolBar {
12
13         private JButton rewind, playpause, stop, fastforward;
14         private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
15         private ImageIcon playIcon, pauseIcon;
16         private MooMouseAdapter mouseAdapter;
17         
18         /**
19          * Creates the toolbar.
20          */
21         
22         public MooToolbar()     {
23                 mouseAdapter = new MooMouseAdapter();
24
25                 rewind = createButton("images/rewind.gif", "Rewind");
26                 add(rewind);
27
28                 playpause = createButton("images/play.gif", "Play");
29                 add(playpause);
30                 playIcon = new ImageIcon("images/play.gif");
31                 pauseIcon = new ImageIcon("images/pause.gif");
32                 
33                 stop = createButton("images/stop.gif", "Stop");
34                 add(stop);
35                 
36                 fastforward = createButton("images/forward.gif", "Fast forward");
37                 add(fastforward);
38                 
39                 JPanel progIndPanel = new JPanel();
40                 progIndPanel.setBorder(BorderFactory.createLineBorder(Color.black));
41                 progIndPanel.setMaximumSize(new Dimension(100,22));
42                 progIndPanel.setLayout(new GridLayout(2,3));
43                 measure = createLabel("Mrs",10);
44                 beats = createLabel("Beat",10);
45                 ticks = createLabel("Tick",10);
46                 measurevalue = createLabel(12);
47                 beatsvalue = createLabel("1",12);
48                 ticksvalue = createLabel("1",12);
49                 progIndPanel.add(measure);
50                 progIndPanel.add(beats);
51                 progIndPanel.add(ticks);
52                 progIndPanel.add(measurevalue);
53                 progIndPanel.add(beatsvalue);
54                 progIndPanel.add(ticksvalue);
55                 add(progIndPanel);
56         }
57                 
58         /**
59          * Creates a button with the specified image and tooltip.
60          * @param imagelocation         the imagelacation of the the image displayed in the button
61          * @param tooltip               the tooltip associated with this button
62          * @return button               the button to be attached to the toolbar
63          */
64         private JButton createButton(String imagelocation, String tooltip) {
65                 JButton button = new JButton (new ImageIcon(imagelocation));
66                 button.setToolTipText(tooltip);
67                 button.addMouseListener(mouseAdapter);
68                 return button;
69         }
70         
71         /**
72          * Creates labels with the specified text and font size. 
73          * @param title         the titel displayed on the label
74          * @param fontsize      the fontzise of the text displayed on the label
75          */
76         private JLabel createLabel(String title, int fontSize){
77                 JLabel value = new JLabel(title,JLabel.CENTER);
78                 value.setFont(new Font("Times New Roman", Font.BOLD, fontSize));
79                 return value;
80         }
81         
82         // int pos = Moosique.getSequencer().getTickPosition();
83         // int measures = pos / (4 * Moosique.getSequence.get)
84         // int beats = (pos - measures * 4 * 96) / 96;
85         // int ticks = (pos - measures*4*96 - beats*96);
86         
87         class MooMouseAdapter extends MouseAdapter {
88                 public void mouseClicked(MouseEvent e) {
89                         if (((JButton)e.getSource()).getToolTipText() == "Play") {
90                                         Moosique.play();
91                                         playpause.setIcon(pauseIcon);
92                                         playpause.setToolTipText("Pause");
93                         } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
94                                         Moosique.pause();
95                                         playpause.setIcon(playIcon);
96                                         playpause.setToolTipText("Resume");
97                         } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
98                                         Moosique.resume();
99                                         playpause.setIcon(pauseIcon);
100                                         playpause.setToolTipText("Pause");
101                         } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
102                                 Moosique.stop();
103                                 playpause.setIcon(playIcon);
104                                 playpause.setToolTipText("Play");
105                         }
106                 }
107
108                 public void mousePressed(MouseEvent e) {
109                         if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
110                                 Moosique.rewind(96);
111                         } else if (((JButton)e.getSource()).getToolTipText() == "Fast forward") {
112                                 Moosique.forward(96);
113                         }
114                 }
115
116                 public void mouseReleased(MouseEvent e) {}
117         }
118 }