3 import java.awt.event.*;
6 * Graphical representation of a MIDI note.
8 * @author Andersson, Andreen, Lanneskog, Pehrson
12 public class MooNoteElement extends JPanel {
16 private boolean selected;
19 * Creates a new note element.
20 * @param mn the note that will be graphically represented
21 * @param rows the number of rows that the note will occupy
23 public MooNoteElement (MooNote mn) {
25 columns = mn.getDuration() / 24;
29 * Returns true if the current NoteElement is selected, otherwise false.
30 * @return if the element is selected
32 public boolean isSelected() {
37 * Selects the current NoteElement.
38 * @param state if the element should be selected
40 public void setSelected(boolean state) {
47 public void paintComponent(Graphics g)
49 super.paintComponent(g);
51 if (note == null || !(g instanceof Graphics2D)) return;
52 Graphics2D g2 = (Graphics2D)g;
55 int pitch = note.getPitch();
57 case 0: n = "C"; break;
58 case 1: n = "C#"; break;
59 case 2: n = "D"; break;
60 case 3: n = "D#"; break;
61 case 4: n = "E"; break;
62 case 5: n = "F"; break;
63 case 6: n = "F#"; break;
64 case 7: n = "G"; break;
65 case 8: n ="G#"; break;
66 case 9: n = "A"; break;
67 case 10: n = "A#"; break;
68 case 11: n = "B"; break;
79 g2.setFont(new Font("Helvetica", Font.PLAIN, 8));
81 g2.drawString(n + " "+ note.getVelocity(), 1, 9);