+import javax.sound.midi.*;
import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
/**
+ * The main view, the container of the track views.
*
- *
- * @author Andersson, Andreen, Lanneskog, Pehrson
- * @version 1
+ * @author Einar Pehrson
*/
-
-public class MooView {
+
+public class MooView extends JScrollPane {
+
+ private JPanel trackPanel;
+
+ /**
+ * Creates the main view
+ */
+ public MooView(Track[] tracks) {
+ super(VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ trackPanel = new JPanel(new GridLayout(1,3), true);
+ 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
+ */
+ public void setTracks(Track[] tracks) {
+ trackPanel.removeAll();
+ ((GridLayout)trackPanel.getLayout()).setColumns(tracks.length);
+ for (int i = 0; i < tracks.length; i++) {
+ trackPanel.add(new MooTrackView(tracks[i]));
+ }
+ trackPanel.validate();
+ validate();
+ }
/**
- * Creates
+ * Calls on each track view to update itself.
*/
- public MooView () {
+ public void update() {
+ Component[] comps = 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, int index) {
+ add(new MooTrackView(track), index);
+ validate();
+ }
+
+ /**
+ * Removes the view for the given track.
+ * @param index the index of the track for which to remove the view
+ */
+ public void removeTrackView(int index) {
+ remove(index);
+ validate();
}
-}
+}
\ No newline at end of file