Hi,

This patch comes from Caolan McNamara.  It completes our Spring and
SpringLayout implementations.  I committed this on Caolan's behalf.  See
this PR for details:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26606

Tom

2006-03-16  Thomas Fitzsimmons  <[EMAIL PROTECTED]>

        PR classpath/26606
        Commit patch by Caolan McNamara  <[EMAIL PROTECTED]>
        * javax/swing/Spring.java: Complete implementation
        * javax/swing/SpringLayout.java: Likewise.

Index: javax/swing/Spring.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/Spring.java,v
retrieving revision 1.5
diff -u -r1.5 Spring.java
--- javax/swing/Spring.java	4 Mar 2006 20:57:25 -0000	1.5
+++ javax/swing/Spring.java	16 Mar 2006 23:20:10 -0000
@@ -60,7 +60,7 @@
 {
 
   /** Indicates a not-set value. **/
-  public static final int UNSET = -2147483648;
+  public static final int UNSET = Integer.MIN_VALUE;
 
   /**
    * Creates a new Spring object. This constructor is used by the static
@@ -71,6 +71,8 @@
     // Nothing to do here.
   }
 
+  //  protected abstract String springdebug();
+
   /**
    * Creates a Spring which min, pref and max values are all the same.
    * These kind of Springs are 'struts'.
@@ -156,6 +158,33 @@
    */
   public abstract void setValue(int value);
 
+  private int getShrinkRange() 
+  {
+    return (getPreferredValue() - getMinimumValue());
+  }
+
+  private int getExpandRange() 
+  {
+    return (getMaximumValue() - getPreferredValue());
+  }
+
+  double getStrain()
+  {
+    int v = getValue();
+    int p = getPreferredValue();
+    int r = (v < p) ? getShrinkRange() : getExpandRange();
+    if (r == 0)
+      r = 1;
+    return (double)(v - p) / r;
+  }
+
+  void setStrain(double strain) 
+  {
+    int r = (strain < 0) ? getShrinkRange() : getExpandRange();
+    int v = (getPreferredValue() + (int)(strain * r));
+    setValue(v);
+  }
+
   /**
    * Creates and returns a Spring, which is always the sum of s1 and s2.
    * min_sum = min_s1 + min_s2, pref_sum = pref_s1 + pref_s2, max_sum =
@@ -323,6 +352,11 @@
     /** The actual value of the spring. */
     private int value;
 
+//     protected String springdebug()
+//     {
+//         return "SimpleSpring of " + value;
+//     }
+
     /**
      * Creates a new SimpleSpring object.
      *
@@ -335,7 +369,7 @@
       min = newMin;
       pref = newPref;
       max = newMax;
-      value = Spring.UNSET;
+      value = newPref;
     }
 
     /**
@@ -375,12 +409,8 @@
      */
     public int getValue()
     {
-
       if (value == Spring.UNSET)
-        {
-          value = pref;
-        }
-	    
+          return pref;
       return value;
     }
 	
@@ -391,21 +421,8 @@
      */
     public void setValue(int val)
     {
-
-      if (val > max)
-        {
-          value = max;
-	}
-      else if (val < min)
-        {
-          value = min;
-	}
-      else
-        {
-          value = val;
-        }
+      value = val;
     }
-
   }
 
 
@@ -424,6 +441,11 @@
     /** The current value for this Spring. */
     private int value;
 
+//     protected String springdebug()
+//     {
+//         return "AddSpring of " + s1.springdebug() + " and " + s2.springdebug();
+//     }
+
     /**
      * Creates a new AddSpring object.
      *
@@ -497,20 +519,24 @@
      */
     public void setValue(int val)
     {
-
-      if (val > getMaximumValue())
-        {
-          value = getMaximumValue();
-        }
-      else if (val < getMinimumValue())
-        {
-          value = getMinimumValue();
-        }
-      else
+      if (val == Spring.UNSET)
+      {
+        if (value != Spring.UNSET)
         {
-          value = val;
+          s1.setValue(Spring.UNSET);
+          s2.setValue(Spring.UNSET);
         }
+        value = Spring.UNSET;
+        return;
+      }
 
+      value = val;
+
+      //Spead the value over the two components
+      double fStrain = getStrain();
+      s1.setStrain(fStrain);
+      int remainder = val - s1.getValue();
+      s2.setValue(remainder);
     }
 	
   }
