3 import java.awt.event.*;
6 * Graphical representation of a MIDI note.
8 * @author Andersson, Andreen, Lanneskog, Pehrson
12 public class MooNoteElement extends JPanel{
15 private boolean selected;
18 * Creates a new note element.
19 * @param mn The note that will be graphically represented
21 public MooNoteElement (MooNote mn) {
23 setPreferredSize(new Dimension(20,20));
25 class MouseList implements MouseListener{
26 public void mouseClicked(MouseEvent event){
27 //Bring upp dialog to edit note.
30 public void mouseEntered(MouseEvent event){
31 //Show note props in statusbar?
34 public void mouseExited(MouseEvent event){
38 public void mousePressed(MouseEvent event){ }
40 public void mouseReleased(MouseEvent event){}
42 MouseListener listener = new MouseList();
43 addMouseListener(listener);
47 * Returns true if the current NoteElement is selected, otherwise false.
48 * @return if the element is selected
50 public boolean isSelected() {
55 * Selects the current NoteElement.
56 * @param state if the element should be selected
58 public void setSelected(boolean state) {
65 public void paintComponent(Graphics g)
67 super.paintComponent(g);
69 if (!(g instanceof Graphics2D))
71 Graphics2D g2 = (Graphics2D)g;
73 String note = ""; //TODO: shoudl really change this name..
74 int pitch = this.note.getPitch();
77 case 0: note = "C"; break;
78 case 1: note = "C#"; break;
79 case 2: note = "D"; break;
80 case 3: note = "D#"; break;
81 case 4: note = "E"; break;
82 case 5: note = "F"; break;
83 case 6: note = "F#"; break;
84 case 7: note = "G"; break;
85 case 8: note ="G#"; break;
86 case 9: note = "A"; break;
87 case 10: note = "A#"; break;
88 case 11: note = "B"; break;
91 g2.drawString(note +" "+(pitch/12), 2, 2);