+ }
+
+ /**
+ * Resets the progress indicator.
+ */
+ public void resetProgInd() {
+ measuresValue.setText("1");
+ beatsValue.setText("1");
+ ticksValue.setText("1");
+ updatePlayButton("Play", playIcon);
+ ticksPerBeat = Moosique.getSequence().getResolution();
+ }
+
+ /**
+ * Creates a button with the specified image and action command / tooltip.
+ */
+ private JButton createButton(String imagelocation, String command) {
+ JButton button = new JButton (new ImageIcon(imagelocation));
+ 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){
+ JLabel label = new JLabel(title,JLabel.CENTER);
+ label.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
+ return label;
+ }
+
+ /**
+ * Formats the given label for the progress indicator.
+ */
+ private JLabel formatProgInd(JLabel label){
+ label.addMouseListener(mouseAdapter);
+ label.setBorder(BorderFactory.createLineBorder(Color.black));
+ label.setBackground(Color.white);
+ 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 command = ((JButton)e.getSource()).getActionCommand();
+ if (command == "Play") {
+ updatePlayButton("Pause", pauseIcon);
+ Moosique.play();
+ } else if (command == "Pause") {
+ updatePlayButton("Resume", playIcon);
+ Moosique.pause();
+ } else if (command == "Resume") {
+ updatePlayButton("Pause", pauseIcon);
+ Moosique.resume();
+ } else if (command == "Stop") {
+ updatePlayButton("Play", playIcon);
+ Moosique.stop();
+ } else if (command == "Record") {
+ MooDialog recordDialog = new MooDialog(MooDialog.RECORD);
+ } else if (command == "Rewind") {
+ updatePlayButton("Play", playIcon);
+ Moosique.setEditPosition(0);
+ Moosique.stop();
+ } else if (command == "Fast forward") {
+
+ }
+ } else if (e.getSource() instanceof JLabel) {
+ long position = Moosique.getEditPosition();
+ if (e.getSource().equals(measuresValue)) {
+ if (SwingUtilities.isRightMouseButton(e)) {
+ position += beatsPerMeasure * ticksPerBeat;
+ } else if (SwingUtilities.isLeftMouseButton(e) && Integer.parseInt(measuresValue.getText()) > 1) {
+ position -= beatsPerMeasure * ticksPerBeat;
+ }
+ } else if (e.getSource().equals(beatsValue)) {
+ if (SwingUtilities.isRightMouseButton(e)) {
+ position += ticksPerBeat;
+ } else if (SwingUtilities.isLeftMouseButton(e) && Integer.parseInt(beatsValue.getText()) > 1) {
+ position -= ticksPerBeat;
+ }
+ } else if (e.getSource().equals(ticksValue)) {
+ if (SwingUtilities.isRightMouseButton(e)) {
+ position += 1;
+ } else if (SwingUtilities.isLeftMouseButton(e) && Integer.parseInt(ticksValue.getText()) > 1) {
+ position -= 1;
+ }
+ }
+ Moosique.setEditPosition(position);
+ Moosique.getGUI().update(position);
+ }