+ public void mouseClicked(MouseEvent e) {
+ select();
+ // Play the note
+ }
+
+ /**
+ * Checks if the mouse is pressed.
+ * Increases the pitch or velocity if the right mouse button is pressed while holding CTRL.
+ * Decreases the pitch or velocity if the left mouse button is pressed while holding CTRL.
+ * @param e the event recieved.
+ */
+ public void mousePressed(MouseEvent e) {
+ if (e.isControlDown()) {
+ if (pitchRect.contains(e.getPoint())) {
+ if (SwingUtilities.isRightMouseButton(e)) {
+ note.setPitch(note.getPitch() + 1);
+ } else if (SwingUtilities.isLeftMouseButton(e)) {
+ note.setPitch(note.getPitch() - 1);
+ }
+ calculateString();
+ repaint();
+ } else if (veloRect.contains(e.getPoint())) {
+ if (SwingUtilities.isRightMouseButton(e)) {
+ note.setVelocity(note.getVelocity() + 1);
+ } else if (SwingUtilities.isLeftMouseButton(e)) {
+ note.setVelocity(note.getVelocity() - 1);
+ }
+ calculateString();
+ repaint();
+ }
+ } else maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ /**
+ * Shows the menu if an OS-specific popup-trigger was activated.
+ */
+ private void maybeShowPopup(MouseEvent e) {
+ if (e.isPopupTrigger() && !e.isControlDown()) popup.show(e.getComponent(), e.getX(), e.getY());
+ }
+ }
+
+ /**
+ * Listens on the actions made to the popupmenu.
+ */
+ class PopupListener implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ Object source = e.getSource();
+ if (source == popupProp) {
+ new MooDialog(note);
+ } else if (source == popupRemove) {
+ remove();
+ } else if (source == popupTransposeOctUp) {
+ note.setPitch(note.getPitch() + 12);
+ update();
+ } else if (source == popupTransposeOctDown) {
+ note.setPitch(note.getPitch() - 12);
+ update();
+ }
+ }
+
+ private void update() {
+ calculateString();
+ repaint();
+ }
+ }
+
+ /**
+ * Asks the MooTrackView that the note element is painted on to remove this element and the note.
+ */
+ protected void remove(){
+ mtv.removeNote(this);