X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=blobdiff_plain;f=MooNoteElement.java;h=60808898339361e3b70a53b21b6ac03c325713d7;hp=9ed1ab9b2004f4a4023cd1467b7343c5ea9e8fd8;hb=1f2ba8a0848ee0c5f0ea94f7bc40ea502c0dff74;hpb=a8dda23889d7c48a8b3313e2a141ed378bf8ff1c diff --git a/MooNoteElement.java b/MooNoteElement.java index 9ed1ab9..6080889 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -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); + + } } /**