]> 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                 setPreferredSize(new Dimension(20,20));
24
25                 class MouseList implements MouseListener{
26                         public void mouseClicked(MouseEvent event){
27                                 //Bring upp dialog to edit note.
28                         }
29
30                         public void mouseEntered(MouseEvent event){
31                                 //Show note props in statusbar?
32                         }
33
34                         public void mouseExited(MouseEvent event){
35                                 //Reset statusbar?
36                         }
37
38                         public void mousePressed(MouseEvent event){     }
39
40                         public void mouseReleased(MouseEvent event){}
41                 };
42                 MouseListener listener = new MouseList();
43                 addMouseListener(listener);
44         }
45
46         /** 
47          * Returns true if the current NoteElement is selected, otherwise false.
48          * @return if the element is selected
49          */
50         public boolean isSelected() {
51                 return selected;
52         }
53
54         /** 
55          * Selects the current NoteElement.
56          * @param state if the element should be selected
57          */
58         public void setSelected(boolean state) {
59                 selected = state;
60         }
61
62         /**
63          *
64          */
65         public void paintComponent(Graphics g)
66         {
67                 super.paintComponent(g);
68
69                 if (!(g instanceof Graphics2D))
70                         return;
71                 Graphics2D g2 = (Graphics2D)g;
72                 
73                 String note = ""; //TODO: shoudl really change this name..
74                 int pitch = this.note.getPitch();
75                 switch( pitch % 12)
76                 {
77                         case 0: note = "C"; break;
78                         case 1: note = "C#"; break;
79                         case 2: note = "D"; break;
80                         case 3: note = "D#"; break;
81                         case 4: note = "E"; break;
82                         case 5: note = "F"; break;
83                         case 6: note = "F#"; break;
84                         case 7: note = "G"; break;
85                         case 8: note ="G#"; break;
86                         case 9: note = "A"; break;
87                         case 10: note = "A#"; break;
88                         case 11: note = "B"; break;
89                 }
90                 
91                 g2.drawString(note +" "+(pitch/12), 2, 2);
92
93         }
94                         
95 }