]> ruin.nu Git - moosique.git/blob - MooNoteElement.java
no message
[moosique.git] / MooNoteElement.java
1 import javax.swing.*;
2 import java.awt.*;
3 import java.awt.event.*;
4
5 /**
6  * Graphical representation of a MIDI note.
7  * 
8  * @author  Andersson, Andreen, Lanneskog, Pehrson
9  * @version 1
10  */
11  
12 public class MooNoteElement extends JPanel {
13
14         private MooNote note;
15         private boolean selected;
16
17         /** 
18          * Creates a new note element.
19          * @param mn The note that will be graphically represented
20          */
21         public MooNoteElement (MooNote mn) {
22                 note = mn;
23         }
24
25         /** 
26          * Returns true if the current NoteElement is selected, otherwise false.
27          * @return if the element is selected
28          */
29         public boolean isSelected() {
30                 return selected;
31         }
32
33         /** 
34          * Selects the current NoteElement.
35          * @param state if the element should be selected
36          */
37         public void setSelected(boolean state) {
38                 selected = state;
39         }
40
41         /**
42          *
43          */
44         public void paintComponent(Graphics g)
45         {
46                 super.paintComponent(g);
47
48                 if (note == null || !(g instanceof Graphics2D)) return;
49                 Graphics2D g2 = (Graphics2D)g;
50
51                 String n = ""; 
52                 int pitch = note.getPitch();
53                 switch (pitch % 12) {
54                         case 0: n = "C"; break;
55                         case 1: n = "C#"; break;
56                         case 2: n = "D"; break;
57                         case 3: n = "D#"; break;
58                         case 4: n = "E"; break;
59                         case 5: n = "F"; break;
60                         case 6: n = "F#"; break;
61                         case 7: n = "G"; break;
62                         case 8: n ="G#"; break;
63                         case 9: n = "A"; break;
64                         case 10: n = "A#"; break;
65                         case 11: n = "B"; break;
66                 }
67                 g2.setFont(new Font("Helvetica", Font.PLAIN, 8));
68                 n = n +(pitch/12);
69                 g2.drawString(n + " "+ note.getVelocity(), 1, 9);
70         }
71 }