@@ -527,8 +553,10 @@
     /** The Spring from which to calculate the negation. */
     private final Spring s;
 
-    /** The current value of this Spring. */
-    private int value;
+//     protected String springdebug()
+//     {
+//         return "MinusSpring of " + s.springdebug();
+//     }
 
     /**
      * Creates a new MinusSpring object.
@@ -538,7 +566,6 @@
     {
       super();
       this.s = s;
-      value = Spring.UNSET;
     }
 
     /** Returns the maximum value of this Spring.
@@ -577,11 +604,7 @@
      */
     public int getValue()
     {
-      if (value == Spring.UNSET)
-        {
-	  value = -s.getValue();
-	}
-      return value;
+      return -s.getValue();
     }
 
     /**
@@ -591,22 +614,11 @@
      */
     public void setValue(int val)
     {
-    
-      if (val > getMaximumValue())
-        {
-          value = getMaximumValue();
-	}
-      else if (val < getMinimumValue())
-	{
-          value = getMinimumValue();
-        }
+      if (val == Spring.UNSET)
+        s.setValue(Spring.UNSET);
       else
-	{
-	  value = val;
-        }
-
+        s.setValue(-val);
     }
-
   }
 
 
@@ -622,6 +634,11 @@
     private final Spring s1;
     private final Spring s2;
 
+//     protected String springdebug()
+//     {
+//         return "MaxSpring of " + s1.springdebug() + " and " + s2.springdebug();
+//     }
+
     /** The current value of this Spring. */
     private int value;
 
