harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r440748 [22/25] - in /incubator/harmony/enhanced/classlib/trunk/modules: accessibility/src/main/java/javax/accessibility/ awt/ awt/make/ awt/src/main/java/common/java/awt/ awt/src/main/java/common/java/awt/datatransfer/ awt/src/main/java/co...
Date Wed, 06 Sep 2006 16:06:30 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Spring.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Spring.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Spring.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Spring.java Wed Sep  6 09:06:15 2006
@@ -23,33 +23,20 @@
 
 public abstract class Spring {
 
-    static final class ConstantSpring extends Spring {
-        private final int minValue;
-        private final int prefValue;
-        private final int maxValue;
-        private int value;
-
-        private ConstantSpring(final int pref) {
-            this(pref, pref, pref);
-        }
-
-        private ConstantSpring(final int min, final int pref, final int max) {
-            this.maxValue = trim(max);
-            this.minValue = trim(min);
-            this.prefValue = trim(pref);
-            value = pref;
-        }
+    static final class HeightSpring extends Spring {
+        final Component component;
+        private int value = Spring.UNSET;
 
         public int getMinimumValue() {
-            return minValue;
+            return trim(component.getMinimumSize().height);
         }
 
         public int getPreferredValue() {
-            return prefValue;
+            return trim(component.getPreferredSize().height);
         }
 
         public int getMaximumValue() {
-            return maxValue;
+            return trim(component.getMaximumSize().height);
         }
 
         public int getValue() {
@@ -61,18 +48,20 @@
         }
 
         public String toString() {
-            return "[" + minValue + ", " + prefValue + ", " + maxValue + "]";
+            return "[Height of " + component.getClass().getName() + ": ("
+                   + getMinimumValue() + ", " + getPreferredValue() + ", "
+                   + getMaximumValue() + ")]";
+        }
+
+        private HeightSpring(final Component component) {
+            this.component = component;
         }
     }
 
     static final class WidthSpring extends Spring {
-        private final Component component;
+        final Component component;
         private int value = Spring.UNSET;
 
-        private WidthSpring(final Component component) {
-            this.component = component;
-        }
-
         public int getMinimumValue() {
             return trim(component.getMinimumSize().width);
         }
@@ -94,30 +83,33 @@
         }
 
         public String toString() {
-            return "Width of " + component.getClass().getName() + ": ["
+            return "[Width of " + component.getClass().getName() + ": ("
                    + getMinimumValue() + ", " + getPreferredValue() + ", "
-                   + getMaximumValue() + "]";
+                   + getMaximumValue() + ")]";
         }
-    }
-
-    static final class HeightSpring extends Spring {
-        private final Component component;
-        private int value = Spring.UNSET;
 
-        private HeightSpring(final Component component) {
+        private WidthSpring(final Component component) {
             this.component = component;
         }
+    }
+
+
+    private static final class ConstantSpring extends Spring {
+        private final int minValue;
+        private final int prefValue;
+        private final int maxValue;
+        private int value;
 
         public int getMinimumValue() {
-            return trim(component.getMinimumSize().height);
+            return minValue;
         }
 
         public int getPreferredValue() {
-            return trim(component.getPreferredSize().height);
+            return prefValue;
         }
 
         public int getMaximumValue() {
-            return trim(component.getMaximumSize().height);
+            return maxValue;
         }
 
         public int getValue() {
@@ -129,18 +121,23 @@
         }
 
         public String toString() {
-            return "Height of " + component.getClass().getName() + ": ["
-                   + getMinimumValue() + ", " + getPreferredValue() + ", "
-                   + getMaximumValue() + "]";
+            return "[" + minValue + ", " + prefValue + ", " + maxValue + "]";
         }
-    }
 
-    static final class MinusSpring extends Spring {
-        private final Spring sourceSpring;
+        private ConstantSpring(final int pref) {
+            this(pref, pref, pref);
+        }
 
-        private MinusSpring(final Spring spring) {
-            sourceSpring = spring;
+        private ConstantSpring(final int min, final int pref, final int max) {
+            this.maxValue = max;
+            this.minValue = min;
+            this.prefValue = pref;
+            value = pref;
         }
+    }
+
+    private static final class MinusSpring extends Spring {
+        private final Spring sourceSpring;
 
         public int getMinimumValue() {
             int val = sourceSpring.getMaximumValue();
@@ -168,7 +165,7 @@
         }
 
         public String toString() {
-            return "-[" + sourceSpring + "]";
+            return "(-" + sourceSpring + ")";
         }
 
         private int negativeValue(final int val) {
@@ -184,9 +181,13 @@
                 return (-1) * value;
             }
         }
+
+        private MinusSpring(final Spring spring) {
+            sourceSpring = spring;
+        }
     }
 
-    static final class MaxSpring extends Spring {
+    private static final class MaxSpring extends Spring {
         private final Spring sourceSpring1;
         private final Spring sourceSpring2;
 
@@ -244,7 +245,6 @@
             final int pref1 = sourceSpring1.getPreferredValue();
             final int pref2 = sourceSpring2.getPreferredValue();
 
-            //TODO check with tests
             if (pref1 < pref2) {
                 sourceSpring1.setValue(Math.min(value, pref1));
                 sourceSpring2.setValue(value);
@@ -255,8 +255,8 @@
         }
 
         public String toString() {
-            return "max([" + sourceSpring1 + "], ["
-                   + sourceSpring2 + "])";
+            return "max(" + sourceSpring1 + ", "
+                   + sourceSpring2 + ")";
         }
 
         private MaxSpring(final Spring spring1, final Spring spring2) {
@@ -265,7 +265,7 @@
         }
     }
 
-    static final class SumSpring extends Spring {
+    private static final class SumSpring extends Spring {
         private final Spring sourceSpring1;
         private final Spring sourceSpring2;
 
@@ -276,24 +276,24 @@
 
         public int getMinimumValue() {
             if (minValue == Spring.UNSET) {
-                minValue  = trim(trim(sourceSpring1.getMinimumValue())
-                                 + trim(sourceSpring2.getMinimumValue()));
+                minValue  = sourceSpring1.getMinimumValue()
+                                 + sourceSpring2.getMinimumValue();
             }
             return minValue;
         }
 
         public int getPreferredValue() {
             if (prefValue == Spring.UNSET) {
-                prefValue  = trim(trim(sourceSpring1.getPreferredValue())
-                                  + trim(sourceSpring2.getPreferredValue()));
+                prefValue  = sourceSpring1.getPreferredValue()
+                                  + sourceSpring2.getPreferredValue();
             }
             return prefValue;
         }
 
         public int getMaximumValue() {
             if (maxValue == Spring.UNSET) {
-                maxValue  = trim(trim(sourceSpring1.getMaximumValue())
-                                 + trim(sourceSpring2.getMaximumValue()));
+                maxValue  = sourceSpring1.getMaximumValue()
+                                 + sourceSpring2.getMaximumValue();
             }
             return maxValue;
         }
@@ -321,7 +321,7 @@
 
             final int c;
             final int c1;
-            final int c2;
+ //           final int c2;
             int val1;
 
             boolean compression = (value <= getPreferredValue());
@@ -331,14 +331,14 @@
                 c = getPreferredValue() - getMinimumValue();
                 c1 = sourceSpring1.getPreferredValue()
                      - sourceSpring1.getMinimumValue();
-                c2 = sourceSpring2.getPreferredValue()
-                     - sourceSpring2.getMinimumValue();
+//                c2 = sourceSpring2.getPreferredValue()
+//                     - sourceSpring2.getMinimumValue();
             } else {
                 c =  getMaximumValue() - getPreferredValue();
                 c1 = sourceSpring1.getMaximumValue()
                      - sourceSpring1.getPreferredValue();
-                c2 = sourceSpring2.getMaximumValue()
-                     - sourceSpring2.getPreferredValue();
+//                c2 = sourceSpring2.getMaximumValue()
+//                     - sourceSpring2.getPreferredValue();
 
             }
 
@@ -347,7 +347,8 @@
                 if ((val1 * c1 >= 0)) {
                     val1 = sourceSpring1.getPreferredValue();
                 } else {
-                    val1 = Spring.UNSET + sourceSpring1.getPreferredValue();
+                    val1 = Spring.TRIMMED_MAX_VALUE
+                           + sourceSpring1.getPreferredValue();
                 }
             } else {
                 val1 = val1 * c1 / c + sourceSpring1.getPreferredValue();
@@ -358,8 +359,8 @@
         }
 
         public String toString() {
-            return "[" + sourceSpring1 + "] + ["
-                   + sourceSpring2 + "]";
+            return "(" + sourceSpring1 + " + "
+                   + sourceSpring2 + ")";
         }
 
         private SumSpring(final Spring spring1, final Spring spring2) {
@@ -368,7 +369,7 @@
         }
     }
 
-    static final class ScaleSpring extends Spring {
+    private static final class ScaleSpring extends Spring {
         private final Spring sourceSpring;
         private float factor;
 
@@ -416,16 +417,30 @@
         }
 
         public String toString() {
-            return factor + " * [" + sourceSpring + "]";
+            return "(" + factor + " * " + sourceSpring + ")";
         }
 
     }
+
     public static final int UNSET = -2147483648;
 
     static final int TRIMMED_MAX_VALUE = Short.MAX_VALUE;
     static final int TRIMMED_MIN_VALUE = Short.MIN_VALUE;
 
 
+    protected Spring() {
+    }
+
+    public abstract int getMinimumValue();
+
+    public abstract int getPreferredValue();
+
+    public abstract int getMaximumValue();
+
+    public abstract void setValue(int value);
+
+    public abstract int getValue();
+
     public static Spring constant(final int pref) {
         return new ConstantSpring(pref);
     }
@@ -459,11 +474,6 @@
         return new HeightSpring(c);
     }
 
-
-    protected Spring() {
-    }
-
-
     private static int trim(final int value) {
         if (value > TRIMMED_MAX_VALUE) {
             return  TRIMMED_MAX_VALUE;
@@ -472,10 +482,4 @@
         }
         return value;
     }
-
-    public abstract int getMinimumValue();
-    public abstract int getPreferredValue();
-    public abstract int getMaximumValue();
-    public abstract int getValue();
-    public abstract void setValue(int value);
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SpringLayout.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SpringLayout.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SpringLayout.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SpringLayout.java Wed Sep  6 09:06:15 2006
@@ -24,27 +24,20 @@
 import java.awt.Dimension;
 import java.awt.LayoutManager2;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
 
 public class SpringLayout implements LayoutManager2 {
-    public static final String WEST = "West";
-    public static final String EAST = "East";
-    public static final String NORTH = "North";
-    public static final String SOUTH = "South";
-
-    private static final byte WEST_EDGE = 0;
-    private static final byte EAST_EDGE = 1;
-    private static final byte NORTH_EDGE = 2;
-    private static final byte SOUTH_EDGE = 3;
-    private static final byte WIDTH = 4;
-    private static final byte HEIGHT = 5;
-
     public static class Constraints {
         private Spring x;
         private Spring y;
-        private Spring width;
-        private Spring height;
 
-        private Spring[] edges = new Spring[4];
+        private final Spring[] constraintSprings = new Spring[6];
+
+        private final ConstraintsOrder horizontalConstraintsOrder;
+        private final ConstraintsOrder verticalConstraintsOrder;
+
 
         public Constraints() {
             this(null, null, null, null);
@@ -63,28 +56,35 @@
 
         public Constraints(final Spring x, final Spring y,
                            final Spring width, final Spring height) {
-             this.width = width;
-             this.height = height;
-             this.edges[WEST_EDGE] = x;
-             this.edges[EAST_EDGE] = Spring.sum(x, width);
-             this.edges[NORTH_EDGE] = y;
-             this.edges[SOUTH_EDGE] = Spring.sum(y, height);
+             horizontalConstraintsOrder = new ConstraintsOrder(EAST_EDGE,
+                                                               WEST_EDGE,
+                                                               WIDTH);
+             constraintSprings[WIDTH] = width;
+             constraintSprings[WEST_EDGE] = x;
+             deriveConstraint(EAST_EDGE);
+
+             verticalConstraintsOrder = new ConstraintsOrder(SOUTH_EDGE,
+                                                             NORTH_EDGE,
+                                                             HEIGHT);
+             constraintSprings[HEIGHT] = height;
+             constraintSprings[NORTH_EDGE] = y;
+             deriveConstraint(SOUTH_EDGE);
         }
 
         public void setX(final Spring x) {
-            edges[WEST_EDGE] = x;
-            width = Spring.sum(edges[EAST_EDGE],
-                               Spring.minus(edges[WEST_EDGE]));
+            constraintSprings[WEST_EDGE] = x;
+            deriveConstraint(horizontalConstraintsOrder.push(WEST_EDGE));
+            this.x = null;
         }
 
         public Spring getX() {
-            return x == null ? calculateX() : x;
+           return x == null ? calculateX() : x;
         }
 
         public void setY(final Spring y) {
-            edges[NORTH_EDGE] = y;
-            height = Spring.sum(edges[SOUTH_EDGE],
-                                Spring.minus(edges[NORTH_EDGE]));
+            constraintSprings[NORTH_EDGE] = y;
+            deriveConstraint(verticalConstraintsOrder.push(NORTH_EDGE));
+            this.y = null;
         }
 
         public Spring getY() {
@@ -92,21 +92,23 @@
         }
 
         public void setWidth(final Spring width) {
-            this.width = width;
-            edges[EAST_EDGE] = Spring.sum(edges[WEST_EDGE], width);
+            constraintSprings[WIDTH] = width;
+            deriveConstraint(horizontalConstraintsOrder.push(WIDTH));
+            x = null;
         }
 
         public Spring getWidth() {
-            return width;
+            return constraintSprings[WIDTH];
         }
 
         public void setHeight(final Spring height) {
-            this.height = height;
-            edges[SOUTH_EDGE] = Spring.sum(edges[NORTH_EDGE], height);
+            constraintSprings[HEIGHT] = height;
+            deriveConstraint(verticalConstraintsOrder.push(HEIGHT));
+            y = null;
         }
 
         public Spring getHeight() {
-            return height;
+            return constraintSprings[HEIGHT];
         }
 
         public void setConstraint(final String edgeName, final Spring s) {
@@ -114,17 +116,17 @@
 
             switch (edge) {
                 case EAST_EDGE :
-                    edges[EAST_EDGE] = s;
-                    edges[WEST_EDGE] = Spring.sum(edges[EAST_EDGE],
-                                                  Spring.minus(width));
+                    constraintSprings[EAST_EDGE] = s;
+                    deriveConstraint(horizontalConstraintsOrder.push(EAST_EDGE));
+                    x = null;
                     break;
                 case WEST_EDGE:
                     setX(s);
                     break;
                 case SOUTH_EDGE:
-                    edges[SOUTH_EDGE] = s;
-                    edges[NORTH_EDGE] = Spring.sum(edges[SOUTH_EDGE],
-                                                   Spring.minus(height));
+                    constraintSprings[SOUTH_EDGE] = s;
+                    deriveConstraint(verticalConstraintsOrder.push(SOUTH_EDGE));
+                    y = null;
                     break;
                 case NORTH_EDGE:
                     setY(s);
@@ -135,54 +137,136 @@
         }
 
         public Spring getConstraint(final String edgeName) {
-            final int edge = SpringLayout.getType(edgeName);
-            if (edge >= 0) {
-                return edges[edge];
+            final int constraintType = SpringLayout.getType(edgeName);
+            if (constraintType >= 0) {
+                 return constraintSprings[constraintType];
             }
             return null;
         }
 
-        private Spring calculateX() {
-            if (edges[WEST_EDGE] != null) {
-                x = edges[WEST_EDGE];
-            } else if (edges[EAST_EDGE] != null) {
-                x = Spring.sum(edges[EAST_EDGE], Spring.minus(width));
-            } else {
-                x = Spring.constant(0);
+        private void deriveConstraint(final byte type) {
+            Spring newValue = null;
+            switch (type) {
+               case WEST_EDGE:
+                   if (constraintSprings[EAST_EDGE] != null && getWidth() != null) {
+                       newValue = Spring.sum(constraintSprings[EAST_EDGE],
+                                             Spring.minus(getWidth()));
+                   }
+                   break;
+               case EAST_EDGE:
+                   if (constraintSprings[WEST_EDGE] != null && getWidth() != null) {
+                       newValue =  Spring.sum(constraintSprings[WEST_EDGE],
+                                              getWidth());
+                   }
+                   break;
+               case WIDTH:
+                   if (constraintSprings[EAST_EDGE] != null
+                       && constraintSprings[WEST_EDGE] != null) {
+
+                       newValue =
+                           Spring.sum(constraintSprings[EAST_EDGE],
+                                      Spring.minus(constraintSprings[WEST_EDGE]));
+                   }
+                   break;
+               case NORTH_EDGE:
+                   if (constraintSprings[SOUTH_EDGE] != null && getHeight() != null) {
+                       newValue =  Spring.sum(constraintSprings[SOUTH_EDGE],
+                                              Spring.minus(getHeight()));
+                   }
+                   break;
+               case SOUTH_EDGE:
+                   if (constraintSprings[NORTH_EDGE] != null && getHeight() != null) {
+                       newValue =  Spring.sum(constraintSprings[NORTH_EDGE],
+                                              getHeight());
+                   }
+                   break;
+               case HEIGHT:
+                   if (constraintSprings[SOUTH_EDGE] != null
+                       && constraintSprings[NORTH_EDGE] != null) {
+
+                       newValue =
+                           Spring.sum(constraintSprings[SOUTH_EDGE],
+                                      Spring.minus(constraintSprings[NORTH_EDGE]));
+                   }
+                   break;
+               default:
+                   return;
             }
-            return x;
+            constraintSprings[type] = newValue;
+        }
+
+        private Spring calculateX() {
+            return constraintSprings[WEST_EDGE];
         }
 
         private Spring calculateY() {
-            if (edges[NORTH_EDGE] != null) {
-                y = edges[NORTH_EDGE];
-            } else if (edges[SOUTH_EDGE] != null) {
-                y = Spring.sum(edges[SOUTH_EDGE], Spring.minus(height));
-            } else {
-                y = Spring.constant(0);
+            return constraintSprings[NORTH_EDGE];
+        }
+
+        private void clearConstraints(final SpringLayout layout) {
+            layout.markedSprings.clear();
+            constraintSprings[WIDTH].setValue(Spring.UNSET);
+            layout.markedSprings.clear();
+            constraintSprings[HEIGHT].setValue(Spring.UNSET);
+
+            layout.markedSprings.clear();
+            constraintSprings[WEST_EDGE].setValue(Spring.UNSET);
+            layout.markedSprings.clear();
+            constraintSprings[EAST_EDGE].setValue(Spring.UNSET);
+
+            layout.markedSprings.clear();
+            constraintSprings[NORTH_EDGE].setValue(Spring.UNSET);
+            layout.markedSprings.clear();
+            constraintSprings[SOUTH_EDGE].setValue(Spring.UNSET);
+        }
+    }
+
+    private static class ConstraintsOrder {
+        private byte[] constraintsOrder = new byte[3];
+        private int offset;
+        public ConstraintsOrder(final byte constraintType1,
+                                final byte constrintType2,
+                                final byte constrintType3) {
+            push(constraintType1);
+            push(constrintType2);
+            push(constrintType3);
+        }
+
+        public byte push(final byte constraintType) {
+            final int nextOffset = (offset + 1) % 3;
+            final int prevOffset = (offset + 2) % 3;
+            final byte oldConstraintType = constraintsOrder[nextOffset];
+
+            if (oldConstraintType == constraintType) {
+                offset = nextOffset;
+                return constraintsOrder[prevOffset];
+            }
+            if (peek() != constraintType) {
+                if (constraintsOrder[prevOffset] == constraintType) {
+                    constraintsOrder[prevOffset] = oldConstraintType;
+                }
+                constraintsOrder[nextOffset] = constraintType;
+
+                offset = nextOffset;
             }
-            return y;
+            return oldConstraintType;
         }
 
-        private void clearConstraints() {
-            x = null;
-            y = null;
-            width.setValue(Spring.UNSET);
-            height.setValue(Spring.UNSET);
-            edges[WEST_EDGE].setValue(Spring.UNSET);
-            edges[EAST_EDGE].setValue(Spring.UNSET);
-            edges[NORTH_EDGE].setValue(Spring.UNSET);
-            edges[SOUTH_EDGE].setValue(Spring.UNSET);
+        public byte peek() {
+            return constraintsOrder[offset];
         }
     }
 
-    private static class ProxySpring extends Spring{
+    private static class ProxySpring extends Spring {
         private final byte edgeType;
-        private final Constraints constraints;
+        private final SpringLayout layout;
+        private final Component component;
 
-        public ProxySpring(final byte edgeType, final Constraints constraints) {
+        public ProxySpring(final byte edgeType, final Component component,
+                                 final SpringLayout layout) {
             this.edgeType = edgeType;
-            this.constraints = constraints;
+            this.layout = layout;
+            this.component = component;
         }
 
         public int getMinimumValue() {
@@ -198,50 +282,95 @@
         }
 
         public int getValue() {
-            return getSpring().getValue();
+            final Spring s = getSpring();
+            if (layout.calculatedSprings.containsKey(s)) {
+                return ((Integer)layout.calculatedSprings.get(s)).intValue();
+            }
+            if (layout.markedSprings.contains(s)) {
+                printCycles();
+                return 0;
+            }
+            layout.markedSprings.add(s);
+            final int value = s.getValue();
+            layout.calculatedSprings.put(s, new Integer(value));
+            return value;
         }
 
         public void setValue(final int value) {
-            getSpring().setValue(value);
+            final Spring s = getSpring();
+            if (layout.markedSprings.contains(s)) {
+                printCycles();
+                return;
+            }
+            layout.markedSprings.add(s);
+            s.setValue(value);
         }
 
-        private Spring getSpring() {
+        public String toString() {
+            String edgeName;
             switch (edgeType) {
-                case WEST_EDGE:
-                    return constraints.getX();
-                case EAST_EDGE:
-                    return Spring.sum(constraints.getX(),
-                                      constraints.getWidth());
-                case NORTH_EDGE:
-                    return constraints.getY();
-
-                case SOUTH_EDGE:
-                    return Spring.sum(constraints.getY(),
-                                      constraints.getHeight());
-                case WIDTH:
-                    return constraints.getWidth();
+               case WEST_EDGE:
+                   edgeName = "WEST";
+                   break;
+               case EAST_EDGE:
+                   edgeName = "EAST";
+                   break;
+               case NORTH_EDGE:
+                   edgeName = "NORTH";
+                   break;
+               case SOUTH_EDGE:
+                   edgeName = "SOUTH";
+                   break;
+               default:
+                   edgeName = "";
+                   break;
+            }
+            return "[ProxySpring for " + edgeName + " edge of component "
+                   + component.getClass().getName() + "]";
+        }
 
-                case HEIGHT:
-                    return constraints.getHeight();
+        private Spring getSpring() {
+            switch (edgeType) {
+            case WEST_EDGE:
+                return layout.getConstraints(component).getX();
+            case EAST_EDGE:
+                return Spring.sum(layout.getConstraints(component).getX(),
+                                  layout.getConstraints(component).getWidth());
+            case NORTH_EDGE:
+                return layout.getConstraints(component).getY();
+
+            case SOUTH_EDGE:
+                return Spring.sum(layout.getConstraints(component).getY(),
+                                  layout.getConstraints(component).getHeight());
+            default:
+                return null;
+            }
+        }
 
-                default:
-                    return null;
+        private void printCycles() {
+            final Iterator iterator = layout.markedSprings.iterator();
+            while (iterator.hasNext()) {
+                System.err.println(iterator.next() + " is cyclic.");
             }
         }
     }
 
-    private static final float CENTERED = 0.5f;
-
-    private HashMap constraintsMap = new HashMap();
-    private HashMap calculatedprings = new HashMap();
-
-    private Container target;
+    public static final String WEST = "West";
+    public static final String EAST = "East";
+    public static final String NORTH = "North";
+    public static final String SOUTH = "South";
 
-    private boolean isLayoutValid = false;
+    private static final float CENTERED = 0.5f;
+    private static final byte WEST_EDGE = 0;
+    private static final byte EAST_EDGE = 1;
+    private static final byte NORTH_EDGE = 2;
+    private static final byte SOUTH_EDGE = 3;
+    private static final byte WIDTH = 4;
+    private static final byte HEIGHT = 5;
 
-    private Dimension minimumSize;
-    private Dimension preferredSize;
-    private Dimension maximumSize;
+    private Map calculatedSprings = new HashMap();
+    private Map constraintsMap = new HashMap();
+    private HashSet markedSprings = new HashSet();
 
     public SpringLayout() {
     }
@@ -254,21 +383,48 @@
         constraintsMap.remove(c);
     }
 
-    public Dimension minimumLayoutSize(final Container parent) {
-        if (!isLayoutValid || target != parent) {
-            calculateLayoutParams();
-        }
-        return minimumSize;
-    }
-
-    public Dimension preferredLayoutSize(final Container parent) {
-        calculateLayoutParams();
-        return preferredSize;
-    }
-
-    public Dimension maximumLayoutSize(final Container parent) {
-        calculateLayoutParams();
-        return maximumSize;
+    public Dimension minimumLayoutSize(final Container container) {
+        Constraints targetConstraints = getConstraints(container);
+        initTargetConstrains(container, targetConstraints);
+
+        return new Dimension(targetConstraints.getWidth()
+                                 .getMinimumValue()
+                             + container.getInsets().left
+                             + container.getInsets().right,
+
+                             targetConstraints.getHeight()
+                                 .getMinimumValue()
+                             + container.getInsets().top
+                             + container.getInsets().bottom);
+    }
+
+    public Dimension preferredLayoutSize(final Container container) {
+      Constraints targetConstraints = getConstraints(container);
+      initTargetConstrains(container, targetConstraints);
+      return new Dimension(targetConstraints.getWidth()
+                               .getPreferredValue()
+                           + container.getInsets().left
+                           + container.getInsets().right,
+
+                           targetConstraints.getHeight()
+                               .getPreferredValue()
+                           + container.getInsets().top
+                           + container.getInsets().bottom);
+    }
+
+    public Dimension maximumLayoutSize(final Container container) {
+        Constraints targetConstraints = getConstraints(container);
+        initTargetConstrains(container, targetConstraints);
+
+        return new Dimension(targetConstraints.getWidth()
+                                 .getMaximumValue()
+                             + container.getInsets().left
+                             + container.getInsets().right,
+
+                             targetConstraints.getHeight()
+                                 .getMaximumValue()
+                             + container.getInsets().top
+                             + container.getInsets().bottom);
     }
 
     public void addLayoutComponent(final Component component,
@@ -287,7 +443,7 @@
     }
 
     public void invalidateLayout(final Container p) {
-        isLayoutValid = false;
+        //Do nothing
     }
 
     public void putConstraint(final String edge1, final Component component1,
@@ -305,7 +461,6 @@
 
         Constraints constraints1 =  getConstraints(component1);
 
-        Spring springValue;
         final byte edge1Type = getType(edge1);
         final byte edge2Type = getType(edge2);
 
@@ -314,30 +469,14 @@
         final boolean edge2IsHorizontal =  edge2Type == EAST_EDGE
                                            || edge2Type == WEST_EDGE;
 
-        springValue = Spring.sum(new ProxySpring(edge2Type,
-                                                 getConstraints(component2)),
-                                 pad);
-        if (edge1IsHorizontal &&  edge2IsHorizontal) {
-
-            if (edge1Type == EAST_EDGE) {
-                constraints1.setConstraint(edge1, springValue);
-            } else {
-                constraints1.edges[WEST_EDGE] = springValue;
-                constraints1.edges[EAST_EDGE] =
-                    Spring.sum(constraints1.edges[WEST_EDGE],
-                               new ProxySpring(WIDTH, constraints1));
-            }
-            constraints1.x = null;
-        } else if (!edge1IsHorizontal && !edge2IsHorizontal) {
-            if (edge1Type == SOUTH_EDGE) {
-                constraints1.setConstraint(edge1, springValue);
-            } else {
-                constraints1.edges[NORTH_EDGE] = springValue;
-                constraints1.edges[SOUTH_EDGE] =
-                    Spring.sum(constraints1.edges[NORTH_EDGE],
-                               new ProxySpring(HEIGHT, constraints1));
-            }
-            constraints1.y = null;
+        if ((edge1IsHorizontal &&  edge2IsHorizontal)
+            || (!edge1IsHorizontal && !edge2IsHorizontal)) {
+
+            constraints1.setConstraint(edge1,
+                                       Spring.sum(new ProxySpring(edge2Type,
+                                                                  component2,
+                                                                  this),
+                                        pad));
         }
     }
 
@@ -346,6 +485,7 @@
         if (constraints != null) {
             return (Constraints) constraints;
         }
+
         constraints = new Constraints(Spring.constant(0),
                                       Spring.constant(0),
                                       Spring.width(component),
@@ -357,35 +497,33 @@
     public Spring getConstraint(final String edgeName,
                                 final Component component) {
 
-        return getConstraints(component).getConstraint(edgeName);
+        return new ProxySpring(getType(edgeName),
+                                     component,
+                                     this);
     }
 
-    public void layoutContainer(final Container parent) {
+    public void layoutContainer(final Container container) {
         Component component;
         Constraints constraints;
 
-        if (target != parent) {
-            target = parent;
-        }
+        Constraints targetConstraints = getConstraints(container);
+        initTargetConstrains(container, targetConstraints);
+        targetConstraints.clearConstraints(this);
 
-        for (int i = 0; i < target.getComponentCount(); i++) {
-           constraints = getConstraints(target.getComponent(i));
-           constraints.clearConstraints();
+        if (container.getLayout() != this) {
+            return;
         }
 
-        calculatedprings.clear();
+        for (int i = 0; i < container.getComponentCount(); i++) {
+            getConstraints(container.getComponent(i)).clearConstraints(this);
+        }
+        calculatedSprings.clear();
 
-        Constraints targetConstraints =  getConstraints(target);
-        targetConstraints.clearConstraints();
-        targetConstraints.getWidth().setValue(target.getWidth());
-        targetConstraints.getHeight().setValue(target.getHeight());
-        targetConstraints.getConstraint(SpringLayout.EAST)
-            .setValue(target.getWidth());
-        targetConstraints.getConstraint(SpringLayout.SOUTH)
-            .setValue(target.getHeight());
+        targetConstraints.getWidth().setValue(container.getWidth());
+        targetConstraints.getHeight().setValue(container.getHeight());
 
-        for (int i = 0; i < target.getComponentCount(); i++) {
-            component = target.getComponent(i);
+        for (int i = 0; i < container.getComponentCount(); i++) {
+            component = container.getComponent(i);
             constraints = getConstraints(component);
 
             component.setBounds(getValue(constraints.getX()),
@@ -393,42 +531,50 @@
                                 getValue(constraints.getWidth()),
                                 getValue(constraints.getHeight()));
         }
-        isLayoutValid = true;
-
     }
 
-    private void calculateLayoutParams() {
-//      Constraints constraints = getConstraints(target);
-//      minimumSize = new Dimension(constraints.getWidth().getMinimumValue(),
-//                                  constraints.getHeight().getMinimumValue());
-//      preferredSize = new Dimension(constraints.getWidth().getPreferredValue(),
-//                                    constraints.getHeight().getPreferredValue());
-//      maximumSize = new Dimension(constraints.getWidth().getMaximumValue(),
-//                                  constraints.getHeight().getMaximumValue());
-        minimumSize = new Dimension(0, 0);
-        preferredSize = new Dimension(0, 0);
-        maximumSize = new Dimension(0, 0);
+    private static byte getType(final String edgeName) {
+        if (EAST.equals(edgeName)) {
+            return EAST_EDGE;
+        } else if (WEST.equals(edgeName)) {
+            return WEST_EDGE;
+        } else if (NORTH.equals(edgeName)) {
+            return NORTH_EDGE;
+        } else if (SOUTH.equals(edgeName)) {
+            return SOUTH_EDGE;
+        }
+        return -1;
     }
 
     private int getValue(final Spring s) {
-        if (!calculatedprings.containsKey(s)) {
-            int value = s.getValue();
-            calculatedprings.put(s, new Integer(value));
+        if (!calculatedSprings.containsKey(s)) {
+            markedSprings.clear();
+            final int value = s.getValue();
+            calculatedSprings.put(s, new Integer(value));
             return value;
         }
-        return ((Integer)calculatedprings.get(s)).intValue();
+        return ((Integer)calculatedSprings.get(s)).intValue();
     }
 
-    private static byte getType(final String edge) {
-        if (EAST.equals(edge)) {
-            return EAST_EDGE;
-        } else if (WEST.equals(edge)) {
-            return WEST_EDGE;
-        } else if (NORTH.equals(edge)) {
-            return NORTH_EDGE;
-        } else if (SOUTH.equals(edge)) {
-            return SOUTH_EDGE;
+    private void initTargetConstrains(final Container target,
+                                      final Constraints targetConstraints) {
+        targetConstraints.setX(Spring.constant(0));
+        targetConstraints.setY(Spring.constant(0));
+
+        Spring width  = targetConstraints.getWidth();
+        if (width instanceof Spring.WidthSpring) {
+            if (((Spring.WidthSpring) width).component == target) {
+                targetConstraints.setWidth(Spring.constant(0, 0,
+                                                          Integer.MAX_VALUE));
+            }
+        }
+
+        Spring height  = targetConstraints.getHeight();
+        if (height instanceof Spring.HeightSpring) {
+            if (((Spring.HeightSpring) height).component == target) {
+                targetConstraints.setHeight(Spring.constant(0, 0,
+                                                           Integer.MAX_VALUE));
+            }
         }
-        return -1;
     }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SwingUtilities.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SwingUtilities.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SwingUtilities.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/SwingUtilities.java Wed Sep  6 09:06:15 2006
@@ -19,6 +19,7 @@
  */
 package javax.swing;
 
+import java.applet.Applet;
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.EventQueue;
@@ -113,10 +114,16 @@
     }
 
     public static void convertPointToScreen(final Point point, final Component component) {
+        if (component == null) {
+            throw new NullPointerException("Cannot convert point from null-component");
+        }
         translateRelatedPoint(point, component, 1, false);
     }
 
     public static void convertPointFromScreen(final Point point, final Component component) {
+        if (component == null) {
+            throw new NullPointerException("Cannot convert point to null-component");
+        }
         translateRelatedPoint(point, component, -1, false);
     }
 
@@ -399,12 +406,10 @@
     public static Component getRoot(final Component component) {
         Component result = getWindowOrAppletAncestor(component);
         Component topRoot = result;
-        /* This commented code should be enabled when JApplet is supported
         while (topRoot instanceof Applet) {
             result = topRoot;
             topRoot = getWindowOrAppletAncestor(topRoot.getParent());
         }
-        */
         return result;
     }
 
@@ -611,8 +616,7 @@
 
     private static Component getWindowOrAppletAncestor(final Component component) {
         Component result = component;
-        // commented code should be enabled when JAppllet is supported
-        while (result != null && !(result instanceof Window /*|| result instanceof Applet */)) {
+        while (result != null && !(result instanceof Window || result instanceof Applet)) {
             result = Utilities.getNotWindowParent(result);
         }
         return result;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java Wed Sep  6 09:06:15 2006
@@ -106,7 +106,7 @@
                         if (params == null) {
                             value = (methodName == null)
                                     ? classObj.newInstance()
-                                    : classObj.getMethod(methodName, (Class[])null).invoke(null, null);
+                                    : classObj.getMethod(methodName, null).invoke(null, null);
                         } else {
                             Class[] mParams = new Class[params.length];
                             for (int i = 0; i < mParams.length; i++) {
@@ -317,10 +317,13 @@
         try {
             String classID = comp.getUIClassID();
             String fullClassName = (String)get(classID);
+            if (fullClassName == null) {
+                getUIError("there is no UI class for " + classID + " key");
+                return null;
+            }
             Class uiClass = (Class)get(fullClassName);
             Method method = null;
-            boolean init = uiClass == null;
-            if (init) {
+            if (uiClass == null) {
                 uiClass = getUIClass(classID);
                 method = getCreateUIMethodPriveledged(uiClass);
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIManager.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIManager.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIManager.java Wed Sep  6 09:06:15 2006
@@ -42,7 +42,6 @@
 import javax.swing.event.SwingPropertyChangeSupport;
 import javax.swing.plaf.ComponentUI;
 
-import org.apache.harmony.misc.SystemUtils;
 import org.apache.harmony.x.swing.Utilities;
 
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/border/TitledBorder.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/border/TitledBorder.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/border/TitledBorder.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/border/TitledBorder.java Wed Sep  6 09:06:15 2006
@@ -112,7 +112,7 @@
         Insets insideInsets = getBorder().getBorderInsets(c);
         Utilities.addInsets(insets, insideInsets);
 
-        if (!Utilities.isEmptyString(title)) {
+        if (!Utilities.isEmptyString(title) && c != null) {
             FontMetrics metrics = c.getFontMetrics(getTitleFont());
             switch (titlePosition) {
             case DEFAULT_POSITION:

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/DefaultColorSelectionModel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/DefaultColorSelectionModel.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/DefaultColorSelectionModel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/DefaultColorSelectionModel.java Wed Sep  6 09:06:15 2006
@@ -45,9 +45,12 @@
     }
 
     public void setSelectedColor(final Color color) {
+        if (color == null) {
+            return;
+        }
         Color oldColor = this.color;
         this.color = color;
-        if (oldColor == null || !oldColor.equals(color)) {
+        if (!oldColor.equals(color)) {
             fireStateChanged();
         }
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/HSBPanel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/HSBPanel.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/HSBPanel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/HSBPanel.java Wed Sep  6 09:06:15 2006
@@ -197,8 +197,12 @@
     }
 
     public void updateChooser() {
-        internalUpdateDisabled = true;
         Color color = getColorSelectionModel().getSelectedColor();
+        if (color == null) {
+            return;
+        }
+        internalUpdateDisabled = true;
+        
         float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
         float[] rgb = color.getRGBComponents(null);
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/PreviewPanel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/PreviewPanel.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/PreviewPanel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/PreviewPanel.java Wed Sep  6 09:06:15 2006
@@ -39,11 +39,11 @@
     private static final int TOP_OFFSET = 10;
     private static final int TEXT_OFFSET = 10;
     
-    private int sampleWidth = 180;
-    private int sampleHeight = 20;
+    private int sampleWidth;
+    private int sampleHeight;
             
-    private int swatchSize = 40;
-    private int swatchOffset = sampleWidth * 2 + TEXT_OFFSET * 2;
+    private int swatchSize;
+    private int swatchOffset;
     
     private Polygon oldColorPoly = new Polygon(new int[]{swatchOffset, swatchOffset + swatchSize, swatchOffset + swatchSize}, 
                                                               new int[]{TOP_OFFSET, TOP_OFFSET, TOP_OFFSET + swatchSize},

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/RGBPanel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/RGBPanel.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/RGBPanel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/RGBPanel.java Wed Sep  6 09:06:15 2006
@@ -55,6 +55,9 @@
 
     public void updateChooser() {
         Color color = getColorSelectionModel().getSelectedColor();
+        if (color == null) {
+            return;
+        }
         float[] rgb = color.getRGBColorComponents(null);
         for (int i = 0; i < 3; i++) {
             int colorComponent = Math.round(rgb[i] * 255);
@@ -74,10 +77,11 @@
                            UIManager.getInt("ColorChooser.rgbGreenMnemonic"),
                            UIManager.getInt("ColorChooser.rgbBlueMnemonic")};
         
-        JPanel panel = new JPanel();
-        panel.setLayout(new GridLayout(3, 1));
+        JPanel panel = new JPanel(new GridLayout(3, 1));
         Color color = getColorSelectionModel().getSelectedColor();
-        float[] rgb = color.getRGBColorComponents(null);
+        float[] rgb = color == null 
+                      ? Color.BLACK.getRGBColorComponents(null) 
+                      : color.getRGBColorComponents(null);
 
         JPanel[] panels = {new JPanel(),
                            new JPanel(),
@@ -102,7 +106,7 @@
                     
                     for (int i = 0; i < 3; i++) {
                         if (e.getSource() == sliders[i]) {
-                            rgb[i] = sliders[i].getValue() / 255.f;
+                            rgb[i] = sliders[i].getValue() / 255f;
                         }
                     }                    
                     getColorSelectionModel().setSelectedColor(new Color(rgb[0], rgb[1], rgb[2]));

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/SwatchesPanel.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/SwatchesPanel.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/SwatchesPanel.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/colorchooser/SwatchesPanel.java Wed Sep  6 09:06:15 2006
@@ -63,7 +63,8 @@
         }
 
         public Dimension getPreferredSize() {
-            return new Dimension((oneColorWidth + 1) * colors.length, (oneColorHeight + 1) * colors[0].length);
+            return new Dimension((oneColorWidth + 1) * colors.length + 1,
+                                 (oneColorHeight + 1) * colors[0].length + 1);
         }
 
         public Dimension getMinimumSize() {
@@ -90,12 +91,10 @@
                     Color paintColor = colors[i][j] != null ? colors[i][j] : this.getBackground();
                     graphics.setColor(paintColor);
                     graphics.fillRect((oneColorWidth + 1) * i, (oneColorHeight + 1)* j, oneColorWidth, oneColorHeight);
+                    graphics.setColor(Color.WHITE);
+                    graphics.draw3DRect((oneColorWidth + 1) * i, (oneColorHeight + 1)* j, oneColorWidth - 1, oneColorHeight - 1, true);
                 }
             }
-            graphics.setColor(Color.BLACK);
-            graphics.drawRect(0, 0, (oneColorWidth + 1) * colors.length - 1,
-                              (oneColorHeight + 1) * colors[0].length - 1);
-
             graphics.setColor(oldColor);
         }
 
@@ -125,15 +124,13 @@
     }
 
     protected void buildChooser() {
-        // TODO: fix layout
         mnemonic = Integer.parseInt(UIManager.getString("ColorChooser.swatchesMnemonic"));
         displayedMnemonicIndex = Integer.parseInt(UIManager.getString("ColorChooser.swatchesDisplayedMnemonicIndex"));
 
         swatchSize = UIManager.getDimension("ColorChooser.swatchesSwatchSize");
         recentSwatchSize = UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize");
 
-        JPanel right = new JPanel();
-        right.setLayout(new BorderLayout());
+        JPanel right = new JPanel(new BorderLayout());
         recentPanel = new SwatchPanel(new Color[RECENT_SWATCH_WIDTH][RECENT_SWATCH_HEIGHT],
                                                   null, recentSwatchSize);
         right.add(BorderLayout.CENTER, new JLabel(UIManager.getString("ColorChooser.swatchesRecentText")));

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicBorders.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicBorders.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicBorders.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicBorders.java Wed Sep  6 09:06:15 2006
@@ -30,6 +30,7 @@
 import java.security.PrivilegedAction;
 
 import javax.swing.AbstractButton;
+import javax.swing.UIManager;
 import javax.swing.border.AbstractBorder;
 import javax.swing.border.BevelBorder;
 import javax.swing.border.Border;
@@ -41,18 +42,15 @@
 
 
 public class BasicBorders {
-    private static Insets borderInsets = new Insets(2, 3, 3, 3);
 
     /*
      * All color constants used in this class are selected to be consistent with
      * Basic L&F color pattern.
      */
-    private static final Color shadow = Color.GRAY;
-    private static final Color darkShadow = Color.DARK_GRAY;
-    private static final Color lightHighlight = Color.WHITE;
-    private static final Color highlight = Color.WHITE;
 
     public static class ButtonBorder extends AbstractBorder implements UIResource {
+        private static Insets borderInsets = new Insets(2, 3, 3, 3);
+        
         protected Color shadow;
         protected Color darkShadow;
         protected Color highlight;
@@ -305,14 +303,20 @@
     }
 
     public static Border getToggleButtonBorder() {
-        ToggleButtonBorder toggleButtonBorder = new ToggleButtonBorder(shadow, darkShadow, highlight, lightHighlight);
+        final String prefix = "ToggleButton.";
+        ToggleButtonBorder toggleButtonBorder = new ToggleButtonBorder(getShadow(prefix),
+                                                                       getDarkShadow(prefix),
+                                                                       getHighlight(prefix),
+                                                                       getLightHighlight(prefix));
         MarginBorder marginBorder = new MarginBorder();
 
         return new BorderUIResource.CompoundBorderUIResource(toggleButtonBorder, marginBorder);
     }
 
     public static Border getTextFieldBorder() {
-        return new FieldBorder(shadow, darkShadow, highlight, lightHighlight);
+        final String prefix = "TextField.";
+        return new FieldBorder(getShadow(prefix), getDarkShadow(prefix),
+                               getHighlight(prefix), getLightHighlight(prefix));
     }
 
     public static Border getSplitPaneDividerBorder() {
@@ -320,11 +324,16 @@
     }
 
     public static Border getSplitPaneBorder() {
-        return new SplitPaneBorder(highlight, darkShadow);
+        final String prefix = "SplitPane.";
+        return new SplitPaneBorder(getHighlight(prefix), getShadow(prefix));
     }
 
     public static Border getRadioButtonBorder() {
-        RadioButtonBorder radioButtonBorder = new RadioButtonBorder(shadow, darkShadow, highlight, lightHighlight);
+        final String prefix = "RadioButton.";
+        RadioButtonBorder radioButtonBorder = new RadioButtonBorder(getShadow(prefix),
+                                                                    getDarkShadow(prefix),
+                                                                    getHighlight(prefix),
+                                                                    getLightHighlight(prefix));
         MarginBorder marginBorder = new MarginBorder();
 
         return new BorderUIResource.CompoundBorderUIResource(radioButtonBorder, marginBorder);
@@ -335,18 +344,29 @@
     }
 
     public static Border getMenuBarBorder() {
-        return new MenuBarBorder(shadow, highlight);
+        final String prefix = "MenuBar.";
+        return new MenuBarBorder(getShadow(prefix), getHighlight(prefix));
     }
 
     public static Border getInternalFrameBorder() {
+        final String prefix = "InternalFrame.";
+        final Color borderColor = UIManager.getColor(prefix + "borderColor");
+        final Color shadow = UIManager.getColor(prefix + "borderShadow");
+        final Color darkShadow = UIManager.getColor(prefix + "borderDarkShadow");
+        final Color highlight = UIManager.getColor(prefix + "borderLight");
+        final Color lightHighlight = UIManager.getColor(prefix + "borderHighlight");
         BevelBorder bevelBorder = new BevelBorder(0, highlight, lightHighlight, darkShadow, shadow);
-        BorderUIResource.LineBorderUIResource lineBorder = new BorderUIResource.LineBorderUIResource(Color.LIGHT_GRAY, 1);
+        BorderUIResource.LineBorderUIResource lineBorder = new BorderUIResource.LineBorderUIResource(borderColor, 1);
 
         return new BorderUIResource.CompoundBorderUIResource(bevelBorder, lineBorder);
     }
 
     public static Border getButtonBorder() {
-        ButtonBorder buttonBorder = new ButtonBorder(shadow, darkShadow, highlight, lightHighlight);
+        final String prefix = "Button.";
+        ButtonBorder buttonBorder = new ButtonBorder(getShadow(prefix),
+                                                     getDarkShadow(prefix),
+                                                     getHighlight(prefix),
+                                                     getLightHighlight(prefix));
         MarginBorder marginBorder = new MarginBorder();
 
         return new BorderUIResource.CompoundBorderUIResource(buttonBorder, marginBorder);
@@ -357,6 +377,9 @@
      * Border used for divider of JSplitPane
      */
     private static class SplitPaneDividerBorder implements Border, UIResource {
+        private static final Color shadow = Color.GRAY;
+        private static final Color lightHighlight = Color.WHITE;
+
         public SplitPaneDividerBorder() {
         }
 
@@ -372,5 +395,20 @@
             return true;
         }
     }
-}
 
+    private static Color getLightHighlight(final String prefix) {
+        return UIManager.getColor(prefix + "light");
+    }
+
+    private static Color getHighlight(final String prefix) {
+        return UIManager.getColor(prefix + "highlight");
+    }
+
+    private static Color getDarkShadow(final String prefix) {
+        return UIManager.getColor(prefix + "darkShadow");
+    }
+
+    private static Color getShadow(final String prefix) {
+        return UIManager.getColor(prefix + "shadow");
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonListener.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonListener.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonListener.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonListener.java Wed Sep  6 09:06:15 2006
@@ -96,7 +96,6 @@
     }
 
     public void stateChanged(final ChangeEvent event) {
-        button.revalidate();
         button.repaint();
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonUI.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonUI.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonUI.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicButtonUI.java Wed Sep  6 09:06:15 2006
@@ -111,6 +111,12 @@
 
     protected void paintText(final Graphics g, final AbstractButton b,
                              final Rectangle textRect, final String text) {
+        paintText(g, (JComponent)b, textRect, text);
+    }
+
+    protected void paintText(final Graphics g, final JComponent c,
+                             final Rectangle textRect, final String text) {
+        final AbstractButton b = (AbstractButton)c;
         final Color color = b.isEnabled() ? b.getForeground() : disabledTextColor;
 
         final int textShiftOffset = getTextShiftOffset();
@@ -118,10 +124,6 @@
         ButtonCommons.paintText(g, b, textRect, text, color);
     }
 
-    protected void paintText(final Graphics g, final JComponent c, final Rectangle textRect, final String text) {
-        paintText(g, (AbstractButton)c, textRect, text);
-    }
-
     protected void paintFocus(final Graphics g, final AbstractButton b, final Rectangle viewRect,
                               final Rectangle textRect, final Rectangle iconRect) {
 
@@ -156,7 +158,7 @@
             listener.installKeyboardActions(button);
         }
         SwingUtilities.replaceUIInputMap(button, JComponent.WHEN_FOCUSED,
-                                         (InputMap)UIManager.get(PROPERTY_PREFIX + "focusInputMap"));
+                                         (InputMap)UIManager.get(getPropertyPrefix() + "focusInputMap"));
     }
 
     protected void uninstallKeyboardActions(final AbstractButton button) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicColorChooserUI.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicColorChooserUI.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicColorChooserUI.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicColorChooserUI.java Wed Sep  6 09:06:15 2006
@@ -24,11 +24,13 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
+import javax.swing.BorderFactory;
 import javax.swing.JColorChooser;
 import javax.swing.JComponent;
 import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
 import javax.swing.LookAndFeel;
+import javax.swing.UIManager;
 import javax.swing.colorchooser.AbstractColorChooserPanel;
 import javax.swing.colorchooser.ColorChooserComponentFactory;
 import javax.swing.colorchooser.ColorSelectionModel;
@@ -160,6 +162,7 @@
         }
         previewPanel.removeAll();
         previewPanel.add(chooser.getPreviewPanel());
+        previewPanel.setBorder(BorderFactory.createTitledBorder(UIManager.getString("ColorChooser.previewText")));
 
         if (previewPanel.getParent() == null) {
             chooser.add(previewPanel, BorderLayout.SOUTH);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxKeyboardActions.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxKeyboardActions.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxKeyboardActions.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxKeyboardActions.java Wed Sep  6 09:06:15 2006
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *  Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -44,16 +44,42 @@
             }
         }
     }
-
-    private static AbstractAction selectNextAction = new PassThroughAction() {
-        public void actionPerformed(final ActionEvent e) {
+    
+    private abstract static class SelectNextPreviousAction extends AbstractAction {
+        private String command;
+        
+        private SelectNextPreviousAction(final String command) {
+            this.command = command;
+        }
+        
+        abstract void selectValue(final BasicComboBoxUI ui);
+        
+        public void actionPerformed(ActionEvent e) {
             JComboBox comboBox = (JComboBox)e.getSource();
             if (!comboBox.isPopupVisible()) {
                 comboBox.showPopup();
             } else {
-                passThroughEvent(e, "selectNextRow");
+                BasicComboBoxUI ui = ((BasicComboBoxUI)comboBox.getUI());
+                JList popupList = ui.popup.getList();
+                Action action = popupList.getActionMap().get(command);
+                if (action != null) {
+                    action.actionPerformed(new ActionEvent(popupList, ActionEvent.ACTION_PERFORMED, command, 
+                                           e.getWhen(), e.getModifiers()));
+                    selectValue(ui);
+                }
             }
         }
+    }
+
+    private static AbstractAction selectPreviousAction = new SelectNextPreviousAction("selectPreviousRow") {
+        void selectValue(final BasicComboBoxUI ui) {
+            ui.selectPreviousPossibleValue();
+        }
+    };
+    private static AbstractAction selectNextAction = new SelectNextPreviousAction("selectNextRow") {
+        void selectValue(final BasicComboBoxUI ui) {
+            ui.selectNextPossibleValue();
+        }
     };
 
     private static AbstractAction togglePopupAction = new AbstractAction() {
@@ -89,7 +115,7 @@
 
 
     private static class HidePopupAction extends AbstractAction {
-        private final JComboBox comboBox;
+        protected final JComboBox comboBox;
 
         public HidePopupAction(final JComboBox comboBox) {
             this.comboBox = comboBox;
@@ -97,28 +123,41 @@
 
         public void actionPerformed(final ActionEvent e) {
             comboBox.hidePopup();
+            setValue();
         }
 
         public boolean isEnabled() {
             return comboBox.isPopupVisible();
         }
+
+        protected void setValue() {
+        }
+    }
+
+    private static class HidePopupAndSetValueAction extends HidePopupAction {
+        public HidePopupAndSetValueAction(final JComboBox comboBox) {
+            super(comboBox);
+        }
+
+        public boolean isEnabled() {
+            return true;
+        }
+
+        protected void setValue() {
+            BasicComboBoxUI ui = ((BasicComboBoxUI)comboBox.getUI());
+            if (ui.isTableEditor) {
+                comboBox.setSelectedIndex(ui.popup.getList().getSelectedIndex());
+            }
+        }
     }
 
     public static void installKeyboardActions(final JComboBox comboBox) {
         Utilities.installKeyboardActions(comboBox, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, "ComboBox.ancestorInputMap", null);
 
         comboBox.getActionMap().put("hidePopup", new HidePopupAction(comboBox));
-        comboBox.getActionMap().put("enterPressed", new HidePopupAction(comboBox));
+        comboBox.getActionMap().put("enterPressed", new HidePopupAndSetValueAction(comboBox));
         comboBox.getActionMap().put("selectNext", selectNextAction);
-        comboBox.getActionMap().put("selectPrevious", new PassThroughAction() {
-            public void actionPerformed(final ActionEvent e) {
-                passThroughEvent(e, "selectPreviousRow");
-            }
-
-            public boolean isEnabled() {
-                return comboBox.isPopupVisible();
-            }
-        });
+        comboBox.getActionMap().put("selectPrevious", selectPreviousAction);
         comboBox.getActionMap().put("togglePopup", togglePopupAction);
         comboBox.getActionMap().put("spacePopup", new AbstractAction() {
             public void actionPerformed(final ActionEvent e) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxUI.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxUI.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxUI.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboBoxUI.java Wed Sep  6 09:06:15 2006
@@ -190,6 +190,11 @@
                 newModel.addListDataListener(listDataListener);
             } else if (StringConstants.COMPONENT_ORIENTATION.equals(event.getPropertyName())) {
                 listBox.setComponentOrientation((ComponentOrientation)event.getNewValue());
+            } else if (StringConstants.IS_TABLE_EDITOR.equals(event.getPropertyName())) {
+                isTableEditor = ((Boolean)event.getNewValue()).booleanValue();
+            } else if (StringConstants.EDITOR_PROPERTY_CHANGED.equals(event.getPropertyName())) {
+                removeEditor();
+                addEditor();
             }
 
             isMinimumSizeDirty = true;
@@ -203,7 +208,9 @@
     private class EditorFocusHandler extends FocusHandler {
         public void focusLost(final FocusEvent e) {
             super.focusLost(e);
-            comboBox.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, null));
+            ActionEvent actionEvent = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, null);
+            editorActionListener.actionPerformed(actionEvent);
+            comboBox.actionPerformed(actionEvent);
         }
     }
 
@@ -287,11 +294,15 @@
     protected MouseMotionListener popupMouseMotionListener;
     protected PropertyChangeListener propertyChangeListener;
 
+    boolean isTableEditor;
+
     private Dimension cachedDisplaySize;
     private Rectangle cachedTextPartBounds = new Rectangle();
     private Insets cachedInsets = new Insets(0, 0, 0, 0);
 
     private FocusListener editorFocusListener;
+    private ActionListener editorActionListener;
+    private Object selectedValue;
     
     private static final String PROTOTYPE_VALUE_FOR_EDITABLE_COMBOBOX = "wwwwwwwwww";
 
@@ -372,6 +383,7 @@
         }
         if (isVisible) {
             popup.show();
+            selectedValue = popup.getList().getSelectedValue();
         } else {
             popup.hide();
         }
@@ -607,14 +619,14 @@
 
     protected void selectNextPossibleValue() {
         int selectedIndex = comboBox.getSelectedIndex();
-        if (selectedIndex != -1 && selectedIndex + 1 < comboBox.getItemCount()) {
+        if (!isTableEditor && selectedIndex != -1 && selectedIndex + 1 < comboBox.getItemCount()) {
             comboBox.setSelectedIndex(selectedIndex + 1);
         }
     }
 
     protected void selectPreviousPossibleValue() {
         int selectedIndex = comboBox.getSelectedIndex();
-        if (selectedIndex != -1 && selectedIndex > 0) {
+        if (!isTableEditor && selectedIndex != -1 && selectedIndex > 0) {
             comboBox.setSelectedIndex(selectedIndex - 1);
         }
     }
@@ -636,10 +648,20 @@
         editor.addFocusListener(editorFocusListener);
         editor.setFont(comboBox.getFont());
         comboBox.getEditor().setItem(comboBox.getSelectedItem());
+        
+        editorActionListener = new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if (selectedValue != null && !selectedValue.equals(popup.getList().getSelectedValue())) {
+                    comboBox.getEditor().setItem(popup.getList().getSelectedValue());
+                }
+            }
+        };
+        comboBox.getEditor().addActionListener(editorActionListener);
     }
 
     protected void unconfigureEditor() {
         editor.removeFocusListener(editorFocusListener);
+        comboBox.getEditor().removeActionListener(editorActionListener);
         editorFocusListener = null;
     }
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboPopup.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboPopup.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboPopup.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicComboPopup.java Wed Sep  6 09:06:15 2006
@@ -205,6 +205,8 @@
                 list.setCellRenderer((ListCellRenderer)event.getNewValue());
             } else if (StringConstants.COMPONENT_ORIENTATION.equals(event.getPropertyName())) {
                 applyComponentOrientation((ComponentOrientation)event.getNewValue());
+            } else if (StringConstants.LIGHTWEIGHT_POPUP_ENABLED_PROPERTY_CHANGED.equals(event.getPropertyName())) {
+                setLightWeightPopupEnabled(((Boolean)event.getNewValue()).booleanValue());
             }
         }
     }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicFileChooserUI.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicFileChooserUI.java?view=diff&rev=440748&r1=440747&r2=440748
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicFileChooserUI.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicFileChooserUI.java Wed Sep  6 09:06:15 2006
@@ -168,7 +168,7 @@
         }
 
         private File translateFile(final String fileName) {
-            if (fileName == null) {
+            if (Utilities.isEmptyString(fileName)) {
                 return null;
             }
 
@@ -232,7 +232,6 @@
         protected CancelSelectionAction() {
             putValue(AbstractAction.NAME, cancelButtonText);
             putValue(AbstractAction.SHORT_DESCRIPTION, cancelButtonToolTipText);
-            putValue(AbstractAction.MNEMONIC_KEY, new Integer(cancelButtonMnemonic));
         }
 
         public void actionPerformed(final ActionEvent e) {
@@ -285,7 +284,6 @@
         protected UpdateAction() {
             putValue(AbstractAction.NAME, updateButtonText);
             putValue(AbstractAction.SHORT_DESCRIPTION, updateButtonToolTipText);
-            putValue(AbstractAction.MNEMONIC_KEY, new Integer(updateButtonMnemonic));
         }
 
         public void actionPerformed(final ActionEvent e) {
@@ -525,10 +523,6 @@
     }
 
     protected void installDefaults(final JFileChooser fc) {
-        saveButtonMnemonic = UIManager.getInt("FileChooser.saveButtonMnemonic");
-        openButtonMnemonic = UIManager.getInt("FileChooser.openButtonMnemonic");
-        cancelButtonMnemonic = UIManager.getInt("FileChooser.cancelButtonMnemonic");
-        updateButtonMnemonic = UIManager.getInt("FileChooser.updateButtonMnemonic");
         helpButtonMnemonic = UIManager.getInt("FileChooser.helpButtonMnemonic");
         directoryOpenButtonMnemonic = UIManager.getInt("FileChooser.directoryOpenButtonMnemonic");
 
@@ -716,12 +710,10 @@
             dialogTitleText = openDialogTitleText;
             approveButtonText = openButtonText;
             approveButtonToolTipText = openButtonToolTipText;
-            approveButtonMnemonic = openButtonMnemonic;
         } else if (type == JFileChooser.SAVE_DIALOG) {
             dialogTitleText = saveDialogTitleText;
             approveButtonText = saveButtonText;
             approveButtonToolTipText = saveButtonToolTipText;
-            approveButtonMnemonic = saveButtonMnemonic;
         } else {
             dialogTitleText = null;
             approveButtonText = fileChooser.getApproveButtonText();



Mime
View raw message