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));
24 setFont(new Font("Helvetica", Font.PLAIN, 10));
26 class MouseList implements MouseListener{
27 public void mouseClicked(MouseEvent event){
28 //Bring upp dialog to edit note.
31 public void mouseEntered(MouseEvent event){
32 //Show note props in statusbar?
35 public void mouseExited(MouseEvent event){
39 public void mousePressed(MouseEvent event){ }
41 public void mouseReleased(MouseEvent event){}
43 MouseListener listener = new MouseList();
44 addMouseListener(listener);
48 * Returns true if the current NoteElement is selected, otherwise false.
49 * @return if the element is selected
51 public boolean isSelected() {
56 * Selects the current NoteElement.
57 * @param state if the element should be selected
59 public void setSelected(boolean state) {
66 public void paintComponent(Graphics g)
68 super.paintComponent(g);
70 if (!(g instanceof Graphics2D))
72 Graphics2D g2 = (Graphics2D)g;
74 String note = ""; //TODO: shoudl really change this name..
75 int pitch = this.note.getPitch();
78 case 0: note = "C"; break;
79 case 1: note = "C#"; break;
80 case 2: note = "D"; break;
81 case 3: note = "D#"; break;
82 case 4: note = "E"; break;
83 case 5: note = "F"; break;
84 case 6: note = "F#"; break;
85 case 7: note = "G"; break;
86 case 8: note ="G#"; break;
87 case 9: note = "A"; break;
88 case 10: note = "A#"; break;
89 case 11: note = "B"; break;
92 g2.drawString(note +" "+(pitch/12), 2, 2);