These fixes let all the MetalScrollBarUI/BasicScrollBarUI Mauve tests
PASS.

2006-02-28  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicScrollBarUI.java
        (getPreferredSize): Fixed add a fixed space between the buttons
        instead of something related to min/max.
        (installComponents): Create and install buttons here.
        (installDefaults): Don't create buttons here.
        * javax/swing/plaf/metal/MetalScrollBarUI.java
        (getMinimumThumbSize): Return (0,0) when UI is not yet installed.
        (getPreferredSize): New method.

/Roman
Index: javax/swing/plaf/basic/BasicScrollBarUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java,v
retrieving revision 1.30
diff -u -r1.30 BasicScrollBarUI.java
--- javax/swing/plaf/basic/BasicScrollBarUI.java	15 Nov 2005 20:32:46 -0000	1.30
+++ javax/swing/plaf/basic/BasicScrollBarUI.java	28 Feb 2006 22:25:00 -0000
@@ -653,19 +653,17 @@
 
     if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
       {
-	width += incrButton.getPreferredSize().getWidth();
-	width += decrButton.getPreferredSize().getWidth();
-
-	width += (scrollbar.getMaximum() - scrollbar.getMinimum());
-	height = UIManager.getInt("ScrollBar.width");
+        width += incrButton.getPreferredSize().getWidth();
+        width += decrButton.getPreferredSize().getWidth();
+        width += 16;
+        height = UIManager.getInt("ScrollBar.width");
       }
     else
       {
-	height += incrButton.getPreferredSize().getHeight();
-	height += decrButton.getPreferredSize().getHeight();
-
-	height += (scrollbar.getMaximum() - scrollbar.getMinimum());
-	width = UIManager.getInt("ScrollBar.width");
+        height += incrButton.getPreferredSize().getHeight();
+        height += decrButton.getPreferredSize().getHeight();
+        height += 16;
+        width = UIManager.getInt("ScrollBar.width");
       }
 
     Insets insets = scrollbar.getInsets();
@@ -721,18 +719,6 @@
    */
   protected void installComponents()
   {
-    if (incrButton != null)
-      scrollbar.add(incrButton);
-    if (decrButton != null)
-      scrollbar.add(decrButton);
-  }
-
-  /**
-   * This method installs the defaults for the scrollbar specified by the
-   * Basic Look and Feel.
-   */
-  protected void installDefaults()
-  {
     int orientation = scrollbar.getOrientation();
     switch (orientation)
       {
@@ -746,6 +732,18 @@
         break;
       }
 
+    if (incrButton != null)
+      scrollbar.add(incrButton);
+    if (decrButton != null)
+      scrollbar.add(decrButton);
+  }
+
+  /**
+   * This method installs the defaults for the scrollbar specified by the
+   * Basic Look and Feel.
+   */
+  protected void installDefaults()
+  {
     LookAndFeel.installColors(scrollbar, "ScrollBar.background",
                               "ScrollBar.foreground");
     LookAndFeel.installBorder(scrollbar, "ScrollBar.border");
Index: javax/swing/plaf/metal/MetalScrollBarUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java,v
retrieving revision 1.12
diff -u -r1.12 MetalScrollBarUI.java
--- javax/swing/plaf/metal/MetalScrollBarUI.java	15 Nov 2005 20:51:37 -0000	1.12
+++ javax/swing/plaf/metal/MetalScrollBarUI.java	28 Feb 2006 22:25:00 -0000
@@ -41,6 +41,7 @@
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics;
+import java.awt.Insets;
 import java.awt.Rectangle;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
@@ -48,6 +49,7 @@
 import javax.swing.JButton;
 import javax.swing.JComponent;
 import javax.swing.JScrollBar;
+import javax.swing.SwingConstants;
 import javax.swing.UIManager;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicScrollBarUI;
@@ -465,11 +467,60 @@
    */
   protected Dimension getMinimumThumbSize()
   {
-    if (isFreeStanding)
-      return MIN_THUMB_SIZE_FREE_STANDING;
+    Dimension retVal;
+    if (scrollbar != null)
+      {
+        if (isFreeStanding)
+          retVal = MIN_THUMB_SIZE_FREE_STANDING;
+        else
+          retVal = MIN_THUMB_SIZE;
+      }
     else
-      return MIN_THUMB_SIZE;
+      retVal = new Dimension(0, 0);
+    return retVal;
   }
-  
+
+  /**
+   * Returns the <code>preferredSize</code> for the specified scroll bar.
+   * For a vertical scrollbar the height is the sum of the preferred heights
+   * of the buttons plus <code>30</code>. The width is fetched from the
+   * <code>UIManager</code> property <code>ScrollBar.width</code>.
+   *
+   * For horizontal scrollbars the width is the sum of the preferred widths
+   * of the buttons plus <code>30</code>. The height is fetched from the
+   * <code>UIManager</code> property <code>ScrollBar.height</code>.
+   *
+   * @param c the scrollbar for which to calculate the preferred size
+   *
+   * @return the <code>preferredSize</code> for the specified scroll bar
+   */
+  public Dimension getPreferredSize(JComponent c)
+  {
+    int height;
+    int width;
+    height = width = 0;
+
+    if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
+      {
+        width += incrButton.getPreferredSize().getWidth();
+        width += decrButton.getPreferredSize().getWidth();
+        width += 30;
+        height = UIManager.getInt("ScrollBar.width");
+      }
+    else
+      {
+        height += incrButton.getPreferredSize().getHeight();
+        height += decrButton.getPreferredSize().getHeight();
+        height += 30;
+        width = UIManager.getInt("ScrollBar.width");
+      }
+
+    Insets insets = scrollbar.getInsets();
+
+    height += insets.top + insets.bottom;
+    width += insets.left + insets.right;
+
+    return new Dimension(width, height);
+  } 
 }
 

Reply via email to