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.
23 mouseAdapter = new MooMouseAdapter();
25 rewind = createButton("images/rewind.gif", "Rewind");
28 playpause = createButton("images/play.gif", "Play");
30 playIcon = new ImageIcon("images/play.gif");
31 pauseIcon = new ImageIcon("images/pause.gif");
33 stop = createButton("images/stop.gif", "Stop");
36 fastforward = createButton("images/forward.gif", "Fast forward");
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("1", 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);
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
64 private JButton createButton(String imagelocation, String tooltip) {
65 JButton button = new JButton (new ImageIcon(imagelocation));
66 button.setToolTipText(tooltip);
67 button.addMouseListener(mouseAdapter);
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
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));
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);
87 class MooMouseAdapter extends MouseAdapter {
88 public void mouseClicked(MouseEvent e) {
89 if (((JButton)e.getSource()).getToolTipText() == "Play") {
91 playpause.setIcon(pauseIcon);
92 playpause.setToolTipText("Pause");
93 } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
95 playpause.setIcon(playIcon);
96 playpause.setToolTipText("Resume");
97 } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
99 playpause.setIcon(pauseIcon);
100 playpause.setToolTipText("Pause");
101 } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
103 playpause.setIcon(playIcon);
104 playpause.setToolTipText("Play");
108 public void mousePressed(MouseEvent e) {
109 if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
111 } else if (((JButton)e.getSource()).getToolTipText() == "Fast forward") {
112 Moosique.forward(96);
116 public void mouseReleased(MouseEvent e) {}