+ * @param parent The MooTrackView that this element will be painted on.
+ * @param mn the note that will be graphically represented
+ */
+ public MooNoteElement (MooTrackView parent, MooNote mn) {
+ mtv = parent;
+ note = mn;
+ calculateString();
+ addMouseListener(new MAdapter());
+ setBorder(BorderFactory.createLineBorder(Color.black));
+ setBackground(bgColor);
+ textColor = Color.black;
+
+ // Defines coordinates.
+ pitchRect = new Rectangle(0, 0, 15, 10);
+ veloRect = new Rectangle(20, 0, 40, 10);
+
+ // Creates pop-up menu.
+ popup = new JPopupMenu();
+ PopupListener pList = new PopupListener();
+ popupProp = new JMenuItem("Preferences...");
+ popupProp.addActionListener(pList);
+ popup.add(popupProp);
+ popupRemove = new JMenuItem("Remove");
+ popupRemove.addActionListener(pList);
+ popup.add(popupRemove);
+ popupTranspOctUp = new JMenuItem("Transpose one octave up");
+ popupTranspOctUp.addActionListener(pList);
+ popup.add(popupTranspOctUp);
+ popupTranspOctDown = new JMenuItem("Transpose one octave down");
+ popupTranspOctDown.addActionListener(pList);
+ popup.add(popupTranspOctDown);
+ }
+
+ /**
+ * Returns the note of this element.
+ * @return the note
+ */
+ public MooNote getNote() {
+ return note;
+ }
+
+ /**
+ * Selects the current NoteElement.
+ */
+ public void select() {
+ selected = true;
+ mtv.selectNote(this);
+ setBackground(invBgColor);
+ textColor = Color.white;
+ repaint();
+ }
+
+ /**
+ * Deselects the current NoteElement.
+ */
+ public void deselect() {
+ selected = false;
+ // mtv.deselectNote(this);
+ setBackground(bgColor);
+ textColor = Color.black;
+ repaint();
+ }
+
+ /**
+ * Draws the string that shows the note's properties.
+ * @param g The Graphics object used to draw the strings.
+ */
+ public void paintComponent(Graphics g)
+ {
+ super.paintComponent(g);
+ if (!(g instanceof Graphics2D)) return;
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setColor(textColor);
+ g2.setFont(new Font("Helvetica", Font.PLAIN, 8));
+ /*
+ switch(columns) {
+ case 0:
+ case 1:
+ ...
+ }
+ */
+
+ g2.drawString(notePitch, 1, 8);
+ g2.drawString("" + noteVelocity, 21, 8);
+ }
+
+ /**
+ * Calculate what the string that shows the note properties should look like.