2 import java.awt.event.*;
6 * Graphical representation of a MIDI track.
8 * @author Andersson , Andreen, Lanneskog, Pehrson
12 public class MooTrackView extends JPanel implements ActionListener {
14 private MooTrackTitle title;
15 private NoteArea notes;
16 private Rectangle box;
17 private JPopupMenu popup;
18 private JMenuItem menuItem;
19 private String newline = "\n";
21 public MooTrackView (Track track) {
22 setLayout(new BorderLayout());
23 this.setBorder(BorderFactory.createLineBorder(Color.black));
24 add(trackTitle(), BorderLayout.NORTH);
25 add(noteView(), BorderLayout.CENTER);
28 private JPanel trackTitle () {
29 title = new MooTrackTitle();
30 title.setPreferredSize(new Dimension(PANEL_WIDTH, TITLE_HEIGHT));
31 title.setBorder(BorderFactory.createLineBorder(Color.black));
35 private JPanel noteView () {
36 notes = new NoteArea();
37 notes.setBackground(Color.white);
38 notes.setBorder(BorderFactory.createLineBorder(Color.black));
40 popup = new JPopupMenu();
41 menuItem = new JMenuItem("Add...");
42 menuItem.addActionListener(this);
44 menuItem = new JMenuItem("Preferences...");
45 menuItem.addActionListener(this);
48 MouseListener popupListener = new PopupListener();
49 notes.addMouseListener(popupListener);
54 public void actionPerformed(ActionEvent e) {
55 JMenuItem source = (JMenuItem)(e.getSource());
56 String s = "Action event detected."
58 + " Event source: " + source.getText();
61 class NoteArea extends JPanel {
62 public void RectanglePanel() {
63 setPreferredSize(new Dimension(20, 20));
67 public void paintComponent(Graphics g) {
68 super.paintComponent(g);
69 Graphics2D g2 = (Graphics2D)g;
70 for (int c=0;c<1000;c=c+20) {
72 for (r=0;r<200;r=r+20) {
73 box = new Rectangle(r,c,20,20);
74 g2.setColor(Color.gray);
81 class PopupListener extends MouseAdapter {
82 public void mousePressed(MouseEvent e) {
86 public void mouseReleased(MouseEvent e) {
90 private void maybeShowPopup(MouseEvent e) {
91 if (e.isPopupTrigger()) {
92 popup.show(e.getComponent(),
98 private static final int PANEL_WIDTH = 65;
99 private static final int TITLE_HEIGHT = 60;
100 private static final int NOTEVIEW_HEIGHT = 200;