This fixes some problems with BoxView, makes the Intel testsuite happy and removes one debug output statement that I left in there.

2006-08-10  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/BoxView.java
        (calculateMajorAxisRequirements): Sum up the preferred and
        maximum sizes.
        (isAfter): Also add in the rectangle's with/height.
        (childAllocation): Don't trigger layout here.
        (layoutMinorAxis): Removed debug output.
        (getWidth): Consider the insets.
        (getHeight): Consider the insets.
        (setSize): Consider the insets.
        (updateRequirements): Check axis and throw
        IllegalArgumentException.

/Roman
Index: javax/swing/text/BoxView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/BoxView.java,v
retrieving revision 1.20
diff -u -1 -2 -r1.20 BoxView.java
--- javax/swing/text/BoxView.java	5 Aug 2006 12:13:21 -0000	1.20
+++ javax/swing/text/BoxView.java	10 Aug 2006 22:01:39 -0000
@@ -467,26 +467,26 @@
     if (res == null)
       res = new SizeRequirements();
 
     float min = 0;
     float pref = 0;
     float max = 0;
 
     int n = getViewCount();
     for (int i = 0; i < n; i++)
       {
         View child = getView(i);
         min += child.getMinimumSpan(axis);
-        pref = child.getPreferredSpan(axis);
-        max = child.getMaximumSpan(axis);
+        pref += child.getPreferredSpan(axis);
+        max += child.getMaximumSpan(axis);
       }
 
     res.minimum = (int) min;
     res.preferred = (int) pref;
     res.maximum = (int) max;
     res.alignment = 0.5F;
 
     return res;
   }
 
   /**
    * Calculates the size requirements of this <code>BoxView</code> along
@@ -559,27 +559,27 @@
    * @param x the X coordinate of the point
    * @param y the Y coordinate of the point
    * @param r the rectangle to test the point against
    *
    * @return <code>true</code> if the specified point lies after the
    *         given <code>Rectangle</code>, <code>false</code> otherwise
    */
   protected boolean isAfter(int x, int y, Rectangle r)
   {
     boolean result = false;
 
     if (myAxis == X_AXIS)
-      result = x > r.x;
+      result = x > r.x + r.width;
     else
-      result = y > r.y;
+      result = y > r.y + r.height;
 
     return result;
   }
 
   /**
    * Returns the child <code>View</code> at the specified location.
    *
    * @param x the X coordinate
    * @param y the Y coordinate
    * @param r the inner allocation of this <code>BoxView</code> on entry,
    *        the allocation of the found child on exit
    *
@@ -614,27 +614,24 @@
    * Computes the allocation for a child <code>View</code>. The parameter
    * <code>a</code> stores the allocation of this <code>CompositeView</code>
    * and is then adjusted to hold the allocation of the child view.
    * 
    * @param index
    *          the index of the child <code>View</code>
    * @param a
    *          the allocation of this <code>CompositeView</code> before the
    *          call, the allocation of the child on exit
    */
   protected void childAllocation(int index, Rectangle a)
   {
-    if (! isAllocationValid())
-      layout(a.width, a.height);
-
     a.x += offsets[X_AXIS][index];
     a.y += offsets[Y_AXIS][index];
     a.width = spans[X_AXIS][index];
     a.height = spans[Y_AXIS][index];
   }
 
   /**
    * Lays out the children of this <code>BoxView</code> with the specified
    * bounds.
    *
    * @param width the width of the allocated region for the children (that
    *        is the inner allocation of this <code>BoxView</code>
@@ -767,25 +764,25 @@
    * @param offsets the array that holds the offsets of the children on exit
    * @param spans the array that holds the spans of the children on exit
    */
   protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets,
                                  int[] spans)
   {
     int count = getViewCount();
     for (int i = 0; i < count; i++)
       {
         View child = getView(i);
         int max = (int) child.getMaximumSpan(axis);
         if (max < targetSpan)
-          {System.err.println("align: " + child);
+          {
             // Align child when it can't be made as wide as the target span.
             float align = child.getAlignment(axis);
             offsets[i] = (int) ((targetSpan - max) * align);
             spans[i] = max;
           }
         else
           {
             // Expand child to target width if possible.
             int min = (int) child.getMinimumSpan(axis);
             offsets[i] = 0;
             spans[i] = Math.max(min, targetSpan);
           }
@@ -802,47 +799,48 @@
   protected boolean isAllocationValid()
   {
     return isLayoutValid(X_AXIS) && isLayoutValid(Y_AXIS);
   }
 
   /**
    * Return the current width of the box. This is the last allocated width.
    *
    * @return the current width of the box
    */
   public int getWidth()
   {
-    return span[X_AXIS];
+    return span[X_AXIS] + getLeftInset() - getRightInset();
   }
 
   /**
    * Return the current height of the box. This is the last allocated height.
    *
    * @return the current height of the box
    */
   public int getHeight()
   {
-    return span[Y_AXIS];
+    return span[Y_AXIS] + getTopInset() - getBottomInset();
   }
 
   /**
    * Sets the size of the view. If the actual size has changed, the layout
    * is updated accordingly.
    *
    * @param width the new width
    * @param height the new height
    */
   public void setSize(float width, float height)
   {
-    layout((int) width, (int) height);
+    layout((int) (width - getLeftInset() - getRightInset()),
+           (int) (height - getTopInset() - getBottomInset()));
   }
 
   /**
    * Returns the span for the child view with the given index for the specified
    * axis.
    *
    * @param axis the axis to examine, either <code>X_AXIS</code> or
    *        <code>Y_AXIS</code>
    * @param childIndex the index of the child for for which to return the span
    *
    * @return the span for the child view with the given index for the specified
    *         axis
@@ -1015,24 +1013,26 @@
       }
   }
 
   /**
    * Updates the view's cached requirements along the specified axis if
    * necessary. The requirements are only updated if the layout for the
    * specified axis is marked as invalid.
    *
    * @param axis the axis
    */
   private void updateRequirements(int axis)
   {
+    if (axis != Y_AXIS && axis != X_AXIS)
+      throw new IllegalArgumentException("Illegal axis: " + axis);
     if (! requirementsValid[axis])
       {
         if (axis == myAxis)
           requirements[axis] = calculateMajorAxisRequirements(axis,
                                                            requirements[axis]);
         else
           requirements[axis] = calculateMinorAxisRequirements(axis,
                                                            requirements[axis]);
         requirementsValid[axis] = true;
       }
   }
 }

Reply via email to