]> ruin.nu Git - moosique.git/blob - MooTrackView.java
no message
[moosique.git] / MooTrackView.java
1 import javax.swing.*;
2 import java.awt.event.*;
3 import java.awt.*;
4
5 /**
6  * Graphical representation of a MIDI track.
7  * 
8  * @author  Andersson , Andreen, Lanneskog, Pehrson
9  * @version 1
10  */
11  
12 public class MooTrackView extends JPanel implements ActionListener {
13
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";
20         
21         public MooTrackView () {
22                 setLayout(new BorderLayout());
23                 this.setBorder(BorderFactory.createLineBorder(Color.black));
24                 add(trackTitle(), BorderLayout.NORTH);
25                 add(noteView(), BorderLayout.CENTER);
26         }
27         
28         private JPanel trackTitle () {
29                 title = new MooTrackTitle();
30                 title.setPreferredSize(new Dimension(PANEL_WIDTH, TITLE_HEIGHT));
31                 title.setBorder(BorderFactory.createLineBorder(Color.black));
32                 return title;
33         }
34
35         private JPanel noteView () {
36                 notes = new NoteArea(); 
37                 notes.setBackground(Color.white);
38                 notes.setBorder(BorderFactory.createLineBorder(Color.black));
39                 
40                 popup = new JPopupMenu();
41         menuItem = new JMenuItem("Add...");
42         menuItem.addActionListener(this);
43         popup.add(menuItem);
44         menuItem = new JMenuItem("Preferences...");
45         menuItem.addActionListener(this);
46         popup.add(menuItem);
47
48         MouseListener popupListener = new PopupListener();
49         notes.addMouseListener(popupListener);
50                 
51                 return notes;           
52         }
53         
54         public void actionPerformed(ActionEvent e) {
55         JMenuItem source = (JMenuItem)(e.getSource());
56         String s = "Action event detected."
57                    + newline
58                    + "    Event source: " + source.getText();
59      }
60     
61         class NoteArea extends JPanel {
62                 public void RectanglePanel() {
63                         setPreferredSize(new Dimension(20, 20));
64                         
65                 }
66                 
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) {
71                                 int r=0;
72                                 for (r=0;r<200;r=r+20) {
73                                         box = new Rectangle(r,c,20,20);
74                                         g2.setColor(Color.gray);
75                                         g2.draw(box);
76                                 }
77                         }
78                 }
79         }
80         
81         class PopupListener extends MouseAdapter {
82         public void mousePressed(MouseEvent e) {
83             maybeShowPopup(e);
84         }
85
86         public void mouseReleased(MouseEvent e) {
87             maybeShowPopup(e);
88         }
89
90         private void maybeShowPopup(MouseEvent e) {
91             if (e.isPopupTrigger()) {
92                 popup.show(e.getComponent(),
93                            e.getX(), e.getY());
94             }
95         }
96     }
97         
98         private static final int PANEL_WIDTH = 65;
99         private static final int TITLE_HEIGHT = 40;
100         private static final int NOTEVIEW_HEIGHT = 200;
101 }