X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooNoteElement.java;h=46b8047c4ae9bf5c1c26ed569fd283ffdafa1bba;hb=0f7c84e646806d501e256452addb980067911d1f;hp=60f153a15a950a42a04abb54e610916fd1a5cd66;hpb=1e06fcb34d222ef2017d4adf888568184dd63ab9;p=moosique.git diff --git a/MooNoteElement.java b/MooNoteElement.java index 60f153a..46b8047 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,78 @@ import javax.swing.*; * @version 1 */ -public class MooNoteElement { +public class MooNoteElement extends JPanel { + + private MooNote note; + private int columns; + private boolean selected; + public static final Color bgColor = new Color(160, 218, 255); /** * Creates a new note element. + * @param mn the note that will be graphically represented + * @param rows the number of rows that the note will occupy */ - public MooNoteElement () { + public MooNoteElement (MooNote mn) { + note = mn; + columns = mn.getDuration() / (Moosique.getSequence().getResolution() / 4); + setBorder(BorderFactory.createLineBorder(Color.black)); + setBackground(bgColor); + } + /** + * 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; + } + + /** + * */ - 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; + } + + /* + switch(columns) { + case 0: + case 1: + ... + } + */ + + 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