1 import javax.sound.midi.*;
4 import java.awt.event.*;
7 * The main view, the container of the track views.
9 * @author Einar Pehrson
12 public class MooView extends JScrollPane {
14 private JPanel trackPanel;
15 private int numberOfTracks;
18 * Creates the main view
20 public MooView(Track[] tracks) {
21 super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
22 numberOfTracks = tracks.length;
23 trackPanel = new JPanel(new GridLayout(1,3), true);
25 setViewportView(trackPanel);
29 * Fills the track panel with track views for all tracks in the current sequence.
30 * @param tracks the tracks for which to add views
32 public void setTracks(Track[] tracks) {
33 trackPanel.removeAll();
34 trackPanel.setLayout(new GridLayout(1,tracks.length));
35 for (int i = 0; i < tracks.length; i++) {
36 trackPanel.add(new MooTrackView(tracks[i]));
38 trackPanel.validate();
42 * Calls on each track view to update itself.
44 public void update() {
45 Component[] comps = getComponents();
46 for (int i = 0; i < comps.length; i++) {
47 if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update();
52 * Creates a view for the given track and adds it to the main view.
53 * @param track the track for which to add a view
54 * @param index the index at which to insert the view
56 public void addTrackView(Track track, int index) {
57 ((GridLayout)trackPanel.getLayout()).setColumns(++numberOfTracks);
58 trackPanel.add(new MooTrackView(track), index);
63 * Removes the view for the given track.
64 * @param index the index of the track for which to remove the view
66 public void removeTrackView(int index) {
68 ((GridLayout)trackPanel.getLayout()).setColumns(--numberOfTracks);