]> ruin.nu Git - moosique.git/blobdiff - MooTrackView.java
*** empty log message ***
[moosique.git] / MooTrackView.java
index bf3590aedc59e2f25663b367beb3f85aef0763cd..8133cda05f372feff297b0718db8b6e0853abef2 100644 (file)
@@ -22,9 +22,11 @@ public class MooTrackView extends JPanel {
        private JMenuItem popupAdd, popupPaste;
        private JMenuItem selPopupCopy, selPopupCut, selPopupRemove, selPopupTranspUpOct, selPopupTranspDownOct;
 
-       private ArrayList coords, selection, copyBuffer; 
+       private ArrayList coords, copyBuffer; 
+       private TreeSet selection;
        private Insets insets;
        private int ticksPerSixteenth, popupY = 0;
+       private boolean leftMouseButtonPressed = false;
        protected static int viewLength = 0;
        protected static int extraHeight = 0;
        public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
@@ -42,7 +44,7 @@ public class MooTrackView extends JPanel {
                // Creates instance variables
                insets = getInsets();
                coords = new ArrayList(track.size() / 2);
-               selection = new ArrayList();
+               selection = new TreeSet();
                copyBuffer = new ArrayList();
 
                // Creates temporary variables
@@ -133,7 +135,7 @@ public class MooTrackView extends JPanel {
 
                // Calculates coordinates.
                x = insets.left;
-               y = insets.top + (int)(mn.getTick() / ticksPerSixteenth) * NOTE_HEIGHT;
+               y = insets.top + Math.round(mn.getTick() / ticksPerSixteenth) * NOTE_HEIGHT;
                height = (mn.getDuration() / ticksPerSixteenth) * NOTE_HEIGHT;
                if (height == 0) height = NOTE_HEIGHT;
                r = new Rectangle(x, y, NOTE_WIDTH, height);
@@ -232,7 +234,7 @@ public class MooTrackView extends JPanel {
         * @param the note to deselect
         */
        public void deselectNote(MooNoteElement elem) {
-               selection.remove(selection.indexOf(elem));
+               selection.remove(elem);
        }
 
        /**
@@ -267,7 +269,7 @@ public class MooTrackView extends JPanel {
                while(it.hasNext()) {
                        copyBuffer.add(((MooNoteElement)it.next()).getNote().clone());
                }
-               Collections.sort(copyBuffer, new Moosique.NoteComparator());
+               Collections.sort(copyBuffer);
        }
 
        /**
@@ -317,6 +319,27 @@ public class MooTrackView extends JPanel {
                }
        }
 
+       /**
+        * Moves the current selection the given number of ticks.
+        * @param ticks         the number of ticks to move the selection.
+        */
+       public void moveSelectedNotes(int ticks) {
+               Iterator it = selection.iterator();
+               while(it.hasNext()) {
+                       MooNoteElement elem = (MooNoteElement)it.next();
+                       elem.getNote().setTick(elem.getNote().getTick() + ticks);
+                       layoutElement(elem, true);
+               }
+       }
+
+       /**
+        * Moves the current selection, depending on the given delta y.
+        * @param y     the number of pixels the selection is moved.
+        */
+       public void maybeMoveSelectedNotes(int y) {
+               moveSelectedNotes(ticksPerSixteenth * (y / NOTE_HEIGHT));
+       }
+
        /**
         * Shows a popup-menu with options for the current selection of note elements.
         * @param c     the component over which to display the menu
@@ -343,6 +366,14 @@ public class MooTrackView extends JPanel {
                }
        }
        
+       /**
+        * Returns whether the left mouse button is currently pressed or not.
+        * @return true if the left mosue button is currently pressed
+        */
+       public boolean isLeftMouseButtonPressed() {
+               return leftMouseButtonPressed;
+       }
+
        /**
         * The adapter used to listen on mouse actions
         */
@@ -362,20 +393,15 @@ public class MooTrackView extends JPanel {
                }
        
                public void mousePressed(MouseEvent e) {
+                       if (SwingUtilities.isLeftMouseButton(e)) leftMouseButtonPressed = true;
                        maybeShowPopup(e);
                }
 
                public void mouseReleased(MouseEvent e) {
+                       if (SwingUtilities.isLeftMouseButton(e)) leftMouseButtonPressed = false;
                        maybeShowPopup(e);
                }
 
-               /**
-                * Selects the notes within the area that was selected.
-                */
-               public void mouseDragged(MouseEvent e) {
-                       
-               }
-
                /**
                 * Shows the menu if an OS-specific popup-trigger was activated.
                 */
@@ -390,7 +416,7 @@ public class MooTrackView extends JPanel {
                 * Grabs the focus when the mouse has entered.
                 */
                public void mouseEntered(MouseEvent e) {
-                       // Moosique.setActiveChannel(track.getChannel());
+                       Moosique.setActiveChannel(title.getChannel());
                        grabFocus();
                }
        }