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