From: Einar Pehrson Date: Tue, 13 May 2003 19:54:46 +0000 (+0000) Subject: Fixed mouse listener for note element X-Git-Url: https://ruin.nu/git/?p=moosique.git;a=commitdiff_plain;h=8cf7c1250a6734bf43381550728a1d8620d294dc Fixed mouse listener for note element --- diff --git a/MooNoteElement.java b/MooNoteElement.java index 46b8047..8e5a3bd 100644 --- a/MooNoteElement.java +++ b/MooNoteElement.java @@ -14,6 +14,7 @@ public class MooNoteElement extends JPanel { private MooNote note; private int columns; private boolean selected; + private Rectangle pitchRect, veloRect; public static final Color bgColor = new Color(160, 218, 255); /** @@ -26,6 +27,10 @@ public class MooNoteElement extends JPanel { columns = mn.getDuration() / (Moosique.getSequence().getResolution() / 4); setBorder(BorderFactory.createLineBorder(Color.black)); setBackground(bgColor); + addMouseListener(new MAdapter()); + + pitchRect = new Rectangle(0, 0, 15, 10); + veloRect = new Rectangle(20, 0, 40, 10); } /** @@ -50,26 +55,27 @@ public class MooNoteElement extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); - if (note == null || !(g instanceof Graphics2D)) return; Graphics2D g2 = (Graphics2D)g; + g2.setFont(new Font("Helvetica", Font.PLAIN, 8)); 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 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; + case 11: n = "B"; break; } + n += pitch / 12; /* switch(columns) { @@ -79,8 +85,30 @@ public class MooNoteElement extends JPanel { } */ - g2.setFont(new Font("Helvetica", Font.PLAIN, 8)); - n = n +(pitch/12); - g2.drawString(n + " "+ note.getVelocity(), 1, 9); + g2.drawString(n, 1, 9); + g2.drawString("" + note.getVelocity(), 21, 9); + } + + class MAdapter extends MouseAdapter { + public void mouseClicked(MouseEvent e) { + if (pitchRect.contains(e.getPoint())) { + if (SwingUtilities.isRightMouseButton(e)) { + note.setPitch(note.getPitch() + 1); + } else if (SwingUtilities.isLeftMouseButton(e)) { + note.setPitch(note.getPitch() - 1); + } + } else if (veloRect.contains(e.getPoint())) { + if (SwingUtilities.isRightMouseButton(e)) { + note.setVelocity(note.getVelocity() + 1); + } else if (SwingUtilities.isLeftMouseButton(e)) { + note.setVelocity(note.getVelocity() - 1); + } + } + e.getComponent().repaint(); + } + + public void mousePressed(MouseEvent e) {} + + public void mouseReleased(MouseEvent e) {} } } \ No newline at end of file diff --git a/MooTrackView.java b/MooTrackView.java index a0da5dc..129b0af 100644 --- a/MooTrackView.java +++ b/MooTrackView.java @@ -14,7 +14,6 @@ import java.util.*; public class MooTrackView extends JPanel implements ActionListener { private Track track; - private MooTrackTitle title; private NoteArea notes; private Rectangle box; private JPopupMenu popup; @@ -26,13 +25,7 @@ public class MooTrackView extends JPanel implements ActionListener { public MooTrackView (Track track) { super(true); this.track = track; - //setPreferredSize(new Dimension(200, 9000)); setLayout(new BorderLayout()); - // setBorder(BorderFactory.createLineBorder(Color.black)); - - //title = new MooTrackTitle(track); - //title.setBorder(BorderFactory.createLineBorder(Color.black)); - //add(title, BorderLayout.NORTH); notes = new NoteArea(track); notes.setBackground(Color.white); @@ -43,13 +36,12 @@ public class MooTrackView extends JPanel implements ActionListener { menuItem.addActionListener(this); popup.add(menuItem); - notePopup = new JPopupMenu(); menuItem = new JMenuItem("Preferences..."); menuItem.addActionListener(this); notePopup.add(menuItem); - notes.addMouseListener(new PopupListener()); +// notes.addMouseListener(new PopupListener()); add(notes, BorderLayout.CENTER); }