From d58b47321636b79f7b3995195e59efc540867e31 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 27 Dec 2007 09:55:45 +0000 Subject: [PATCH] fixes for IExpandLayout and added some complex tests for it svn changeset:3291/svn branch:trunk --- .../terminal/gwt/client/ui/IExpandLayout.java | 34 ++++++-- .../toolkit/tests/TestForExpandLayout2.java | 65 +++++++++++++++ .../toolkit/tests/TestForExpandLayout3.java | 80 +++++++++++++++++++ 3 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 src/com/itmill/toolkit/tests/TestForExpandLayout2.java create mode 100644 src/com/itmill/toolkit/tests/TestForExpandLayout3.java diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java index c80816ba5f..313d45bbef 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java @@ -181,14 +181,16 @@ public class IExpandLayout extends ComplexPanel implements } void setSpacingEnabled(boolean b) { - setStyleName(getElement(), CLASSNAME + "-" + StyleConstants.VERTICAL_SPACING, b); + setStyleName(getElement(), CLASSNAME + "-" + + StyleConstants.VERTICAL_SPACING, b); } } class HorizontalWidgetWrapper extends WidgetWrapper { - Element td; - String valign = "top"; + private Element td; + private String valign = "top"; + private String align = "left"; public HorizontalWidgetWrapper(Element element) { if (DOM.getElementProperty(element, "nodeName").equals("TD")) { @@ -251,6 +253,11 @@ public class IExpandLayout extends ComplexPanel implements } valign = verticalAlignment; } + if (!align.equals(horizontalAlignment)) { + DOM.setStyleAttribute(getContainerElement(), "textAlign", + horizontalAlignment); + align = horizontalAlignment; + } } public Element getContainerElement() { @@ -262,7 +269,8 @@ public class IExpandLayout extends ComplexPanel implements } void setSpacingEnabled(boolean b) { - setStyleName(getElement(), CLASSNAME + "-" + StyleConstants.HORIZONTAL_SPACING, b); + setStyleName(getElement(), CLASSNAME + "-" + + StyleConstants.HORIZONTAL_SPACING, b); } } @@ -340,6 +348,7 @@ public class IExpandLayout extends ComplexPanel implements pixels = 0; } DOM.setStyleAttribute(me, "height", pixels + "px"); + DOM.setStyleAttribute(me, "overflow", "hidden"); } if (expandedWidget == null) { @@ -366,15 +375,26 @@ public class IExpandLayout extends ComplexPanel implements private int getTopMargin() { if (topMargin < 0) { - topMargin = DOM.getElementPropertyInt(childContainer, "offsetTop"); + topMargin = DOM.getElementPropertyInt(childContainer, "offsetTop") + - DOM.getElementPropertyInt(getElement(), "offsetTop"); + } + if (topMargin < 0) { + // FIXME shouldn't happen + return 0; + } else { + return topMargin; } - return topMargin; } private int getBottomMargin() { if (bottomMargin < 0) { - bottomMargin = DOM.getElementPropertyInt(me, "offsetHeight") + bottomMargin = DOM.getElementPropertyInt(me, "offsetTop") + + DOM.getElementPropertyInt(me, "offsetHeight") - DOM.getElementPropertyInt(breakElement, "offsetTop"); + if (bottomMargin < 0) { + // FIXME shouldn't happen + return 0; + } } return bottomMargin; } diff --git a/src/com/itmill/toolkit/tests/TestForExpandLayout2.java b/src/com/itmill/toolkit/tests/TestForExpandLayout2.java new file mode 100644 index 0000000000..fa668139b2 --- /dev/null +++ b/src/com/itmill/toolkit/tests/TestForExpandLayout2.java @@ -0,0 +1,65 @@ +/* +@ITMillApache2LicenseForJavaFiles@ + */ + +package com.itmill.toolkit.tests; + +import com.itmill.toolkit.terminal.Size; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.ExpandLayout; +import com.itmill.toolkit.ui.Label; +import com.itmill.toolkit.ui.Panel; + +/** + * + * @author IT Mill Ltd. + */ +public class TestForExpandLayout2 extends CustomComponent { + + ExpandLayout main; + + public TestForExpandLayout2() { + createNewView(); + setCompositionRoot(main); + } + + public void createNewView() { + main = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL); + + Panel left = new Panel("Left column"); + left.getSize().setHeight(100, Size.UNITS_PERCENTAGE); + left.getSize().setWidth(150); + main.addComponent(left); + + ExpandLayout center = new ExpandLayout(); + center.addComponent(new Label("header")); + Panel mainContent = new Panel(); + center.addComponent(mainContent); + center.expand(mainContent); + mainContent.getSize().setSizeFull(); + + ExpandLayout buttons = new ExpandLayout( + ExpandLayout.ORIENTATION_HORIZONTAL); + buttons.getSize().setHeight(30, Size.UNITS_PIXELS); + Button b1 = new Button("Save"); + Button b2 = new Button("Cancel"); + Button b3 = new Button("Logout"); + buttons.addComponent(b1); + buttons.setComponentAlignment(b1, ExpandLayout.ALIGNMENT_RIGHT, + ExpandLayout.ALIGNMENT_TOP); + buttons.addComponent(b2); + buttons.addComponent(b3); + center.addComponent(buttons); + + main.addComponent(center); + main.expand(center); + + Panel right = new Panel("Right column"); + right.getSize().setHeight(100, Size.UNITS_PERCENTAGE); + right.getSize().setWidth(200); + + main.addComponent(right); + + } +} diff --git a/src/com/itmill/toolkit/tests/TestForExpandLayout3.java b/src/com/itmill/toolkit/tests/TestForExpandLayout3.java new file mode 100644 index 0000000000..08c4bb0c98 --- /dev/null +++ b/src/com/itmill/toolkit/tests/TestForExpandLayout3.java @@ -0,0 +1,80 @@ +/* +@ITMillApache2LicenseForJavaFiles@ + */ + +package com.itmill.toolkit.tests; + +import com.itmill.toolkit.terminal.Size; +import com.itmill.toolkit.ui.Button; +import com.itmill.toolkit.ui.CustomComponent; +import com.itmill.toolkit.ui.DateField; +import com.itmill.toolkit.ui.ExpandLayout; + +/** + * + * @author IT Mill Ltd. + */ +public class TestForExpandLayout3 extends CustomComponent { + + ExpandLayout main = new ExpandLayout(); + + DateField df; + + public TestForExpandLayout3() { + setCompositionRoot(main); + createNewView(); + } + + public void createNewView() { + main.removeAllComponents(); + + ExpandLayout el; + Button b; + Button b2; + + el = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL); + + b = new Button("SDFS"); + b2 = new Button("DSFSDFDFSSDF"); + + el.addComponent(b); + el.addComponent(b2); + + el.expand(b); + el.setComponentAlignment(b, ExpandLayout.ALIGNMENT_RIGHT, + ExpandLayout.ALIGNMENT_VERTICAL_CENTER); + main.addComponent(el); + + el = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL); + + b = new Button("SDFS"); + b2 = new Button("DSFSDFDFSSDF"); + + el.addComponent(b); + el.addComponent(b2); + + el.expand(b); + el.setComponentAlignment(b, ExpandLayout.ALIGNMENT_HORIZONTAL_CENTER, + ExpandLayout.ALIGNMENT_VERTICAL_CENTER); + el.getSize().setHeight(60, Size.UNITS_PIXELS); + el.setMargin(true); + main.addComponent(el); + + el = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL); + + b = new Button("SDFS"); + b2 = new Button("DSFSDFDFSSDF"); + + el.addComponent(b); + el.addComponent(b2); + + el.expand(b); + el.setComponentAlignment(b, ExpandLayout.ALIGNMENT_RIGHT, + ExpandLayout.ALIGNMENT_BOTTOM); + el.getSize().setHeight(100, Size.UNITS_PIXELS); + el.setSpacing(true); + + main.addComponent(el); + + } +} -- 2.39.5