From: Joonas Lehtinen
Date: Thu, 3 Jul 2008 22:22:54 +0000 (+0000)
Subject: IOrderedLayout implementation is now feature complete and thus horizontal and vertica...
X-Git-Tag: 6.7.0.beta1~4476
X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f7c4099b8d532950913123bec0fa46792e1664cc;p=vaadin-framework.git
IOrderedLayout implementation is now feature complete and thus horizontal and vertical variants have become unnecessary. Removing. Also fixed couple of layouting issues.
svn changeset:5047/svn branch:trunk
---
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java
index 7982afda44..b98cdec668 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetSet.java
@@ -28,8 +28,7 @@ import com.itmill.toolkit.terminal.gwt.client.ui.IListSelect;
import com.itmill.toolkit.terminal.gwt.client.ui.IMenuBar;
import com.itmill.toolkit.terminal.gwt.client.ui.INativeSelect;
import com.itmill.toolkit.terminal.gwt.client.ui.IOptionGroup;
-import com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal;
-import com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical;
+import com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayout;
import com.itmill.toolkit.terminal.gwt.client.ui.IPanel;
import com.itmill.toolkit.terminal.gwt.client.ui.IPasswordField;
import com.itmill.toolkit.terminal.gwt.client.ui.IPopupCalendar;
@@ -79,12 +78,9 @@ public class DefaultWidgetSet implements WidgetSet {
} else if ("com.itmill.toolkit.terminal.gwt.client.ui.IWindow"
.equals(className)) {
return new IWindow();
- } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical"
+ } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayout"
.equals(className)) {
- return new IOrderedLayoutVertical();
- } else if ("com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal"
- .equals(className)) {
- return new IOrderedLayoutHorizontal();
+ return new IOrderedLayout();
} else if ("com.itmill.toolkit.terminal.gwt.client.ui.ILabel"
.equals(className)) {
return new ILabel();
@@ -212,11 +208,7 @@ public class DefaultWidgetSet implements WidgetSet {
} else if ("window".equals(tag)) {
return "com.itmill.toolkit.terminal.gwt.client.ui.IWindow";
} else if ("orderedlayout".equals(tag)) {
- if ("horizontal".equals(uidl.getStringAttribute("orientation"))) {
- return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutHorizontal";
- } else {
- return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayoutVertical";
- }
+ return "com.itmill.toolkit.terminal.gwt.client.ui.IOrderedLayout";
} else if ("label".equals(tag)) {
return "com.itmill.toolkit.terminal.gwt.client.ui.ILabel";
} else if ("link".equals(tag)) {
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 52e52bf009..c38014d346 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
@@ -16,9 +16,11 @@ import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
import com.itmill.toolkit.terminal.gwt.client.Caption;
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.StyleConstants;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
+import com.itmill.toolkit.terminal.gwt.client.Util;
/**
* Abstract base class for ordered layouts. Use either vertical or horizontal
@@ -26,7 +28,8 @@ import com.itmill.toolkit.terminal.gwt.client.UIDL;
*
* @author IT Mill Ltd
*/
-public abstract class IOrderedLayout extends Panel implements Container {
+public class IOrderedLayout extends Panel implements Container,
+ ContainerResizedListener {
public static final String CLASSNAME = "i-orderedlayout";
@@ -50,7 +53,7 @@ public abstract class IOrderedLayout extends Panel implements Container {
* Elements that provides the Layout interface implementation. Root element
* of the component. In vertical mode this is the outmost div.
*/
- private Element root;
+ private final Element root;
/**
* Margin element of the component. In vertical mode, this is div inside
@@ -85,13 +88,6 @@ public abstract class IOrderedLayout extends Panel implements Container {
/** Information about margin states. */
private MarginInfo margins = new MarginInfo(0);
- /** Construct a nre IOrderedLayout in given orientation mode. */
- public IOrderedLayout(int orientation) {
- orientationMode = orientation;
- constructDOM();
- setStyleName(CLASSNAME);
- }
-
/**
* Construct the DOM of the orderder layout.
*
@@ -108,10 +104,18 @@ public abstract class IOrderedLayout extends Panel implements Container {
*
*
*/
- private void constructDOM() {
+ public IOrderedLayout() {
+
root = DOM.createDiv();
margin = DOM.createDiv();
DOM.appendChild(root, margin);
+ DOM.setStyleAttribute(margin, "overflow", "hidden");
+ createAndEmptyWrappedChildContainer();
+ setElement(root);
+ setStyleName(CLASSNAME);
+ }
+
+ private void createAndEmptyWrappedChildContainer() {
if (orientationMode == ORIENTATION_HORIZONTAL) {
final String structure = "";
DOM.setInnerHTML(margin, structure);
@@ -119,8 +123,29 @@ public abstract class IOrderedLayout extends Panel implements Container {
.getFirstChild(margin)));
} else {
wrappedChildContainer = margin;
+ DOM.setInnerHTML(margin, "");
}
- setElement(root);
+ }
+
+ /** Update orientation, if it has changed */
+ private void updateOrientation(int newOrientationMode) {
+
+ // Only change when needed
+ if (orientationMode == newOrientationMode) {
+ return;
+ }
+
+ orientationMode = newOrientationMode;
+
+ createAndEmptyWrappedChildContainer();
+
+ // Reinsert all widget wrappers to this container
+ for (int i = 0; i < childWidgetWrappers.size(); i++) {
+ DOM.appendChild(wrappedChildContainer,
+ ((WidgetWrapper) childWidgetWrappers.get(i)).getElement());
+ }
+
+ Util.runDescendentsLayout(this);
}
/** Update the contents of the layout from UIDL. */
@@ -128,6 +153,10 @@ public abstract class IOrderedLayout extends Panel implements Container {
this.client = client;
+ updateOrientation("horizontal".equals(uidl
+ .getStringAttribute("orientation")) ? ORIENTATION_HORIZONTAL
+ : ORIENTATION_VERTICAL);
+
// Ensure correct implementation
if (client.updateComponent(this, uidl, false)) {
return;
@@ -229,33 +258,35 @@ public abstract class IOrderedLayout extends Panel implements Container {
public void setWidth(String width) {
super.setWidth(width);
- if (ORIENTATION_VERTICAL == orientationMode) {
- return;
- }
- if (width == null || "".equals(width)) {
- // Removing fixed size is needed only when it is in use
- if (fixedCellSize) {
+ if (width == null || "".equals(width)) {
+ DOM.setStyleAttribute(margin, "width", "");
+ if (fixedCellSize && orientationMode == ORIENTATION_HORIZONTAL) {
removeFixedSizes();
}
} else {
- fixedCellSize = true;
+ DOM.setStyleAttribute(margin, "width", "100%");
+ if (orientationMode == ORIENTATION_HORIZONTAL) {
+ fixedCellSize = true;
+ }
}
}
public void setHeight(String height) {
super.setHeight(height);
- if (ORIENTATION_HORIZONTAL == orientationMode) {
- return;
- }
+
if (height == null || "".equals(height)) {
+ DOM.setStyleAttribute(margin, "height", "");
// Removing fixed size is needed only when it is in use
- if (fixedCellSize) {
+ if (fixedCellSize && orientationMode == ORIENTATION_VERTICAL) {
removeFixedSizes();
}
} else {
- fixedCellSize = true;
+ DOM.setStyleAttribute(margin, "height", "100%");
+ if (orientationMode == ORIENTATION_VERTICAL) {
+ fixedCellSize = true;
+ }
}
}
@@ -276,13 +307,10 @@ public abstract class IOrderedLayout extends Panel implements Container {
for (Iterator i = childWidgetWrappers.iterator(); i.hasNext();) {
Element we = ((WidgetWrapper) i.next()).getElement();
DOM.setStyleAttribute(we, wh, "");
- DOM.setStyleAttribute(we, overflow, "");
+ DOM.setStyleAttribute(we, "overflow", "");
}
// margin
- DOM.setStyleAttribute(margin,
- (orientationMode == ORIENTATION_HORIZONTAL) ? "overflowX"
- : "overflowY", "");
DOM.setStyleAttribute(margin,
(orientationMode == ORIENTATION_HORIZONTAL) ? "width"
: "height", "");
@@ -307,9 +335,6 @@ public abstract class IOrderedLayout extends Panel implements Container {
return;
}
- DOM.setStyleAttribute(margin,
- (orientationMode == ORIENTATION_HORIZONTAL) ? "overflowX"
- : "overflowY", "hidden");
DOM.setStyleAttribute(margin,
(orientationMode == ORIENTATION_HORIZONTAL) ? "width"
: "height", "100%");
@@ -352,11 +377,13 @@ public abstract class IOrderedLayout extends Panel implements Container {
size -= ws;
DOM.setStyleAttribute(we, wh, "" + ws + "px");
if (firstTime) {
- DOM.setStyleAttribute(we, overflow, "hidden");
+ DOM.setStyleAttribute(we, "overflow", "hidden");
}
}
fixedCellSize = true;
+
+ Util.runDescendentsLayout(this);
}
protected void handleMargins(UIDL uidl) {
@@ -735,4 +762,9 @@ public abstract class IOrderedLayout extends Panel implements Container {
return childWidgets.iterator();
}
+ /* documented at super */
+ public void iLayout() {
+ updateFixedSizes();
+ Util.runDescendentsLayout(this);
+ }
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutHorizontal.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutHorizontal.java
index 105103e901..323cced03b 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutHorizontal.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutHorizontal.java
@@ -4,78 +4,45 @@
package com.itmill.toolkit.terminal.gwt.client.ui;
-import com.google.gwt.user.client.DOM;
import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
-import com.itmill.toolkit.terminal.gwt.client.UIDL;
-import com.itmill.toolkit.terminal.gwt.client.Util;
public class IOrderedLayoutHorizontal extends IOrderedLayout implements
ContainerResizedListener {
-
- private String height;
- private boolean relativeHeight;
- private int marginHeight = 0;
-
- public IOrderedLayoutHorizontal() {
- super(ORIENTATION_HORIZONTAL);
- }
-
- public void setHeight(String newHeight) {
- super.setHeight(newHeight);
- if (newHeight != null && !newHeight.equals("")) {
- if (!newHeight.equals(height)) {
- height = newHeight;
- if (newHeight.indexOf("%") > 0) {
- relativeHeight = true;
- DOM.setStyleAttribute(getElement(), "overflow", "hidden");
- } else {
- relativeHeight = false;
- DOM.setStyleAttribute(getElement(), "overflow", "");
- }
- setInternalHeight();
- }
- } else {
- if (newHeight != null) {
- // clear existing height values
- DOM.setStyleAttribute(getElement(), "overflow", "");
- DOM.setStyleAttribute(DOM.getFirstChild(margin), "height", "");
-
- newHeight = null;
- relativeHeight = false;
- }
- }
- }
-
- protected void handleMargins(UIDL uidl) {
- super.handleMargins(uidl);
- if (height != null) {
- marginHeight = -1;
- setInternalHeight();
- }
- }
-
- private void setInternalHeight() {
- int availSpace = DOM
- .getElementPropertyInt(getElement(), "clientHeight");
- if (marginHeight < 0) {
- DOM.setStyleAttribute(margin, "height", height);
- int tmp = DOM.getElementPropertyInt(margin, "offsetHeight");
- marginHeight = tmp
- - DOM.getElementPropertyInt(getElement(), "clientHeight");
- DOM.setStyleAttribute(margin, "height", "");
- }
-
- availSpace -= marginHeight;
-
- DOM.setStyleAttribute(DOM.getFirstChild(margin), "height", availSpace
- + "px");
-
- }
-
- public void iLayout() {
- if (relativeHeight) {
- setInternalHeight();
- }
- Util.runDescendentsLayout(this);
- }
+ /*
+ * private String height; private boolean relativeHeight; private final int
+ * marginHeight = 0;
+ *
+ * public IOrderedLayoutHorizontal() { super(ORIENTATION_HORIZONTAL); }
+ */
+ /*
+ * public void setHeight(String newHeight) { super.setHeight(newHeight); if
+ * (newHeight != null && !newHeight.equals("")) { if
+ * (!newHeight.equals(height)) { height = newHeight; if
+ * (newHeight.indexOf("%") > 0) { relativeHeight = true;
+ * DOM.setStyleAttribute(getElement(), "overflow", "hidden"); } else {
+ * relativeHeight = false; DOM.setStyleAttribute(getElement(), "overflow",
+ * ""); } setInternalHeight(); } } else { if (newHeight != null) { // clear
+ * existing height values DOM.setStyleAttribute(getElement(), "overflow",
+ * ""); DOM.setStyleAttribute(DOM.getFirstChild(margin), "height", "");
+ *
+ * newHeight = null; relativeHeight = false; } } }
+ *
+ * protected void handleMargins(UIDL uidl) { super.handleMargins(uidl); if
+ * (height != null) { marginHeight = -1; setInternalHeight(); } }
+ *
+ * private void setInternalHeight() { int availSpace = DOM
+ * .getElementPropertyInt(getElement(), "clientHeight"); if (marginHeight <
+ * 0) { DOM.setStyleAttribute(margin, "height", height); int tmp =
+ * DOM.getElementPropertyInt(margin, "offsetHeight"); marginHeight = tmp -
+ * DOM.getElementPropertyInt(getElement(), "clientHeight");
+ * DOM.setStyleAttribute(margin, "height", ""); }
+ *
+ * availSpace -= marginHeight;
+ *
+ * DOM.setStyleAttribute(DOM.getFirstChild(margin), "height", availSpace +
+ * "px"); }
+ *
+ * public void iLayout() { if (relativeHeight) { setInternalHeight(); }
+ * Util.runDescendentsLayout(this); }
+ */
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutVertical.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutVertical.java
index 1214c85421..56f827833b 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutVertical.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayoutVertical.java
@@ -5,8 +5,7 @@
package com.itmill.toolkit.terminal.gwt.client.ui;
public class IOrderedLayoutVertical extends IOrderedLayout {
-
- public IOrderedLayoutVertical() {
- super(ORIENTATION_VERTICAL);
- }
+ /*
+ * public IOrderedLayoutVertical() { super(ORIENTATION_VERTICAL); }
+ */
}