@@ -684,7 +701,7 @@
     public int getValue()
     {
       if (value == Spring.UNSET)
-        {
+      {
           int val1 = s1.getValue();
           int val2 = s2.getValue();
           value = Math.max(val1, val2);
@@ -699,19 +716,32 @@
      */
     public void setValue(int val)
     {
-
-      if (val > getMaximumValue())
-        {
-          value = getMaximumValue();
-	}
-      else if (val < getMinimumValue())
-        {
-          value = getMinimumValue();
-        }
-      else
+      if (val == Spring.UNSET)
+      {
+        if (value != Spring.UNSET)
         {
-          value = val;
+          s1.setValue(Spring.UNSET);
+          s2.setValue(Spring.UNSET);
         }
+        value = Spring.UNSET;
+        return;
+      }
+
+      value = val;
+
+      int p1 = s1.getPreferredValue();
+      int p2 = s2.getPreferredValue();
+
+      if (p1 < p2)
+      {
+        s1.setValue(Math.min(val, p1));
+        s2.setValue(val);
+      }
+      else 
+      {
+        s1.setValue(val);
+        s2.setValue(Math.min(val, p2));
+      }
     }
   }
 }
Index: javax/swing/SpringLayout.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/SpringLayout.java,v
retrieving revision 1.8
diff -u -r1.8 SpringLayout.java
--- javax/swing/SpringLayout.java	4 Mar 2006 20:57:25 -0000	1.8
+++ javax/swing/SpringLayout.java	16 Mar 2006 23:20:10 -0000
@@ -110,13 +110,22 @@
     /** The Spring for the bottom edge. */
     private Spring south;
 
+    /** 
+     In each axis the user can set three values, i.e. x, width, east, if all
+     three are set, then there's no room for manoeuvre so in those cases the 
+     third will be described by the below spring which is calculated in terms 
+     of the other two
+    */
+    private Spring v;
+    private Spring h;
+
     /**
      * Creates a new Constraints object.
      * There is no constraint set.
      */
     public Constraints()
     {
-      x = y = height = width = east = south = null;
+      x = y = height = width = east = south = v = h = null;
     }
 
     /**
@@ -129,7 +138,7 @@
     {
       this.x = x;
       this.y = y;
-      width = height = east = south = null;
+      width = height = east = south = v = h = null;
     }
 
     /**
@@ -146,7 +155,7 @@
       this.y = y;
       this.width = width;
       this.height = height;
-      east = south = null;
+      east = south = v = h = null;
     }
 
     /**
@@ -180,22 +189,13 @@
     {
       Spring retVal = null;
       if (edgeName.equals(SpringLayout.NORTH))
-	retVal = y;
+	retVal = getY();
       else if (edgeName.equals(SpringLayout.WEST))
-        retVal = x;
+        retVal = getX();
       else if (edgeName.equals(SpringLayout.SOUTH))
-        {
-          retVal = south;
-	  if ((retVal == null) && (y != null) && (height != null))
-            retVal = Spring.sum(y, height);
-        }
+        retVal = getSouth();
       else if (edgeName.equals(SpringLayout.EAST))
-        {
-          retVal = east;
-          if ((retVal == null) && (x != null) && (width != null))
-            retVal = Spring.sum(x, width);
-	}
-
+        retVal = getEast();
       return retVal;
     }
 
@@ -206,12 +206,11 @@
      */
     public Spring getHeight()
     {
-      Spring retVal = height;
-      if ((retVal == null) && (y != null) && (south != null))
-        {
-          retVal = Spring.sum(south, Spring.minus(y));
-        }
-      return retVal;
+      if (height != null)
+        return height;
+      else if ((v == null) && (y != null) && (south != null))
+          v = Spring.sum(south, Spring.minus(y));
+      return v;
     }
 
     /**
@@ -221,12 +220,11 @@
      */
     public Spring getWidth()
     {
-      Spring retVal = width;
-      if ((retVal == null) && (x != null) && (east != null))
-        {
-          retVal = Spring.sum(east, Spring.minus(x));
-	}
-      return retVal;
+      if (width != null)
+        return width;
+      else if ((h == null) && (x != null) && (east != null))
+        h = Spring.sum(east, Spring.minus(x));
+      return h;
     }
 
     /**
@@ -236,12 +234,11 @@
      */
     public Spring getX()
     {
-      Spring retVal = x;
-      if ((retVal == null) && (width != null) && (east != null))
-        {
-          retVal = Spring.sum(east, Spring.minus(width));
-        }
-      return retVal;
+      if (x != null)
+        return x;
+      else if ((h == null) && (width != null) && (east != null))
+        h = Spring.sum(east, Spring.minus(width));
+      return h;
     }
 
     /**
@@ -251,12 +248,39 @@
      */
     public Spring getY()
     {
-      Spring retVal = y;
-      if ((retVal == null) && (height != null) && (south != null))
-        {
-          retVal = Spring.sum(south, Spring.minus(height));
-        }
-      return retVal;
+      if (y != null)
+        return y;
+      else if ((v == null) && (height != null) && (south != null))
+        v = Spring.sum(south, Spring.minus(height));
+      return v;
+    }
+
+    /**
+     * Returns the constraint for the lower edge of the component.
+     *
+     * @return the lower-edge constraint (== SOUTH).
+     */
+    public Spring getSouth()
+    {
+      if (south != null)
+        return south;
+      else if ((v == null) && (height != null) && (y != null))
+        v = Spring.sum(y, height);
+      return v;
+    }
+
+    /**
+     * Returns the constraint for the right edge of the component.
+     *
+     * @return the right-edge constraint (== EAST).
+     */
+    public Spring getEast()
+    {
+      if (east != null)
+        return east;
+      else if ((h == null) && (width != null) && (x != null))
+        h = Spring.sum(x, width);
+      return h;
     }
 
     /**
@@ -272,29 +296,13 @@
     {
     
       if (edgeName.equals(SpringLayout.WEST))
-        {
-          x = s;
-	  if ((width != null) && (east != null))
-            width = Spring.sum(east, Spring.minus(x));
-        }
+        setX(s);
       else if (edgeName.equals(SpringLayout.NORTH))
-        {
-          y = s;
-          if ((height != null) && (south != null))
-          height = Spring.sum(south, Spring.minus(y));
-        }
+        setY(s);
       else if (edgeName.equals(SpringLayout.EAST))
-        {
-          east = s;
-          if ((x != null) && (width != null))
-            x = Spring.sum(east, Spring.minus(width));
-        }
+        setEast(s);
       else if (edgeName.equals(SpringLayout.SOUTH))
-        {
-          south = s;
-          if ((height != null) && (y != null))
-	    y = Spring.sum(south, Spring.minus(height));
-        }
+        setSouth(s);
 
     }
 
@@ -306,9 +314,9 @@
     public void setHeight(Spring s)
     {
       height = s;
-      if ((south != null) && (y != null))
-        south = Spring.sum(y, height);
-
+      v = null;
+      if ((south != null) && (y != null) && (height != null))
+          south = null;
     }
 
     /**
@@ -319,9 +327,9 @@
     public void setWidth(Spring s)
     {
       width = s;
-      if ((east != null) && (x != null))
-        east = Spring.sum(x, width);
-
+      h = null;
+      if ((east != null) && (x != null) && (width != null))
+        east = null;
     }
 
     /**
@@ -332,9 +340,9 @@
     public void setX(Spring s)
     {
       x = s;
-      if ((width != null) && (east != null))
-        width = Spring.sum(east, Spring.minus(x));
-
+      h = null;
+      if ((width != null) && (east != null) && (x != null))
+        width = null;
     }
 
     /**
@@ -345,9 +353,55 @@
     public void setY(Spring s)
     {
       y = s;
-      if ((height != null) && (south != null))
-        height = Spring.sum(south, Spring.minus(y));
+      v = null;
+      if ((height != null) && (south != null) && (y != null))
+        height = null;
+    }
 
+    /**
+     * Sets the SOUTH-constraint.
+     *
+     * @param s the constraint to be set.
+     */
+    public void setSouth(Spring s)
+    {
+      south = s;
+      v = null;
+      if ((height != null) && (south != null) && (y != null))
+        y = null;
+    }
+
+    /**
+     * Sets the EAST-constraint.
+     *
+     * @param s the constraint to be set.
+     */
+    public void setEast(Spring s)
+    {
+      east = s;
+      h = null;
+      if ((width != null) && (east != null) && (x != null))
+        x = null;
+    }
+
+    public void dropCalcResult()
+    {
+      if (x != null)
+        x.setValue(Spring.UNSET);
+      if (y != null)
+        y.setValue(Spring.UNSET);
+      if (width != null)
+        width.setValue(Spring.UNSET);
+      if (height != null)
+        height.setValue(Spring.UNSET);
+      if (east != null) 
+        east.setValue(Spring.UNSET);
+      if (south != null)
+        south.setValue(Spring.UNSET);
+      if (h != null)
+        h.setValue(Spring.UNSET);
+      if (v != null)
+        v.setValue(Spring.UNSET);
     }
   }
 
