3 import java.awt.event.*;
4 import javax.sound.midi.*;
7 * The application's toolbar, with the most frequently used commands.
9 * @author Björn Lanneskog
11 public class MooToolbar extends JToolBar {
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 public static final Color bgColor = new Color(192, 224, 255);
20 * Creates the toolbar.
25 mouseAdapter = new MooMouseAdapter();
27 // Creates playback buttons
28 rewind = createButton("images/rewind.gif", "Rewind");
30 playpause = createButton("images/play.gif", "Play");
32 playIcon = new ImageIcon("images/play.gif");
33 pauseIcon = new ImageIcon("images/pause.gif");
34 stop = createButton("images/stop.gif", "Stop");
36 fastforward = createButton("images/forward.gif", "Fast forward");
39 // Creates progress indicator
40 JPanel progIndPanel = new JPanel();
41 progIndPanel.setMaximumSize(new Dimension(120,27));
42 progIndPanel.setLayout(new GridLayout(2,4));
43 measure = createLabel("Mrs",10);
44 beats = createLabel("Beat",10);
45 ticks = createLabel("Tick",10);
46 measurevalue = createLabel("1", 16);
47 beatsvalue = createLabel("1",16);
48 ticksvalue = createLabel("1",16);
50 JPanel spacenorth = new JPanel();
51 spacenorth.setBackground(bgColor);
52 progIndPanel.add(spacenorth);
54 progIndPanel.add(measure);
55 progIndPanel.add(beats);
56 progIndPanel.add(ticks);
58 JPanel spacesouth = new JPanel();
59 spacesouth.setBackground(bgColor);
60 progIndPanel.add(spacesouth);
62 progIndPanel.add(measurevalue);
63 progIndPanel.add(beatsvalue);
64 progIndPanel.add(ticksvalue);
69 * Creates a button with the specified image and tooltip.
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
74 private JButton createButton(String imagelocation, String tooltip) {
75 JButton button = new JButton (new ImageIcon(imagelocation));
76 button.setToolTipText(tooltip);
77 button.addMouseListener(mouseAdapter);
82 * Creates labels with the specified text and font size.
83 * @param title the titel displayed on the label
84 * @param fontsize the fontzise of the text displayed on the label
86 private JLabel createLabel(String title, int fontSize){
87 JLabel value = new JLabel(title,JLabel.CENTER);
88 value.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
89 value.setBorder(BorderFactory.createLineBorder(Color.black));
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);
98 class MooMouseAdapter extends MouseAdapter {
99 public void mouseClicked(MouseEvent e) {
100 if (((JButton)e.getSource()).getToolTipText() == "Play") {
102 playpause.setIcon(pauseIcon);
103 playpause.setToolTipText("Pause");
104 } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
106 playpause.setIcon(playIcon);
107 playpause.setToolTipText("Resume");
108 } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
110 playpause.setIcon(pauseIcon);
111 playpause.setToolTipText("Pause");
112 } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
114 playpause.setIcon(playIcon);
115 playpause.setToolTipText("Play");
119 public void mousePressed(MouseEvent e) {
120 if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
122 } else if (((JButton)e.getSource()).getToolTipText() == "Fast forward") {
123 Moosique.forward(96);
127 public void mouseReleased(MouseEvent e) {}