X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooNoteElement.java;h=6f372349e5372c2e657f71333366075c0d4dfe50;hb=6f345a1ba4d0a66dcc4c10558fe28ba50c8d33e5;hp=4b5d967ab9b3c8721020a4a236efa6352b7fd11e;hpb=8efaf48c550d5462b987e6a9e0f4efd14bc8b483;p=moosique.git diff --git a/MooNoteElement.java b/MooNoteElement.java index 4b5d967..6f37234 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -13,7 +13,6 @@ public class MooNoteElement extends JPanel { private MooTrackView mtv; private MooNote note; - private int columns; private boolean selected; private Rectangle pitchRect, veloRect; public static final Color bgColor = new Color(160, 218, 255); @@ -24,14 +23,13 @@ public class MooNoteElement extends JPanel { /** * Creates a new note element. + * @param parent The MooTrackView that this element will be painted on. * @param mn the note that will be graphically represented - * @param rows the number of rows that the note will occupy */ public MooNoteElement (MooTrackView parent, MooNote mn) { mtv = parent; note = mn; calculateString(); - columns = mn.getDuration() / (Moosique.getSequence().getResolution() / 4); setBorder(BorderFactory.createLineBorder(Color.black)); setBackground(bgColor); addMouseListener(new MAdapter()); @@ -70,7 +68,8 @@ public class MooNoteElement extends JPanel { } /** - * + * Draws the string that shows the note's properties. + * @param g The Graphics object used to draw the strings. */ public void paintComponent(Graphics g) { @@ -90,6 +89,9 @@ public class MooNoteElement extends JPanel { g2.drawString("" + noteVelocity, 21, 9); } + /** + * Calculate what the string that shows the note properties should look like. + */ protected void calculateString(){ noteVelocity = ""; @@ -115,11 +117,25 @@ public class MooNoteElement extends JPanel { noteVelocity = ""+note.getVelocity(); } + /** + * Gets the note that is element represents + * @return the MooNote object. + */ public MooNote getNote(){ return note; } + /** + * Listener that checks the mouse actions on this element. + */ class MAdapter extends MouseAdapter { + /** + * Checks if the mouse is pressed. + * Pops up the menu if right mousebutton is used. + * Increases the pitch or velocity if the right mousebutton is pressed while holding ctrl down. + * Decreases the pitch or velocity if the left mousebutton is pressed while holding ctrl down. + * @param e The events recieved. + */ public void mousePressed(MouseEvent e) { if (e.isControlDown()) { if (pitchRect.contains(e.getPoint())) { @@ -138,13 +154,15 @@ public class MooNoteElement extends JPanel { calculateString(); } e.getComponent().repaint(); - } - if (e.isPopupTrigger()) { + } else if (e.isPopupTrigger()) { popup.show(e.getComponent(), e.getX(), e.getY()); } } } + /** + * Listens on the actions made to the popupmenu. + */ class PopupListener implements ActionListener { public void actionPerformed(ActionEvent e) { Object source = e.getSource(); @@ -156,8 +174,11 @@ public class MooNoteElement extends JPanel { } } + /** + * Asks the MooTrackView that it's painted on to remove this element and the note. + */ protected void remove(){ - mtv.remove(this); + mtv.removeNote(this, note); } }