This fixes a minor issue in BlockView and cleans up some code.

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

        * javax/swing/text/html/BlockView.java
        (cssHeight): Removed.
        (cssWidth): Removed.
        (cssSpans): New field. Replaces the two fields above.
        (BlockView): Allocate cssSpans array.
        (layoutMinorAxis): Fetch and use child span, not this view's span.
        (setCSSSpan): Adjusted to use cssSpans array.
        (setPropertiesFromAttributes): Adjusted to use cssSpans array.

/Roman

Index: javax/swing/text/html/BlockView.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/BlockView.java,v
retrieving revision 1.4
diff -u -1 -5 -r1.4 BlockView.java
--- javax/swing/text/html/BlockView.java	5 Nov 2006 20:23:12 -0000	1.4
+++ javax/swing/text/html/BlockView.java	9 Nov 2006 16:39:11 -0000
@@ -57,49 +57,47 @@
  */
 public class BlockView extends BoxView
 {
 
   /**
    * The attributes for this view.
    */
   private AttributeSet attributes;
 
   /**
    * The box painter for this view.
    */
   private StyleSheet.BoxPainter painter;
 
   /**
-   * The width as specified in the stylesheet, null if not specified.
+   * The width and height as specified in the stylesheet, null if not
+   * specified. The first value is the X_AXIS, the second the Y_AXIS. You
+   * can index this directly by the X_AXIS and Y_AXIS constants.
    */
-  private Length cssWidth;
-
-  /**
-   * The height as specified in the stylesheet, null if not specified.
-   */
-  private Length cssHeight;
+  private Length[] cssSpans;
 
   /**
    * Creates a new view that represents an html box. 
    * This can be used for a number of elements.
    * 
    * @param elem - the element to create a view for
    * @param axis - either View.X_AXIS or View.Y_AXIS
    */
   public BlockView(Element elem, int axis)
   {
     super(elem, axis);
+    cssSpans = new Length[2];
   }
 
   /**
    * Creates the parent view for this. It is called before
    * any other methods, if the parent view is working properly.
    * Implemented to forward to the superclass and call
    * setPropertiesFromAttributes to set the paragraph 
    * properties.
    * 
    * @param parent - the new parent, or null if the view
    * is being removed from a parent it was added to. 
    */
   public void setParent(View parent)
   {
     super.setParent(parent);
@@ -129,31 +127,31 @@
         // If we have set the span from CSS, then we need to adjust
         // the margins.
         SizeRequirements parent = super.calculateMajorAxisRequirements(axis,
                                                                        null);
         int margin = axis == X_AXIS ? getLeftInset() + getRightInset()
                                     : getTopInset() + getBottomInset();
         r.minimum -= margin;
         r.preferred -= margin;
         r.maximum -= margin;
         constrainSize(axis, r, parent);
       }
     else
       r = super.calculateMajorAxisRequirements(axis, r);
     return r;
   }
