X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooNoteElement.java;h=e854a44fd030a0f211635a8b5b715623097c9bff;hb=c83e74facf762222fe4578f175408cc50d360518;hp=969433fb928eec864372b0a68f23950f4b65d5ad;hpb=f2a6b00defcf7804b30e8d167015500e33d6cedb;p=moosique.git diff --git a/MooNoteElement.java b/MooNoteElement.java index 969433f..e854a44 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -9,9 +9,11 @@ import java.awt.event.*; * @version 1 */ -public class MooNoteElement extends JPanel{ +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 @@ -19,6 +21,7 @@ public class MooNoteElement extends JPanel{ 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,30 +67,33 @@ public class MooNoteElement extends JPanel{ { super.paintComponent(g); + if (note == null) + return; + if (!(g instanceof Graphics2D)) return; Graphics2D g2 = (Graphics2D)g; - - String note = ""; //TODO: shoudl really change this name.. - int pitch = this.note.getPitch(); + + String n = ""; + int pitch = note.getPitch(); switch( pitch % 12) { - case 0: note = "C"; break; - case 1: note = "C#"; break; - case 2: note = "D"; break; - case 3: note = "D#"; break; - case 4: note = "E"; break; - case 5: note = "F"; break; - case 6: note = "F#"; break; - case 7: note = "G"; break; - case 8: note ="G#"; break; - case 9: note = "A"; break; - case 10: note = "A#"; break; - case 11: note = "B"; break; + 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(note +" "+(pitch/12), 2, 2); + + g2.drawString(n +" "+(pitch/12), 2, 2); } - + }