]> ruin.nu Git - moosique.git/blobdiff - MooNoteElement.java
no message
[moosique.git] / MooNoteElement.java
index 8471b53d649fa8b9c49136d3113c85c8f41b4db5..beb5702b0467b663f102f2482e73cf75cbcb96fb 100644 (file)
@@ -1,25 +1,71 @@
 import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
 
-/*
+/**
  * Graphical representation of a MIDI note.
  * 
  * @author  Andersson, Andreen, Lanneskog, Pehrson
  * @version 1
  */
  
-public class MooNoteElement {
+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;
+       }
+
+       /** 
+        * Returns true if the current NoteElement is selected, otherwise false.
+        * @return if the element is selected
         */
-       public MooNoteElement () {
+       public boolean isSelected() {
+               return selected;
+       }
 
+       /** 
+        * Selects the current NoteElement.
+        * @param state if the element should be selected
+        */
+       public void setSelected(boolean state) {
+               selected = state;
        }
 
-       /* 
-        * 
+       /**
+        *
         */
-       public void () {
-       
+       public void paintComponent(Graphics g)
+       {
+               super.paintComponent(g);
+
+               if (note == null || !(g instanceof Graphics2D)) return;
+               Graphics2D g2 = (Graphics2D)g;
+
+               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.setFont(new Font("Helvetica", Font.PLAIN, 8));
+               n = n +(pitch/12);
+               g2.drawString(n + " "+ note.getVelocity(), 1, 9);
        }
-}
+}
\ No newline at end of file