2 import java.awt.event.*;
4 import javax.sound.midi.*;
7 * Moosiques GUI representing a toolbar, with the most frequently used commands.
9 * @author Björn Lanneskog
11 public class MooToolbar extends JToolBar implements ActionListener {
13 private JButton rewind, playpause, stop, fastforward;
14 private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
15 private Image pauseimage, playimage;
18 * Constructs a toolbar
23 rewind = createButton("images/rewind.gif", "rewind");
26 playpause = createButton("images/play.gif", "play/pause");
29 stop = createButton("images/stop.gif", "stop");
32 fastforward = createButton("images/forward.gif", "fast forward");
35 JPanel panel = new JPanel();
36 panel.setMaximumSize(new Dimension(100,22));
37 panel.setLayout(new GridLayout(2,4));
40 panel.add(new JPanel());
42 measure = createProjIndLabel("Mrs",10);
45 beats = createProjIndLabel("Beat",10);
48 ticks = createProjIndLabel("Tick",10);
51 panel.add(new JPanel());
53 measurevalue = createProjIndLabel("1",10);
54 panel.add(measurevalue);
56 beatsvalue = createProjIndLabel("1",10);
57 panel.add(beatsvalue);
59 ticksvalue = createProjIndLabel("1",10);
60 panel.add(ticksvalue);
62 playimage = Toolkit.getDefaultToolkit().getImage("images/play.gif");
63 pauseimage = Toolkit.getDefaultToolkit().getImage("images/pause.gif");
68 * creates a JButton for the toolbar
69 * @param imagelocation the imagelacation of the the image displayed in the button
70 * @param tooltip the tooltip associated with this button
71 * @return button the button to be attached to the toolbar
73 private JButton createButton(String imagelocation, String tooltip) {
74 JButton button = new JButton (new ImageIcon(imagelocation));
75 button.setToolTipText(tooltip);
76 button.addActionListener(this);
81 * creates JLabels for the progressindikator, attached to the toolbar
82 * @param title the titel displayed on the label
83 * @param fontsize the fontzise of the text displayed on the label
84 * @param titelvalue the label that is a part of the progressindikator
86 private JLabel createProjIndLabel(String title, int fontsize){
87 JLabel titelvalue = new JLabel(title,JLabel.CENTER);
88 titelvalue.setFont(new Font("Times New Roman",
89 Font.PLAIN ,fontsize));
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);
99 public void actionPerformed(ActionEvent e) {
101 if (((JButton)e.getSource()).getToolTipText() == "rewind") {
102 //få in rewindmetoden
103 } else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
104 ImageIcon playpauseIcon = ((ImageIcon)playpause.getIcon());
105 if (Moosique.getSequencer().isRunning()) {
107 playpauseIcon.setImage(playimage);
110 playpauseIcon.setImage(pauseimage);
113 } else if (((JButton)e.getSource()).getToolTipText() == "stop") {
116 } else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
117 // få in fastforwardmetoden