]> ruin.nu Git - moosique.git/blob - MooTrackView.java
vad sägs om bordern?
[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         private String newline = "\n";
21         
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);
27         }
28         
29         private JPanel trackTitle () {
30                 title = new MooTrackTitle();
31                 title.setPreferredSize(new Dimension(PANEL_WIDTH, TITLE_HEIGHT));
32                 title.setBorder(BorderFactory.createLineBorder(Color.black));
33                 return title;
34         }
35
36         private JPanel noteView () {
37                 notes = new NoteArea(); 
38                 notes.setBackground(Color.white);
39                 notes.setBorder(BorderFactory.createLineBorder(Color.black));
40                 
41                 popup = new JPopupMenu();
42         menuItem = new JMenuItem("Add...");
43         menuItem.addActionListener(this);
44         popup.add(menuItem);
45         menuItem = new JMenuItem("Preferences...");
46         menuItem.addActionListener(this);
47         popup.add(menuItem);
48
49         MouseListener popupListener = new PopupListener();
50         notes.addMouseListener(popupListener);
51                 
52                 return notes;           
53         }
54         
55         public void actionPerformed(ActionEvent e) {
56         JMenuItem source = (JMenuItem)(e.getSource());
57         String s = "Action event detected."
58                    + newline
59                    + "    Event source: " + source.getText();
60      }
61     
62         class NoteArea extends JPanel {
63                 public void RectanglePanel() {
64                         setPreferredSize(new Dimension(20, 20));
65                         
66                 }
67                 
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) {
72                                 int r=0;
73                                 for (r=0;r<200;r=r+20) {
74                                         box = new Rectangle(r,c,20,20);
75                                         g2.setColor(Color.gray);
76                                         g2.draw(box);
77                                 }
78                         }
79                 }
80         }
81         
82         class PopupListener extends MouseAdapter {
83         public void mousePressed(MouseEvent e) {
84             maybeShowPopup(e);
85         }
86
87         public void mouseReleased(MouseEvent e) {
88             maybeShowPopup(e);
89         }
90
91         private void maybeShowPopup(MouseEvent e) {
92             if (e.isPopupTrigger()) {
93                 popup.show(e.getComponent(),
94                            e.getX(), e.getY());
95             }
96         }
97     }
98         
99         private static final int PANEL_WIDTH = 60;
100         private static final int TITLE_HEIGHT = 55;
101         private static final int NOTEVIEW_HEIGHT = 200;
102 }