+ /**
+ * Selects the given note
+ * @param the note to select
+ */
+ public void selectNote(MooNoteElement elem) {
+ selection.add(elem);
+ }
+
+ /**
+ * Deselects the given note
+ * @param the note to deselect
+ */
+ public void deselectNote(MooNoteElement elem) {
+ selection.remove(selection.indexOf(elem));
+ }
+
+ /**
+ * Deselects all notes.
+ */
+ public void deselectAllNotes() {
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ ((MooNoteElement)it.next()).deselect();
+ }
+ selection.clear();
+ }
+
+ /**
+ * Determines if the given MooNoteElement is the only one in the track view that is selected.
+ * @return if the given element is the only selected one
+ */
+ public boolean isTheOnlySelected(MooNoteElement elem) {
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ if (!it.next().equals(elem)) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Copies the current selection.
+ */
+ public void copySelectedNotes() {
+ copyBuffer = new ArrayList(selection.size());
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ copyBuffer.add(((MooNoteElement)it.next()).getNote().clone());
+ }
+ Collections.sort(copyBuffer, new Moosique.NoteComparator());
+ }
+
+ /**
+ * Cuts the current selection.
+ */
+ public void cutSelectedNotes() {
+ copySelectedNotes();
+ removeSelectedNotes();
+ }
+
+ /**
+ * Pastes the current copy buffer at the given timestamp.
+ */
+ public void pasteCopiedNotes() {
+ int row = (popupY - insets.top) / NOTE_HEIGHT;
+ long timestamp = (long)(ticksPerSixteenth * row);
+ if (copyBuffer.size() > 0) {
+ long startTime = ((MooNote)copyBuffer.get(0)).getTick();
+ Iterator it = copyBuffer.iterator();
+ while(it.hasNext()) {
+ MooNote mn = (MooNote)((MooNote)it.next()).clone();
+ mn.setTick(mn.getTick() - startTime + timestamp);
+ addNote(mn);
+ }
+ }
+ }
+
+ /**
+ * Removes the current selection.
+ */
+ public void removeSelectedNotes() {
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ removeNote((MooNoteElement)it.next());
+ }
+ selection.clear();
+ }
+
+ /**
+ * Transposes all selected notes the given number of halftones.
+ */
+ private void transposeSelectedNotes(int halftones) {
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ MooNoteElement elem = (MooNoteElement)it.next();
+ elem.transpose(halftones);
+ }
+ }
+
+ /**
+ * Moves the current selection, if the mouse was pressed on a note element
+ * and then released in another row.
+ * @param srcY the y-coordinate of the point in which the mouse button was pressed
+ * @param destY the y-coordinate of the point in which the mouse button was released
+ */
+ public void maybeMoveSelectedNotes(int srcY, int destY) {
+ int srcRow = (srcY - insets.top) / NOTE_HEIGHT;
+ int destRow = (destY - insets.top) / NOTE_HEIGHT;
+ long timeDiff = (long)(ticksPerSixteenth * (destRow - srcRow));
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ MooNoteElement elem = (MooNoteElement)it.next();
+ elem.getNote().setTick(elem.getNote().getTick() + timeDiff);
+ layoutElement(elem, true);
+ }
+ }
+
+ /**
+ * Shows a popup-menu with options for the current selection of note elements.
+ * @param c the component over which to display the menu
+ * @param x the x-coordinate in which to display the menu
+ * @param y the y-coordinate in which to display the menu
+ */
+ public void showSelectionPopup(Component c, int x, int y) {
+ selPopup.show(c, x, y);
+ }
+
+ /**
+ * Draws the grid that is on the background.
+ * @param g The Graphics object used to draw the grid.
+ */