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;
17 public static final Color bgColor = new Color(160, 218, 255);
20 * Creates a new note element.
21 * @param mn the note that will be graphically represented
22 * @param rows the number of rows that the note will occupy
24 public MooNoteElement (MooNote mn) {
26 columns = mn.getDuration() / 24;
27 setBorder(BorderFactory.createLineBorder(Color.black));
28 setBackground(bgColor);
32 * Returns true if the current NoteElement is selected, otherwise false.
33 * @return if the element is selected
35 public boolean isSelected() {
40 * Selects the current NoteElement.
41 * @param state if the element should be selected
43 public void setSelected(boolean state) {
50 public void paintComponent(Graphics g)
52 super.paintComponent(g);
54 if (note == null || !(g instanceof Graphics2D)) return;
55 Graphics2D g2 = (Graphics2D)g;
58 int pitch = note.getPitch();
60 case 0: n = "C"; break;
61 case 1: n = "C#"; break;
62 case 2: n = "D"; break;
63 case 3: n = "D#"; break;
64 case 4: n = "E"; break;
65 case 5: n = "F"; break;
66 case 6: n = "F#"; break;
67 case 7: n = "G"; break;
68 case 8: n ="G#"; break;
69 case 9: n = "A"; break;
70 case 10: n = "A#"; break;
71 case 11: n = "B"; break;
82 g2.setFont(new Font("Helvetica", Font.PLAIN, 8));
84 g2.drawString(n + " "+ note.getVelocity(), 1, 9);