public class MooView extends JScrollPane {
- private Track[] tracks;
- private MooTrackView[] trackViews;
private JPanel trackPanel;
+ private int numberOfTracks;
/**
* Creates the main view
*/
- public MooView(Sequence seq) {
+ public MooView(Track[] tracks) {
super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
- tracks = seq.getTracks();
-
-
+ numberOfTracks = tracks.length;
trackPanel = new JPanel(new GridLayout(1,3), true);
- createTrackViews();
+ setTracks(tracks);
setViewportView(trackPanel);
}
/**
* Fills the track panel with track views for all tracks in the current sequence.
+ * @param tracks the tracks for which to add views
*/
- private void createTrackViews() {
+ public void setTracks(Track[] tracks) {
trackPanel.removeAll();
- ((GridLayout)trackPanel.getLayout()).setColumns(tracks.length);
- trackViews = new MooTrackView[tracks.length];
+ trackPanel.setLayout(new GridLayout(1,tracks.length));
for (int i = 0; i < tracks.length; i++) {
- trackViews[i] = new MooTrackView(tracks[i]);
trackPanel.add(new MooTrackView(tracks[i]));
}
trackPanel.validate();
}
- public void setSequence(Sequence seq) {
- tracks = seq.getTracks();
- createTrackViews();
- }
-
+ /**
+ * Calls on each track view to update itself.
+ */
public void update() {
- // Calls on each track view to update itself.
- for (int i = 0; i < trackViews.length; i++) {
- //trackViews[i].update();
+ Component[] comps = getComponents();
+ for (int i = 0; i < comps.length; i++) {
+ if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update();
}
}
+
/**
* Creates a view for the given track and adds it to the main view.
* @param track the track for which to add a view
+ * @param index the index at which to insert the view
*/
- public void addTrackView(Track track) {
-
+ public void addTrackView(Track track, int index) {
+ ((GridLayout)trackPanel.getLayout()).setColumns(++numberOfTracks);
+ trackPanel.add(new MooTrackView(track), index);
+ validate();
}
/**
* Removes the view for the given track.
- * @param track the track for which to remove the view
+ * @param index the index of the track for which to remove the view
*/
- public void removeTrackView(Track track) {
-
+ public void removeTrackView(int index) {
+ remove(index);
+ ((GridLayout)trackPanel.getLayout()).setColumns(--numberOfTracks);
+ validate();
}
-}
+}
\ No newline at end of file