- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D)g;
- for (int c = 0; c < viewLength ; c += NOTE_HEIGHT) {
- for (int r = 0; r < (10*NOTE_WIDTH); r += NOTE_WIDTH) {
- box = new Rectangle(r, c, NOTE_WIDTH, NOTE_HEIGHT);
- g2.setColor(Color.gray);
- g2.draw(box);
- }
+ /**
+ * 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);
+ }
+
+ /**
+ * Draws the grid that is on the background.
+ * @param g The Graphics object used to draw the grid.
+ */
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Graphics2D g2 = (Graphics2D)g;
+ for (int c = 0; c < viewLength || c < getHeight(); c += NOTE_HEIGHT) {
+ for (int r = 0; r < (10 * NOTE_WIDTH); r += NOTE_WIDTH) {
+ box = new Rectangle(r, c, NOTE_WIDTH, NOTE_HEIGHT);
+ g2.setColor(Color.gray);
+ g2.draw(box);