]> ruin.nu Git - moosique.git/commitdiff
*** empty log message ***
authorEinar Pehrson <einarp@itstud.chalmers.se>
Fri, 16 May 2003 13:34:36 +0000 (13:34 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Fri, 16 May 2003 13:34:36 +0000 (13:34 +0000)
MooTrackView.java

index 22c7eccce7edfe962336bd8caa989ea4ef24eef0..b06355430b125be17116ef370a5c26a761f55563 100644 (file)
@@ -17,7 +17,7 @@ public class MooTrackView extends JPanel {
        private Rectangle box;
 
        private JPopupMenu popup;
        private Rectangle box;
 
        private JPopupMenu popup;
-       private JMenuItem menuItem;
+       private JMenuItem popupAdd;
        private ArrayList rects;
        protected static int viewLength = 0;
        protected static int extraHeight = 0;
        private ArrayList rects;
        protected static int viewLength = 0;
        protected static int extraHeight = 0;
@@ -56,16 +56,17 @@ public class MooTrackView extends JPanel {
 
                // Creates pop-up menu.
                popup = new JPopupMenu();
 
                // Creates pop-up menu.
                popup = new JPopupMenu();
-               menuItem = new JMenuItem("Add note...");
-               // menuItem.addActionListener();
-               popup.add(menuItem);
+               PopupListener pList = new PopupListener();
+               popupAdd = new JMenuItem("Add note...");
+               popupAdd.addActionListener(pList);
+               popup.add(popupAdd);
 
                // Adds listeners for popup menu and keyboard synthesizer.
                addMouseListener(new MAdapter());
                addKeyListener(new MooKeyboard());
        }
 
 
                // Adds listeners for popup menu and keyboard synthesizer.
                addMouseListener(new MAdapter());
                addKeyListener(new MooKeyboard());
        }
 
-       public void layoutElement(MooNoteElement elem, boolean old){
+       public void layoutElementMooNoteElement elem, boolean old){
                // If the element is currently in the view, removes its coordinates from the list.
                Rectangle r = new Rectangle();
                if (old){
                // If the element is currently in the view, removes its coordinates from the list.
                Rectangle r = new Rectangle();
                if (old){
@@ -123,8 +124,17 @@ public class MooTrackView extends JPanel {
                return false;
        }
        
                return false;
        }
        
-       public void remove(MooNoteElement elem) {
-               remove((Component)elem);
+       public void addNote(MooNote mn) {
+               mn.addTo(track);
+               MooNoteElement elem = new MooNoteElement(this, mn);
+               add(elem);
+               layoutElement(elem, false);
+               setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
+       }
+
+       public void removeNote(MooNoteElement elem, MooNote mn) {
+               mn.removeFrom(track);
+               remove(elem);
                elem.getNote().removeFrom(track);
                validate();
                repaint();
                elem.getNote().removeFrom(track);
                validate();
                repaint();
@@ -154,4 +164,13 @@ public class MooTrackView extends JPanel {
                        grabFocus();
                }
        }
                        grabFocus();
                }
        }
-}
+
+       class PopupListener implements ActionListener {
+               public void actionPerformed(ActionEvent e) {
+                       Object source = e.getSource();
+                       if  (source == popupAdd) {
+                               addNote(new MooNote());
+                               // int channel, int pitch, int velocity, long timestamp, int duration
+               }
+       }
+}
\ No newline at end of file