]> ruin.nu Git - moosique.git/blob - MooView.java
Fixed some bugs
[moosique.git] / MooView.java
1 import javax.sound.midi.*;
2 import javax.swing.*;
3 import java.awt.*;
4 import java.awt.event.*;
5
6 /**
7  * The main view, the container of the track views.
8  * 
9  * @author  Einar Pehrson
10  */
11
12 public class MooView extends JScrollPane {
13
14         private JPanel trackPanel;
15
16         /** 
17          * Creates the main view
18          */
19         public MooView(Track[] tracks) {
20                 super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
21                 trackPanel = new JPanel(new GridLayout(1,3), true);
22                 setTracks(tracks);
23                 setViewportView(trackPanel);
24         }
25
26         /** 
27          * Fills the track panel with track views for all tracks in the current sequence.
28          * @param tracks        the tracks for which to add views
29          */
30         public void setTracks(Track[] tracks) {
31                 trackPanel.removeAll();
32                 ((GridLayout)trackPanel.getLayout()).setColumns(tracks.length);
33                 for (int i = 0; i < tracks.length; i++) {
34                         trackPanel.add(new MooTrackView(tracks[i]));
35                 }
36                 trackPanel.validate();
37                 validate();
38         }
39
40         /** 
41          * Calls on each track view to update itself.
42          */
43         public void update() {
44                 Component[] comps = c.getComponents();
45                 for (int i = 0; i < comps.length; i++) {
46                         ((MooTrackView)comps[i]).update();
47                 }
48         }
49
50         /** 
51          * Creates a view for the given track and adds it to the main view.
52          * @param track         the track for which to add a view
53          * @param index         the index at which to insert the view
54          */
55         public void addTrackView(Track track, int index) {
56                 add(new MooTrackView(track), index);
57                 validate();
58         }
59
60         /** 
61          * Removes the view for the given track.
62          * @param index         the index of the track for which to remove the view
63          */
64         public void removeTrackView(int index) {
65                 remove(index);
66                 validate();
67         }
68 }