]> ruin.nu Git - moosique.git/blob - MooNoteElement.java
.
[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)
49                         return;
50
51                 if (!(g instanceof Graphics2D))
52                         return;
53                 Graphics2D g2 = (Graphics2D)g;
54
55                 String n = ""; 
56                 int pitch = note.getPitch();
57                 switch( pitch % 12)
58                 {
59                         case 0: n = "C"; break;
60                         case 1: n = "C#"; break;
61                         case 2: n = "D"; break;
62                         case 3: n = "D#"; break;
63                         case 4: n = "E"; break;
64                         case 5: n = "F"; break;
65                         case 6: n = "F#"; break;
66                         case 7: n = "G"; break;
67                         case 8: n ="G#"; break;
68                         case 9: n = "A"; break;
69                         case 10: n = "A#"; break;
70                         case 11: n = "B"; break;
71                 }
72                 g2.setFont(new Font("Helvetica", Font.PLAIN, 10));
73                 n = n +(pitch/12);
74                 g2.drawString(n, 1, 11);
75                 g2.drawString(""+note.getVelocity(),1,23);
76
77         }
78
79 }