aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2008-12-18 10:04:02 +0000
committerArtur Signell <artur.signell@itmill.com>2008-12-18 10:04:02 +0000
commit3469a517c185aafe1ca2b13902e8412d39f5b46c (patch)
treecc65985ac72e0dc0bc92d51c57f03a09269da204
parentb6bbf6e0bb04e008d9b353ecb2c26791ad131a13 (diff)
downloadvaadin-framework-3469a517c185aafe1ca2b13902e8412d39f5b46c.tar.gz
vaadin-framework-3469a517c185aafe1ca2b13902e8412d39f5b46c.zip
Changed Util.notifyParentOfSizeChange and Util.componentSizeUpdated to accept Paintables instead of Widgets as non-Paintable widgets passed to the method will cause a ClassCastException
svn changeset:6262/svn branch:trunk
-rwxr-xr-xsrc/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java85
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ICaption.java10
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/Util.java25
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java2
4 files changed, 73 insertions, 49 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
index 8d1d4271ae..e3092aa6b5 100755
--- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
@@ -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() {
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java b/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java
index 2859a1d256..b2d00ca672 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ICaption.java
@@ -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.");
}
}
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Util.java b/src/com/itmill/toolkit/terminal/gwt/client/Util.java
index 278c046068..2e7892a697 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/Util.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/Util.java
@@ -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);
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
index 624afedcba..12295239f5 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
@@ -815,7 +815,7 @@ public class IOrderedLayout extends CellBasedLayout {
* This was a component-only update and the possible size change
* must be propagated to the layout
*/
- client.captionSizeUpdated((Widget) component);
+ client.captionSizeUpdated(component);
}
}