]> ruin.nu Git - moosique.git/blob - MooTrackView.java
Changed window size and TrackView generation. Updated Toolbar listeners, and cleaned...
[moosique.git] / MooTrackView.java
1 import javax.swing.*;
2 import java.awt.event.*;
3 import java.awt.*;
4 import javax.sound.midi.*;
5
6 /**
7  * Graphical representation of a MIDI track.
8  * 
9  * @author  Andersson , Andreen, Lanneskog, Pehrson
10  * @version 1
11  */
12  
13 public class MooTrackView extends JPanel implements ActionListener {
14
15         private MooTrackTitle title;
16         private NoteArea notes;
17         private Rectangle box;
18         private JPopupMenu popup;
19         private JMenuItem menuItem;
20         
21         private static final int NOTEVIEW_HEIGHT = 200;
22         
23         public MooTrackView (Track track) {
24                 setLayout(new BorderLayout());
25                 this.setBorder(BorderFactory.createLineBorder(Color.black));
26
27                 title = new MooTrackTitle();
28                 title.setBorder(BorderFactory.createLineBorder(Color.black));
29                 add(title, BorderLayout.NORTH);
30
31                 notes = new NoteArea(); 
32                 notes.setBackground(Color.white);
33                 notes.setBorder(BorderFactory.createLineBorder(Color.black));
34
35                 popup = new JPopupMenu();
36                 menuItem = new JMenuItem("Add...");
37                 menuItem.addActionListener(this);
38                 popup.add(menuItem);
39                 menuItem = new JMenuItem("Preferences...");
40                 menuItem.addActionListener(this);
41                 popup.add(menuItem);
42
43                 notes.addMouseListener(new PopupListener());
44                 add(notes, BorderLayout.CENTER);
45         }
46         
47         public void actionPerformed(ActionEvent e) {}
48     
49         class NoteArea extends JPanel {
50                 public void RectanglePanel() {
51                         setPreferredSize(new Dimension(20, 20));
52                 }
53                 
54                 public void paintComponent(Graphics g) {
55                         super.paintComponent(g);
56                         Graphics2D g2 = (Graphics2D)g;
57                         for (int c = 0; c < 1000; c += 20) {
58                                 int r=0;
59                                 for (r = 0; r < 200; r += 20) {
60                                         box = new Rectangle(r, c, 20, 20);
61                                         g2.setColor(Color.gray);
62                                         g2.draw(box);
63                                 }
64                         }
65                 }
66         }
67         
68         class PopupListener extends MouseAdapter {
69                 public void mousePressed(MouseEvent e) {
70                         maybeShowPopup(e);
71                 }
72         
73                 public void mouseReleased(MouseEvent e) {
74                         maybeShowPopup(e);
75                 }
76         
77                 private void maybeShowPopup(MouseEvent e) {
78                         if (e.isPopupTrigger()) {
79                                 popup.show(e.getComponent(), e.getX(), e.getY());
80                         }
81                 }
82         }
83 }