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;
19 * Creates the toolbar.
24 mouseAdapter = new MooMouseAdapter();
26 // Creates playback buttons
27 rewind = createButton("images/rewind.gif", "Rewind");
29 playpause = createButton("images/play.gif", "Play");
31 playIcon = new ImageIcon("images/play.gif");
32 pauseIcon = new ImageIcon("images/pause.gif");
33 stop = createButton("images/stop.gif", "Stop");
35 fastforward = createButton("images/forward.gif", "Fast forward");
38 // Creates progress indicator
39 JPanel progIndPanel = new JPanel();
40 progIndPanel.setMaximumSize(new Dimension(120,27));
41 progIndPanel.setLayout(new GridLayout(2,4));
42 measure = createLabel("Mrs",10);
43 beats = createLabel("Beat",10);
44 ticks = createLabel("Tick",10);
45 measurevalue = createLabel("1", 16);
46 beatsvalue = createLabel("1",16);
47 ticksvalue = createLabel("1",16);
48 progIndPanel.add(new JPanel());
49 progIndPanel.add(measure);
50 progIndPanel.add(beats);
51 progIndPanel.add(ticks);
52 progIndPanel.add(new JPanel());
53 progIndPanel.add(measurevalue);
54 progIndPanel.add(beatsvalue);
55 progIndPanel.add(ticksvalue);
60 * Creates a button with the specified image and tooltip.
61 * @param imagelocation the imagelacation of the the image displayed in the button
62 * @param tooltip the tooltip associated with this button
63 * @return button the button to be attached to the toolbar
65 private JButton createButton(String imagelocation, String tooltip) {
66 JButton button = new JButton (new ImageIcon(imagelocation));
67 button.setToolTipText(tooltip);
68 button.addMouseListener(mouseAdapter);
73 * Creates labels with the specified text and font size.
74 * @param title the titel displayed on the label
75 * @param fontsize the fontzise of the text displayed on the label
77 private JLabel createLabel(String title, int fontSize){
78 JLabel value = new JLabel(title,JLabel.CENTER);
79 value.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
80 value.setBorder(BorderFactory.createLineBorder(Color.black));
84 // int pos = Moosique.getSequencer().getTickPosition();
85 // int measures = pos / (4 * Moosique.getSequence.get)
86 // int beats = (pos - measures * 4 * 96) / 96;
87 // int ticks = (pos - measures*4*96 - beats*96);
89 class MooMouseAdapter extends MouseAdapter {
90 public void mouseClicked(MouseEvent e) {
91 if (((JButton)e.getSource()).getToolTipText() == "Play") {
93 playpause.setIcon(pauseIcon);
94 playpause.setToolTipText("Pause");
95 } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
97 playpause.setIcon(playIcon);
98 playpause.setToolTipText("Resume");
99 } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
101 playpause.setIcon(pauseIcon);
102 playpause.setToolTipText("Pause");
103 } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
105 playpause.setIcon(playIcon);
106 playpause.setToolTipText("Play");
110 public void mousePressed(MouseEvent e) {
111 if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
113 } else if (((JButton)e.getSource()).getToolTipText() == "Fast forward") {
114 Moosique.forward(96);
118 public void mouseReleased(MouseEvent e) {}