X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooTrackView.java;h=780e3c017521c0f3015e2fa91c819ad237502e8f;hb=97d462f234af2325fb0707b8bd35cec1ee429dd5;hp=bcbfc09e1e2d8e5464c745d40cff1a6327af62a1;hpb=aa695d60dbd53407f60548ec18ed7be4e65937ce;p=moosique.git diff --git a/MooTrackView.java b/MooTrackView.java index bcbfc09..780e3c0 100644 --- a/MooTrackView.java +++ b/MooTrackView.java @@ -17,61 +17,47 @@ public class MooTrackView extends JPanel implements ActionListener { private Rectangle box; private JPopupMenu popup; private JMenuItem menuItem; - private String newline = "\n"; + + private static final int NOTEVIEW_HEIGHT = 200; public MooTrackView (Track track) { setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(Color.black)); - add(trackTitle(), BorderLayout.NORTH); - add(noteView(), BorderLayout.CENTER); - } - - private JPanel trackTitle () { + title = new MooTrackTitle(); - title.setPreferredSize(new Dimension(PANEL_WIDTH, TITLE_HEIGHT)); title.setBorder(BorderFactory.createLineBorder(Color.black)); - return title; - } + add(title, BorderLayout.NORTH); - private JPanel noteView () { notes = new NoteArea(); notes.setBackground(Color.white); notes.setBorder(BorderFactory.createLineBorder(Color.black)); - + popup = new JPopupMenu(); - menuItem = new JMenuItem("Add..."); - menuItem.addActionListener(this); - popup.add(menuItem); - menuItem = new JMenuItem("Preferences..."); - menuItem.addActionListener(this); - popup.add(menuItem); + menuItem = new JMenuItem("Add..."); + menuItem.addActionListener(this); + popup.add(menuItem); + menuItem = new JMenuItem("Preferences..."); + menuItem.addActionListener(this); + popup.add(menuItem); - MouseListener popupListener = new PopupListener(); - notes.addMouseListener(popupListener); - - return notes; + notes.addMouseListener(new PopupListener()); + add(notes, BorderLayout.CENTER); } - public void actionPerformed(ActionEvent e) { - JMenuItem source = (JMenuItem)(e.getSource()); - String s = "Action event detected." - + newline - + " Event source: " + source.getText(); - } + public void actionPerformed(ActionEvent e) {} class NoteArea extends JPanel { public void RectanglePanel() { setPreferredSize(new Dimension(20, 20)); - } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; - for (int c=0;c<1000;c=c+20) { + for (int c = 0; c < 1000; c += 20) { int r=0; - for (r=0;r<200;r=r+20) { - box = new Rectangle(r,c,20,20); + for (r = 0; r < 200; r += 20) { + box = new Rectangle(r, c, 20, 20); g2.setColor(Color.gray); g2.draw(box); } @@ -80,23 +66,18 @@ public class MooTrackView extends JPanel implements ActionListener { } class PopupListener extends MouseAdapter { - public void mousePressed(MouseEvent e) { - maybeShowPopup(e); - } - - public void mouseReleased(MouseEvent e) { - maybeShowPopup(e); - } - - private void maybeShowPopup(MouseEvent e) { - if (e.isPopupTrigger()) { - popup.show(e.getComponent(), - e.getX(), e.getY()); - } - } - } + public void mousePressed(MouseEvent e) { + maybeShowPopup(e); + } - private static final int PANEL_WIDTH = 60; - private static final int TITLE_HEIGHT = 55; - private static final int NOTEVIEW_HEIGHT = 200; -} + public void mouseReleased(MouseEvent e) { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) { + if (e.isPopupTrigger()) { + popup.show(e.getComponent(), e.getX(), e.getY()); + } + } + } +} \ No newline at end of file