@@ -356,7 +410,6 @@
    */
   public SpringLayout()
   {
-
     constraintsMap = new HashMap();
   }
 
@@ -373,7 +426,6 @@
     constraintsMap.put(component, constraint);
   }
 
-
   /**
    * Adds a layout component and a constraint object to this layout.
    * This method is usually only called by a [EMAIL PROTECTED] java.awt.Container}s add
@@ -389,6 +441,158 @@
   }
 
   /**
+   * The trick to SpringLayout is that the network of Springs needs to
+   * completely created before the positioning results are generated.
+   *
+   * Using the springs directly during network creation will set their values 
+   * before the network is completed, Using Deferred Springs during creation of 
+   * the network allows all the edges to be connected together and the network 
+   * to be created without resolving the Springs until their results need to be 
+   * known, at which point the network is complete and the spring addition and 
+   * and substitution calculations will work on a complete and valid network.
+   *
+   * @author Caolan McNamara ([EMAIL PROTECTED])
+   */
+  private static class DeferredSpring extends Spring 
+  {
+    private SpringLayout sl;
+    private String edgeName;
+    private Component c;
+
+//     protected String springdebug()
+//     {
+//         return "DeferredSpring of edge" + edgeName + " of " + "something";
+//     }
+
+    public DeferredSpring(SpringLayout s, String edge, Component component)
+    {
+        sl = s;
+        edgeName = edge;
+        c = component;
+    }
+
+    private Spring resolveSpring() 
+    {
+        return sl.getConstraints(c).getConstraint(edgeName);
+    }
+
+    public int getMaximumValue() 
+    {
+        return resolveSpring().getMaximumValue();
+    }
+
+    public int getMinimumValue() 
+    {
+        return resolveSpring().getMinimumValue();
+    }
+
+    public int getPreferredValue() 
+    {
+        return resolveSpring().getPreferredValue();
+    }
+
+    public int getValue() 
+    {
+        int nRet = resolveSpring().getValue();
+        if (nRet == Spring.UNSET)
+            nRet = getPreferredValue();
+        return nRet;
+    }
+
+    public void setValue(int size) 
+    {
+        resolveSpring().setValue(size);
+    }
+  }
+
+  private static abstract class DeferredDimension extends Spring
+  {
+    private int value;
+
+    public DeferredDimension()
+    {
+      value = Spring.UNSET;
+    }
+
+    public void setValue(int val)
+    {
+      value = val;
+    }
+
+    public int getValue()
+    {
+      if (value == Spring.UNSET)
+          return getPreferredValue();
+      return value;
+    }
+  }
+
+  private static class DeferredWidth extends DeferredDimension
+  {
+    private Component c;
+
+
+    public DeferredWidth(Component component)
+    {
+        c = component;
+    }
+
+//     protected String springdebug()
+//     {
+//         return "DeferredWidth of " + "something";
+//     }
+
+    //clip max to a value we can do meaningful calculation with
+    public int getMaximumValue() 
+    {
+        int widget_width = c.getMaximumSize().width;
+        return Math.min(Short.MAX_VALUE, widget_width);
+    }
+
+    public int getMinimumValue() 
+    {
+        return c.getMinimumSize().width;
+    }
+
+    public int getPreferredValue() 
+    {
+        return c.getPreferredSize().width;
+    }
+  }
+
+  private static class DeferredHeight extends DeferredDimension
+  {
+    private Component c;
+
+//     protected String springdebug()
+//     {
+//         return "DeferredHeight of " + "something";
+//     }
+
+    public DeferredHeight(Component component)
+    {
+        c = component;
+    }
+
+    //clip max to a value we can do meaningful calculations with it
+    public int getMaximumValue() 
+    {
+        int widget_height = c.getMaximumSize().height;
+        return Math.min(Short.MAX_VALUE, widget_height);
+    }
+
+    public int getMinimumValue() 
+    {
+        return c.getMinimumSize().height;
+    }
+
+    public int getPreferredValue() 
+    {
+        return c.getPreferredSize().height;
+    }
+  }
+
+  /**
    * Returns the constraint of the edge named by <code>edgeName</code>.
    *
    * @param c the component from which to get the constraint.
@@ -399,8 +603,7 @@
    */
   public Spring getConstraint(String edgeName, Component c)
   {
-    Constraints constraints = getConstraints(c);
-    return constraints.getConstraint(edgeName);
+    return new DeferredSpring(this, edgeName, c);
   }
 
   /**
@@ -416,28 +619,16 @@
     Constraints constraints = (Constraints) constraintsMap.get(c);
 
     if (constraints == null)
-      {
-        Container parent = c.getParent();
-        constraints = new Constraints();
-
-        if (parent != null)
-          {
-            constraints.setX(Spring.constant(parent.getInsets().left));
-            constraints.setY(Spring.constant(parent.getInsets().top));
-          }
-        else
-          {
-            constraints.setX(Spring.constant(0));
-            constraints.setY(Spring.constant(0));
-          }
-      }
-    constraints.setWidth(Spring.constant(c.getMinimumSize().width,
-                                         c.getPreferredSize().width,
-                                         c.getMaximumSize().width));
-    constraints.setHeight(Spring.constant(c.getMinimumSize().height,
-                                          c.getPreferredSize().height,
-                                          c.getMaximumSize().height));
-    constraintsMap.put(c, constraints);
+    {
+      constraints = new Constraints();
+
+      constraints.setWidth(new DeferredWidth(c));
+      constraints.setHeight(new DeferredHeight(c));
+      constraints.setX(Spring.constant(0));
+      constraints.setY(Spring.constant(0));
+
+      constraintsMap.put(c, constraints);
+    }
 
     return constraints;
   }
@@ -475,6 +666,22 @@
     // nothing to do here yet
   }
 
+  private Constraints initContainer(Container p)
+  {
+    Constraints c = getConstraints(p);
+
+    c.setX(Spring.constant(0));
+    c.setY(Spring.constant(0));
+    c.setWidth(null);
+    c.setHeight(null);
+    if (c.getEast() == null)
+      c.setEast(Spring.constant(0, 0, Integer.MAX_VALUE));
+    if (c.getSouth() == null) 
+      c.setSouth(Spring.constant(0, 0, Integer.MAX_VALUE));
+
+    return c;
+  }
+
   /**
    * Lays out the container <code>p</code>.
    *
@@ -482,28 +689,40 @@
    */
   public void layoutContainer(Container p)
   {
+    java.awt.Insets insets = p.getInsets();
 
-    addLayoutComponent(p, new Constraints(Spring.constant(0),
-                                          Spring.constant(0)));
+    Component[] components = p.getComponents();
+
+    Constraints cs = initContainer(p);
+    cs.dropCalcResult();
+
+    for (int index = 0 ; index < components.length; index++)
+    {
+        Component c = components[index];
+        getConstraints(c).dropCalcResult();
+    }
 
     int offsetX = p.getInsets().left;
     int offsetY = p.getInsets().right;
 
-    Component[] components = p.getComponents();
-    for (int index = 0; index < components.length; index++)
-      {
-        Component c = components[index];
+    cs.getX().setValue(0);
+    cs.getY().setValue(0);
+    cs.getWidth().setValue(p.getWidth() - offsetX - insets.right);
+    cs.getHeight().setValue(p.getHeight() - offsetY - insets.bottom);
 
-        Constraints constraints = getConstraints(c);
-        int x = constraints.getX().getValue();
-        int y = constraints.getY().getValue();
-        int width = constraints.getWidth().getValue();
-        int height = constraints.getHeight().getValue();
-
-        c.setLocation(x + offsetX, y + offsetY);
-        c.setSize(width, height);
-      }
+    for (int index = 0; index < components.length; index++)
+    {
+      Component c = components[index];
 
+      Constraints constraints = getConstraints(c);
+      
+      int x = constraints.getX().getValue();
+      int y = constraints.getY().getValue();
+      int width = constraints.getWidth().getValue();
+      int height = constraints.getHeight().getValue();
+      
+      c.setBounds(x + offsetX, y + offsetY, width, height);
+    }
   }
 
   /**
@@ -515,29 +734,12 @@
    */
   public Dimension maximumLayoutSize(Container p)
   {
-    int maxX = 0;
-    int maxY = 0;
+    java.awt.Insets insets = p.getInsets();
 
-    int offsetX = p.getInsets().left;
-    int offsetY = p.getInsets().right;
+    Constraints cs = initContainer(p);
 
-    Component[] components = p.getComponents();
-    for (int index = 0; index < components.length; index++)
-      {
-        Component c = components[index];
-        Constraints constraints = getConstraints(c);
-        int x = constraints.getX().getMaximumValue();
-        int y = constraints.getY().getMaximumValue();
-        int width = constraints.getWidth().getMaximumValue();
-        int height = constraints.getHeight().getMaximumValue();
-
-        int rightEdge = offsetX + x + width;
-        if (rightEdge > maxX)
-          maxX = rightEdge;
-        int bottomEdge = offsetY + y + height;
-        if (bottomEdge > maxY)
-          maxY = bottomEdge;
-      }
+    int maxX = cs.getWidth().getMaximumValue() + insets.left + insets.right;
+    int maxY = cs.getHeight().getMaximumValue() + insets.top + insets.bottom;
 
     return new Dimension(maxX, maxY);
   }
