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