+ * @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();
+ setBorder(BorderFactory.createLineBorder(Color.black));
+ setBackground(bgColor);
+ addMouseListener(new MAdapter());
+
+ // 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);
+ popupTransposeOctUp = new JMenuItem("Transpose one octave up");
+ popupTransposeOctUp.addActionListener(pList);
+ popup.add(popupTransposeOctUp);
+ popupTransposeOctDown = new JMenuItem("Transpose one octave down");
+ popupTransposeOctDown.addActionListener(pList);
+ popup.add(popupTransposeOctDown);
+
+ }
+
+ /**
+ * Returns true if the current NoteElement is selected, otherwise false.
+ * @return if the element is selected
+ */
+ public boolean isSelected() {
+ return selected;
+ }
+
+ /**
+ * Returns the note of this element.
+ * @return the note
+ */
+ public MooNote getNote() {
+ return note;
+ }
+
+ /**
+ * Selects the current NoteElement.
+ * @param state if the element should be selected
+ */
+ public void setSelected(boolean state) {
+ selected = state;
+ }
+
+ /**
+ * 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.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.