@@ -552,29 +754,12 @@
    */
   public Dimension minimumLayoutSize(Container p)
   {
-    int maxX = 0;
-    int maxY = 0;
+    java.awt.Insets insets = p.getInsets();
 
-    int offsetX = p.getInsets().left;
-    int offsetY = p.getInsets().right;
+    Constraints cs = initContainer(p);
 
-    Component[] components = p.getComponents();
-    for (int index = 0; index < components.length; index++)
-      {
-        Component c = components[index];
-        Constraints constraints = getConstraints(c);
-        int x = constraints.getX().getMinimumValue();
-        int y = constraints.getY().getMinimumValue();
-        int width = constraints.getWidth().getMinimumValue();
-        int height = constraints.getHeight().getMinimumValue();
-
-        int rightEdge = offsetX + x + width;
-        if (rightEdge > maxX)
-          maxX = rightEdge;
-        int bottomEdge = offsetY + y + height;
-        if (bottomEdge > maxY)
-          maxY = bottomEdge;
-      }
+    int maxX = cs.getWidth().getMinimumValue() + insets.left + insets.right;
+    int maxY = cs.getHeight().getMinimumValue() + insets.top + insets.bottom;
 
     return new Dimension(maxX, maxY);
   }
@@ -588,29 +773,13 @@
    */
   public Dimension preferredLayoutSize(Container p)
   {
-    int maxX = 0;
-    int maxY = 0;
+    java.awt.Insets insets = p.getInsets();
 
-    int offsetX = p.getInsets().left;
-    int offsetY = p.getInsets().right;
+    Constraints cs = initContainer(p);
+
+    int maxX = cs.getWidth().getPreferredValue() + insets.left + insets.right;
+    int maxY = cs.getHeight().getPreferredValue() + insets.top + insets.bottom;
 
-    Component[] components = p.getComponents();
-    for (int index = 0; index < components.length; index++)
-      {
-        Component c = components[index];
-        Constraints constraints = getConstraints(c);
-        int x = constraints.getX().getPreferredValue();
-        int y = constraints.getY().getPreferredValue();
-        int width = constraints.getWidth().getPreferredValue();
-        int height = constraints.getHeight().getPreferredValue();
-
-        int rightEdge = offsetX + x + width;
-        if (rightEdge > maxX)
-          maxX = rightEdge;
-        int bottomEdge = offsetY + y + height;
-        if (bottomEdge > maxY)
-          maxY = bottomEdge;
-      }
     return new Dimension(maxX, maxY);
   }
 
@@ -628,12 +797,7 @@
   public void putConstraint(String e1, Component c1, int pad, String e2, 
                             Component c2)
   {
-    Constraints constraints1 = getConstraints(c1);
-    Constraints constraints2 = getConstraints(c2);
-
-    Spring strut = Spring.constant(pad);
-    Spring otherEdge = constraints2.getConstraint(e2);
-    constraints1.setConstraint(e1, Spring.sum(strut, otherEdge));
+    putConstraint(e1, c1, Spring.constant(pad), e2, c2);
   }
 
   /**
@@ -651,9 +815,8 @@
                             Component c2)
   {
     Constraints constraints1 = getConstraints(c1);
-    Constraints constraints2 = getConstraints(c2);
 
-    Spring otherEdge = constraints2.getConstraint(e2);
+    Spring otherEdge = getConstraint(e2, c2);
     constraints1.setConstraint(e1, Spring.sum(s, otherEdge));
 
   }

Reply via email to