]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes for IExpandLayout and added some complex tests for it
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 27 Dec 2007 09:55:45 +0000 (09:55 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 27 Dec 2007 09:55:45 +0000 (09:55 +0000)
svn changeset:3291/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java
src/com/itmill/toolkit/tests/TestForExpandLayout2.java [new file with mode: 0644]
src/com/itmill/toolkit/tests/TestForExpandLayout3.java [new file with mode: 0644]

index c80816ba5fd4cc8c15d853aee6c635e87b179a27..313d45bbef7994b2b5834a24d92eae7b1470efb6 100644 (file)
@@ -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 (file)
index 0000000..fa66813
--- /dev/null
@@ -0,0 +1,65 @@
+/* \r
+@ITMillApache2LicenseForJavaFiles@\r
+ */\r
+\r
+package com.itmill.toolkit.tests;\r
+\r
+import com.itmill.toolkit.terminal.Size;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.CustomComponent;\r
+import com.itmill.toolkit.ui.ExpandLayout;\r
+import com.itmill.toolkit.ui.Label;\r
+import com.itmill.toolkit.ui.Panel;\r
+\r
+/**\r
+ * \r
+ * @author IT Mill Ltd.\r
+ */\r
+public class TestForExpandLayout2 extends CustomComponent {\r
+\r
+    ExpandLayout main;\r
+\r
+    public TestForExpandLayout2() {\r
+        createNewView();\r
+        setCompositionRoot(main);\r
+    }\r
+\r
+    public void createNewView() {\r
+        main = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL);\r
+\r
+        Panel left = new Panel("Left column");\r
+        left.getSize().setHeight(100, Size.UNITS_PERCENTAGE);\r
+        left.getSize().setWidth(150);\r
+        main.addComponent(left);\r
+\r
+        ExpandLayout center = new ExpandLayout();\r
+        center.addComponent(new Label("header"));\r
+        Panel mainContent = new Panel();\r
+        center.addComponent(mainContent);\r
+        center.expand(mainContent);\r
+        mainContent.getSize().setSizeFull();\r
+\r
+        ExpandLayout buttons = new ExpandLayout(\r
+                ExpandLayout.ORIENTATION_HORIZONTAL);\r
+        buttons.getSize().setHeight(30, Size.UNITS_PIXELS);\r
+        Button b1 = new Button("Save");\r
+        Button b2 = new Button("Cancel");\r
+        Button b3 = new Button("Logout");\r
+        buttons.addComponent(b1);\r
+        buttons.setComponentAlignment(b1, ExpandLayout.ALIGNMENT_RIGHT,\r
+                ExpandLayout.ALIGNMENT_TOP);\r
+        buttons.addComponent(b2);\r
+        buttons.addComponent(b3);\r
+        center.addComponent(buttons);\r
+\r
+        main.addComponent(center);\r
+        main.expand(center);\r
+\r
+        Panel right = new Panel("Right column");\r
+        right.getSize().setHeight(100, Size.UNITS_PERCENTAGE);\r
+        right.getSize().setWidth(200);\r
+\r
+        main.addComponent(right);\r
+\r
+    }\r
+}\r
diff --git a/src/com/itmill/toolkit/tests/TestForExpandLayout3.java b/src/com/itmill/toolkit/tests/TestForExpandLayout3.java
new file mode 100644 (file)
index 0000000..08c4bb0
--- /dev/null
@@ -0,0 +1,80 @@
+/* \r
+@ITMillApache2LicenseForJavaFiles@\r
+ */\r
+\r
+package com.itmill.toolkit.tests;\r
+\r
+import com.itmill.toolkit.terminal.Size;\r
+import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.CustomComponent;\r
+import com.itmill.toolkit.ui.DateField;\r
+import com.itmill.toolkit.ui.ExpandLayout;\r
+\r
+/**\r
+ * \r
+ * @author IT Mill Ltd.\r
+ */\r
+public class TestForExpandLayout3 extends CustomComponent {\r
+\r
+    ExpandLayout main = new ExpandLayout();\r
+\r
+    DateField df;\r
+\r
+    public TestForExpandLayout3() {\r
+        setCompositionRoot(main);\r
+        createNewView();\r
+    }\r
+\r
+    public void createNewView() {\r
+        main.removeAllComponents();\r
+\r
+        ExpandLayout el;\r
+        Button b;\r
+        Button b2;\r
+\r
+        el = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL);\r
+\r
+        b = new Button("SDFS");\r
+        b2 = new Button("DSFSDFDFSSDF");\r
+\r
+        el.addComponent(b);\r
+        el.addComponent(b2);\r
+\r
+        el.expand(b);\r
+        el.setComponentAlignment(b, ExpandLayout.ALIGNMENT_RIGHT,\r
+                ExpandLayout.ALIGNMENT_VERTICAL_CENTER);\r
+        main.addComponent(el);\r
+\r
+        el = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL);\r
+\r
+        b = new Button("SDFS");\r
+        b2 = new Button("DSFSDFDFSSDF");\r
+\r
+        el.addComponent(b);\r
+        el.addComponent(b2);\r
+\r
+        el.expand(b);\r
+        el.setComponentAlignment(b, ExpandLayout.ALIGNMENT_HORIZONTAL_CENTER,\r
+                ExpandLayout.ALIGNMENT_VERTICAL_CENTER);\r
+        el.getSize().setHeight(60, Size.UNITS_PIXELS);\r
+        el.setMargin(true);\r
+        main.addComponent(el);\r
+\r
+        el = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL);\r
+\r
+        b = new Button("SDFS");\r
+        b2 = new Button("DSFSDFDFSSDF");\r
+\r
+        el.addComponent(b);\r
+        el.addComponent(b2);\r
+\r
+        el.expand(b);\r
+        el.setComponentAlignment(b, ExpandLayout.ALIGNMENT_RIGHT,\r
+                ExpandLayout.ALIGNMENT_BOTTOM);\r
+        el.getSize().setHeight(100, Size.UNITS_PIXELS);\r
+        el.setSpacing(true);\r
+\r
+        main.addComponent(el);\r
+\r
+    }\r
+}\r