X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooNoteElement.java;h=1225fe9833ad905f5c98a65136c86cd058357831;hb=74c2bdb1ef88c7fee1e1288ef63f639ec3a8821c;hp=60f153a15a950a42a04abb54e610916fd1a5cd66;hpb=1e06fcb34d222ef2017d4adf888568184dd63ab9;p=moosique.git diff --git a/MooNoteElement.java b/MooNoteElement.java index 60f153a..1225fe9 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -1,4 +1,6 @@ import javax.swing.*; +import java.awt.*; +import java.awt.event.*; /** * Graphical representation of a MIDI note. @@ -7,19 +9,87 @@ import javax.swing.*; * @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 () { + public MooNoteElement (MooNote mn) { + note = mn; + setPreferredSize(new Dimension(20,20)); + + class MouseList implements MouseListener{ + public void mouseClicked(MouseEvent event){ + //Bring upp dialog to edit note. + } + + public void mouseEntered(MouseEvent event){ + //Show note props in statusbar? + } + + public void mouseExited(MouseEvent event){ + //Reset statusbar? + } + + public void mousePressed(MouseEvent event){ } + + public void mouseReleased(MouseEvent event){} + }; + 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 () { - + public void setSelected(boolean state) { + selected = state; + } + + /** + * + */ + public void paintComponent(Graphics g) + { + super.paintComponent(g); + + if (!(g instanceof Graphics2D)) + return; + Graphics2D g2 = (Graphics2D)g; + + String note = ""; //TODO: shoudl really change this name.. + int pitch = this.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; + } + + g2.drawString(note +" "+(pitch/12), 2, 2); + } -} + +} \ No newline at end of file