2 import java.awt.event.*;
4 import javax.sound.midi.*;
7 * Graphical representation of a MIDI track.
9 * @author Andersson , Andreen, Lanneskog, Pehrson
13 public class MooTrackView extends JPanel implements ActionListener {
15 private MooTrackTitle title;
16 private NoteArea notes;
17 private Rectangle box;
18 private JPopupMenu popup;
19 private JMenuItem menuItem;
20 private String newline = "\n";
22 public MooTrackView (Track track) {
23 setLayout(new BorderLayout());
24 this.setBorder(BorderFactory.createLineBorder(Color.black));
25 add(trackTitle(), BorderLayout.NORTH);
26 add(noteView(), BorderLayout.CENTER);
29 private JPanel trackTitle () {
30 title = new MooTrackTitle();
31 title.setPreferredSize(new Dimension(PANEL_WIDTH, TITLE_HEIGHT));
32 title.setBorder(BorderFactory.createLineBorder(Color.black));
36 private JPanel noteView () {
37 notes = new NoteArea();
38 notes.setBackground(Color.white);
39 notes.setBorder(BorderFactory.createLineBorder(Color.black));
41 popup = new JPopupMenu();
42 menuItem = new JMenuItem("Add...");
43 menuItem.addActionListener(this);
45 menuItem = new JMenuItem("Preferences...");
46 menuItem.addActionListener(this);
49 MouseListener popupListener = new PopupListener();
50 notes.addMouseListener(popupListener);
55 public void actionPerformed(ActionEvent e) {
56 JMenuItem source = (JMenuItem)(e.getSource());
57 String s = "Action event detected."
59 + " Event source: " + source.getText();
62 class NoteArea extends JPanel {
63 public void RectanglePanel() {
64 setPreferredSize(new Dimension(20, 20));
68 public void paintComponent(Graphics g) {
69 super.paintComponent(g);
70 Graphics2D g2 = (Graphics2D)g;
71 for (int c=0;c<1000;c=c+20) {
73 for (r=0;r<200;r=r+20) {
74 box = new Rectangle(r,c,20,20);
75 g2.setColor(Color.gray);
82 class PopupListener extends MouseAdapter {
83 public void mousePressed(MouseEvent e) {
87 public void mouseReleased(MouseEvent e) {
91 private void maybeShowPopup(MouseEvent e) {
92 if (e.isPopupTrigger()) {
93 popup.show(e.getComponent(),
99 private static final int PANEL_WIDTH = 65;
100 private static final int TITLE_HEIGHT = 60;
101 private static final int NOTEVIEW_HEIGHT = 200;