All containers MUST now implement Container which includes the getAllocatedSpace() method used by the relative size calculator.
This also fixes OrderedLayout bugs #2021, #2034, #2030, #2102
Also fixes #2127
svn changeset:5570/svn branch:trunk
}
/* Placing error indicator right after the widget with empty caption */
-.i-orderedlayout-c * { float:left; display: block;}
+.i-orderedlayout-c * { float:left;}
.i-orderedlayout-w-e { float:left;}
* html .i-orderedlayout-c, * html .i-orderedlayout-w { height: 1%; }
-.i-orderedlayout-w { display: block; }
.i-orderedlayout-c { float:left; display: block;}
.i-orderedlayout-w:after, .i-orderedlayout-c:after {
content: ".";
* needs application specific planning and CSS tuning.
*/
@media print {
+
.i-generated-body {
height: auto;
min-height: 20cm;
overflow: visible;
}
+
.i-app {
height:auto;
min-height: 20cm;
}
/* Placing error indicator right after the widget with empty caption */
-.i-orderedlayout-c * { float:left; display: block;}
+.i-orderedlayout-c * { float:left;}
.i-orderedlayout-w-e { float:left;}
* html .i-orderedlayout-c, * html .i-orderedlayout-w { height: 1%; }
-.i-orderedlayout-w { display: block; }
.i-orderedlayout-c { float:left; display: block;}
.i-orderedlayout-w:after, .i-orderedlayout-c:after {
content: ".";
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.FloatSize;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
import com.itmill.toolkit.terminal.gwt.client.ui.Field;
import com.itmill.toolkit.terminal.gwt.client.ui.IContextMenu;
import com.itmill.toolkit.terminal.gwt.client.ui.INotification;
private final Vector pendingVariables = new Vector();
- private final HashMap idToPaintable = new HashMap();
+ private final HashMap<String, Paintable> idToPaintable = new HashMap<String, Paintable>();
- private final HashMap paintableToId = new HashMap();
+ private final HashMap<Paintable, String> paintableToId = new HashMap<Paintable, String>();
/** Contains ExtendedTitleInfo by paintable id */
- private final HashMap paintableToTitle = new HashMap();
+ private final HashMap<Paintable, TooltipInfo> paintableToTitle = new HashMap<Paintable, TooltipInfo>();
+
+ private final HashMap<Widget, FloatSize> componentRelativeSizes = new HashMap<Widget, FloatSize>();
+ private final HashMap<Widget, Size> componentOffsetSizes = new HashMap<Widget, Size>();
private final WidgetSet widgetSet;
final JSONArray changes = (JSONArray) ((JSONObject) json)
.get("changes");
- Set<Widget> sizeUpdatedWidgets = new HashSet<Widget>();
+ Vector<Widget> updatedWidgets = new Vector<Widget>();
for (int i = 0; i < changes.size(); i++) {
try {
final Paintable paintable = getPaintable(uidl.getId());
if (paintable != null) {
Widget widget = (Widget) paintable;
- int w = widget.getOffsetWidth();
- int h = widget.getOffsetHeight();
paintable.updateFromUIDL(uidl, this);
- if (w != widget.getOffsetWidth()
- || h != widget.getOffsetHeight()) {
- sizeUpdatedWidgets.add((Widget) paintable);
- }
+ updatedWidgets.add(widget);
} else {
if (!uidl.getTag().equals("window")) {
ClientExceptionHandler
}
}
+ // Check which widgets' size has been updated
+ Set<Widget> sizeUpdatedWidgets = new HashSet<Widget>();
+
+ for (Widget widget : updatedWidgets) {
+ Size oldSize = componentOffsetSizes.get(widget);
+ Size newSize = new Size(widget.getOffsetWidth(), widget
+ .getOffsetHeight());
+
+ if (oldSize == null || !oldSize.equals(newSize)) {
+ sizeUpdatedWidgets.add(widget);
+ componentOffsetSizes.put(widget, newSize);
+ }
+
+ }
+
Util.componentSizeUpdated(sizeUpdatedWidgets);
if (meta != null) {
}
if (html.length() != 0) {
- INotification n = new INotification(1000 * 60 * 45); //45min
+ INotification n = new INotification(1000 * 60 * 45); // 45min
n.addEventListener(new NotificationRedirect(url));
n.show(html, INotification.CENTERED_TOP,
INotification.STYLE_SYSTEM);
}
public void unregisterPaintable(Paintable p) {
- Object id = paintableToId.get(p);
+ String id = paintableToId.get(p);
idToPaintable.remove(id);
paintableToTitle.remove(id);
paintableToId.remove(p);
* Paintable ID
*/
public Paintable getPaintable(String id) {
- return (Paintable) idToPaintable.get(id);
+ return idToPaintable.get(id);
}
private void addVariableToQueue(String paintableId, String variableName,
// Switch to correct implementation if needed
if (!widgetSet.isCorrectImplementation(component, uidl)) {
- final Container parent = Util.getParentLayout(component);
+ final Container parent = Util.getLayout(component);
if (parent != null) {
final Widget w = (Widget) widgetSet.createWidget(uidl);
parent.replaceChildComponent(component, w);
}
}
- updateComponentSize(component, uidl);
-
boolean enabled = !uidl.getBooleanAttribute("disabled");
if (component instanceof FocusWidget) {
FocusWidget fw = (FocusWidget) component;
// Set captions
if (manageCaption) {
- final Container parent = Util.getParentLayout(component);
+ final Container parent = Util.getLayout(component);
if (parent != null) {
parent.updateCaption((Paintable) component, uidl);
}
DOM.setElementProperty(component.getElement(), "id", uidl.getId());
}
+ /*
+ * updateComponentSize need to be after caption update so caption can be
+ * taken into account
+ */
+
+ updateComponentSize(component, uidl);
+
return false;
}
private void updateComponentSize(Widget component, UIDL uidl) {
String w = uidl.hasAttribute("width") ? uidl
.getStringAttribute("width") : "";
- component.setWidth(w);
+
String h = uidl.hasAttribute("height") ? uidl
.getStringAttribute("height") : "";
- component.setHeight(h);
+
+ float relativeWidth = Util.parseRelativeSize(w);
+ float relativeHeight = Util.parseRelativeSize(h);
+
+ if (relativeHeight >= 0.0 || relativeWidth >= 0.0) {
+ // One or both is relative
+ FloatSize relativeSize = new FloatSize(relativeWidth,
+ relativeHeight);
+ componentRelativeSizes.put(component, relativeSize);
+ handleComponentRelativeSize(component);
+ } else if (relativeHeight < 0.0 && relativeWidth < 0.0) {
+ // No relative sizes
+ componentRelativeSizes.remove(component);
+ }
+
+ if (relativeHeight < 0.0) {
+ component.setHeight(h);
+ }
+ if (relativeWidth < 0.0) {
+ component.setWidth(w);
+ }
+ }
+
+ /**
+ * Traverses recursively ancestors until ContainerResizedListener child
+ * widget is found. They will delegate it further if needed.
+ *
+ * @param container
+ */
+ public void runDescendentsLayout(HasWidgets container) {
+// getConsole().log(
+// "runDescendentsLayout("
+// + container.getClass().getName().replaceAll(
+// "[^\\.]*\\.", "") + "/" + container.hashCode()
+// + ")");
+ final Iterator childWidgets = container.iterator();
+ while (childWidgets.hasNext()) {
+ final Widget child = (Widget) childWidgets.next();
+
+ if (child instanceof Paintable) {
+ handleComponentRelativeSize(child);
+ }
+
+ if (child instanceof ContainerResizedListener) {
+ ((ContainerResizedListener) child).iLayout();
+ } else if (child instanceof HasWidgets) {
+ final HasWidgets childContainer = (HasWidgets) child;
+ runDescendentsLayout(childContainer);
+ }
+
+ }
+ }
+
+ public void handleComponentRelativeSize(Widget child) {
+ Widget widget = child;
+ FloatSize relativeSize = componentRelativeSizes.get(widget);
+ if (relativeSize == null) {
+ return;
+ }
+
+ Size availPixels = Util.getLayout(widget).getAllocatedSpace(widget);
+ if (relativeSize.getWidth() >= 0) {
+
+ if (availPixels != null) {
+
+ int width = availPixels.getWidth();
+ width *= relativeSize.getWidth() / 100.0;
+
+ if (width >= 0) {
+// getConsole().log(
+// "Widget " + widget.getClass().getName() + "/"
+// + widget.hashCode() + " relative width "
+// + relativeSize.getWidth() + "%: " + width
+// + "px");
+ widget.setWidth(width + "px");
+ }
+ } else {
+ widget.setWidth(relativeSize.getWidth() + "%");
+ ApplicationConnection.getConsole().error(
+ Util.getLayout(widget).getClass().getName()
+ + " did not produce allocatedSpace for "
+ + widget.getClass().getName());
+ }
+ }
+ if (relativeSize.getHeight() >= 0) {
+ if (availPixels != null) {
+
+ int height = availPixels.getHeight();
+ height *= relativeSize.getHeight() / 100.0;
+
+ if (height >= 0) {
+// getConsole().log(
+// "Widget " + widget.getClass().getName() + "/"
+// + widget.hashCode() + " relative height "
+// + relativeSize.getHeight() + "%: " + height
+// + "px");
+ widget.setHeight(height + "px");
+ }
+ } else {
+ widget.setHeight(relativeSize.getHeight() + "%");
+ ApplicationConnection.getConsole().error(
+ Util.getLayout(widget).getClass().getName()
+ + " did not produce allocatedSpace for "
+ + widget.getClass().getName());
+ }
+ }
+
}
/**
*
*/
public TooltipInfo getTitleInfo(Paintable titleOwner) {
- TooltipInfo info = (TooltipInfo) paintableToTitle.get(titleOwner);
+ TooltipInfo info = paintableToTitle.get(titleOwner);
if (info == null) {
info = new TooltipInfo();
paintableToTitle.put(titleOwner, info);
public void run() {
getConsole().log(
"Running re-layout of " + view.getClass().getName());
- Util.runDescendentsLayout(view);
+ runDescendentsLayout(view);
isPending = false;
}
};
package com.itmill.toolkit.terminal.gwt.client;
+import java.util.Set;
+
import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public interface Container extends Paintable {
* Called when a child components size has been updated in the rendering
* phase.
*
+ * @param child
+ * Set of child widgets whose size have changed
* @return true if the size of the Container remains the same, false if the
* event need to be propagated to the Containers parent
*/
- boolean childComponentSizesUpdated();
+ boolean requestLayout(Set<Paintable> child);
+
+ /**
+ * Returns the size currently allocated for the child component.
+ *
+ * @param child
+ * @return
+ */
+ Size getAllocatedSpace(Widget child);
+
}
* container has resized. runAnchestorsLayout(HasWidgets parent) function
* from Util class may be a good helper for this.
*
- * The width and height parameters specifies the space available for the
- * component (in pixels) if the parent container can or want to produce
- * these numbers. If the parent container does not know (has not calculated)
- * or cannot produce (undefined dimensions) one of these numbers -1 is
- * passed.
- *
- * Note that these numbers should not be considered the maximum size for the
- * widget if the layout has undefined dimension. In that case the currently
- * allocated space is passed (eg. OrderedLayout with undefined width might
- * pass availableWidth 100 if the widest component in the layout is 100 but
- * it will still stretch if another 200 pixel wide component is rendered)
*/
- public void iLayout(int availableWidth, int availableHeight);
+ public void iLayout();
}
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HTML;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
import com.itmill.toolkit.terminal.gwt.client.ui.Icon;
public class ICaption extends HTML {
private boolean placedAfterComponent = false;
+ private Size requiredSpace = new Size(0, 0);
+
/**
*
* @param component
}
+ requiredSpace.setWidth(getOffsetWidth());
+ requiredSpace.setHeight(getOffsetHeight());
}
public void onBrowserEvent(Event event) {
public boolean shouldBePlacedAfterComponent() {
return placedAfterComponent;
}
+
+ public Size getRequiredSpace() {
+ return requiredSpace;
+ }
+
+ public int getWidth() {
+ int width = 0;
+ if (icon != null) {
+ width += icon.getOffsetWidth();
+ }
+ if (captionText != null) {
+ width += captionText.getOffsetWidth();
+ }
+ if (requiredFieldIndicator != null) {
+ width += requiredFieldIndicator.getOffsetWidth();
+ }
+ if (errorIndicatorElement != null) {
+ width += errorIndicatorElement.getOffsetWidth();
+ }
+
+ if (BrowserInfo.get().isIE6() && shouldBePlacedAfterComponent()) {
+ // FIXME: Should find out what the real issue is
+ // Workaround for IE6 weirdness
+ width += 3;
+ }
+
+ return width;
+
+ }
+
+ public int getHeight() {
+ return getOffsetHeight();
+ }
+
+ public void setAlignment(String alignment) {
+ DOM.setStyleAttribute(getElement(), "textAlign", alignment);
+
+ }
}
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client;\r
+\r
+import com.google.gwt.user.client.Element;\r
+\r
+/**\r
+ * Contains size information about a rendered container and its content area.\r
+ * \r
+ * @author Artur Signell\r
+ * \r
+ */\r
+public class RenderInformation {\r
+\r
+ private Size contentArea = new Size(0, 0);\r
+ private Size renderedSize = new Size(-1, -1);\r
+\r
+ public void setContentAreaWidth(int w) {\r
+ contentArea.setWidth(w);\r
+ }\r
+\r
+ public void setContentAreaHeight(int h) {\r
+ contentArea.setHeight(h);\r
+ }\r
+\r
+ public Size getContentAreaSize() {\r
+ return contentArea;\r
+\r
+ }\r
+\r
+ public Size getRenderedSize() {\r
+ return renderedSize;\r
+ }\r
+\r
+ /**\r
+ * Update the size of the widget.\r
+ * \r
+ * @param widget\r
+ * \r
+ * @return true if the size has changed since last update\r
+ */\r
+ public boolean updateSize(Element element) {\r
+ Size newSize = new Size(element.getOffsetWidth(), element\r
+ .getOffsetHeight());\r
+ if (newSize.equals(renderedSize)) {\r
+ return false;\r
+ } else {\r
+ renderedSize = newSize;\r
+ return true;\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return "RenderInformation [contentArea=" + contentArea\r
+ + ",renderedSize=" + renderedSize + "]";\r
+\r
+ }\r
+\r
+ public static class FloatSize {\r
+\r
+ private float width, height;\r
+\r
+ public FloatSize(float width, float height) {\r
+ this.width = width;\r
+ this.height = height;\r
+ }\r
+\r
+ public float getWidth() {\r
+ return width;\r
+ }\r
+\r
+ public void setWidth(float width) {\r
+ this.width = width;\r
+ }\r
+\r
+ public float getHeight() {\r
+ return height;\r
+ }\r
+\r
+ public void setHeight(float height) {\r
+ this.height = height;\r
+ }\r
+\r
+ }\r
+\r
+ public static class Size {\r
+\r
+ private int width, height;\r
+\r
+ @Override\r
+ public boolean equals(Object obj) {\r
+ Size other = (Size) obj;\r
+ return other.width == width && other.height == height;\r
+ }\r
+\r
+ public Size(int width, int height) {\r
+ this.height = height;\r
+ this.width = width;\r
+ }\r
+\r
+ public int getWidth() {\r
+ return width;\r
+ }\r
+\r
+ public void setWidth(int width) {\r
+ this.width = width;\r
+ }\r
+\r
+ public int getHeight() {\r
+ return height;\r
+ }\r
+\r
+ public void setHeight(int height) {\r
+ this.height = height;\r
+ }\r
+\r
+ @Override\r
+ public String toString() {\r
+ return "Size [width=" + width + ",height=" + height + "]";\r
+ }\r
+ }\r
+\r
+}\r
package com.itmill.toolkit.terminal.gwt.client;
+import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
public class Util {
return;
}
- Set<Container> parents = new HashSet<Container>();
+ Map<Container, Set<Paintable>> childWidgets = new HashMap<Container, Set<Paintable>>();
for (Widget widget : widgets) {
Widget parent = widget.getParent();
parent = parent.getParent();
}
if (parent != null) {
- parents.add((Container) parent);
+ Set<Paintable> set = childWidgets.get(parent);
+ if (set == null) {
+ set = new HashSet<Paintable>();
+ childWidgets.put((Container) parent, set);
+ }
+ set.add((Paintable) widget);
}
}
Set<Widget> parentChanges = new HashSet<Widget>();
- for (Container parent : parents) {
- if (!parent.childComponentSizesUpdated()) {
+ for (Container parent : childWidgets.keySet()) {
+ if (!parent.requestLayout(childWidgets.get(parent))) {
parentChanges.add((Widget) parent);
}
}
componentSizeUpdated(parentChanges);
}
- /**
- * Traverses recursively ancestors until ContainerResizedListener child
- * widget is found. They will delegate it futher if needed.
- *
- * @param container
- */
- public static void runDescendentsLayout(HasWidgets container) {
- final Iterator childWidgets = container.iterator();
- while (childWidgets.hasNext()) {
- final Widget child = (Widget) childWidgets.next();
- if (child instanceof ContainerResizedListener) {
- int w = -1, h = -1;
-
- if (container instanceof WidgetSpaceAllocator) {
- w = ((WidgetSpaceAllocator) container)
- .getAllocatedWidth(child);
- h = ((WidgetSpaceAllocator) container)
- .getAllocatedHeight(child);
- }
-
- ((ContainerResizedListener) child).iLayout(w, h);
- } else if (child instanceof HasWidgets) {
- final HasWidgets childContainer = (HasWidgets) child;
- runDescendentsLayout(childContainer);
- }
+ public static float parseRelativeSize(String size) {
+ if (size == null || !size.endsWith("%")) {
+ return -1;
}
- }
- public interface WidgetSpaceAllocator {
- int getAllocatedWidth(Widget child);
+ try {
+ return Float.parseFloat(size.substring(0, size.length() - 1));
+ } catch (Exception e) {
+ ClientExceptionHandler.displayError(
+ "Unable to parse relative size", e);
+ }
- int getAllocatedHeight(Widget child);
+ return -1;
}
/**
* @param component
* @return closest parent Container
*/
- public static Container getParentLayout(Widget component) {
+ public static Container getLayout(Widget component) {
Widget parent = component.getParent();
while (parent != null && !(parent instanceof Container)) {
parent = parent.getParent();
}
- if (parent != null && ((Container) parent).hasChildComponent(component)) {
+ if (parent != null) {
+ assert ((Container) parent).hasChildComponent(component);
+
return (Container) parent;
}
return null;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public class IAccordion extends ITabsheetBase implements
ContainerResizedListener {
super.setHeight(height);
}
- private void iLayout() {
- iLayout(-1, -1);
- }
-
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
StackItem item = getSelectedStack();
if (item == null) {
return;
item.setHeight("");
}
- Util.runDescendentsLayout(item);
+ client.runDescendentsLayout(item);
}
/**
}
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
public class IButton extends Button implements Paintable {
+ private String width = null;
+
public static final String CLASSNAME = "i-button";
String id;
}
}
- public void setStyleName(String style) {
- super.setStyleName(style);
- if (BrowserInfo.get().isIE7()) {
- /*
- * Workaround for IE7 bug (#2014) where button width is growing when
- * changing styles
- */
- Element e = getElement();
- String w = DOM.getStyleAttribute(e, "width");
- DOM.setStyleAttribute(e, "width", "1px");
- DOM.setStyleAttribute(e, "width", w);
- }
- }
-
public void setText(String text) {
DOM.setInnerText(captionElement, text);
}
}
}
+ @Override
+ public void setWidth(String width) {
+ /* Workaround for IE7 button size part 1 (#2014) */
+ if (BrowserInfo.get().isIE7() && this.width != null) {
+ if (this.width.equals(width)) {
+ return;
+ }
+
+ if (width == null) {
+ width = "";
+ }
+ }
+
+ this.width = width;
+ super.setWidth(width);
+
+ /* Workaround for IE7 button size part 2 (#2014) */
+ if (BrowserInfo.get().isIE7()) {
+ super.setWidth(width);
+ }
+ }
+
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
-import com.itmill.toolkit.terminal.gwt.client.Util.WidgetSpaceAllocator;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public class ICoordinateLayout extends ComplexPanel implements Container,
- ContainerResizedListener, WidgetSpaceAllocator {
+ ContainerResizedListener {
/** Class name, prefix in styling */
public static final String CLASSNAME = "i-coordinatelayout";
if (!toUpdate.isEmpty()) {
// Run layout functions for children
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
// Go over all children and calculate their positions
for (Iterator<Widget> componentIterator = toUpdate.iterator(); componentIterator
Widget componentWidget = componentIterator.next();
CustomCaption componentHeader = componentToHeader
- .get((Paintable) componentWidget);
+ .get(componentWidget);
CustomCaption componentMarker = componentToMarker
- .get((Paintable) componentWidget);
+ .get(componentWidget);
// Reset position info
resetPositionAttributes(componentWidget);
resetPositionAttributes(w);
Element widgetElement = w.getElement();
Element areaElement;
- CustomCaption componentHeader = componentToHeader.get((Paintable) w);
- CustomCaption componentMarker = componentToMarker.get((Paintable) w);
+ CustomCaption componentHeader = componentToHeader.get(w);
+ CustomCaption componentMarker = componentToMarker.get(w);
// Attach the widget to the sides of the surrounding area element
if (sidesToAttach[TOP] || sidesToAttach[HEIGHT]) {
DOM.appendChild(areaElement, c.getElement());
}
- resetPositionAttributes((Widget) c);
+ resetPositionAttributes(c);
parentTop = getPositionValue(parentElement, "top");
parentRight = getPositionValue(parentElement, "right");
componentToZ.put(component, new Integer(zIndex));
// Set caption z-index (same as parent components z)
- if (componentToHeader.get((Paintable) component) != null) {
- CustomCaption h = componentToHeader.get((Paintable) component);
+ if (componentToHeader.get(component) != null) {
+ CustomCaption h = componentToHeader.get(component);
DOM.setStyleAttribute(h.getElement(), "zIndex", "" + zIndex);
}
- if (componentToMarker.get((Paintable) component) != null) {
- CustomCaption m = componentToMarker.get((Paintable) component);
+ if (componentToMarker.get(component) != null) {
+ CustomCaption m = componentToMarker.get(component);
DOM.setStyleAttribute(m.getElement(), "zIndex", "" + zIndex);
}
}
float multiplier = (float) relative[i] / 100;
if (i == LEFT || i == RIGHT || i == WIDTH) {
- float width = (float) layout[WIDTH];
+ float width = layout[WIDTH];
relative[i] = (int) (width * multiplier);
} else {
- float height = (float) layout[HEIGHT];
+ float height = layout[HEIGHT];
relative[i] = (int) (height * multiplier);
}
}
newSize[TOP] = marginInfo.hasTop() ? margins[0] : 0;
newSize[BOTTOM] = marginInfo.hasBottom() ? margins[2] : 0;
newSize[RIGHT] = marginInfo.hasRight() ? margins[1] : 0;
- newSize[WIDTH] = this.getOffsetWidth() - newSize[LEFT] - newSize[RIGHT];
- newSize[HEIGHT] = this.getOffsetHeight() - newSize[TOP]
- - newSize[BOTTOM];
+ newSize[WIDTH] = getOffsetWidth() - newSize[LEFT] - newSize[RIGHT];
+ newSize[HEIGHT] = getOffsetHeight() - newSize[TOP] - newSize[BOTTOM];
return newSize;
}
String[] cssValues = new String[cssProperties.length];
Element e = DOM.createDiv();
- DOM.appendChild(this.getElement(), e);
+ DOM.appendChild(getElement(), e);
DOM.setStyleAttribute(e, "position", "absolute");
DOM.setStyleAttribute(e, "height", "100px");
DOM.setStyleAttribute(e, "width", "100px");
margins[i] = 0;
}
}
- DOM.removeChild(this.getElement(), e);
+ DOM.removeChild(getElement(), e);
return margins;
}
* @return
*/
protected native String getMargin(Element e, String CSSProp)/*-{
- return $wnd.getComputedStyle(e,null).getPropertyValue(CSSProp);
- }-*/;
+ return $wnd.getComputedStyle(e,null).getPropertyValue(CSSProp);
+ }-*/;
/**
* Retrieves margin info in IE
* @return
*/
protected native String getIEMargin(Element e)/*-{
- return e.currentStyle.margin;
- }-*/;
+ return e.currentStyle.margin;
+ }-*/;
/**
* @return all components that are not captions
// If removing a component, remove its area
if (!(w instanceof CustomCaption)) {
- DOM.removeChild(this.getElement(), componentToArea.get(w));
+ DOM.removeChild(getElement(), componentToArea.get(w));
}
componentList.remove(w);
return wasRemoved;
}
- public int getAllocatedHeight(Widget child) {
- Element area = componentToArea.get(child);
- if (area != null) {
- return area.getOffsetHeight();
- } else {
- return layout[HEIGHT];
- }
- }
-
- public int getAllocatedWidth(Widget child) {
- Element area = componentToArea.get(child);
- if (area != null) {
- return area.getOffsetWidth();
- } else {
- return layout[WIDTH];
- }
- }
-
/**
* Custom caption class to encapsulate different caption parts
*/
}
}
+ public Size getAllocatedSpace(Widget child) {
+ Element area = componentToArea.get(child);
+ if (area != null) {
+ return new Size(area.getOffsetWidth(), area.getOffsetHeight());
+ } else {
+ return new Size(layout[WIDTH], layout[HEIGHT]);
+ }
+ }
+
+ public boolean requestLayout(Set<Paintable> child) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void iLayout() {
+ // TODO Auto-generated method stub
+
+ }
+
}// class ICoordinateLayout
package com.itmill.toolkit.terminal.gwt.client.ui;
+import java.util.Set;
+
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public class ICustomComponent extends SimplePanel implements Container {
// TODO custom component could handle its composition roots caption
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ Size space = new Size(getElement().getOffsetWidth(), getElement()
+ .getOffsetHeight());
+
+ return space;
+ }
+
}
import com.itmill.toolkit.terminal.gwt.client.ICaptionWrapper;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
/**
* Custom Layout implements complex layout defined with HTML template.
widgetToCaptionWrapper.clear();
}
- private void iLayout() {
- iLayout(-1, -1);
- }
-
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
if (!iLayoutJS(DOM.getFirstChild(getElement()))) {
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
}
}
* containers in custom layout he/she can notify children after resize.
*/
public void notifyChildrenOfSizeChange() {
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
}
public void onDetach() {
}
}-*/;
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.StyleConstants;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
/**
* @author IT Mill Ltd
*/
protected Element childContainer;
- protected ApplicationConnection client;
+ protected ApplicationConnection client = null;
- protected HashMap componentToCaption = new HashMap();
+ protected HashMap<Paintable, ICaption> componentToCaption = new HashMap<Paintable, ICaption>();
/*
* Elements that provides the Layout interface implementation.
*/
protected Element element;
- private Widget expandedWidget;
+ private Widget expandedWidget = null;
private UIDL expandedWidgetUidl;
private int spacingSize = -1;
private boolean rendering;
+ private RenderInformation renderInformation = new RenderInformation();
+ private int spaceForExpandedWidget;
+
public IExpandLayout() {
this(IExpandLayout.ORIENTATION_VERTICAL);
}
return getWidgetIndex(component) >= 0;
}
- private void iLayout() {
- iLayout(-1, -1);
- }
+ public void iLayout() {
+ renderInformation.updateSize(getElement());
- public void iLayout(int availableWidth, int availableHeight) {
if (orientationMode == ORIENTATION_HORIZONTAL) {
int pixels;
if ("".equals(height)) {
final int availableSpace = getAvailableSpace();
+ // Cannot use root element for layout as it contains margins
+ Element expandElement = expandedWidget.getElement();
+ Element expandedParentElement = DOM.getParent(expandElement);
+ if (orientationMode == ORIENTATION_VERTICAL) {
+ renderInformation.setContentAreaWidth(expandedParentElement
+ .getOffsetWidth());
+ } else {
+ renderInformation.setContentAreaHeight(expandedParentElement
+ .getOffsetHeight());
+
+ }
+
final int usedSpace = getUsedSpace();
- int spaceForExpandedWidget = availableSpace - usedSpace;
+ spaceForExpandedWidget = availableSpace - usedSpace;
if (spaceForExpandedWidget < EXPANDED_ELEMENTS_MIN_WIDTH) {
// TODO fire warning for developer
}
// setting overflow auto lazy off during layout function
- DOM.setStyleAttribute(DOM.getParent(expandedWidget.getElement()),
- "overflow", "hidden");
+ DOM.setStyleAttribute(expandedParentElement, "overflow", "hidden");
// TODO save previous size and only propagate if really changed
- Util.runDescendentsLayout(this);
+ if (client != null) {
+ client.runDescendentsLayout(this);
+ }
// setting overflow back to auto
- DOM.setStyleAttribute(DOM.getParent(expandedWidget.getElement()),
- "overflow", "auto");
+ DOM.setStyleAttribute(expandedParentElement, "overflow", "auto");
}
}
public void removeCaption(Widget w) {
- final ICaption c = (ICaption) componentToCaption.get(w);
+ final ICaption c = componentToCaption.get(w);
if (c != null) {
this.remove(c);
componentToCaption.remove(w);
}
public boolean removePaintable(Paintable p) {
- final ICaption c = (ICaption) componentToCaption.get(p);
+ final ICaption c = componentToCaption.get(p);
if (c != null) {
componentToCaption.remove(c);
remove(c);
public void replaceChildComponent(Widget from, Widget to) {
client.unregisterPaintable((Paintable) from);
- final ICaption c = (ICaption) componentToCaption.get(from);
+ final ICaption c = componentToCaption.get(from);
if (c != null) {
remove(c);
componentToCaption.remove(c);
public void updateCaption(Paintable component, UIDL uidl) {
- ICaption c = (ICaption) componentToCaption.get(component);
+ ICaption c = componentToCaption.get(component);
boolean captionSizeMayHaveChanged = false;
if (ICaption.isNeeded(uidl)) {
// functions
DOM.setStyleAttribute(DOM.getParent(expandedWidget.getElement()),
"overflow", "auto");
+
+ /*
+ * If a caption has been added we need to recalculate the space
+ * available for the component
+ */
+ getWidgetWrapperFor(expandedWidget).setExpandedSize(
+ spaceForExpandedWidget);
+
}
// workaround for safari bug #1870
rendering = false;
}
- public boolean childComponentSizesUpdated() {
- // TODO Auto-generated method stub
- return false;
+ public boolean requestLayout(Set<Paintable> child) {
+ if (height != null && width != null) {
+ /*
+ * If the height and width has been specified for this container the
+ * child components cannot make the size of the layout change
+ */
+
+ return true;
+ }
+
+ if (renderInformation.updateSize(getElement())) {
+ /*
+ * Size has changed so we let the child components know about the
+ * new size.
+ */
+ iLayout();
+
+ return false;
+ } else {
+ /*
+ * Size has not changed so we do not need to propagate the event
+ * further
+ */
+ return true;
+ }
+
+ }
+
+ public Size getAllocatedSpace(Widget child) {
+ int width = 0, height = 0;
+
+ if (orientationMode == ORIENTATION_HORIZONTAL) {
+ height = renderInformation.getContentAreaSize().getHeight();
+ if (child == expandedWidget) {
+ width = spaceForExpandedWidget;
+ }
+ } else {
+ // VERTICAL
+ width = renderInformation.getContentAreaSize().getWidth();
+ if (child == expandedWidget) {
+ height = spaceForExpandedWidget;
+
+ ICaption caption = componentToCaption.get(child);
+ if (caption != null) {
+ height -= caption.getOffsetHeight();
+ }
+ }
+ }
+
+ return new Size(width, height);
}
}
\r
package com.itmill.toolkit.terminal.gwt.client.ui;\r
\r
+import java.util.Set;\r
+\r
import com.google.gwt.user.client.DOM;\r
import com.google.gwt.user.client.Element;\r
import com.google.gwt.user.client.ui.ComplexPanel;\r
import com.google.gwt.user.client.ui.Widget;\r
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;\r
+import com.itmill.toolkit.terminal.gwt.client.ClientExceptionHandler;\r
import com.itmill.toolkit.terminal.gwt.client.Container;\r
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;\r
import com.itmill.toolkit.terminal.gwt.client.IErrorMessage;\r
import com.itmill.toolkit.terminal.gwt.client.Paintable;\r
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;\r
import com.itmill.toolkit.terminal.gwt.client.UIDL;\r
-import com.itmill.toolkit.terminal.gwt.client.Util;\r
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;\r
\r
-public class IForm extends ComplexPanel implements Paintable,\r
+public class IForm extends ComplexPanel implements Container,\r
ContainerResizedListener {\r
\r
+ private String height;\r
+\r
+ private String width;\r
+\r
public static final String CLASSNAME = "i-form";\r
\r
private Container lo;\r
\r
private Container footer;\r
\r
+ private ApplicationConnection client;\r
+\r
+ private RenderInformation renderInformation = new RenderInformation();\r
+\r
+ private int borderPaddingHorizontal;\r
+\r
+ private int borderPaddingVertical;\r
+\r
public IForm() {\r
setElement(DOM.createFieldSet());\r
setStyleName(CLASSNAME);\r
}\r
\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ this.client = client;\r
+\r
if (client.updateComponent(this, uidl, false)) {\r
return;\r
}\r
DOM.setInnerHTML(desc, "");\r
}\r
\r
- iLayout(-1, -1);\r
+ iLayout();\r
\r
final UIDL layoutUidl = uidl.getChildUIDL(0);\r
Container newLo = (Container) client.getPaintable(layoutUidl);\r
}\r
}\r
\r
- public void iLayout(int availableWidth, int availableHeight) {\r
- Util.runDescendentsLayout(this);\r
+ public void iLayout() {\r
+\r
+ renderInformation.updateSize(getElement());\r
+\r
+ renderInformation.setContentAreaHeight(renderInformation\r
+ .getRenderedSize().getHeight()\r
+ - borderPaddingVertical);\r
+ renderInformation.setContentAreaWidth(renderInformation\r
+ .getRenderedSize().getWidth()\r
+ - borderPaddingHorizontal);\r
+\r
+ client.runDescendentsLayout(this);\r
+ }\r
+\r
+ public Size getAllocatedSpace(Widget child) {\r
+ return renderInformation.getContentAreaSize();\r
+ }\r
+\r
+ public boolean hasChildComponent(Widget component) {\r
+ return component != null && (component == lo || component == footer);\r
+ }\r
+\r
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {\r
+ // TODO Auto-generated method stub\r
+\r
+ }\r
+\r
+ public boolean requestLayout(Set<Paintable> child) {\r
+\r
+ if (height != null && width != null) {\r
+ /*\r
+ * If the height and width has been specified the child components\r
+ * cannot make the size of the layout change\r
+ */\r
+\r
+ return true;\r
+ }\r
+\r
+ if (renderInformation.updateSize(getElement())) {\r
+ return false;\r
+ } else {\r
+ return true;\r
+ }\r
+\r
+ }\r
+\r
+ public void updateCaption(Paintable component, UIDL uidl) {\r
+ // TODO Auto-generated method stub\r
+\r
}\r
\r
+ @Override\r
+ public void setHeight(String height) {\r
+ this.height = height;\r
+\r
+ super.setHeight(height);\r
+\r
+ if (height.endsWith("px")) {\r
+ try {\r
+ borderPaddingVertical = getElement().getOffsetHeight()\r
+ - Integer.parseInt(height.substring(0,\r
+ height.length() - 2));\r
+ } catch (Exception e) {\r
+ ClientExceptionHandler.displayError(e);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public void setWidth(String width) {\r
+ this.width = width;\r
+\r
+ super.setWidth(width);\r
+\r
+ if (width.endsWith("px")) {\r
+ try {\r
+ borderPaddingHorizontal = getElement().getOffsetWidth()\r
+ - Integer.parseInt(width.substring(0,\r
+ width.length() - 2));\r
+ } catch (Exception e) {\r
+ ClientExceptionHandler.displayError(e);\r
+ }\r
+ }\r
+ }\r
}\r
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.itmill.toolkit.terminal.gwt.client.StyleConstants;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
/**
* Two col Layout that places caption on left col and field on right col
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.StyleConstants;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public class IGridLayout extends SimplePanel implements Paintable, Container,
ContainerResizedListener {
private String width;
+ private ApplicationConnection client;
+
public IGridLayout() {
super();
DOM.appendChild(getElement(), margin);
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ this.client = client;
if (client.updateComponent(this, uidl, true)) {
return;
wrapper.updateCaption(uidl);
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
- }
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
- private void iLayout() {
- iLayout(-1, -1);
}
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
if (needsLayout) {
super.setWidth(width);
if (meterElement == null) {
} else {
grid.setWidth("");
}
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import java.util.Vector;
import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
-import com.itmill.toolkit.terminal.gwt.client.Util.WidgetSpaceAllocator;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
/**
* Full implementation of OrderedLayout client peer.
* @author IT Mill Ltd
*/
public class IOrderedLayout extends Panel implements Container,
- ContainerResizedListener, WidgetSpaceAllocator {
+ ContainerResizedListener {
public static final String CLASSNAME = "i-orderedlayout";
*/
private boolean childLayoutsHaveChanged = false;
- private int renderedHeight;
+ private boolean isRendering = false;
- private int renderedWidth;
+ private RenderInformation renderInformation = new RenderInformation();
/**
* Construct the DOM of the orderder layout.
/** Update the contents of the layout from UIDL. */
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
+ isRendering = true;
this.client = client;
// Only non-cached UIDL:s can introduce changes
handleAlignmentsSpacingAndMargins(uidl);
// Reset sizes for the children
- updateChildSizes(-1, -1);
+ updateChildSizes();
// Paint children
for (int i = 0; i < childsToPaint.size(); i++) {
// Update child layouts
// TODO This is most probably unnecessary and should be done within
// update Child H/W
- if (childLayoutsHaveChanged) {
- Util.runDescendentsLayout(this);
- childLayoutsHaveChanged = false;
- }
+ // if (childLayoutsHaveChanged) {
+ // client.runDescendentsLayout(this);
+ // childLayoutsHaveChanged = false;
+ // }
/* Store the rendered size so we later can see if it has changed */
- renderedWidth = root.getOffsetWidth();
- renderedHeight = root.getOffsetHeight();
+ if (renderInformation.updateSize(root)) {
+ client.runDescendentsLayout(this);
+ }
+
+ isRendering = false;
}
*/
public void setWidth(String newWidth) {
- width = newWidth == null || "".equals(newWidth) ? null : newWidth;
-
- // As we use divs at root - for them using 100% width should be
- // calculated with ""
- super.setWidth("");
+ if (newWidth == null || newWidth.equals("")) {
+ width = null;
+ } else {
+ width = newWidth;
+ }
// Update child layouts
childLayoutsHaveChanged = true;
}
/** Recalculate and apply the space given for each child in this layout. */
- private void updateChildSizes(int renderedWidth, int renderedHeight) {
+ private void updateChildSizes() {
int numChild = childWidgets.size();
int childHeightTotal = -1;
// Vertical layout is calculated by us
if (height != null) {
- // Calculate the space for fixed contents minus marginals
- if (tableMode) {
-
- // If we know explicitly set pixel-size, use that
- if (height.endsWith("px")) {
- try {
- childHeightTotal = Integer.parseInt(height.substring(0,
- height.length() - 2));
-
- // For negative sizes, use measurements
- if (childHeightTotal < 0) {
- childHeightTotal = rootOffsetMeasure("offsetHeight");
- }
- } catch (NumberFormatException e) {
-
- // In case of invalid number, try to measure the size;
- childHeightTotal = rootOffsetMeasure("offsetHeight");
- }
- } else if (height.endsWith("%") && renderedHeight >= 0) {
- // If we have a relative height and know how large we are we
- // can
- // simply use that
- childWidthTotal = renderedHeight;
- } else {
- // If not pixels, nor percentage, try to measure the size
- childHeightTotal = rootOffsetMeasure("offsetHeight");
- }
-
+ if (height.endsWith("px")) {
+ childHeightTotal = Integer.parseInt(height.substring(0, height
+ .length() - 2));
} else {
- childHeightTotal = DOM.getElementPropertyInt(getElement(),
- "offsetHeight");
+ // TODO This might be wrong but only reached if height is
+ // specified by other means than pixels or %
+ childHeightTotal = getElement().getOffsetHeight();
}
+ // Calculate the space for fixed contents minus marginals
+ childHeightTotal = getElement().getOffsetHeight();
+
childHeightTotal -= margins.hasTop() ? marginTop : 0;
childHeightTotal -= margins.hasBottom() ? marginBottom : 0;
// layout is calculated by us
if (width != null) {
- // Calculate the space for fixed contents minus marginals
- // If we know explicitly set pixel-size, use that
if (width.endsWith("px")) {
- try {
- childWidthTotal = Integer.parseInt(width.substring(0, width
- .length() - 2));
-
- // For negative sizes, use measurements
- if (childWidthTotal < 0) {
- childWidthTotal = rootOffsetMeasure("offsetWidth");
- }
-
- } catch (NumberFormatException e) {
-
- // In case of invalid number, try to measure the size;
- childWidthTotal = rootOffsetMeasure("offsetWidth");
- }
- } else if (width.endsWith("%") && renderedWidth >= 0) {
- // If we have a relative width and know how large we are we can
- // simply use that
- childWidthTotal = renderedWidth;
+ childWidthTotal = Integer.parseInt(width.substring(0, width
+ .length() - 2));
} else {
- // If not pixels, nor percentage, try to measure the size
- childWidthTotal = rootOffsetMeasure("offsetWidth");
+ // TODO This might be wrong but only reached if width is
+ // specified by other means than pixels or %
+ childWidthTotal = getElement().getOffsetWidth();
}
childWidthTotal -= margins.hasLeft() ? marginLeft : 0;
}
WidgetWrapper ww = (WidgetWrapper) i.next();
ww.forceSize(w, h);
- }
- }
- /**
- * Measure how much space the root element could get.
- *
- * This measures the space allocated by the parent for the root element
- * without letting root element to affect the calculation.
- *
- * @param offset
- * offsetWidth or offsetHeight
- */
- private int rootOffsetMeasure(String offset) {
- // TODO This method must be optimized!
- Element measure = DOM.createDiv();
- DOM.setStyleAttribute(measure, "height", "100%");
- Element parent = DOM.getParent(getElement());
- DOM.insertBefore(parent, measure, getElement());
- // FIXME Do not detach from DOM this way. At least proper detach, attach
- // must be called. Affects odd behavior in childs, performance issues
- // and flickering. See #2102
- DOM.removeChild(parent, getElement());
- int size = DOM.getElementPropertyInt(measure, offset);
- DOM.insertBefore(parent, getElement(), measure);
- DOM.removeChild(parent, measure);
- // In case the no space would be given for this element
- // without pushing, use the current side of the root
- return size;
+ }
}
/** Parse alignments from UIDL and pass whem to correct widgetwrappers */
/** Caption element when used. */
ICaption caption = null;
+ Size captionSize = new Size(-1, -1);
/**
* Last set pixel height for the wrapper. -1 if vertical clipping is not
int lastForcedPixelHeight = -1;
/**
- * Last set pidel width for the wrapper. -1 if horizontal clipping is
+ * Last set pixel width for the wrapper. -1 if horizontal clipping is
* not used.
*/
int lastForcedPixelWidth = -1;
/** Widget Wrapper root element */
Element wrapperElement;
+ private String horizontalAlignment = "left";
+
+ private String verticalAlignment = "top";
+
/** Set the root element */
public WidgetWrapper() {
resetRootElement();
// Set size
DOM.setStyleAttribute(e, "width", pixelWidth < 0 ? "" : pixelWidth
+ "px");
- DOM.setStyleAttribute(e, "height",
- pixelHeight < 0 ? (e == clipperDiv ? "100%" : "")
- : pixelHeight + "px");
+
+ if (pixelHeight >= 0) {
+ DOM.setStyleAttribute(e, "height", pixelHeight + "px");
+ } else {
+ if (e == clipperDiv && !BrowserInfo.get().isIE()) {
+ DOM.setStyleAttribute(e, "height", "100%");
+ }
+
+ }
// Set cached values
lastForcedPixelWidth = pixelWidth;
private void createClipperDiv() {
clipperDiv = DOM.createDiv();
final Element e = getElementWrappingClipperDiv();
- String classe = DOM.getElementAttribute(e, "class");
+ String clipperClass = "i-orderedlayout-cl-"
+ + (orientationMode == ORIENTATION_HORIZONTAL ? "h" : "v");
+
+ String elementClass = e.getClassName();
+
+ if (elementClass != null && elementClass.length() > 0) {
+ clipperClass += " " + elementClass;
+ }
+
while (DOM.getChildCount(e) > 0) {
final Element c = DOM.getFirstChild(e);
DOM.removeChild(e, c);
DOM.appendChild(clipperDiv, c);
}
- if (classe != null && classe.length() > 0) {
- DOM.removeElementAttribute(e, "class");
- DOM.setElementAttribute(clipperDiv, "class", classe);
+
+ if (elementClass != null && elementClass.length() > 0) {
+ e.setClassName("");
}
+
DOM.appendChild(e, clipperDiv);
+ clipperDiv.setClassName(clipperClass);
+
}
/** Undo createClipperDiv() */
private void removeClipperDiv() {
final Element e = getElementWrappingClipperDiv();
- String classe = DOM.getElementAttribute(clipperDiv, "class");
+ String clipperClass = clipperDiv.getClassName();
+
+ String elementClass = clipperClass.replaceAll(
+ "i-orderedlayout-cl-.", "").trim();
while (DOM.getChildCount(clipperDiv) > 0) {
final Element c = DOM.getFirstChild(clipperDiv);
DOM.removeChild(clipperDiv, c);
}
DOM.removeChild(e, clipperDiv);
clipperDiv = null;
- if (classe != null && classe.length() > 0) {
- DOM.setElementAttribute(e, "class", classe);
+ if (elementClass != null && elementClass.length() > 0) {
+ e.setClassName(elementClass);
}
}
if (tableMode) {
if (orientationMode == ORIENTATION_HORIZONTAL) {
wrapperElement = DOM.createTD();
+ DOM.setStyleAttribute(wrapperElement, "height", "100%");
} else {
wrapperElement = DOM.createTR();
DOM.appendChild(wrapperElement, DOM.createTD());
final Widget widget = (Widget) paintable;
final Element captionWrapper = getElementWrappingWidgetAndCaption();
+ boolean captionDimensionOrPositionUpdated = false;
+
// The widget needs caption
if (ICaption.isNeeded(uidl)) {
// Update caption contents
caption.updateCaption(uidl);
+ caption.setAlignment(horizontalAlignment);
+
+ int captionHeight = caption.getElement().getOffsetHeight();
+ int captionWidth = caption.getElement().getOffsetWidth();
+ if (captionHeight != captionSize.getHeight()
+ || captionWidth != captionSize.getWidth()) {
+ captionSize = new Size(captionWidth, captionHeight);
+ captionDimensionOrPositionUpdated = true;
+ }
+
final boolean after = caption.shouldBePlacedAfterComponent();
final Element captionElement = caption.getElement();
final Element widgetElement = widget.getElement();
DOM.insertChild(captionWrapper, captionElement, 0);
}
+ captionDimensionOrPositionUpdated = true;
} else
// Caption exists. Move it to correct position if needed
widget.removeStyleName("i-orderedlayout-w-e");
caption.removeStyleName("i-orderedlayout-w-c");
}
- }
- }
+ captionDimensionOrPositionUpdated = true;
+ }
- // Caption is not needed
- else {
+ } else {
+ // Caption is not needed
// Remove existing caption from DOM
if (caption != null) {
caption = null;
DOM.setElementAttribute(captionWrapper, "class", "");
widget.removeStyleName("i-orderedlayout-w-e");
+
+ captionDimensionOrPositionUpdated = true;
}
}
+
+ if (captionDimensionOrPositionUpdated) {
+ client.handleComponentRelativeSize((Widget) paintable);
+ }
}
/**
* Set alignments for this wrapper.
*/
void setAlignment(String verticalAlignment, String horizontalAlignment) {
+ this.verticalAlignment = verticalAlignment;
+ this.horizontalAlignment = horizontalAlignment;
// use one-cell table to implement horizontal alignments, only
// for values other than top-left (which is default)
alignmentTD = innermostTDinAlignmnetStructure = null;
}
}
+
+ DOM.setStyleAttribute(getElementWrappingWidgetAndCaption(),
+ "textAlign", horizontalAlignment);
+
}
/** Set class for spacing */
}
public int getAllocatedHeight() {
+ int reduce = verticalPadding;
+ if (caption != null) {
+ if (orientationMode == ORIENTATION_VERTICAL
+ || (orientationMode == ORIENTATION_HORIZONTAL && !caption
+ .shouldBePlacedAfterComponent())) {
+ reduce += caption.getHeight();
+ }
+ }
+
if (lastForcedPixelHeight == -1) {
if (height == null) {
/*
* We have no height specified so return the space allocated
* by components so far
*/
+
return getElementWrappingClipperDiv().getOffsetHeight()
- - horizontalPadding;
+ - reduce;
}
- return -1;
+ // This should not be possible...
+ return 0;
}
int available = lastForcedPixelHeight;
+ available -= reduce;
+
// Must remove caption height to report correct size to child
- if (caption != null) {
- available -= caption.getOffsetHeight();
- }
+ // if (caption != null) {
+ // available -= caption.getOffsetHeight();
+ // }
+
return available;
}
public int getAllocatedWidth() {
+ int reduce = horizontalPadding;
+ if (caption != null && caption.shouldBePlacedAfterComponent()) {
+ reduce += caption.getWidth();
+ }
+
if (width == null) {
/*
* We have no width specified so return the space allocated by
* components so far
*/
- return getElementWrappingClipperDiv().getOffsetWidth()
- - horizontalPadding;
+ return getElementWrappingClipperDiv().getOffsetWidth() - reduce;
+ } else if (lastForcedPixelWidth > -1) {
+ return lastForcedPixelWidth - reduce;
+ } else {
+ return 0;
}
-
- return lastForcedPixelWidth;
}
+
}
/* documented at super */
}
/* documented at super */
- public void iLayout(int availableWidth, int availableHeight) {
- updateChildSizes(availableWidth, availableHeight);
- Util.runDescendentsLayout(this);
- childLayoutsHaveChanged = false;
- }
-
- public int getAllocatedHeight(Widget child) {
- final int index = childWidgets.indexOf(child);
- if (index >= 0) {
- WidgetWrapper wrapper = childWidgetWrappers.get(index);
- return wrapper.getAllocatedHeight();
+ public void iLayout() {
+ if (isRendering) {
+ return;
}
- return -1;
- }
-
- public int getAllocatedWidth(Widget child) {
- final int index = childWidgets.indexOf(child);
- if (index >= 0) {
- WidgetWrapper wrapper = childWidgetWrappers.get(index);
- return wrapper.getAllocatedWidth();
+ updateChildSizes();
+ if (client != null) {
+ client.runDescendentsLayout(this);
}
-
- return -1;
+ childLayoutsHaveChanged = false;
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> children) {
if (height != null && width != null) {
/*
- * If the height and width has been specified for this layout the
+ * If the height and width has been specified for this container the
* child components cannot make the size of the layout change
*/
return true;
}
- int currentHeight = getElement().getOffsetHeight();
- int currentWidth = getElement().getOffsetWidth();
-
- if (currentHeight != renderedHeight || currentWidth != renderedWidth) {
+ if (renderInformation.updateSize(root)) {
/*
* Size has changed so we let the child components know about the
* new size.
*/
- iLayout(-1, -1);
+ iLayout();
+
return false;
} else {
/*
}
+ public Size getAllocatedSpace(Widget child) {
+ final int index = childWidgets.indexOf(child);
+ if (index >= 0) {
+ WidgetWrapper wrapper = childWidgetWrappers.get(index);
+ int w = wrapper.getAllocatedWidth();
+ int h = wrapper.getAllocatedHeight();
+
+ return new Size(w, h);
+
+ }
+
+ return new Size(0, 0);
+ }
}
package com.itmill.toolkit.terminal.gwt.client.ui;
+import java.util.Set;
+
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.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
+import com.itmill.toolkit.terminal.gwt.client.ClientExceptionHandler;
+import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.IErrorMessage;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
-public class IPanel extends SimplePanel implements Paintable,
+public class IPanel extends SimplePanel implements Container,
ContainerResizedListener {
public static final String CLASSNAME = "i-panel";
private int scrollLeft;
+ private RenderInformation renderInformation = new RenderInformation();
+
+ private int borderPaddingHorizontal = 0;
+
public IPanel() {
super();
DOM.appendChild(getElement(), captionNode);
this.client = client;
id = uidl.getId();
- // Panel size. Height needs to be saved for later use
- height = uidl.hasAttribute("height") ? uidl
- .getStringAttribute("height") : null;
- setWidth(uidl.hasAttribute("width") ? uidl.getStringAttribute("width")
- : "");
-
// Restore default stylenames
DOM
.setElementProperty(captionNode, "className", CLASSNAME
}
}
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
iLayout(true);
}
public void iLayout(boolean runGeckoFix) {
+ renderInformation.updateSize(getElement());
if (BrowserInfo.get().isIE6() && width != null && !width.equals("")) {
/*
// Calculate used height
super.setHeight("");
- final int usedHeight = DOM.getElementPropertyInt(bottomDecoration,
- "offsetTop")
- + DOM.getElementPropertyInt(bottomDecoration,
- "offsetHeight")
- - DOM.getElementPropertyInt(getElement(), "offsetTop");
+ if (BrowserInfo.get().isIE() && !hasChildren) {
+ DOM.setStyleAttribute(contentNode, "height", "0px");
+ }
+
+ final int bottomTop = DOM.getElementPropertyInt(bottomDecoration,
+ "offsetTop");
+ final int bottomHeight = DOM.getElementPropertyInt(
+ bottomDecoration, "offsetHeight");
+ final int elementTop = DOM.getElementPropertyInt(getElement(),
+ "offsetTop");
+
+ final int usedHeight = bottomTop + bottomHeight - elementTop;
// Calculate content area height (don't allow negative values)
- int h = targetHeight - usedHeight;
- if (h < 0) {
- h = 0;
+ int contentAreaHeight = targetHeight - usedHeight;
+ if (contentAreaHeight < 0) {
+ contentAreaHeight = 0;
}
+ renderInformation.setContentAreaHeight(contentAreaHeight);
+
// Set proper values for content element
- DOM.setStyleAttribute(contentNode, "height", h + "px");
+ DOM.setStyleAttribute(contentNode, "height", contentAreaHeight
+ + "px");
DOM.setStyleAttribute(contentNode, "overflow", "auto");
// Restore content to flow
if (hasChildren) {
DOM.setStyleAttribute(contentEl, "position", origPositioning);
}
+
// restore scroll position
DOM.setElementPropertyInt(contentNode, "scrollTop", scrollTop);
DOM.setElementPropertyInt(contentNode, "scrollLeft", scrollLeft);
DOM.setStyleAttribute(contentNode, "height", "");
}
+ if (width != null && !width.equals("")) {
+ renderInformation.setContentAreaWidth(renderInformation
+ .getRenderedSize().getWidth()
+ - borderPaddingHorizontal);
+ }
+
if (runGeckoFix && BrowserInfo.get().isGecko()) {
// workaround for #1764
if (width == null || width.equals("")) {
}
}
}
- Util.runDescendentsLayout(this);
+
+ client.runDescendentsLayout(this);
}
@Override
*/
@Override
public void setHeight(String height) {
- // NOP
+ this.height = height;
}
/**
@Override
public void setWidth(String width) {
this.width = width;
- // Let browser handle 100% width (DIV element takes all size by
- // default).
- // This way we can specify borders for Panel's outer element.
- if (width.equals("100%")) {
- super.setWidth("");
+
+ super.setWidth(width);
+
+ if (width.endsWith("px")) {
+ try {
+ // FIXME: More sane implementation
+ borderPaddingHorizontal = Util.measureHorizontalPadding(
+ contentNode, -2);
+ if (borderPaddingHorizontal < 0) {
+ borderPaddingHorizontal = -borderPaddingHorizontal;
+ }
+ } catch (Exception e) {
+ ClientExceptionHandler.displayError(e);
+ }
+ }
+
+ }
+
+ public boolean hasChildComponent(Widget component) {
+ if (component != null && component == layout) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+ // TODO
+ }
+
+ public Size getAllocatedSpace(Widget child) {
+ return renderInformation.getContentAreaSize();
+ }
+
+ public boolean requestLayout(Set<Paintable> child) {
+
+ if (height != null && width != null) {
+ /*
+ * If the height and width has been specified the child components
+ * cannot make the size of the layout change
+ */
+
+ return true;
+ }
+
+ if (renderInformation.updateSize(getElement())) {
+ return false;
} else {
- super.setWidth(width);
+ return true;
}
+
+ }
+
+ public void updateCaption(Paintable component, UIDL uidl) {
+ // TODO
}
}
import com.itmill.toolkit.terminal.gwt.client.ICaptionWrapper;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public class IPopupView extends HTML implements Paintable {
}
public static native void nativeBlur(Element e) /*-{
- if(e.focus) {
- e.blur();
- }
- }-*/;
+ if(e.focus) {
+ e.blur();
+ }
+ }-*/;
private class CustomPopup extends IToolkitOverlay implements Container {
}
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}// class CustomPopup
}// class IPopupView
initializedAndAttached = true;
}
- private void iLayout() {
- iLayout(-1, -1);
- }
-
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
if (height != null) {
if (height.equals("100%")) {
/*
setValue(new Double(v), animate, roundup);\r
}\r
\r
- public void iLayout(int availableWidth, int availableHeight) {\r
+ public void iLayout() {\r
if (vertical) {\r
setHeight();\r
}\r
package com.itmill.toolkit.terminal.gwt.client.ui;
+import java.util.Set;
+
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
+import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
-public class ISplitPanel extends ComplexPanel implements Paintable,
+public class ISplitPanel extends ComplexPanel implements Container,
ContainerResizedListener {
public static final String CLASSNAME = "i-splitpanel";
private Element draggingCurtain;
+ private ApplicationConnection client;
+
+ private String width = null;
+
+ private String height = null;
+
+ private RenderInformation renderInformationFirst = new RenderInformation();
+ private RenderInformation renderInformationSecond = new RenderInformation();
+
public ISplitPanel() {
this(ORIENTATION_HORIZONTAL);
}
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ this.client = client;
+
if (client.updateComponent(this, uidl, true)) {
return;
}
+ renderInformationFirst.updateSize(getElement());
+
setSplitPosition(uidl.getStringAttribute("position"));
locked = uidl.hasAttribute("locked");
iLayout();
}
- private void iLayout() {
- iLayout(-1, -1);
- }
-
/*
* Calculates absolutely positioned container places/sizes (non-Javadoc)
*
* @see com.itmill.toolkit.terminal.gwt.client.NeedsLayout#layout()
*/
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
if (!isAttached()) {
return;
}
+
+ renderInformationFirst.updateSize(getElement());
+
int wholeSize;
int pixelPosition;
DOM.setStyleAttribute(secondContainer, "left",
(pixelPosition + getSplitterSize()) + "px");
+ int contentHeight = renderInformationFirst.getRenderedSize()
+ .getHeight();
+ renderInformationFirst.setContentAreaHeight(contentHeight);
+ renderInformationFirst.setContentAreaWidth(getSplitterSize());
+ renderInformationSecond.setContentAreaHeight(contentHeight);
+ renderInformationSecond.setContentAreaWidth(secondContainerWidth);
+
break;
case ORIENTATION_VERTICAL:
wholeSize = DOM.getElementPropertyInt(wrapper, "clientHeight");
secondContainerHeight + "px");
DOM.setStyleAttribute(secondContainer, "top",
(pixelPosition + getSplitterSize()) + "px");
+
+ int contentWidth = renderInformationFirst.getRenderedSize()
+ .getWidth();
+ renderInformationFirst.setContentAreaHeight(getSplitterSize());
+ renderInformationFirst.setContentAreaWidth(contentWidth);
+ renderInformationSecond.setContentAreaHeight(secondContainerHeight);
+ renderInformationSecond.setContentAreaWidth(contentWidth);
+
break;
}
if (Util.isIE7()) {
// Part I of IE7 weirdness hack, will be set to auto in layout phase
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
DeferredCommand.addCommand(new Command() {
public void execute() {
DOM.setStyleAttribute(firstContainer, "overflow", "auto");
}
});
} else {
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
if (!(resizing && BrowserInfo.get().isGecko())) {
DOM.setStyleAttribute(firstContainer, "overflow", "auto");
DOM.setStyleAttribute(secondContainer, "overflow", "auto");
}
}
+ renderInformationFirst.updateSize(getElement());
+
}
private void setFirstWidget(Widget w) {
return splitterSize;
}
+ @Override
+ public void setHeight(String height) {
+ this.height = height;
+ super.setHeight(height);
+ }
+
+ @Override
+ public void setWidth(String width) {
+ this.width = width;
+ super.setWidth(width);
+ }
+
+ public Size getAllocatedSpace(Widget child) {
+ if (child == firstChild) {
+ return renderInformationFirst.getContentAreaSize();
+ } else if (child == secondChild) {
+ return renderInformationSecond.getContentAreaSize();
+ }
+
+ return null;
+ }
+
+ public boolean hasChildComponent(Widget component) {
+ return (component != null && (component == firstChild || component == secondChild));
+ }
+
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+ // TODO Auto-generated method stub
+ }
+
+ public boolean requestLayout(Set<Paintable> child) {
+ if (height != null && width != null) {
+ /*
+ * If the height and width has been specified the child components
+ * cannot make the size of the layout change
+ */
+
+ return true;
+ }
+
+ if (renderInformationFirst.updateSize(getElement())) {
+ return false;
+ } else {
+ return true;
+ }
+
+ }
+
+ public void updateCaption(Paintable component, UIDL uidl) {
+ // TODO Auto-generated method stub
+
+ }
+
}
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
public class ITabsheet extends ITabsheetBase implements
ContainerResizedListener {
private boolean waitingForResponse;
+ private RenderInformation renderInformation = new RenderInformation();
+
/**
* Previous visible widget is set invisible with CSS (not display: none, but
* visibility: hidden), to avoid flickering during render process. Normal
|| (this.width == null && width != null)
|| !width.equals(oldWidth)) {
// Run descendant layout functions
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
}
}
- private void iLayout() {
- iLayout(-1, -1);
- }
+ public void iLayout() {
+ renderInformation.updateSize(getElement());
- public void iLayout(int availableWidth, int availableHeight) {
if (height != null && height != "") {
super.setHeight(height);
DOM.setStyleAttribute(contentNode, "height", "");
DOM.setStyleAttribute(contentNode, "overflow", "");
}
- Util.runDescendentsLayout(this);
+
+ if (client != null) {
+ client.runDescendentsLayout(this);
+ }
+
+ renderInformation.setContentAreaWidth(tp.getElement().getOffsetWidth());
+ renderInformation.setContentAreaHeight(tp.getElement()
+ .getOffsetHeight());
updateTabScroller();
+
}
/**
c.updateCaption(uidl);
}
- public boolean childComponentSizesUpdated() {
- // TODO Auto-generated method stub
- return false;
+ public boolean requestLayout(Set<Paintable> child) {
+ if (height != null && width != null) {
+ /*
+ * If the height and width has been specified for this container the
+ * child components cannot make the size of the layout change
+ */
+
+ return true;
+ }
+
+ if (renderInformation.updateSize(getElement())) {
+ /*
+ * Size has changed so we let the child components know about the
+ * new size.
+ */
+ iLayout();
+
+ return false;
+ } else {
+ /*
+ * Size has not changed so we do not need to propagate the event
+ * further
+ */
+ return true;
+ }
+
+ }
+
+ public Size getAllocatedSpace(Widget child) {
+ // All tabs have equal amount of space allocated
+
+ return renderInformation.getContentAreaSize();
}
}
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+ this.client = client;
// Ensure correct implementation
if (client.updateComponent(this, uidl, true)) {
}
// Update member references
- this.client = client;
id = uidl.getId();
disabled = uidl.hasAttribute("disabled");
*
*/
public class ITextField extends TextBoxBase implements Paintable, Field,
- ChangeListener, FocusListener, ContainerResizedListener {
+ ChangeListener, FocusListener {
/**
* The input node CSS classname.
private String valueBeforeEdit = null;
private boolean immediate = false;
- private float proportionalHeight = -1;
- private float proportionalWidth = -1;
private int extraHorizontalPixels = -1;
private int extraVerticalPixels = -1;
} catch (e) {}
}-*/;
- public void setHeight(String height) {
- if (height != null && height.indexOf("%") > 0) {
- // special handling for proportional height
- proportionalHeight = Float.parseFloat(height.substring(0, height
- .indexOf("%"))) / 100;
- iLayout();
- } else {
- super.setHeight(height);
- proportionalHeight = -1;
- }
- }
-
- public void setWidth(String width) {
- if (width != null && width.indexOf("%") > 0) {
- // special handling for proportional w
- proportionalWidth = Float.parseFloat(width.substring(0, width
- .indexOf("%"))) / 100;
- iLayout();
- } else {
- super.setWidth(width);
- proportionalWidth = -1;
- }
- }
-
- private void iLayout() {
- iLayout(-1, -1);
- }
-
- public void iLayout(int availableWidth, int availableHeight) {
- if (proportionalWidth >= 0) {
- int availPixels = availableWidth;
- if (availPixels < 0) {
- availPixels = (DOM.getElementPropertyInt(DOM
- .getParent(getElement()), "clientWidth"));
- }
- availPixels *= proportionalWidth;
-
- availPixels -= getExtraHorizontalPixels();
- if (availPixels >= 0) {
- super.setWidth(availPixels + "px");
- }
- }
- if (proportionalHeight >= 0) {
- int availPixels = availableHeight;
- if (availPixels < 0) {
- availPixels = (DOM.getElementPropertyInt(DOM
- .getParent(getElement()), "clientHeight"));
- }
- availPixels *= proportionalHeight;
- availPixels -= getExtraVerticalPixels();
-
- if (availPixels >= 0) {
- super.setHeight(availPixels + "px");
- }
- }
- }
-
/**
* @return space used by components paddings and borders
*/
DOM.removeChild(DOM.getParent(getElement()), clone);
}
+ @Override
+ public void setHeight(String height) {
+ if (height.endsWith("px")) {
+ int h = Integer.parseInt(height.substring(0, height.length() - 2));
+ h -= getExtraVerticalPixels();
+ super.setHeight(h + "px");
+ } else {
+ super.setHeight(height);
+ }
+ }
+
+ @Override
+ public void setWidth(String width) {
+ if (width.endsWith("px")) {
+ int h = Integer.parseInt(width.substring(0, width.length() - 2));
+ h -= getExtraHorizontalPixels();
+ if (h <= 0) {
+ h = 0;
+ }
+
+ super.setWidth(h + "px");
+ } else {
+ super.setWidth(width);
+ }
+ }
+
}
return fieldExtraWidth;\r
}\r
\r
- private void iLayout() {\r
- iLayout(-1, -1);\r
- }\r
-\r
- public void iLayout(int availableWidth, int availableHeight) {\r
+ public void iLayout() {\r
if (needLayout) {\r
text.setWidth((getOffsetWidth() - getFieldExtraWidth()) + "px");\r
}\r
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
+import com.itmill.toolkit.terminal.gwt.client.Container;
import com.itmill.toolkit.terminal.gwt.client.Focusable;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
/**
*
*/
-public class IView extends SimplePanel implements Paintable,
+public class IView extends SimplePanel implements Container,
WindowResizeListener, WindowCloseListener {
private static final String CLASSNAME = "i-view";
*/
private Timer resizeTimer;
+ private RenderInformation renderInformation = new RenderInformation();
+
public IView(String elementId) {
super();
setStyleName(CLASSNAME);
setWidget((Widget) lo);
layout = lo;
}
+
+ updateContentAreaSize();
+
layout.updateFromUIDL(childUidl, client);
// Update subwindows
onWindowResized(Window.getClientWidth(), Window.getClientHeight());
// IE somehow fails some layout on first run, force layout
// functions
- // Util.runDescendentsLayout(this);
+ // client.runDescendentsLayout(this);
+
+ }
+ private void updateContentAreaSize() {
+ renderInformation.setContentAreaWidth(getElement().getOffsetWidth());
+
+ // For some reason IView has a 1 pixel padding
+ renderInformation
+ .setContentAreaHeight(getElement().getOffsetHeight() - 1);
}
public void onBrowserEvent(Event event) {
.getConsole()
.log(
"Running layout functions due window resize");
- Util.runDescendentsLayout(IView.this);
+ connection.runDescendentsLayout(IView.this);
}
}
};
DOM.setStyleAttribute(getElement(), "overflow", "hidden");
ApplicationConnection.getConsole().log(
"Running layout functions due window resize");
- Util.runDescendentsLayout(this);
+ connection.runDescendentsLayout(this);
DOM.setStyleAttribute(getElement(), "overflow", overflow);
}
+
+ updateContentAreaSize();
+
}
public native static void goTo(String url)
return null;
}
+ public Size getAllocatedSpace(Widget child) {
+ return renderInformation.getContentAreaSize();
+ }
+
+ public boolean hasChildComponent(Widget component) {
+ return (component != null && component == layout);
+ }
+
+ public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+ // TODO Auto-generated method stub
+ }
+
+ public boolean requestLayout(Set<Paintable> child) {
+ /*
+ * Can never propagate further and we do not want need to re-layout the
+ * layout which has caused this request.
+ */
+ return true;
+
+ }
+
+ public void updateCaption(Paintable component, UIDL uidl) {
+ // TODO Auto-generated method stub
+ }
+
}
client.updateVariable(id, "height", h, false);
}
// Update child widget dimensions
- Util.runDescendentsLayout(this);
+ client.runDescendentsLayout(this);
}
@Override
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
+import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
import com.itmill.toolkit.terminal.gwt.client.ui.AlignmentInfo;
private int offsetHeight;
+ protected ApplicationConnection client;
+
public IAbsoluteGrid() {
ap = new AbsolutePanel();
initWidget(ap);
}
}
- public void iLayout(int availableWidth, int availableHeight) {
+ public void iLayout() {
boolean sizeChanged = false;
int newWidth = getOffsetWidth();
if (offsetWidth != newWidth) {
cell.render();
cell.vAling();
}
- Util.runDescendentsLayout(ap);
+ client.runDescendentsLayout(ap);
}
}
offsetHeight = 0;
offsetWidth = 0;
}
+
+ public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {
+ this.client = client;
+ }
+
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation.Size;
import com.itmill.toolkit.terminal.gwt.client.ui.MarginInfo;
/**
public static final String CLASSNAME = "i-gridlayout";
private int spacing;
private HashMap paintableToCellMap = new HashMap();
- private ApplicationConnection client;
private MarginPixels mp;
private String oldStyleString = "";
}
public void updateFromUIDL(UIDL uidl, final ApplicationConnection client) {
- this.client = client;
+ super.updateFromUIDL(uidl, client);
if (client.updateComponent(this, uidl, true)) {
return;
return marginPixels;
}
- public boolean childComponentSizesUpdated() {
+ public boolean requestLayout(Set<Paintable> child) {
// TODO Auto-generated method stub
return false;
}
+ public Size getAllocatedSpace(Widget child) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
class MarginPixels {