This fixes the layout information for JTextFields (and presumably other text components too).

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

        PR 28928
        * javax/swing/plaf/basic/BasicTextUI.java
        (RootView.getPreferredSpan): Default to 10 when there is no
        real view.
        (RootView.getMinimumSpan): Forward to view and default to 10
        when there is no real view.
        (RootView.getMaximumSpan): Return Integer.MAX_VALUE.
        (getMaximumSize): Check for overflow.
        * javax/swing/text/FieldView.java
        (getResizeWeight): Removed unneeded assignment.

/Roman
Index: javax/swing/text/FieldView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/FieldView.java,v
retrieving revision 1.17
diff -u -1 -2 -r1.17 FieldView.java
--- javax/swing/text/FieldView.java	15 May 2006 15:42:47 -0000	1.17
+++ javax/swing/text/FieldView.java	2 Sep 2006 11:28:22 -0000
@@ -36,26 +36,24 @@
 exception statement from your version. */
 
 
 package javax.swing.text;
 
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Rectangle;
 import java.awt.Shape;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 
 import javax.swing.BoundedRangeModel;
 import javax.swing.JTextField;
 import javax.swing.SwingUtilities;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 
 public class FieldView extends PlainView
 {
   BoundedRangeModel horizontalVisibility;
   
@@ -216,25 +214,25 @@
       }
     catch (BadLocationException e)
       {
 	// Should never happen
 	AssertionError ae = new AssertionError();
 	ae.initCause(e);
 	throw ae;
       }
   }
 
   public int getResizeWeight(int axis)
   {
-    return axis = axis == X_AXIS ? 1 : 0;
+    return axis == X_AXIS ? 1 : 0;
   }
   
   public Shape modelToView(int pos, Shape a, Position.Bias bias)
     throws BadLocationException
   {
     Shape newAlloc = adjustAllocation(a);
     return super.modelToView(pos, newAlloc, bias);
   }
   
   public void paint(Graphics g, Shape s)
   {
     if (horizontalVisibility == null)
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.94
diff -u -1 -2 -r1.94 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java	31 Aug 2006 19:25:07 -0000	1.94
+++ javax/swing/plaf/basic/BasicTextUI.java	2 Sep 2006 11:28:23 -0000
@@ -353,40 +353,24 @@
 
     /**
      * Returns the <code>Container</code> that contains this view. This
      * normally will be the text component that is managed by this TextUI.
      *
      * @return the <code>Container</code> that contains this view
      */
     public Container getContainer()
     {
       return textComponent;
     }
 
-    /**
-     * Returns the preferred span along the specified <code>axis</code>.
-     * This is delegated to the real root view.
-     *
-     * @param axis the axis for which the preferred span is queried
-     *
-     * @return the preferred span along the axis
-     */
-    public float getPreferredSpan(int axis)
-    {
-      if (view != null)
-        return view.getPreferredSpan(axis);
-
-      return Integer.MAX_VALUE;
-    }
-
     public void setSize(float w, float h)
     {
       if (view != null)
         view.setSize(w, h);
     }
 
     /**
      * Paints the view. This is delegated to the real root view.
      *
      * @param g the <code>Graphics</code> context to paint to
      * @param s the allocation for the View
      */
@@ -545,24 +529,58 @@
     public Document getDocument()
     {
       return textComponent.getDocument();
     }
 
     /**
      * Returns the attributes, which is null for the RootView.
      */
     public AttributeSet getAttributes()
     {
       return null;
     }
+
+    /**
+     * Overridden to forward to the view.
+     */
+    public float getPreferredSpan(int axis)
+    {
+      // The RI returns 10 in the degenerate case.
+      float span = 10;
+      if (view != null)
+        span = view.getPreferredSpan(axis);
+      return span;
+    }
+
+    /**
+     * Overridden to forward to the real view.
+     */
+    public float getMinimumSpan(int axis)
+    {
+      // The RI returns 10 in the degenerate case.
+      float span = 10;
+      if (view != null)
+        span = view.getMinimumSpan(axis);
+      return span;
+    }
+
+    /**
+     * Overridden to return Integer.MAX_VALUE.
+     */
+    public float getMaximumSpan(int axis)
+    {
+      // The RI returns Integer.MAX_VALUE here, regardless of the real view's
+      // maximum size.
+      return Integer.MAX_VALUE;
+    }
   }
 
   /**
    * The EditorKit used by this TextUI.
    */
   private static EditorKit kit;
 
   /**
    * The combined event handler for text components.
    *
    * This is package private to avoid accessor methods.
    */
@@ -995,42 +1013,43 @@
   /**
    * Returns the maximum size for text components that use this UI.
    *
    * This returns (Integer.MAX_VALUE, Integer.MAX_VALUE).
    *
    * @param c not used here
    *
    * @return the maximum size for text components that use this UI
    */
   public Dimension getMaximumSize(JComponent c)
   {
     Dimension d = new Dimension();
+    Insets i = c.getInsets();
     Document doc = textComponent.getDocument();
     // We need to lock here, since we require the view hierarchy to _not_
     // change in between.
     if (doc instanceof AbstractDocument)
       ((AbstractDocument) doc).readLock();
     try
       {
-        d.width = (int) rootView.getMaximumSpan(View.X_AXIS);
-        d.height = (int) rootView.getMaximumSpan(View.Y_AXIS);
+        // Check for overflow here.
+        d.width = (int) Math.min((long) rootView.getMaximumSpan(View.X_AXIS)
+                                 + i.left + i.right, Integer.MAX_VALUE);
+        d.height = (int) Math.min((long) rootView.getMaximumSpan(View.Y_AXIS)
+                                  + i.top + i.bottom, Integer.MAX_VALUE);
       }
     finally
       {
         if (doc instanceof AbstractDocument)
           ((AbstractDocument) doc).readUnlock();
       }
-    Insets i = c.getInsets();
-    d.width += i.left + i.right;
-    d.height += i.top + i.bottom;
     return d;
   }
 
   /**
    * Returns the minimum size for text components. This returns the size
    * of the component's insets.
    *
    * @return the minimum size for text components
    */
   public Dimension getMinimumSize(JComponent c)
   {
     Dimension d = new Dimension();
@@ -1114,25 +1133,24 @@
     // is a selection because a highlighter can be used to do more than
     // marking selected text.
     if (highlighter != null)
       {
         // Handle restoring of the color here to prevent
         // drawing problems when the Highlighter implementor
         // forgets to restore it.
         Color oldColor = g.getColor();
         highlighter.paint(g);
         g.setColor(oldColor);
       }
       
-
     rootView.paint(g, getVisibleEditorRect());
 
     if (caret != null && textComponent.hasFocus())
       caret.paint(g);
   }
 
   /**
    * Paints the background of the text component.
    *
    * @param g the <code>Graphics</code> context to paint to
    */
   protected void paintBackground(Graphics g)

Reply via email to