]> ruin.nu Git - moosique.git/blobdiff - MooNoteElement.java
*** empty log message ***
[moosique.git] / MooNoteElement.java
index 9ed1ab9b2004f4a4023cd1467b7343c5ea9e8fd8..60808898339361e3b70a53b21b6ac03c325713d7 100644 (file)
@@ -9,7 +9,7 @@ import java.awt.event.*;
  * @version 1
  */
  
-public class MooNoteElement extends JPanel {
+public class MooNoteElement extends JPanel implements Comparable{
 
        private MooTrackView mtv;
        private MooNote note;
@@ -65,6 +65,14 @@ public class MooNoteElement extends JPanel {
                return note;
        }
 
+       /** 
+        * Compares the note of this element to that of another note.
+        * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object
+        */
+       public int compareTo(Object o) {
+               return note.compareTo(((MooNoteElement)o).getNote());
+       }
+
        /** 
         * Selects the current NoteElement.
         */
@@ -227,7 +235,12 @@ public class MooNoteElement extends JPanel {
                }
 
                public void mouseReleased(MouseEvent e) {
-                       if (!maybeShowPopup(e) && !mouseIn) mtv.maybeMoveSelectedNotes(getY(), getY() + e.getY());
+                       if (!maybeShowPopup(e) && !mouseIn) {
+                               int y = e.getY();
+                               if (y < 0) mtv.maybeMoveSelectedNotes((int)Math.floor((double)y / MooTrackView.NOTE_HEIGHT) * MooTrackView.NOTE_HEIGHT);
+                               if (y > getHeight()) mtv.maybeMoveSelectedNotes((int)Math.ceil(((double)y - getHeight()) / MooTrackView.NOTE_HEIGHT) * MooTrackView.NOTE_HEIGHT);
+                               
+                       }
                }
 
                /**