]> ruin.nu Git - moosique.git/blob - MooNoteElement.java
should now draw the text representation.
[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         /** 
16          * Creates a new note element.
17          * @param mn The note that will be graphically represented
18          */
19         public MooNoteElement (MooNote mn) {
20                 note = mn;
21                 setPreferredSize(new Dimension(20,20));
22
23                 class MouseList implements MouseListener{
24                         public void mouseClicked(MouseEvent event){
25                                 //Bring upp dialog to edit note.
26                         }
27
28                         public void mouseEntered(MouseEvent event){
29                                 //Show note props in statusbar?
30                         }
31
32                         public void mouseExited(MouseEvent event){
33                                 //Reset statusbar?
34                         }
35
36                         public void mousePressed(MouseEvent event){     }
37
38                         public void mouseReleased(MouseEvent event){}
39                 };
40                 MouseListener listener = new MouseList();
41                 addMouseListener(listener);
42                         
43         }
44
45         /**
46          *
47          */
48         public void paintComponent(Graphics g)
49         {
50                 super.paintComponent(g);
51
52                 if (!(g instanceof Graphics2D))
53                         return;
54                 Graphics2D g2 = (Graphics2D)g;
55                 
56                 String note = ""; //TODO: shoudl really change this name..
57                 int pitch = this.note.getPitch();
58                 switch( pitch % 12)
59                 {
60                         case 0: note = "C"; break;
61                         case 1: note = "C#"; break;
62                         case 2: note = "D"; break;
63                         case 3: note = "D#"; break;
64                         case 4: note = "E"; break;
65                         case 5: note = "F"; break;
66                         case 6: note = "F#"; break;
67                         case 7: note = "G"; break;
68                         case 8: note ="G#"; break;
69                         case 9: note = "A"; break;
70                         case 10: note = "A#"; break;
71                         case 11: note = "B"; break;
72                 }
73                 
74                 g2.drawString(note +" "+(pitch/12), 2, 2);
75
76         }
77                         
78 }