]> source.dussan.org Git - vaadin-framework.git/commitdiff
Changed Util.notifyParentOfSizeChange and Util.componentSizeUpdated to accept Paintab...
authorArtur Signell <artur.signell@itmill.com>
Thu, 18 Dec 2008 10:04:02 +0000 (10:04 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 18 Dec 2008 10:04:02 +0000 (10:04 +0000)
svn changeset:6262/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/ICaption.java
src/com/itmill/toolkit/terminal/gwt/client/Util.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java

index 8d1d4271ae73467eee6cc02663644772b200f15c..e3092aa6b5a0a8f91088001814e95352c003b94a 100755 (executable)
@@ -124,8 +124,8 @@ public class ApplicationConnection {
     /** redirectTimer scheduling interval in seconds */
     private int sessionExpirationInterval;
 
-    private ArrayList<Widget> relativeSizeChanges = new ArrayList<Widget>();;
-    private ArrayList<Widget> captionSizeChanges = new ArrayList<Widget>();
+    private ArrayList<Paintable> relativeSizeChanges = new ArrayList<Paintable>();;
+    private ArrayList<Paintable> componentCaptionSizeChanges = new ArrayList<Paintable>();;
 
     private Date requestStartTime;;
 
@@ -598,9 +598,9 @@ public class ApplicationConnection {
         final JSONArray changes = (JSONArray) ((JSONObject) json)
                 .get("changes");
 
-        Vector<Widget> updatedWidgets = new Vector<Widget>();
+        Vector<Paintable> updatedWidgets = new Vector<Paintable>();
         relativeSizeChanges.clear();
-        captionSizeChanges.clear();
+        componentCaptionSizeChanges.clear();
 
         for (int i = 0; i < changes.size(); i++) {
             try {
@@ -619,8 +619,7 @@ public class ApplicationConnection {
                     paintable.updateFromUIDL(uidl, this);
                     // paintable may have changed during render to another
                     // implementation, use the new one for updated widgets map
-                    updatedWidgets
-                            .add((Widget) idToPaintable.get(uidl.getId()));
+                    updatedWidgets.add(idToPaintable.get(uidl.getId()));
                 } else {
                     if (!uidl.getTag().equals("window")) {
                         ClientExceptionHandler
@@ -638,18 +637,19 @@ public class ApplicationConnection {
         }
 
         // Check which widgets' size has been updated
-        Set<Widget> sizeUpdatedWidgets = new HashSet<Widget>();
+        Set<Paintable> sizeUpdatedWidgets = new HashSet<Paintable>();
 
         updatedWidgets.addAll(relativeSizeChanges);
-        sizeUpdatedWidgets.addAll(captionSizeChanges);
+        sizeUpdatedWidgets.addAll(componentCaptionSizeChanges);
 
-        for (Widget widget : updatedWidgets) {
+        for (Paintable paintable : updatedWidgets) {
+            Widget widget = (Widget) paintable;
             Size oldSize = componentOffsetSizes.get(widget);
             Size newSize = new Size(widget.getOffsetWidth(), widget
                     .getOffsetHeight());
 
             if (oldSize == null || !oldSize.equals(newSize)) {
-                sizeUpdatedWidgets.add(widget);
+                sizeUpdatedWidgets.add(paintable);
                 componentOffsetSizes.put(widget, newSize);
             }
 
@@ -1088,12 +1088,12 @@ public class ApplicationConnection {
             if (componentRelativeSizes.put(component, relativeSize) == null
                     && componentOffsetSizes.containsKey(component)) {
                 // The component has changed from absolute size to relative size
-                relativeSizeChanges.add(component);
+                relativeSizeChanges.add((Paintable) component);
             }
         } else if (relativeHeight < 0.0 && relativeWidth < 0.0) {
             if (componentRelativeSizes.remove(component) != null) {
                 // The component has changed from relative size to absolute size
-                relativeSizeChanges.add(component);
+                relativeSizeChanges.add((Paintable) component);
             }
         }
 
@@ -1138,7 +1138,7 @@ public class ApplicationConnection {
      * development. Published to JavaScript.
      */
     public void forceLayout() {
-        Util.componentSizeUpdated((Set) paintableToId.keySet());
+        Util.componentSizeUpdated(paintableToId.keySet());
     }
 
     private void internalRunDescendentsLayout(HasWidgets container) {
@@ -1180,6 +1180,8 @@ public class ApplicationConnection {
      * @return true if the child has a relative size
      */
     public boolean handleComponentRelativeSize(Widget child) {
+        final boolean debugSizes = false;
+
         Widget widget = child;
         FloatSize relativeSize = getRelativeSize(child);
         if (relativeSize == null) {
@@ -1200,6 +1202,7 @@ public class ApplicationConnection {
         } else {
             renderSpace = parent.getAllocatedSpace(widget);
         }
+
         if (relativeSize.getHeight() >= 0) {
             if (renderSpace != null) {
 
@@ -1226,14 +1229,25 @@ public class ApplicationConnection {
                     height = 0;
                 }
 
-                // getConsole().log(
-                // "Widget " + Util.getSimpleName(widget) + "/"
-                // + widget.hashCode() + " relative height "
-                // + relativeSize.getHeight() + "% of "
-                // + renderSpace.getHeight() + "px (reported by "
-                //
-                // + Util.getSimpleName(parent) + "/"
-                // + parent.hashCode() + ") : " + height + "px");
+                if (debugSizes) {
+                    getConsole()
+                            .log(
+                                    "Widget "
+                                            + Util.getSimpleName(widget)
+                                            + "/"
+                                            + widget.hashCode()
+                                            + " relative height "
+                                            + relativeSize.getHeight()
+                                            + "% of "
+                                            + renderSpace.getHeight()
+                                            + "px (reported by "
+
+                                            + Util.getSimpleName(parent)
+                                            + "/"
+                                            + (parent == null ? "?" : parent
+                                                    .hashCode()) + ") : "
+                                            + height + "px");
+                }
                 widget.setHeight(height + "px");
             } else {
                 widget.setHeight(relativeSize.getHeight() + "%");
@@ -1270,13 +1284,24 @@ public class ApplicationConnection {
                     width = 0;
                 }
 
-                // getConsole().log(
-                // "Widget " + Util.getSimpleName(widget) + "/"
-                // + widget.hashCode() + " relative width "
-                // + relativeSize.getWidth() + "% of "
-                // + renderSpace.getWidth() + "px (reported by "
-                // + Util.getSimpleName(parent) + "/"
-                // + parent.hashCode() + ") : " + width + "px");
+                if (debugSizes) {
+                    getConsole()
+                            .log(
+                                    "Widget "
+                                            + Util.getSimpleName(widget)
+                                            + "/"
+                                            + widget.hashCode()
+                                            + " relative width "
+                                            + relativeSize.getWidth()
+                                            + "% of "
+                                            + renderSpace.getWidth()
+                                            + "px (reported by "
+                                            + Util.getSimpleName(parent)
+                                            + "/"
+                                            + (parent == null ? "?" : parent
+                                                    .hashCode()) + ") : "
+                                            + width + "px");
+                }
                 widget.setWidth(width + "px");
             } else {
                 widget.setWidth(relativeSize.getWidth() + "%");
@@ -1481,8 +1506,8 @@ public class ApplicationConnection {
         windowName = newName;
     }
 
-    public void captionSizeUpdated(Widget component) {
-        captionSizeChanges.add(component);
+    public void captionSizeUpdated(Paintable component) {
+        componentCaptionSizeChanges.add(component);
     }
 
     public void analyzeLayouts() {
index 2859a1d256f64d696cf1cb0e607433e9c2f5e3d0..b2d00ca6720cc0328f856aa032ac7f208cd0eb6c 100644 (file)
@@ -8,7 +8,6 @@ import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ui.Icon;
 
 public class ICaption extends HTML {
@@ -235,11 +234,12 @@ public class ICaption extends HTML {
              * the responsibility of reacting to ONLOAD from ICaption to layouts
              */
             if (owner != null) {
-                Util.notifyParentOfSizeChange((Widget) owner, true);
+                Util.notifyParentOfSizeChange(owner, true);
             } else {
-                ApplicationConnection.getConsole().log(
-                        "Warning: Icon load was not notified "
-                                + "by ICaption due paren was unknown");
+                ApplicationConnection
+                        .getConsole()
+                        .log(
+                                "Warning: Icon load event was not propagated because ICaption owner is unknown.");
             }
         }
     }
index 278c046068aae489cba59cec67397db7323f3484..2e7892a697c5de0196e03ffc934af97f982b9bc6 100644 (file)
@@ -36,7 +36,7 @@ public class Util {
     }-*/;
 
     private static final int LAZY_SIZE_CHANGE_TIMEOUT = 400;
-    private static Set<Widget> latelyChangedWidgets = new HashSet<Widget>();
+    private static Set<Paintable> latelyChangedWidgets = new HashSet<Paintable>();
 
     private static Timer lazySizeChangeTimer = new Timer() {
         private boolean lazySizeChangeTimerScheduled = false;
@@ -74,7 +74,7 @@ public class Util {
      * @param lazy
      *            run componentSizeUpdated lazyly
      */
-    public static void notifyParentOfSizeChange(Widget widget, boolean lazy) {
+    public static void notifyParentOfSizeChange(Paintable widget, boolean lazy) {
         if (!(widget instanceof Paintable)) {
             ApplicationConnection.getConsole().log(
                     "Notified widget must be paintable not "
@@ -85,7 +85,7 @@ public class Util {
             latelyChangedWidgets.add(widget);
             lazySizeChangeTimer.schedule(LAZY_SIZE_CHANGE_TIMEOUT);
         } else {
-            Set<Widget> widgets = new HashSet<Widget>();
+            Set<Paintable> widgets = new HashSet<Paintable>();
             widgets.add(widget);
             Util.componentSizeUpdated(widgets);
         }
@@ -97,18 +97,17 @@ public class Util {
      * 
      * @param widgets
      */
-    public static void componentSizeUpdated(Set<Widget> widgets) {
+    public static void componentSizeUpdated(Set<Paintable> widgets) {
         if (widgets.isEmpty()) {
             return;
         }
 
         Map<Container, Set<Paintable>> childWidgets = new HashMap<Container, Set<Paintable>>();
 
-        for (Widget widget : widgets) {
+        for (Paintable widget : widgets) {
             ApplicationConnection.getConsole().log(
                     "Widget " + Util.getSimpleName(widget) + " size updated");
-
-            Widget parent = widget.getParent();
+            Widget parent = ((Widget) widget).getParent();
             while (parent != null && !(parent instanceof Container)) {
                 parent = parent.getParent();
             }
@@ -118,14 +117,14 @@ public class Util {
                     set = new HashSet<Paintable>();
                     childWidgets.put((Container) parent, set);
                 }
-                set.add((Paintable) widget);
+                set.add(widget);
             }
         }
 
-        Set<Widget> parentChanges = new HashSet<Widget>();
+        Set<Paintable> parentChanges = new HashSet<Paintable>();
         for (Container parent : childWidgets.keySet()) {
             if (!parent.requestLayout(childWidgets.get(parent))) {
-                parentChanges.add((Widget) parent);
+                parentChanges.add(parent);
             }
         }
 
@@ -594,11 +593,11 @@ public class Util {
     public static void updateRelativeChildrenAndSendSizeUpdateEvent(
             ApplicationConnection client, HasWidgets container) {
         updateRelativeChildrenAndSendSizeUpdateEvent(client, container,
-                (Widget) container);
+                (Paintable) container);
     }
 
     public static void updateRelativeChildrenAndSendSizeUpdateEvent(
-            ApplicationConnection client, HasWidgets container, Widget widget) {
+            ApplicationConnection client, HasWidgets container, Paintable widget) {
         /*
          * Relative sized children must be updated first so the component has
          * the correct outer dimensions when signaling a size change to the
@@ -610,7 +609,7 @@ public class Util {
             client.handleComponentRelativeSize(w);
         }
 
-        HashSet<Widget> widgets = new HashSet<Widget>();
+        HashSet<Paintable> widgets = new HashSet<Paintable>();
         widgets.add(widget);
         Util.componentSizeUpdated(widgets);
     }
index 624afedcba7e7694f957ad7e31bfb36f7791b923..12295239f5ed9a1a163a7621b161b62d120ee037 100644 (file)
@@ -815,7 +815,7 @@ public class IOrderedLayout extends CellBasedLayout {
              * This was a component-only update and the possible size change\r
              * must be propagated to the layout\r
              */\r
-            client.captionSizeUpdated((Widget) component);\r
+            client.captionSizeUpdated(component);\r
         }\r
     }\r
 \r