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);
73 if (!(g instanceof Graphics2D))
75 Graphics2D g2 = (Graphics2D)g;
78 int pitch = note.getPitch();
81 case 0: n = "C"; break;
82 case 1: n = "C#"; break;
83 case 2: n = "D"; break;
84 case 3: n = "D#"; break;
85 case 4: n = "E"; break;
86 case 5: n = "F"; break;
87 case 6: n = "F#"; break;
88 case 7: n = "G"; break;
89 case 8: n ="G#"; break;
90 case 9: n = "A"; break;
91 case 10: n = "A#"; break;
92 case 11: n = "B"; break;
95 g2.drawString(n +" "+(pitch/12), 2, 2);