*/
public MooToolbar() {
+ setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
// setAlignmentX(LEFT_ALIGNMENT);
setFloatable(false);
mouseAdapter = new MAdapter();
* Resets the progress indicator.
*/
public void resetProgInd() {
- measuresValue.setText("1");
- beatsValue.setText("1");
- ticksValue.setText("1");
- playpause.setIcon(playIcon);
- playpause.setToolTipText("Play");
- ticksPerBeat = Moosique.getSequence().getResolution();
+ measuresValue.setText("1");
+ beatsValue.setText("1");
+ ticksValue.setText("1");
+ updatePlayButton("Play", playIcon);
+ ticksPerBeat = Moosique.getSequence().getResolution();
}
- /*
- * Creates a button with the specified image and tooltip.
+ /**
+ * Creates a button with the specified image and action command / tooltip.
*/
- private JButton createButton(String imagelocation, String tooltip) {
+ private JButton createButton(String imagelocation, String command) {
JButton button = new JButton (new ImageIcon(imagelocation));
- button.setToolTipText(tooltip);
+ button.setToolTipText(command);
+ button.setActionCommand(command);
button.addMouseListener(mouseAdapter);
return button;
}
- /*
+ /**
* Creates labels with the specified text and font size.
*/
private JLabel createLabel(String title, int fontSize){
return label;
}
- /*
+ /**
* Formats the given label for the progress indicator.
*/
private JLabel formatProgInd(JLabel label){
return label;
}
+ /**
+ * Updates the play button with the given command and icon.
+ */
+ private void updatePlayButton(String command, Icon icon) {
+ playpause.setIcon(icon);
+ playpause.setActionCommand(command);
+ playpause.setToolTipText(command);
+ }
+
class MAdapter extends MouseAdapter {
public void mouseClicked(MouseEvent e) {
if (e.getSource() instanceof JButton) {
- String toolTip = ((JButton)e.getSource()).getToolTipText();
- if (toolTip == "Play") {
- playpause.setIcon(pauseIcon);
- playpause.setToolTipText("Pause");
+ String command = ((JButton)e.getSource()).getActionCommand();
+ if (command == "Play") {
+ updatePlayButton("Pause", pauseIcon);
Moosique.play();
- } else if (toolTip == "Pause") {
- playpause.setIcon(playIcon);
- playpause.setToolTipText("Resume");
+ } else if (command == "Pause") {
+ updatePlayButton("Resume", playIcon);
Moosique.pause();
- } else if (toolTip == "Resume") {
- playpause.setIcon(pauseIcon);
- playpause.setToolTipText("Pause");
+ } else if (command == "Resume") {
+ updatePlayButton("Pause", pauseIcon);
Moosique.resume();
- } else if (toolTip == "Stop") {
+ } else if (command == "Rewind") {
+ System.out.println("Rewound!");
+ // Different implementation, perhaps?
+ updatePlayButton("Play", playIcon);
+ Moosique.setEditPosition(0);
+ Moosique.stop();
+ } else if (command == "Fast forward") {
+ } else if (command == "Stop") {
+ updatePlayButton("Play", playIcon);
Moosique.stop();
}
} else if (e.getSource() instanceof JLabel) {
}
}
- public void mousePressed(MouseEvent e) {
+/* public void mousePressed(MouseEvent e) {
if (e.getSource() instanceof JButton) {
if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
Moosique.rewind(beatsPerMeasure * ticksPerBeat);
}
public void mouseReleased(MouseEvent e) {}
- }
+*/ }
}