From 818ab6ab5ec8c97cc5f6abefd5601e81ff75ee0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 14 Feb 2012 10:34:16 +0200 Subject: [PATCH] SplitPanel working with the MeasureManager (#8313) --- .../gwt/client/ui/VAbstractSplitPanel.java | 131 ++---------------- .../ui/VAbstractSplitPanelPaintable.java | 14 +- 2 files changed, 19 insertions(+), 126 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java index f1a932b3a3..9a24384f1e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanel.java @@ -4,9 +4,8 @@ package com.vaadin.terminal.gwt.client.ui; -import java.util.Set; - import com.google.gwt.dom.client.Node; +import com.google.gwt.dom.client.Style; import com.google.gwt.event.dom.client.TouchCancelEvent; import com.google.gwt.event.dom.client.TouchCancelHandler; import com.google.gwt.event.dom.client.TouchEndEvent; @@ -22,15 +21,10 @@ 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.ContainerResizedListener; -import com.vaadin.terminal.gwt.client.RenderInformation; -import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VConsole; -public class VAbstractSplitPanel extends ComplexPanel implements Container, - ContainerResizedListener { +public class VAbstractSplitPanel extends ComplexPanel { private boolean enabled = false; @@ -78,21 +72,10 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container, ApplicationConnection client; - private String width = ""; - - private String height = ""; - - private RenderSpace firstRenderSpace = new RenderSpace(0, 0, true); - private RenderSpace secondRenderSpace = new RenderSpace(0, 0, true); - - RenderInformation renderInformation = new RenderInformation(); - String id; boolean immediate; - boolean rendering = false; - /* The current position of the split handle in either percentages or pixels */ String position; @@ -254,36 +237,33 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container, : getOffsetHeight()) + "px"; } + String attributeName; if (orientation == ORIENTATION_HORIZONTAL) { if (positionReversed) { - DOM.setStyleAttribute(splitter, "right", pos); + attributeName = "right"; } else { - DOM.setStyleAttribute(splitter, "left", pos); + attributeName = "left"; } } else { if (positionReversed) { - DOM.setStyleAttribute(splitter, "bottom", pos); + attributeName = "bottom"; } else { - DOM.setStyleAttribute(splitter, "top", pos); + attributeName = "top"; } } - iLayout(); - client.runDescendentsLayout(this); + Style style = splitter.getStyle(); + if (!pos.equals(style.getProperty(attributeName))) { + style.setProperty(attributeName, pos); + updateSizes(); + } } - /* - * Calculates absolutely positioned container places/sizes (non-Javadoc) - * - * @see com.vaadin.terminal.gwt.client.NeedsLayout#layout() - */ - public void iLayout() { + void updateSizes() { if (!isAttached()) { return; } - renderInformation.updateSize(getElement()); - int wholeSize; int pixelPosition; @@ -313,12 +293,6 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container, DOM.setStyleAttribute(secondContainer, "left", (pixelPosition + getSplitterSize()) + "px"); - int contentHeight = renderInformation.getRenderedSize().getHeight(); - firstRenderSpace.setHeight(contentHeight); - firstRenderSpace.setWidth(pixelPosition); - secondRenderSpace.setHeight(contentHeight); - secondRenderSpace.setWidth(secondContainerWidth); - break; case ORIENTATION_VERTICAL: wholeSize = DOM.getElementPropertyInt(wrapper, "clientHeight"); @@ -346,12 +320,6 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container, DOM.setStyleAttribute(secondContainer, "top", (pixelPosition + getSplitterSize()) + "px"); - int contentWidth = renderInformation.getRenderedSize().getWidth(); - firstRenderSpace.setHeight(pixelPosition); - firstRenderSpace.setWidth(contentWidth); - secondRenderSpace.setHeight(secondContainerHeight); - secondRenderSpace.setWidth(contentWidth); - break; } @@ -606,79 +574,6 @@ public class VAbstractSplitPanel extends ComplexPanel implements Container, return splitterSize; } - @Override - public void setHeight(String height) { - if (this.height.equals(height)) { - return; - } - - this.height = height; - super.setHeight(height); - - if (!rendering && client != null) { - setSplitPosition(position); - } - } - - @Override - public void setWidth(String width) { - if (this.width.equals(width)) { - return; - } - - this.width = width; - super.setWidth(width); - - if (!rendering && client != null) { - setSplitPosition(position); - } - } - - public RenderSpace getAllocatedSpace(Widget child) { - if (child == firstChild) { - return firstRenderSpace; - } else if (child == secondChild) { - return secondRenderSpace; - } - - return null; - } - - public boolean hasChildComponent(Widget component) { - return (component != null && (component == firstChild || component == secondChild)); - } - - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - if (oldComponent == firstChild) { - setFirstWidget(newComponent); - } else if (oldComponent == secondChild) { - setSecondWidget(newComponent); - } - } - - public boolean requestLayout(Set children) { - // content size change might cause change to its available space - // (scrollbars) - for (Widget widget : children) { - client.handleComponentRelativeSize(widget); - } - 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 { - return true; - } - - } - /** * Updates the new split position back to server. */ diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java index ccf3119d13..8b21c26960 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java @@ -16,7 +16,7 @@ import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; public abstract class VAbstractSplitPanelPaintable extends - VAbstractPaintableWidgetContainer { + VAbstractPaintableWidgetContainer implements ResizeRequired { public static final String SPLITTER_CLICK_EVENT_IDENTIFIER = "sp_click"; @@ -68,13 +68,11 @@ public abstract class VAbstractSplitPanelPaintable extends public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { getWidgetForPaintable().client = client; getWidgetForPaintable().id = uidl.getId(); - getWidgetForPaintable().rendering = true; getWidgetForPaintable().immediate = uidl.hasAttribute("immediate"); super.updateFromUIDL(uidl, client); if (!isRealUpdate(uidl)) { - getWidgetForPaintable().rendering = false; return; } getWidgetForPaintable().setEnabled( @@ -123,15 +121,15 @@ public abstract class VAbstractSplitPanelPaintable extends newFirstChildPaintable.updateFromUIDL(uidl.getChildUIDL(0), client); newSecondChildPaintable.updateFromUIDL(uidl.getChildUIDL(1), client); - getWidgetForPaintable().renderInformation - .updateSize(getWidgetForPaintable().getElement()); - // This is needed at least for cases like #3458 to take // appearing/disappearing scrollbars into account. client.runDescendentsLayout(getWidgetForPaintable()); + } - getWidgetForPaintable().rendering = false; - + public void onResize() { + VAbstractSplitPanel splitPanel = getWidgetForPaintable(); + splitPanel.setSplitPosition(splitPanel.position); + splitPanel.updateSizes(); } @Override -- 2.39.5