2 import java.awt.event.*;
4 import javax.sound.midi.*;
5 import javax.swing.Icon;
8 * Moosiques GUI representing a toolbar, with the most frequently used commands.
10 * @author Björn Lanneskog
12 public class MooToolbar extends JToolBar implements ActionListener {
14 private JButton rewind, playpause, stop, fastforward;
15 private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
16 private Image pauseimage, playimage;
19 * Constructs a toolbar
24 rewind = createButton("images/rewind.gif", "rewind");
27 playpause = createButton("images/play.gif", "play/pause");
30 stop = createButton("images/stop.gif", "stop");
33 fastforward = createButton("images/forward.gif", "fast forward");
36 JPanel panel = new JPanel();
37 panel.setMaximumSize(new Dimension(100,22));
38 panel.setLayout(new GridLayout(2,4));
41 panel.add(new JPanel());
43 measure = createProjIndLabel("Mrs",10);
46 beats = createProjIndLabel("Beat",10);
49 ticks = createProjIndLabel("Tick",10);
52 panel.add(new JPanel());
54 measurevalue = createProjIndLabel("1",10);
55 panel.add(measurevalue);
57 beatsvalue = createProjIndLabel("1",10);
58 panel.add(beatsvalue);
60 ticksvalue = createProjIndLabel("1",10);
61 panel.add(ticksvalue);
63 playimage = Toolkit.getDefaultToolkit().getImage("images/play.gif");
64 pauseimage = Toolkit.getDefaultToolkit().getImage("images/pause.gif");
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
74 private JButton createButton(String imagelocation, String tooltip) {
75 JButton button = new JButton (new ImageIcon(imagelocation));
76 button.setToolTipText(tooltip);
77 button.addActionListener(this);
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 titelvalue the label that is a part of the progressindikator
87 private JLabel createProjIndLabel(String title, int fontsize){
88 JLabel titelvalue = new JLabel(title,JLabel.CENTER);
89 titelvalue.setFont(new Font("Times New Roman",
90 Font.PLAIN ,fontsize));
94 // int pos = Moosique.getSequencer().getTickPosition();
95 // int measures = pos / (4 * Moosique.getSequence.get)
96 // int beats = (pos - measures * 4 * 96) / 96;
97 // int ticks = (pos - measures*4*96 - beats*96);
100 public void actionPerformed(ActionEvent e) {
102 if (((JButton)e.getSource()).getToolTipText() == "rewind") {
103 //få in rewindmetoden
104 } else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
105 if (Moosique.getSequence().isRunning()) {
107 playpause.getIcon().setImage(playimage);
110 playpause.getIcon().setImage(pauseimage);
113 } else if (((JButton)e.getSource()).getToolTipText() == "stop") {
116 } else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
117 // få in fastforwardmetoden