From: Leif Åstrand Date: Fri, 10 Feb 2012 09:59:18 +0000 (+0200) Subject: Remove almost unused CellBasedLayout (#8313) X-Git-Tag: 7.0.0.alpha2~434^2~65 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9bdd94a01fdd7221597c29b4efb10ae41cb447f0;p=vaadin-framework.git Remove almost unused CellBasedLayout (#8313) --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java index 5302fa6f67..f269a5d1a2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VGridLayout.java @@ -26,7 +26,6 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout; import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer; public class VGridLayout extends SimplePanel implements Container { @@ -860,7 +859,7 @@ public class VGridLayout extends SimplePanel implements Container { } else { // A new component cc = new ChildComponentContainer(paintable, - CellBasedLayout.ORIENTATION_VERTICAL); + ChildComponentContainer.ORIENTATION_VERTICAL); widgetToComponentContainer.put(w, cc); cc.setWidth(""); canvas.add(cc, 0, 0); diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java deleted file mode 100644 index 9b38ba23ae..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayout.java +++ /dev/null @@ -1,343 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.terminal.gwt.client.ui.layout; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import com.google.gwt.dom.client.DivElement; -import com.google.gwt.dom.client.Document; -import com.google.gwt.dom.client.Node; -import com.google.gwt.dom.client.NodeList; -import com.google.gwt.dom.client.Style; -import com.google.gwt.user.client.ui.ComplexPanel; -import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.Container; -import com.vaadin.terminal.gwt.client.VPaintableMap; -import com.vaadin.terminal.gwt.client.VPaintableWidget; -import com.vaadin.terminal.gwt.client.ui.VMarginInfo; - -public abstract class CellBasedLayout extends ComplexPanel implements Container { - - protected Map widgetToComponentContainer = new HashMap(); - - protected ApplicationConnection client = null; - - public DivElement root; - - public static final int ORIENTATION_VERTICAL = 0; - public static final int ORIENTATION_HORIZONTAL = 1; - - protected Margins activeMargins = new Margins(0, 0, 0, 0); - protected VMarginInfo activeMarginsInfo = new VMarginInfo(-1); - - protected boolean spacingEnabled = false; - protected final Spacing spacingFromCSS = new Spacing(12, 12); - protected final Spacing activeSpacing = new Spacing(0, 0); - - boolean dynamicWidth; - - boolean dynamicHeight; - - private final DivElement clearElement = Document.get().createDivElement(); - - private String lastStyleName = ""; - - boolean marginsNeedsRecalculation = false; - - protected String STYLENAME_SPACING = ""; - protected String STYLENAME_MARGIN_TOP = ""; - protected String STYLENAME_MARGIN_RIGHT = ""; - protected String STYLENAME_MARGIN_BOTTOM = ""; - protected String STYLENAME_MARGIN_LEFT = ""; - - public static class Spacing { - - public int hSpacing = 0; - public int vSpacing = 0; - - public Spacing(int hSpacing, int vSpacing) { - this.hSpacing = hSpacing; - this.vSpacing = vSpacing; - } - - @Override - public String toString() { - return "Spacing [hSpacing=" + hSpacing + ",vSpacing=" + vSpacing - + "]"; - } - - } - - public CellBasedLayout() { - super(); - - setElement(Document.get().createDivElement()); - getElement().getStyle().setProperty("overflow", "hidden"); - if (BrowserInfo.get().isIE()) { - getElement().getStyle().setProperty("position", "relative"); - getElement().getStyle().setProperty("zoom", "1"); - } - - root = Document.get().createDivElement(); - root.getStyle().setProperty("overflow", "hidden"); - if (BrowserInfo.get().isIE()) { - root.getStyle().setProperty("position", "relative"); - } - - getElement().appendChild(root); - - Style style = clearElement.getStyle(); - style.setProperty("width", "0px"); - style.setProperty("height", "0px"); - style.setProperty("clear", "both"); - style.setProperty("overflow", "hidden"); - root.appendChild(clearElement); - - } - - public boolean hasChildComponent(Widget component) { - return widgetToComponentContainer.containsKey(component); - } - - @Override - public void setStyleName(String styleName) { - super.setStyleName(styleName); - - if (isAttached() && marginsNeedsRecalculation - || !lastStyleName.equals(styleName)) { - measureMarginsAndSpacing(); - lastStyleName = styleName; - marginsNeedsRecalculation = false; - } - - } - - @Override - public void setWidth(String width) { - super.setWidth(width); - - /* - * Ensure the the dynamic width stays up to date even if size is altered - * only on client side. - */ - if (width == null || width.equals("")) { - dynamicWidth = true; - } else { - dynamicWidth = false; - } - } - - @Override - public void setHeight(String height) { - super.setHeight(height); - - /* - * Ensure the the dynamic height stays up to date even if size is - * altered only on client side. - */ - if (height == null || height.equals("")) { - dynamicHeight = true; - } else { - dynamicHeight = false; - } - } - - public void addOrMoveChild(ChildComponentContainer childComponent, - int position) { - if (childComponent.getParent() == this) { - if (getWidgetIndex(childComponent) != position) { - // Detach from old position child. - childComponent.removeFromParent(); - - // Logical attach. - getChildren().insert(childComponent, position); - - root.insertBefore(childComponent.getElement(), root - .getChildNodes().getItem(position)); - - adopt(childComponent); - } - } else { - widgetToComponentContainer.put(childComponent.getWidget(), - childComponent); - - // Logical attach. - getChildren().insert(childComponent, position); - - // avoid inserts (they are slower than appends) - boolean insert = true; - if (widgetToComponentContainer.size() == position) { - insert = false; - } - if (insert) { - root.insertBefore(childComponent.getElement(), root - .getChildNodes().getItem(position)); - } else { - root.insertBefore(childComponent.getElement(), clearElement); - } - // Adopt. - adopt(childComponent); - - } - - } - - public Collection getComponentContainers() { - return widgetToComponentContainer.values(); - } - - public ChildComponentContainer getComponentContainer(Widget child) { - return widgetToComponentContainer.get(child); - } - - public boolean isDynamicWidth() { - return dynamicWidth; - } - - public boolean isDynamicHeight() { - return dynamicHeight; - } - - private static DivElement measurement; - private static DivElement measurement2; - private static DivElement measurement3; - private static DivElement helper; - - static { - helper = Document.get().createDivElement(); - helper.setInnerHTML("
" - + "
" - + "
" - + "
"); - NodeList childNodes = helper.getChildNodes(); - measurement = (DivElement) childNodes.getItem(0); - measurement2 = (DivElement) measurement.getFirstChildElement(); - measurement3 = (DivElement) childNodes.getItem(1); - } - - protected boolean measureMarginsAndSpacing() { - if (!isAttached()) { - return false; - } - - // Measure spacing (actually CSS padding) - measurement3.setClassName(STYLENAME_SPACING - + (spacingEnabled ? "-on" : "-off")); - - String sn = getStylePrimaryName() + "-margin"; - - if (activeMarginsInfo.hasTop()) { - sn += " " + STYLENAME_MARGIN_TOP; - } - if (activeMarginsInfo.hasBottom()) { - sn += " " + STYLENAME_MARGIN_BOTTOM; - } - if (activeMarginsInfo.hasLeft()) { - sn += " " + STYLENAME_MARGIN_LEFT; - } - if (activeMarginsInfo.hasRight()) { - sn += " " + STYLENAME_MARGIN_RIGHT; - } - - // Measure top and left margins (actually CSS padding) - measurement.setClassName(sn); - - root.appendChild(helper); - - activeSpacing.vSpacing = measurement3.getOffsetHeight(); - activeSpacing.hSpacing = measurement3.getOffsetWidth(); - - activeMargins.setMarginTop(measurement2.getOffsetTop()); - activeMargins.setMarginLeft(measurement2.getOffsetLeft()); - activeMargins.setMarginRight(measurement.getOffsetWidth() - - activeMargins.getMarginLeft()); - activeMargins.setMarginBottom(measurement.getOffsetHeight() - - activeMargins.getMarginTop()); - - // ApplicationConnection.getConsole().log("Margins: " + activeMargins); - // ApplicationConnection.getConsole().log("Spacing: " + activeSpacing); - // Util.alert("Margins: " + activeMargins); - root.removeChild(helper); - - // apply margin - Style style = root.getStyle(); - style.setPropertyPx("marginLeft", activeMargins.getMarginLeft()); - style.setPropertyPx("marginRight", activeMargins.getMarginRight()); - style.setPropertyPx("marginTop", activeMargins.getMarginTop()); - style.setPropertyPx("marginBottom", activeMargins.getMarginBottom()); - - return true; - } - - protected ChildComponentContainer getFirstChildComponentContainer() { - int size = getChildren().size(); - if (size < 1) { - return null; - } - - return (ChildComponentContainer) getChildren().get(0); - } - - public void removeChildrenAfter(int pos) { - // Remove all children after position "pos" but leave the clear element - // in place - - int toRemove = getChildren().size() - pos; - while (toRemove-- > 0) { - /* flag to not if widget has been moved and rendered elsewhere */ - boolean relocated = false; - ChildComponentContainer child = (ChildComponentContainer) getChildren() - .get(pos); - Widget widget = child.getWidget(); - if (widget == null) { - // a rare case where child component has been relocated and - // rendered elsewhere - // clean widgetToComponentContainer map by iterating the correct - // mapping - Iterator iterator = widgetToComponentContainer.keySet() - .iterator(); - while (iterator.hasNext()) { - Widget key = iterator.next(); - if (widgetToComponentContainer.get(key) == child) { - widget = key; - relocated = true; - break; - } - } - if (widget == null) { - throw new NullPointerException(); - } - } - // ChildComponentContainer remove = - widgetToComponentContainer.remove(widget); - remove(child); - if (!relocated) { - VPaintableMap paintableMap = VPaintableMap.get(client); - VPaintableWidget p = paintableMap.getPaintable(widget); - paintableMap.unregisterPaintable(p); - } - } - - } - - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - ChildComponentContainer componentContainer = widgetToComponentContainer - .remove(oldComponent); - if (componentContainer == null) { - return; - } - - componentContainer.setPaintable(VPaintableMap.get(client).getPaintable( - newComponent)); - client.unregisterPaintable(VPaintableMap.get(client).getPaintable( - oldComponent)); - widgetToComponentContainer.put(newComponent, componentContainer); - } - -} diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java deleted file mode 100644 index 752462dcf6..0000000000 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/CellBasedLayoutPaintable.java +++ /dev/null @@ -1,83 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ -package com.vaadin.terminal.gwt.client.ui.layout; - -import com.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer; -import com.vaadin.terminal.gwt.client.ui.VMarginInfo; - -public abstract class CellBasedLayoutPaintable extends - VAbstractPaintableWidgetContainer { - - @Override - public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - getWidgetForPaintable().client = client; - - // Only non-cached UIDL:s can introduce changes - if (isCachedUpdate(uidl)) { - return; - } - - /** - * Margin and spacind detection depends on classNames and must be set - * before setting size. Here just update the details from UIDL and from - * overridden setStyleName run actual margin detections. - */ - updateMarginAndSpacingInfo(uidl); - - /* - * This call should be made first. Ensure correct implementation, handle - * size etc. - */ - super.updateFromUIDL(uidl, client); - - handleDynamicDimensions(uidl); - } - - private void handleDynamicDimensions(UIDL uidl) { - String w = uidl.hasAttribute("width") ? uidl - .getStringAttribute("width") : ""; - - String h = uidl.hasAttribute("height") ? uidl - .getStringAttribute("height") : ""; - - if (w.equals("")) { - getWidgetForPaintable().dynamicWidth = true; - } else { - getWidgetForPaintable().dynamicWidth = false; - } - - if (h.equals("")) { - getWidgetForPaintable().dynamicHeight = true; - } else { - getWidgetForPaintable().dynamicHeight = false; - } - - } - - void updateMarginAndSpacingInfo(UIDL uidl) { - if (!uidl.hasAttribute("invisible")) { - int bitMask = uidl.getIntAttribute("margins"); - if (getWidgetForPaintable().activeMarginsInfo.getBitMask() != bitMask) { - getWidgetForPaintable().activeMarginsInfo = new VMarginInfo( - bitMask); - getWidgetForPaintable().marginsNeedsRecalculation = true; - } - boolean spacing = uidl.getBooleanAttribute("spacing"); - if (spacing != getWidgetForPaintable().spacingEnabled) { - getWidgetForPaintable().marginsNeedsRecalculation = true; - getWidgetForPaintable().spacingEnabled = spacing; - } - } - } - - @Override - protected abstract CellBasedLayout createWidget(); - - @Override - public CellBasedLayout getWidgetForPaintable() { - return (CellBasedLayout) super.getWidgetForPaintable(); - } -} diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java b/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java index b263f8b5d4..dffb418660 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java @@ -25,6 +25,9 @@ import com.vaadin.terminal.gwt.client.ui.AlignmentInfo; public class ChildComponentContainer extends Panel { + public static final int ORIENTATION_VERTICAL = 0; + public static final int ORIENTATION_HORIZONTAL = 1; + /** * Size of the container DIV excluding any margins and also excluding the * expansion amount (containerExpansion) @@ -152,7 +155,7 @@ public class ChildComponentContainer extends Panel { } public void setOrientation(int orientation) { - if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) { + if (orientation == ORIENTATION_HORIZONTAL) { setFloat(getElement(), "left"); } else { setFloat(getElement(), ""); @@ -618,7 +621,7 @@ public class ChildComponentContainer extends Panel { */ public boolean widgetHasSizeSpecified(int orientation) { String size; - if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) { + if (orientation == ORIENTATION_HORIZONTAL) { size = widget.getElement().getStyle().getProperty("width"); } else { size = widget.getElement().getStyle().getProperty("height"); @@ -630,7 +633,7 @@ public class ChildComponentContainer extends Panel { if (relativeSize == null) { return false; } - if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) { + if (orientation == ORIENTATION_HORIZONTAL) { return relativeSize.getWidth() >= 0; } else { return relativeSize.getHeight() >= 0; @@ -666,7 +669,7 @@ public class ChildComponentContainer extends Panel { public int expand(int orientation, int spaceForExpansion) { int expansionAmount = (int) (spaceForExpansion * expandRatio); - if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) { + if (orientation == ORIENTATION_HORIZONTAL) { // HORIZONTAL containerExpansion.setWidth(expansionAmount); } else { @@ -678,7 +681,7 @@ public class ChildComponentContainer extends Panel { } public void expandExtra(int orientation, int extra) { - if (orientation == CellBasedLayout.ORIENTATION_HORIZONTAL) { + if (orientation == ORIENTATION_HORIZONTAL) { // HORIZONTAL containerExpansion.setWidth(containerExpansion.getWidth() + extra); } else {