]> ruin.nu Git - moosique.git/blobdiff - MooNoteElement.java
some changes
[moosique.git] / MooNoteElement.java
index 8b71b3cfb31e72caabf1edff3479f1dd930beecf..c39d2b58804af037d5f355bd5744e451d421661e 100644 (file)
@@ -2,7 +2,7 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 
-/*
+/**
  * Graphical representation of a MIDI note.
  * 
  * @author  Andersson, Andreen, Lanneskog, Pehrson
@@ -12,13 +12,16 @@ import java.awt.event.*;
 public class MooNoteElement extends JPanel{
 
        private MooNote note;
-       /* 
+       private boolean selected;
+
+       /** 
         * Creates a new note element.
         * @param mn The note that will be graphically represented
         */
        public MooNoteElement (MooNote mn) {
                note = mn;
                setPreferredSize(new Dimension(20,20));
+               setFont(new Font("Helvetica", Font.PLAIN, 10));
 
                class MouseList implements MouseListener{
                        public void mouseClicked(MouseEvent event){
@@ -39,7 +42,22 @@ public class MooNoteElement extends JPanel{
                };
                MouseListener listener = new MouseList();
                addMouseListener(listener);
-                       
+       }
+
+       /** 
+        * Returns true if the current NoteElement is selected, otherwise false.
+        * @return if the element is selected
+        */
+       public boolean isSelected() {
+               return selected;
+       }
+
+       /** 
+        * Selects the current NoteElement.
+        * @param state if the element should be selected
+        */
+       public void setSelected(boolean state) {
+               selected = state;
        }
 
        /**
@@ -49,11 +67,33 @@ public class MooNoteElement extends JPanel{
        {
                super.paintComponent(g);
 
+               if (note == null)
+                       return;
+
                if (!(g instanceof Graphics2D))
                        return;
                Graphics2D g2 = (Graphics2D)g;
 
-               //Draw the note representation
+               String n = ""; 
+               int pitch = note.getPitch();
+               switch( pitch % 12)
+               {
+                       case 0: n = "C"; break;
+                       case 1: n = "C#"; break;
+                       case 2: n = "D"; break;
+                       case 3: n = "D#"; break;
+                       case 4: n = "E"; break;
+                       case 5: n = "F"; break;
+                       case 6: n = "F#"; break;
+                       case 7: n = "G"; break;
+                       case 8: n ="G#"; break;
+                       case 9: n = "A"; break;
+                       case 10: n = "A#"; break;
+                       case 11: n = "B"; break;
+               }
+
+               g2.drawString(n +" "+(pitch/12), 2, 2);
+
        }
-                       
+
 }