-  
+
   /**
    * Calculates the requirements along the minor axis.
    * This is implemented to call the superclass and then
    * adjust it if the CSS width or height attribute is specified
    * and applicable.
    * 
    * @param axis - the axis to check the requirements for.
    * @param r - the SizeRequirements. If null, one is created.
    * @return the new SizeRequirements object.
    */
   protected SizeRequirements calculateMinorAxisRequirements(int axis,
                                                             SizeRequirements r)
   {
     if (r == null)
       r = new SizeRequirements();
@@ -177,49 +175,40 @@
   }
 
   /**
    * Sets the span on the SizeRequirements object according to the
    * according CSS span value, when it is set.
    * 
    * @param r the size requirements
    * @param axis the axis
    *
    * @return <code>true</code> when the CSS span has been set,
    *         <code>false</code> otherwise
    */
   private boolean setCSSSpan(SizeRequirements r, int axis)
   {
     boolean ret = false;
-    if (axis == X_AXIS)
+    Length span = cssSpans[axis];
+    // We can't set relative CSS spans here because we don't know
+    // yet about the allocated span. Instead we use the view's
+    // normal requirements.
+    if (span != null && ! span.isPercentage())
       {
-        if (cssWidth != null && ! cssWidth.isPercentage())
-          {
-            r.minimum = (int) cssWidth.getValue();
-            r.preferred = (int) cssWidth.getValue();
-            r.maximum = (int) cssWidth.getValue();
-            ret = true;
-          }
-      }
-    else
-      {
-        if (cssHeight != null && ! cssWidth.isPercentage())
-          {
-            r.minimum = (int) cssHeight.getValue();
-            r.preferred = (int) cssHeight.getValue();
-            r.maximum = (int) cssHeight.getValue();
-            ret = true;
-          }
+        r.minimum = (int) span.getValue();
+        r.preferred = (int) span.getValue();
+        r.maximum = (int) span.getValue();
+        ret = true;
       }
     return ret;
   }
 
   /**
    * Constrains the <code>r</code> requirements according to
    * <code>min</code>.
    *
    * @param axis the axis
    * @param r the requirements to constrain
    * @param min the constraining requirements
    */
   private void constrainSize(int axis, SizeRequirements r,
                              SizeRequirements min)
   {
@@ -238,60 +227,63 @@
    * the allocations to the children along the minor axis.
    * 
    * @param targetSpan - the total span given to the view, also 
    * used to layout the children.
    * @param axis - the minor axis
    * @param offsets - the offsets from the origin of the view for
    * all the child views. This is a return value and is filled in by this
    * function.
    * @param spans - the span of each child view. This is a return value and is 
    * filled in by this function.
    */
   protected void layoutMinorAxis(int targetSpan, int axis,
                                  int[] offsets, int[] spans)
   {
     int viewCount = getViewCount();
-    Length length = axis == X_AXIS ? cssWidth : cssHeight;
+    CSS.Attribute spanAtt = axis == X_AXIS ? CSS.Attribute.WIDTH
+                                           : CSS.Attribute.HEIGHT;
     for (int i = 0; i < viewCount; i++)
       {
         View view = getView(i);
         int min = (int) view.getMinimumSpan(axis);
         int max;
-        // Handle percentage span value.
-        if (length != null && length.isPercentage())
+        // Handle CSS span value of child.
+        AttributeSet atts = view.getAttributes();
+        Length length = (Length) atts.getAttribute(spanAtt);
+        if (length != null)
           {
             min = Math.max((int) length.getValue(targetSpan), min);
             max = min;
           }
         else
           max = (int) view.getMaximumSpan(axis);
 
         if (max < targetSpan)
           {
             // Align child.
             float align = view.getAlignment(axis);
             offsets[i] = (int) ((targetSpan - max) * align);
             spans[i] = max;
           }
         else
           {
             offsets[i] = 0;
             spans[i] = Math.max(min, targetSpan);
           }
       }
   }
-  
+
   /**
    * Paints using the given graphics configuration and shape.
    * This delegates to the css box painter to paint the
    * border and background prior to the interior.
    * 
    * @param g - Graphics configuration
    * @param a - the Shape to render into.
    */
   public void paint(Graphics g, Shape a)
   {
     Rectangle rect = a instanceof Rectangle ? (Rectangle) a : a.getBounds();
     painter.paint(g, rect.x, rect.y, rect.width, rect.height, this);
     super.paint(g, a);
   }
   
@@ -426,30 +418,30 @@
     attributes = ss.getViewAttributes(this);
 
     // Fetch painter.
     painter = ss.getBoxPainter(attributes);
 
     // Update insets.
     if (attributes != null)
       {
         setInsets((short) painter.getInset(TOP, this),
                   (short) painter.getInset(LEFT, this),
                   (short) painter.getInset(BOTTOM, this),
                   (short) painter.getInset(RIGHT, this));
       }
 
     // Fetch width and height.
-    cssWidth = (Length) attributes.getAttribute(CSS.Attribute.WIDTH);
-    cssHeight = (Length) attributes.getAttribute(CSS.Attribute.HEIGHT);
+    cssSpans[X_AXIS] = (Length) attributes.getAttribute(CSS.Attribute.WIDTH);
+    cssSpans[Y_AXIS] = (Length) attributes.getAttribute(CSS.Attribute.HEIGHT);
   }
-  
+
   /**
    * Gets the default style sheet.
    * 
    * @return the style sheet
    */
   protected StyleSheet getStyleSheet()
   {
     HTMLDocument doc = (HTMLDocument) getDocument();
     return doc.getStyleSheet();
   }
 }

Reply via email to