]> ruin.nu Git - moosique.git/commitdiff
FIXED THE MULTICOLUMN BUG!!!
authorEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 00:14:07 +0000 (00:14 +0000)
committerEinar Pehrson <einarp@itstud.chalmers.se>
Tue, 13 May 2003 00:14:07 +0000 (00:14 +0000)
How? findComponentAt(x,y) couldn't return Containers, i.e. ALL JComponents.
Instead, stored coordinates of all placed panels, and checked for intersections.

Added a progress indicator for loading files. Kinda nice.

MooTrackView.java
MooView.java

index 864ed07b2fe6a30a4431d12084973ac9399ace09..5efb00238f5366180076fcc8b65a48d83b431a70 100644 (file)
@@ -2,6 +2,7 @@ import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import javax.sound.midi.*;
+import java.util.*;
 
 /**
  * Graphical representation of a MIDI track.
@@ -65,6 +66,7 @@ public class MooTrackView extends JPanel implements ActionListener {
                public static final int NOTE_HEIGHT = 10;
                public static final int NOTE_WIDTH = 40;
                private int trackLength;
+               private ArrayList rects;
 
                public NoteArea(Track track) {
                        // Configuring panel
@@ -72,10 +74,11 @@ public class MooTrackView extends JPanel implements ActionListener {
                        trackLength = 140;
                        setPreferredSize(new Dimension(200, 140 * NOTE_HEIGHT));
 
-                       // Temporary variables
+                       // Creating temporary variables
                        MidiEvent note;
                        MooNoteElement elem;
                        int x, y, height;
+                       rects = new ArrayList(track.size() / 2);
 
                        // Placing note elements
                        Insets insets = getInsets();
@@ -90,17 +93,29 @@ public class MooTrackView extends JPanel implements ActionListener {
                                        // Moves the note element to the appropriate place.
                                        x = insets.left;
                                        y = insets.top + (int)(mn.getTick() / 24) * NOTE_HEIGHT;
-                                       height = (mn.getDuration() / 24) * NOTE_HEIGHT;
-                                       if (height == 0) height = NOTE_HEIGHT;
-                                       while(findComponentAt(x, y) instanceof MooNoteElement ||
-                                             findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
-                                       elem.setBounds(x, y, NOTE_WIDTH, height);
+                                       height = NOTE_HEIGHT;
+                                       // height = (mn.getDuration() / 24) * NOTE_HEIGHT;
+                                       Rectangle r = new Rectangle(x, y, NOTE_WIDTH, height);
+                                       while(isOccupied(r)) r.translate(NOTE_WIDTH, 0);
+                                       elem.setBounds(r);
+                                       rects.add(r);
                                        if (viewLength < (y + height)) viewLength = y + height;
+
+                                       // while(findComponentAt(x, y) instanceof MooNoteElement ||
+                                       //       findComponentAt(x, y + height - 1) instanceof MooNoteElement) x += NOTE_WIDTH;
                                }
-                               setPreferredSize(new Dimension(200,viewLength));
+                               setPreferredSize(new Dimension(200, viewLength));
                        }
                        validate();
                }
+               
+               private boolean isOccupied(Rectangle r) {
+                       Iterator it = rects.iterator();
+                       while (it.hasNext()) {
+                               if(r.intersects((Rectangle)it.next())) return true;
+                       }
+                       return false;
+               }
 
                public void paintComponent(Graphics g) {
                        super.paintComponent(g);
@@ -130,4 +145,4 @@ public class MooTrackView extends JPanel implements ActionListener {
                        }
                }
        }
-}
+}
\ No newline at end of file
index 1155b7a36fe52ab788ccd385ecb5e33e57c54deb..9ee52b3636abd882686e27658e3f4193c12fd10f 100644 (file)
@@ -47,7 +47,7 @@ public class MooView extends JPanel {
                        titlePanel.add(new MooTrackTitle(tracks[0]));
                } else {
                        // Creates dialog for progress bar.
-                       JDialog progressDialog = new JDialog(Moosique.getGUI(), "Visualizing MIDI file...", false);
+                       JDialog progressDialog = new JDialog(Moosique.getGUI(), "Visualizing...", false);
                        JProgressBar progressBar = new JProgressBar(0, tracks.length);
                        progressBar.setValue(0);
                        progressBar.setStringPainted(true);
@@ -67,6 +67,7 @@ public class MooView extends JPanel {
                        progressDialog.dispose();
                }
                trackPanel.validate();
+               trackViews.setViewportView(trackPanel);
        }
 
        /**