]> ruin.nu Git - moosique.git/commitdiff
Changed window size and TrackView generation. Updated Toolbar listeners, and cleaned...
authorEinar Pehrson <einarp@itstud.chalmers.se>
Sat, 10 May 2003 16:30:35 +0000 (16:30 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Sat, 10 May 2003 16:30:35 +0000 (16:30 +0000)
MooGUI.java
MooToolbar.java
MooTrackView.java
Moosique.java

index f0c108ae7a800831ecc371584081433c34fc29d6..5a545838831f2b5ac4656655a1d813528e6f53c1 100644 (file)
@@ -9,7 +9,7 @@ import java.awt.event.*;
  * @author  Mikael Andreen
  */
  
-public class MooGUI extends JFrame implements WindowListener {
+public class MooGUI extends JFrame {
 
        private Sequence seq;
 
@@ -35,7 +35,6 @@ public class MooGUI extends JFrame implements WindowListener {
 
                // Adds toolbar.
                pane.add(new MooToolbar(), BorderLayout.NORTH);
-               addWindowListener(this);
 
                // Adds tracks.
                trackPanel = new JPanel(true);
@@ -46,13 +45,13 @@ public class MooGUI extends JFrame implements WindowListener {
                statusBar = new JLabel("Welcome to Moosique!", JLabel.CENTER);
                pane.add(statusBar, BorderLayout.SOUTH);
 
-               addWindowListener(this);
+               addWindowListener(new MooGUICloser());
                pack();
-               Dimension bounds = new Dimension(400,300);
-               setSize(bounds.width,bounds.height);
-               setLocation((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (bounds.width / 2), (Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (bounds.height / 2));
+               Dimension bounds = Toolkit.getDefaultToolkit().getScreenSize();
+               setSize(bounds.width,bounds.height - 60);
+               setLocation(0, 0);
                // setResizable(false);
-               // setBackground(Color.white);
+               setBackground(Color.white);
                setVisible(true);
                show();
        }
@@ -77,18 +76,16 @@ public class MooGUI extends JFrame implements WindowListener {
        private void createTrackViews() {
                trackPanel.removeAll();
                Track[] tracks = seq.getTracks();
+               trackPanel.setLayout(new GridLayout(1, tracks.length));
                trackViews = new MooTrackView[tracks.length];
                for (int i = 0; i < tracks.length; i++) {
                        trackViews[i] = new MooTrackView(tracks[i]);
                        trackPanel.add(new MooTrackView(tracks[i]));
                }
+               trackPanel.validate();
        }
 
-       public void windowOpened(WindowEvent e) {}
-       public void windowClosing(WindowEvent e) {Moosique.quit();}
-       public void windowClosed(WindowEvent e) {}
-       public void windowIconified(WindowEvent e) {}
-       public void windowDeiconified(WindowEvent e) {}
-       public void windowActivated(WindowEvent e) {}
-       public void windowDeactivated(WindowEvent e) {}
-}
+       class MooGUICloser extends WindowAdapter {
+               public void windowClosing(WindowEvent e) {Moosique.quit();}
+       }
+}
\ No newline at end of file
index ebb626e9ed06db1569251158e6fa0363f246ffa5..76db3676c996fad875c1529c2580f2c30d3449ca 100644 (file)
@@ -4,121 +4,115 @@ import java.awt.*;
 import javax.sound.midi.*;
 
 /**
- * Moosiques GUI representing a toolbar, with the most frequently used commands.
+ * The application's toolbar, with the most frequently used commands.
  * 
  * @author  Björn Lanneskog
  */
-public class MooToolbar extends JToolBar implements ActionListener     {
+public class MooToolbar extends JToolBar {
 
        private JButton rewind, playpause, stop, fastforward;
        private JLabel measure, beats, ticks, measurevalue, beatsvalue, ticksvalue;
-       private Image pauseimage, playimage;
+       private ImageIcon playIcon, pauseIcon;
+       private MooMouseAdapter mouseAdapter;
        
        /**
-        * Constructs a toolbar
+        * Creates the toolbar.
         */
        
        public MooToolbar()     {
-       
-               rewind = createButton("images/rewind.gif", "rewind");
+               mouseAdapter = new MooMouseAdapter();
+
+               rewind = createButton("images/rewind.gif", "Rewind");
                add(rewind);
 
-               playpause = createButton("images/play.gif", "play/pause");
+               playpause = createButton("images/play.gif", "Play");
                add(playpause);
+               playIcon = new ImageIcon("images/play.gif");
+               pauseIcon = new ImageIcon("images/pause.gif");
                
-               stop = createButton("images/stop.gif", "stop");
+               stop = createButton("images/stop.gif", "Stop");
                add(stop);
                
-               fastforward = createButton("images/forward.gif", "fast forward");
+               fastforward = createButton("images/forward.gif", "Fast forward");
                add(fastforward);
                
-               JPanel panel = new JPanel();
-               panel.setMaximumSize(new Dimension(120,27));
-               panel.setLayout(new GridLayout(2,4));
-               
-               add(panel);
-               
-               panel.add(new JPanel());
-               
-               measure = createProjIndLabel("Mrs", 10);
-               panel.add(measure);
-               
-               beats = createProjIndLabel("Beat", 10);
-               panel.add(beats);
-               
-               ticks = createProjIndLabel("Tick", 10);
-               panel.add(ticks);
-               
-               panel.add(new JPanel());
+               JPanel progIndPanel = new JPanel();
+               progIndPanel.setBorder(BorderFactory.createLineBorder(Color.black));
+               progIndPanel.setMaximumSize(new Dimension(100,22));
+               progIndPanel.setLayout(new GridLayout(2,3));
+               measure = createLabel("Mrs",10);
+               beats = createLabel("Beat",10);
+               ticks = createLabel("Tick",10);
+               measurevalue = createLabel(12);
+               beatsvalue = createLabel("1",12);
+               ticksvalue = createLabel("1",12);
+               progIndPanel.add(measure);
+               progIndPanel.add(beats);
+               progIndPanel.add(ticks);
+               progIndPanel.add(measurevalue);
+               progIndPanel.add(beatsvalue);
+               progIndPanel.add(ticksvalue);
+               add(progIndPanel);
+       }
                
-               measurevalue = createProjIndLabel("1", 12);
-               panel.add(measurevalue);
-               
-               beatsvalue = createProjIndLabel("1",12);
-               panel.add(beatsvalue);
-               
-               ticksvalue = createProjIndLabel("1", 12);
-               panel.add(ticksvalue);
-               
-               playimage = Toolkit.getDefaultToolkit().getImage("images/play.gif");
-               pauseimage = Toolkit.getDefaultToolkit().getImage("images/pause.gif");
-               
-               }
-               
-               /**
-                * creates a JButton for the toolbar
-                * @param imagelocation         the imagelacation of the the image displayed in the button
-                * @param tooltip               the tooltip associated with this button
-                * @return button               the button to be attached to the toolbar
-                */
-               private JButton createButton(String imagelocation, String tooltip) {
-                       JButton button = new JButton (new ImageIcon(imagelocation));
-                       button.setToolTipText(tooltip);
-                       button.addActionListener(this);
-                       return button;
-               }
-               
-               /**
-                * creates JLabels for the progressindikator, attached to the toolbar
-                * @param title         the titel displayed on the label
-                * @param fontsize      the fontzise of the text displayed on the label
-                * @param fontstyle     the fontstyle of the text displayed on the label
-                * @return titelvalue   the label that is a part of the progressindikator
-                */
-               private JLabel createProjIndLabel(String title, int fontsize){
-                       JLabel titelvalue = new JLabel(title,JLabel.CENTER);
-                       titelvalue.setFont(new Font("Times New Roman",
-                       Font.BOLD ,fontsize));
-                       titelvalue.setBorder(BorderFactory.createLineBorder(Color.black));
-                       return titelvalue;
-               }
-               // int pos = Moosique.getSequencer().getTickPosition();
-               // int measures = pos / (4 * Moosique.getSequence.get)
-               // int beats = (pos - measures * 4 * 96) / 96;
-               // int ticks = (pos - measures*4*96 - beats*96);
-               
-                       
-               public void actionPerformed(ActionEvent e) {
+       /**
+        * Creates a button with the specified image and tooltip.
+        * @param imagelocation         the imagelacation of the the image displayed in the button
+        * @param tooltip               the tooltip associated with this button
+        * @return button               the button to be attached to the toolbar
+        */
+       private JButton createButton(String imagelocation, String tooltip) {
+               JButton button = new JButton (new ImageIcon(imagelocation));
+               button.setToolTipText(tooltip);
+               button.addMouseListener(mouseAdapter);
+               return button;
+       }
+       
+       /**
+        * Creates labels with the specified text and font size. 
+        * @param title         the titel displayed on the label
+        * @param fontsize      the fontzise of the text displayed on the label
+        */
+       private JLabel createLabel(String title, int fontSize){
+               JLabel value = new JLabel(title,JLabel.CENTER);
+               value.setFont(new Font("Times New Roman", Font.BOLD, fontSize));
+               return value;
+       }
+       
+       // int pos = Moosique.getSequencer().getTickPosition();
+       // int measures = pos / (4 * Moosique.getSequence.get)
+       // int beats = (pos - measures * 4 * 96) / 96;
+       // int ticks = (pos - measures*4*96 - beats*96);
        
-                      if (((JButton)e.getSource()).getToolTipText() == "rewind") {
-                               //få in rewindmetoden
-                       }       else if (((JButton)e.getSource()).getToolTipText() == "play/pause") {
-                                       ImageIcon playpauseIcon = ((ImageIcon)playpause.getIcon());
-                                       if (Moosique.getSequencer().isRunning()) {
-                                               Moosique.pause();
-                                               playpauseIcon.setImage(playimage);
-                                       } else {
-                                               Moosique.play();
-                                               playpauseIcon.setImage(pauseimage);
-                                       }
-                       
-                       }       else if (((JButton)e.getSource()).getToolTipText() == "stop") {
-                                       Moosique.stop();
-                                       
-                       }       else if (((JButton)e.getSource()).getToolTipText() == "fastforward") {
-                                       // få in fastforwardmetoden
-                       
+       class MooMouseAdapter extends MouseAdapter {
+               public void mouseClicked(MouseEvent e) {
+                       if (((JButton)e.getSource()).getToolTipText() == "Play") {
+                                       Moosique.play();
+                                       playpause.setIcon(pauseIcon);
+                                       playpause.setToolTipText("Pause");
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Pause") {
+                                       Moosique.pause();
+                                       playpause.setIcon(playIcon);
+                                       playpause.setToolTipText("Resume");
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Resume") {
+                                       Moosique.resume();
+                                       playpause.setIcon(pauseIcon);
+                                       playpause.setToolTipText("Pause");
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Stop") {
+                               Moosique.stop();
+                               playpause.setIcon(playIcon);
+                               playpause.setToolTipText("Play");
                        }
                }
-               
-}
+
+               public void mousePressed(MouseEvent e) {
+                       if (((JButton)e.getSource()).getToolTipText() == "Rewind") {
+                               Moosique.rewind(96);
+                       } else if (((JButton)e.getSource()).getToolTipText() == "Fast forward") {
+                               Moosique.forward(96);
+                       }
+               }
+
+               public void mouseReleased(MouseEvent e) {}
+       }
+}
\ No newline at end of file
index bcbfc09e1e2d8e5464c745d40cff1a6327af62a1..780e3c017521c0f3015e2fa91c819ad237502e8f 100644 (file)
@@ -17,61 +17,47 @@ public class MooTrackView extends JPanel implements ActionListener {
        private Rectangle box;
        private JPopupMenu popup;
        private JMenuItem menuItem;
-       private String newline = "\n";
+       
+       private static final int NOTEVIEW_HEIGHT = 200;
        
        public MooTrackView (Track track) {
                setLayout(new BorderLayout());
                this.setBorder(BorderFactory.createLineBorder(Color.black));
-               add(trackTitle(), BorderLayout.NORTH);
-               add(noteView(), BorderLayout.CENTER);
-       }
-       
-       private JPanel trackTitle () {
+
                title = new MooTrackTitle();
-               title.setPreferredSize(new Dimension(PANEL_WIDTH, TITLE_HEIGHT));
                title.setBorder(BorderFactory.createLineBorder(Color.black));
-               return title;
-       }
+               add(title, BorderLayout.NORTH);
 
-       private JPanel noteView () {
                notes = new NoteArea(); 
                notes.setBackground(Color.white);
                notes.setBorder(BorderFactory.createLineBorder(Color.black));
-               
+
                popup = new JPopupMenu();
-        menuItem = new JMenuItem("Add...");
-        menuItem.addActionListener(this);
-        popup.add(menuItem);
-        menuItem = new JMenuItem("Preferences...");
-        menuItem.addActionListener(this);
-        popup.add(menuItem);
+               menuItem = new JMenuItem("Add...");
+               menuItem.addActionListener(this);
+               popup.add(menuItem);
+               menuItem = new JMenuItem("Preferences...");
+               menuItem.addActionListener(this);
+               popup.add(menuItem);
 
-        MouseListener popupListener = new PopupListener();
-        notes.addMouseListener(popupListener);
-               
-               return notes;           
+               notes.addMouseListener(new PopupListener());
+               add(notes, BorderLayout.CENTER);
        }
        
-       public void actionPerformed(ActionEvent e) {
-        JMenuItem source = (JMenuItem)(e.getSource());
-        String s = "Action event detected."
-                   + newline
-                   + "    Event source: " + source.getText();
-     }
+       public void actionPerformed(ActionEvent e) {}
     
        class NoteArea extends JPanel {
                public void RectanglePanel() {
                        setPreferredSize(new Dimension(20, 20));
-                       
                }
                
                public void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        Graphics2D g2 = (Graphics2D)g;
-                       for (int c=0;c<1000;c=c+20) {
+                       for (int c = 0; c < 1000; c += 20) {
                                int r=0;
-                               for (r=0;r<200;r=r+20) {
-                                       box = new Rectangle(r,c,20,20);
+                               for (r = 0; r < 200; r += 20) {
+                                       box = new Rectangle(r, c, 20, 20);
                                        g2.setColor(Color.gray);
                                        g2.draw(box);
                                }
@@ -80,23 +66,18 @@ public class MooTrackView extends JPanel implements ActionListener {
        }
        
        class PopupListener extends MouseAdapter {
-        public void mousePressed(MouseEvent e) {
-            maybeShowPopup(e);
-        }
-
-        public void mouseReleased(MouseEvent e) {
-            maybeShowPopup(e);
-        }
-
-        private void maybeShowPopup(MouseEvent e) {
-            if (e.isPopupTrigger()) {
-                popup.show(e.getComponent(),
-                           e.getX(), e.getY());
-            }
-        }
-    }
+               public void mousePressed(MouseEvent e) {
+                       maybeShowPopup(e);
+               }
        
-       private static final int PANEL_WIDTH = 60;
-       private static final int TITLE_HEIGHT = 55;
-       private static final int NOTEVIEW_HEIGHT = 200;
-}
+               public void mouseReleased(MouseEvent e) {
+                       maybeShowPopup(e);
+               }
+       
+               private void maybeShowPopup(MouseEvent e) {
+                       if (e.isPopupTrigger()) {
+                               popup.show(e.getComponent(), e.getX(), e.getY());
+                       }
+               }
+       }
+}
\ No newline at end of file
index 669d2361bdfd8b893d27ea0d4f811a267625ebf2..b7c92c30f9af86ad1c7efeadbe8a390853ec7b72 100644 (file)
@@ -181,7 +181,7 @@ public class Moosique {
         * @param measures      the number of measures to rewind
         */
        public static void rewind(long ticks) {
-               position -= ticks;
+               setPosition(position - ticks);
        }
 
        /** 
@@ -189,7 +189,7 @@ public class Moosique {
         * @param measures      the number of measures to fast forward
         */
        public static void forward(long ticks) {
-               position += ticks;
+               setPosition(position + ticks);
        }
 
        /**