From 79342a1a97b74d3bf8d89dad0714e0a674c8f41a Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 12 Jun 2008 11:16:53 +0000 Subject: [PATCH] fixes #1805 svn changeset:4862/svn branch:trunk --- .../terminal/gwt/client/ui/IGridLayout.java | 53 ++++++++++++++++-- .../toolkit/tests/tickets/Ticket1805.java | 55 +++++++++++++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/com/itmill/toolkit/tests/tickets/Ticket1805.java diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java index 4789d9d8aa..4e6a55541c 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java @@ -20,32 +20,57 @@ import com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConst import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper; 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; -public class IGridLayout extends SimplePanel implements Paintable, Container { +public class IGridLayout extends SimplePanel implements Paintable, Container, + ContainerResizedListener { public static final String CLASSNAME = "i-gridlayout"; private Grid grid = new Grid(); + private boolean needsLayout = false; + + private Element margin = DOM.createDiv(); + + private Element meterElement; + + private String width; + public IGridLayout() { super(); + DOM.appendChild(getElement(), margin); + DOM.setStyleAttribute(getElement(), "overflow", "hidden"); setStyleName(CLASSNAME); setWidget(grid); } + protected Element getContainerElement() { + return margin; + } + + public void setWidth(String width) { + this.width = width; + if (width != null && !width.equals("")) { + needsLayout = true; + } else { + needsLayout = false; + grid.setWidth(""); + } + } + public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { if (client.updateComponent(this, uidl, false)) { return; } - final MarginInfo margins = new MarginInfo(uidl .getIntAttribute("margins")); - Element margin = getElement(); setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_TOP, margins.hasTop()); setStyleName(margin, CLASSNAME + "-" + StyleConstants.MARGIN_RIGHT, @@ -57,7 +82,7 @@ public class IGridLayout extends SimplePanel implements Paintable, Container { setStyleName(margin, CLASSNAME + "-" + "spacing", uidl .hasAttribute("spacing")); - + iLayout(); grid.updateFromUIDL(uidl, client); } @@ -220,4 +245,24 @@ public class IGridLayout extends SimplePanel implements Paintable, Container { } + public void iLayout() { + if (needsLayout) { + super.setWidth(width); + if (meterElement == null) { + meterElement = DOM.createDiv(); + DOM.setStyleAttribute(meterElement, "overflow", "hidden"); + DOM.setStyleAttribute(meterElement, "height", "0"); + DOM.appendChild(getContainerElement(), meterElement); + } + int contentWidth = DOM.getElementPropertyInt(meterElement, + "offsetWidth"); + int offsetWidth = getOffsetWidth(); + + grid.setWidth((offsetWidth - (offsetWidth - contentWidth)) + "px"); + } else { + grid.setWidth(""); + } + Util.runDescendentsLayout(this); + } + } diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket1805.java b/src/com/itmill/toolkit/tests/tickets/Ticket1805.java new file mode 100644 index 0000000000..e9a84531d4 --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket1805.java @@ -0,0 +1,55 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.data.Property.ValueChangeEvent; +import com.itmill.toolkit.data.Property.ValueChangeListener; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.GridLayout; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.Window; + +public class Ticket1805 extends com.itmill.toolkit.Application { + + public void init() { + final Window main = new Window(getClass().getName().substring( + getClass().getName().lastIndexOf(".") + 1)); + setMainWindow(main); + main.getLayout().setMargin(false); + + Label description = new Label( + "GridLayout with 100% (no height), is wanted to " + + "share all available width with columns " + + "relatively to their natural width. And it " + + "should still work with margins and spacings"); + main.addComponent(description); + + final GridLayout grid = new GridLayout(4, 1); + + final TextField size = new TextField("Grid width in css unit"); + size.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + String width = size.getValue().toString(); + if (width == null || width.equals("")) { + grid.setSizeUndefined(); + } else { + grid.setWidth(width); + } + } + }); + main.addComponent(size); + main.addComponent(new Button("set size")); + + grid.setMargin(true); + grid.setSpacing(true); + + grid.addComponent(new Label("WIDE")); + grid.addComponent(new Label("_I_")); + grid.addComponent(new Label("VEEEEEEEEEEERY_WIDE")); + Label label = new Label("|"); + grid.addComponent(label); + grid.setComponentAlignment(label, GridLayout.ALIGNMENT_RIGHT, + GridLayout.ALIGNMENT_TOP); + main.addComponent(grid); + } + +} -- 2.39.5