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(120,27));
37 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", 12);
55 panel.add(measurevalue);
57 beatsvalue = createProjIndLabel("1",12);
58 panel.add(beatsvalue);
60 ticksvalue = createProjIndLabel("1", 12);
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 fontstyle the fontstyle of the text displayed on the label
86 * @return titelvalue the label that is a part of the progressindikator
88 private JLabel createProjIndLabel(String title, int fontsize){
89 JLabel titelvalue = new JLabel(title,JLabel.CENTER);
90 titelvalue.setFont(new Font("Times New Roman",
91 Font.BOLD ,fontsize));
92 titelvalue.setBorder(BorderFactory.createLineBorder(Color.black));
95 // int pos = Moosique.getSequencer().getTickPosition();
96 // int measures = pos / (4 * Moosique.getSequence.get)
97 // int beats = (pos - measures * 4 * 96) / 96;
98 // int ticks = (pos - measures*4*96 - beats*96);
101 public void actionPerformed(ActionEvent e) {
103 if (((JButton)e.getSource()).getToolTipText() == "rewind") {
104 //få in rewindmetoden
105 } else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
106 ImageIcon playpauseIcon = ((ImageIcon)playpause.getIcon());
107 if (Moosique.getSequencer().isRunning()) {
109 playpauseIcon.setImage(playimage);
112 playpauseIcon.setImage(pauseimage);
115 } else if (((JButton)e.getSource()).getToolTipText() == "stop") {
118 } else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
119 // få in fastforwardmetoden