]> ruin.nu Git - moosique.git/blobdiff - MooView.java
*** empty log message ***
[moosique.git] / MooView.java
index 9ee52b3636abd882686e27658e3f4193c12fd10f..ca9d68db48ad49fb5fa0732489532a92b2bb512e 100644 (file)
@@ -2,6 +2,7 @@ import javax.sound.midi.*;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
+import java.beans.*;
 
 /**
  * The main view, the container of the track views.
@@ -9,31 +10,26 @@ import java.awt.event.*;
  * @author  Einar Pehrson
  */
 
-public class MooView extends JPanel {
+public class MooView extends JScrollPane {
 
        private JPanel trackPanel;
        private JPanel titlePanel;
        private int numberOfTracks;
-       private JScrollPane trackViews;
-       private JScrollPane trackTitles;
 
        /** 
         * Creates the main view
         */
        public MooView(Track[] tracks) {
-               trackViews = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+               super(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                trackPanel = new JPanel(new GridLayout(1,3), true);
-               trackViews.setViewportView(trackPanel);
+               setViewportView(trackPanel);
 
-               trackTitles = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                titlePanel = new JPanel(new GridLayout(1,3),true);
-               trackTitles.setViewportView(titlePanel);
 
-               numberOfTracks = tracks.length;
+               JViewport columnHeader = new JViewport();
+               columnHeader.setView(titlePanel);
+               setColumnHeaderView(columnHeader);
                setTracks(tracks);
-               setLayout(new BorderLayout());
-               add(trackTitles, BorderLayout.NORTH);
-               add(trackViews, BorderLayout.CENTER);
        }
 
        /** 
@@ -41,7 +37,8 @@ public class MooView extends JPanel {
         * @param tracks        the tracks for which to add views
         */
        public void setTracks(Track[] tracks) {
-               if (tracks.length == 1) {
+               numberOfTracks = tracks.length;
+               if (numberOfTracks == 1) {
                        // If MIDI file is of type 0, creates a view for the track.
                        trackPanel.add(new MooTrackView(tracks[0]));
                        titlePanel.add(new MooTrackTitle(tracks[0]));
@@ -58,7 +55,7 @@ public class MooView extends JPanel {
        
                        // Starts filling the track panel with track views, while updating the progress bar.
                        trackPanel.removeAll();
-                       trackPanel.setLayout(new GridLayout(1,tracks.length));
+                       trackPanel.setLayout(new GridLayout(1,numberOfTracks));
                        for (int i = 1; i < tracks.length; i++) {
                                trackPanel.add(new MooTrackView(tracks[i]));
                                titlePanel.add(new MooTrackTitle(tracks[i]));
@@ -66,17 +63,27 @@ public class MooView extends JPanel {
                        }
                        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();
-               trackViews.setViewportView(trackPanel);
+               setViewportView(trackPanel);
        }
 
        /** 
         * Calls on each track view to update itself.
         */
-       public void update() {
+       public void update(long tickPosition) {
                Component[] comps = getComponents();
                for (int i = 0; i < comps.length; i++) {
-                       if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update();
+                       if(comps[i] instanceof MooTrackView) ((MooTrackView)comps[i]).update(tickPosition);
                }
        }