]> ruin.nu Git - moosique.git/blob - MooNoteElement.java
Changed MooNoteElement constructor
[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          * @param rows  the number of rows that the note will occupy
21          */
22         public MooNoteElement (MooNote mn, int rows) {
23                 note = mn;
24         }
25
26         /** 
27          * Returns true if the current NoteElement is selected, otherwise false.
28          * @return if the element is selected
29          */
30         public boolean isSelected() {
31                 return selected;
32         }
33
34         /** 
35          * Selects the current NoteElement.
36          * @param state if the element should be selected
37          */
38         public void setSelected(boolean state) {
39                 selected = state;
40         }
41
42         /**
43          *
44          */
45         public void paintComponent(Graphics g)
46         {
47                 super.paintComponent(g);
48
49                 if (note == null || !(g instanceof Graphics2D)) return;
50                 Graphics2D g2 = (Graphics2D)g;
51
52                 String n = ""; 
53                 int pitch = note.getPitch();
54                 switch (pitch % 12) {
55                         case 0: n = "C"; break;
56                         case 1: n = "C#"; break;
57                         case 2: n = "D"; break;
58                         case 3: n = "D#"; break;
59                         case 4: n = "E"; break;
60                         case 5: n = "F"; break;
61                         case 6: n = "F#"; break;
62                         case 7: n = "G"; break;
63                         case 8: n ="G#"; break;
64                         case 9: n = "A"; break;
65                         case 10: n = "A#"; break;
66                         case 11: n = "B"; break;
67                 }
68                 g2.setFont(new Font("Helvetica", Font.PLAIN, 8));
69                 n = n +(pitch/12);
70                 g2.drawString(n + " "+ note.getVelocity(), 1, 9);
71         }
72 }