X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=MooView.java;h=76391f9d20caf3d170c3a90fc29509e7eca5ee92;hb=c83e74facf762222fe4578f175408cc50d360518;hp=620478ca09b8857983b2cba25d4618e1612b21c1;hpb=cd7d6166d73969c1c811ac7153cc6eee59a6a685;p=moosique.git diff --git a/MooView.java b/MooView.java index 620478c..76391f9 100644 --- a/MooView.java +++ b/MooView.java @@ -11,8 +11,6 @@ import java.awt.event.*; public class MooView extends JScrollPane { - private Track[] tracks; - private MooTrackView[] trackViews; private JPanel trackPanel; /** @@ -20,46 +18,51 @@ public class MooView extends JScrollPane { */ public MooView(Track[] tracks) { super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED); - - this.tracks = tracks; - 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]; for (int i = 0; i < tracks.length; i++) { - trackViews[i] = new MooTrackView(tracks[i]); trackPanel.add(new MooTrackView(tracks[i])); } trackPanel.validate(); + validate(); } - public void update(Track[] tracks) { - this.tracks = tracks; - createTrackViews(); + /** + * Calls on each track view to update itself. + */ + public void update() { + Component[] comps = c.getComponents(); + for (int i = 0; i < comps.length; i++) { + ((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) { + 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); + validate(); } } \ No newline at end of file