+ // Starts filling the track panel with track views, while updating the progress bar.
+ GridLayout gL = new GridLayout(1,numberOfTracks);
+ trackPanel.setLayout(gL);
+ for (int i = 1; i < tracks.length; i++) {
+ if (Moosique.shouldBeDrawn(tracks[i])) {
+ MooTrackTitle title = new MooTrackTitle(tracks[i]);
+ titlePanel.add(title);
+ MooTrackView mtv = new MooTrackView(tracks[i], title);
+ trackPanel.add(mtv);
+ title.setTrackView(mtv);
+ if (showProgress) progressBar.setValue(i);
+ else System.out.print(".");
+ } else {
+ gL.setColumns(--numberOfTracks);
+ trackPanel.setLayout(gL);
+ }
+ }
+ if (showProgress) progressDialog.dispose();
+ }
+/* JPanel filler = new JPanel();
+ int totalViewLength = trackPanel.getComponents().length * MooTrackView.VIEW_WIDTH;
+ if (totalViewLength < getWidth()) {
+ System.out.println("Adding filler since width = " + getWidth() + " and tracks = " + totalViewLength);
+ ((GridLayout)trackPanel.getLayout()).setColumns(numberOfTracks + 1);
+ filler.setPreferredSize(new Dimension(getWidth() - totalViewLength, 140 * MooTrackView.NOTE_HEIGHT));
+ trackPanel.add(filler);
+ setPreferredSize(new Dimension(getWidth(), getHeight()));
+ }
+*/
+ trackPanel.validate();
+ setViewportView(trackPanel);
+ }
+
+ /**
+ * Calls on each track view to update itself.
+ */
+ public void update(long tickPosition) {
+ getViewport().setViewPosition(new Point((int)getViewport().getViewPosition().getX(), (int)(tickPosition / (Moosique.getSequence().getResolution() / 4)) * MooTrackView.NOTE_HEIGHT));
+ }
+
+
+ /**
+ * Creates a view for the given track and adds it to the main view.
+ * @param track the track for which to find the view
+ */
+ public MooTrackView getTrackView(Track track) {
+ for (int i = 0; i < trackPanel.getComponents().length; i++) {
+ MooTrackView mtv = (MooTrackView)(trackPanel.getComponents())[i];
+ if(mtv.getTrack() == track) return mtv;
+ }
+ return null;
+ }
+
+ /**
+ * 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) {
+ ((GridLayout)trackPanel.getLayout()).setColumns(++numberOfTracks);
+ ((GridLayout)titlePanel.getLayout()).setColumns(++numberOfTracks);
+ MooTrackTitle title = new MooTrackTitle(track);
+ titlePanel.add(title, index);
+ trackPanel.add(new MooTrackView(track, title), index);
+ validate();