+ /**
+ * Moves the current selection the given number of ticks.
+ * @param ticks the number of ticks to move the selection.
+ */
+ public void moveSelectedNotes(int ticks) {
+ if (ticks < 0) {
+ // If the selection should be moved upwards, traverses the list in the natural order.
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ MooNoteElement elem = (MooNoteElement)it.next();
+ elem.getNote().setTick(elem.getNote().getTick() + ticks);
+ layoutElement(elem, true);
+ }
+ } else {
+ // If the selection should be moved downwards, traverses the list in the opposite order.
+ ArrayList selectedList = new ArrayList(selection);
+ ListIterator it = selectedList.listIterator(selectedList.size());
+ while(it.hasPrevious()) {
+ MooNoteElement elem = (MooNoteElement)it.previous();
+ 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));
+ }
+
+ /**
+ * Enables keyboard recording.
+ */
+ public void enableKeyboardRecording() {
+ keyboard.recordEnable();
+ }
+
+ /**
+ * Disables keyboard recording.
+ */
+ public void disableKeyboardRecording() {
+ keyboard.recordDisable();
+ }
+
+ /**
+ * Adds a menu item with the given command to the given popup menu.
+ */
+ private JMenuItem addMenuItem(JPopupMenu menu, String command) {
+ JMenuItem item = new JMenuItem(command);
+ item.addActionListener(new PopupListener());
+ menu.add(item);
+ return item;
+ }
+
+ /**
+ * Adds a menu item with the given command to the given menu.
+ */
+ private JMenuItem addMenuItem(JMenu menu, String command) {
+ JMenuItem item = new JMenuItem(command);
+ item.addActionListener(new PopupListener());
+ menu.add(item);
+ return item;
+ }
+
+ /**
+ * Creates a transpose sub menu with the given title in the given popup menu,
+ * inserting the items into the given array.
+ */
+ private JMenu createTransposeMenu(JPopupMenu menu, JMenuItem[] items, String title) {
+ JMenu trans = new JMenu("Transpose " + title);
+ menu.add(trans);
+ items[0] = addMenuItem(trans, "One octave");
+ for (int i = 1; i < 12; i++) {
+ items[i] = addMenuItem(trans, (i) + " halftones");
+ }
+ return trans;
+ }
+
+ /**
+ * 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);
+ }
+