]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated #1878 test case to a generic test case which includes expand layout
authorArtur Signell <artur.signell@itmill.com>
Tue, 2 Sep 2008 05:55:28 +0000 (05:55 +0000)
committerArtur Signell <artur.signell@itmill.com>
Tue, 2 Sep 2008 05:55:28 +0000 (05:55 +0000)
svn changeset:5319/svn branch:trunk

src/com/itmill/toolkit/tests/tickets/Ticket1878.java

index 7ccc289aa4ad0892a3a882bc1c84ea398630d6f1..62573a6f2d55588fb2676d84e1326c21e04f0437 100644 (file)
@@ -5,6 +5,7 @@ import com.itmill.toolkit.terminal.Resource;
 import com.itmill.toolkit.terminal.ThemeResource;\r
 import com.itmill.toolkit.terminal.UserError;\r
 import com.itmill.toolkit.ui.Button;\r
+import com.itmill.toolkit.ui.ExpandLayout;\r
 import com.itmill.toolkit.ui.GridLayout;\r
 import com.itmill.toolkit.ui.Layout;\r
 import com.itmill.toolkit.ui.OrderedLayout;\r
@@ -13,13 +14,17 @@ import com.itmill.toolkit.ui.TextField;
 import com.itmill.toolkit.ui.Window;\r
 import com.itmill.toolkit.ui.Button.ClickEvent;\r
 import com.itmill.toolkit.ui.Button.ClickListener;\r
+import com.itmill.toolkit.ui.Layout.AlignmentHandler;\r
 \r
 public class Ticket1878 extends Application {\r
 \r
     private Layout orderedLayout;\r
     private Layout gridLayout;\r
+    private Layout expandLayout;\r
     private GridLayout mainLayout;\r
-    private Button switchButton;\r
+    private Button switchToGridButton;\r
+    private Button switchToOrderedButton;\r
+    private Button switchToExpandButton;\r
 \r
     public void init() {\r
         Window w = new Window(getClass().getSimpleName());\r
@@ -30,14 +35,41 @@ public class Ticket1878 extends Application {
         w.setLayout(mainLayout);\r
         orderedLayout = createOL();\r
         gridLayout = createGL();\r
-        switchButton = new Button("Switch to GridLayout", new ClickListener() {\r
+        expandLayout = createEL();\r
 \r
-            public void buttonClick(ClickEvent event) {\r
-                changeLayout();\r
-            }\r
+        switchToGridButton = new Button("Switch to GridLayout",\r
+                new ClickListener() {\r
+\r
+                    public void buttonClick(ClickEvent event) {\r
+                        changeLayout(switchToGridButton, gridLayout);\r
+                    }\r
+\r
+                });\r
+        switchToOrderedButton = new Button("Switch to OrderedLayout",\r
+                new ClickListener() {\r
+\r
+                    public void buttonClick(ClickEvent event) {\r
+                        changeLayout(switchToOrderedButton, orderedLayout);\r
+                    }\r
+\r
+                });\r
+        switchToOrderedButton.setEnabled(false);\r
+        switchToExpandButton = new Button("Switch to ExpandLayout",\r
+                new ClickListener() {\r
+\r
+                    public void buttonClick(ClickEvent event) {\r
+                        changeLayout(switchToExpandButton, expandLayout);\r
+                    }\r
 \r
-        });\r
-        mainLayout.addComponent(switchButton);\r
+                });\r
+\r
+        OrderedLayout buttonLayout = new OrderedLayout(\r
+                OrderedLayout.ORIENTATION_HORIZONTAL);\r
+        buttonLayout.addComponent(switchToOrderedButton);\r
+        buttonLayout.addComponent(switchToGridButton);\r
+        buttonLayout.addComponent(switchToExpandButton);\r
+\r
+        mainLayout.addComponent(buttonLayout);\r
         mainLayout.addComponent(orderedLayout);\r
         // w.setLayout(orderedLayout);\r
     }\r
@@ -46,23 +78,25 @@ public class Ticket1878 extends Application {
         GridLayout layout = new GridLayout(1, 5);\r
 \r
         GridLayout l1 = new GridLayout(1, 3);\r
-        createOrderedLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
-                "150", "100%", null);\r
-        createOrderedLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
-                "100", "100%", null);\r
+        createLayout(l1,\r
+                new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL),\r
+                "1000", "150", "100%", null, true);\r
+        createLayout(l1,\r
+                new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL),\r
+                "1000", "150", "100", null, false);\r
         GridLayout l2 = new GridLayout(6, 1);\r
-        createOrderedLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "200",\r
-                "500");\r
-        createOrderedLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "200",\r
-                "500", "100%", null);\r
-        createOrderedLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "150",\r
-                "500");\r
-        createOrderedLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "150",\r
-                "500", "100%", null);\r
-        createOrderedLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "100",\r
-                "500");\r
-        createOrderedLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "100",\r
-                "500", "100%", null);\r
+        createLayout(l2, new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL),\r
+                "200", "500", true);\r
+        createLayout(l2, new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL),\r
+                "200", "500", "100%", null, true);\r
+        createLayout(l2, new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL),\r
+                "150", "500", true);\r
+        createLayout(l2, new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL),\r
+                "150", "500", "100%", null, true);\r
+        createLayout(l2, new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL),\r
+                "100", "500", true);\r
+        createLayout(l2, new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL),\r
+                "100", "500", "100%", null, true);\r
         layout.addComponent(l1);\r
         layout.addComponent(l2);\r
 \r
@@ -73,112 +107,96 @@ public class Ticket1878 extends Application {
         GridLayout layout = new GridLayout(1, 5);\r
 \r
         GridLayout l1 = new GridLayout(1, 3);\r
-        createGridLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
-                "150", "100%", null);\r
-        createGridLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
-                "100", "100%", null);\r
+        createLayout(l1, new GridLayout(8, 1), "1000", "150", "100%", null,\r
+                true);\r
+        createLayout(l1, new GridLayout(8, 1), "1000", "150", "100", null,\r
+                false);\r
         GridLayout l2 = new GridLayout(6, 1);\r
-        createGridLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "200", "500");\r
-        createGridLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "200", "500",\r
-                "100%", null);\r
-        createGridLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "150", "500");\r
-        createGridLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "150", "500",\r
-                "100%", null);\r
-        createGridLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "100", "500");\r
-        createGridLayout(l2, OrderedLayout.ORIENTATION_VERTICAL, "100", "500",\r
-                "100%", null);\r
+        createLayout(l2, new GridLayout(1, 8), "200", "500", true);\r
+        createLayout(l2, new GridLayout(1, 8), "200", "500", "100%", null, true);\r
+        createLayout(l2, new GridLayout(1, 8), "150", "500", true);\r
+        createLayout(l2, new GridLayout(1, 8), "150", "500", "100%", null, true);\r
+        createLayout(l2, new GridLayout(1, 8), "100", "500", true);\r
+        createLayout(l2, new GridLayout(1, 8), "100", "500", "100%", null, true);\r
         layout.addComponent(l1);\r
         layout.addComponent(l2);\r
 \r
         return layout;\r
     }\r
 \r
-    protected void changeLayout() {\r
-        java.util.Iterator i = mainLayout.getComponentIterator();\r
-        i.next();\r
-        Layout l = (Layout) i.next();\r
-        if (l == orderedLayout) {\r
-            switchButton.setCaption("Switch to OrderedLayout");\r
-            mainLayout.replaceComponent(l, gridLayout);\r
-        } else {\r
-            switchButton.setCaption("Switch to GridLayout");\r
-            mainLayout.replaceComponent(l, orderedLayout);\r
-        }\r
-    }\r
-\r
-    private static void createOrderedLayout(GridLayout parentLayout, int dir,\r
-            String w, String h) {\r
-        createOrderedLayout(parentLayout, dir, w, h, null, null);\r
-    }\r
-\r
-    private static void createOrderedLayout(GridLayout parentLayout, int dir,\r
-            String w, String h, String componentWidth, String componentHeight) {\r
-        OrderedLayout ol = new OrderedLayout(dir);\r
-\r
-        String dirText = (dir == OrderedLayout.ORIENTATION_HORIZONTAL ? "H"\r
-                : "V");\r
-        String cWidth = componentWidth == null ? "" : " - " + componentWidth;\r
-        Panel p = new Panel("OL/" + dirText + " " + w + "x" + h + cWidth, ol);\r
-\r
-        p.setWidth(w);\r
-        p.setHeight(h);\r
-\r
-        ol.setSizeFull();\r
+    private static Layout createEL() {\r
+        GridLayout layout = new GridLayout(1, 5);\r
 \r
-        String captions[] = new String[] { "TextField with caption", null };\r
-        Resource icons[] = new Resource[] {\r
-                new ThemeResource("icons/16/document-delete.png"), null };\r
-        boolean required[] = new boolean[] { true, false };\r
-        TextField fields[][] = new TextField[captions.length][icons.length];\r
-        for (int caption = 0; caption < captions.length; caption++) {\r
-            for (int icon = 0; icon < icons.length; icon++) {\r
-                for (int req = 0; req < required.length; req++) {\r
-                    TextField tf = createTextFieldWithError(captions[caption],\r
-                            icons[icon], required[req]);\r
+        GridLayout l1 = new GridLayout(1, 3);\r
+        createLayout(l1, new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL),\r
+                "1000", "150", "100", null, true);\r
+        createLayout(l1, new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL),\r
+                "1000", "150", "50", null, false);\r
 \r
-                    fields[caption][icon] = tf;\r
-                    if (componentWidth != null) {\r
-                        tf.setWidth(componentWidth);\r
-                    }\r
+        GridLayout l2 = new GridLayout(6, 1);\r
+        createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL),\r
+                "200", "500", true);\r
+        createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL),\r
+                "200", "500", "100%", null, true);\r
+        createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL),\r
+                "150", "500", true);\r
+        createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL),\r
+                "150", "500", "100%", null, true);\r
+        createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL),\r
+                "100", "500", true);\r
+        createLayout(l2, new ExpandLayout(ExpandLayout.ORIENTATION_VERTICAL),\r
+                "100", "500", "100%", null, true);\r
+        layout.addComponent(l1);\r
+        layout.addComponent(l2);\r
 \r
-                    if (componentHeight != null) {\r
-                        tf.setHeight(componentWidth);\r
-                    }\r
+        return layout;\r
+    }\r
 \r
-                    p.addComponent(tf);\r
-                    ol.setComponentAlignment(tf, OrderedLayout.ALIGNMENT_LEFT,\r
-                            OrderedLayout.ALIGNMENT_BOTTOM);\r
-                }\r
-            }\r
-        }\r
+    protected void changeLayout(Button b, Layout newLayout) {\r
+        switchToOrderedButton.setEnabled(true);\r
+        switchToGridButton.setEnabled(true);\r
+        switchToExpandButton.setEnabled(true);\r
 \r
-        parentLayout.addComponent(p);\r
+        b.setEnabled(false);\r
+        java.util.Iterator i = mainLayout.getComponentIterator();\r
+        i.next();\r
+        Layout l = (Layout) i.next();\r
 \r
+        mainLayout.replaceComponent(l, newLayout);\r
     }\r
 \r
-    private static void createGridLayout(GridLayout parentLayout, int dir,\r
-            String w, String h) {\r
-        createGridLayout(parentLayout, dir, w, h, null, null);\r
+    private static void createLayout(GridLayout parentLayout, Layout newLayout,\r
+            String w, String h, boolean align) {\r
+        createLayout(parentLayout, newLayout, w, h, null, null, align);\r
     }\r
 \r
-    private static void createGridLayout(GridLayout parentLayout, int dir,\r
-            String w, String h, String componentWidth, String componentHeight) {\r
-        GridLayout gl;\r
-        if (dir == OrderedLayout.ORIENTATION_HORIZONTAL) {\r
-            gl = new GridLayout(8, 1);\r
+    private static void createLayout(GridLayout parentLayout, Layout newLayout,\r
+            String w, String h, String componentWidth, String componentHeight,\r
+            boolean align) {\r
+        int dir;\r
+        String type;\r
+        if (newLayout instanceof ExpandLayout) {\r
+            dir = ((ExpandLayout) newLayout).getOrientation();\r
+            type = "EL";\r
+        } else if (newLayout instanceof OrderedLayout) {\r
+            dir = ((OrderedLayout) newLayout).getOrientation();\r
+            type = "OL";\r
         } else {\r
-            gl = new GridLayout(1, 8);\r
+            dir = ((GridLayout) newLayout).getColumns() == 1 ? OrderedLayout.ORIENTATION_VERTICAL\r
+                    : OrderedLayout.ORIENTATION_HORIZONTAL;\r
+            type = "GL";\r
         }\r
-\r
         String dirText = (dir == OrderedLayout.ORIENTATION_HORIZONTAL ? "H"\r
                 : "V");\r
+        String alignText = align ? "-A" : "";\r
         String cWidth = componentWidth == null ? "" : " - " + componentWidth;\r
-        Panel p = new Panel("GL/" + dirText + " " + w + "x" + h + cWidth, gl);\r
+        Panel p = new Panel(type + "/" + dirText + alignText + " " + w + "x"\r
+                + h + cWidth, newLayout);\r
 \r
         p.setWidth(w);\r
         p.setHeight(h);\r
 \r
-        gl.setSizeFull();\r
+        newLayout.setSizeFull();\r
 \r
         String captions[] = new String[] { "TextField with caption", null };\r
         Resource icons[] = new Resource[] {\r
@@ -194,15 +212,21 @@ public class Ticket1878 extends Application {
                     fields[caption][icon] = tf;\r
                     if (componentWidth != null) {\r
                         tf.setWidth(componentWidth);\r
+                        tf.setValue(tf.getValue() + " w:" + componentWidth);\r
                     }\r
 \r
                     if (componentHeight != null) {\r
                         tf.setHeight(componentWidth);\r
+                        tf.setValue(tf.getValue() + " h:" + componentHeight);\r
                     }\r
 \r
                     p.addComponent(tf);\r
-                    gl.setComponentAlignment(tf, OrderedLayout.ALIGNMENT_LEFT,\r
-                            OrderedLayout.ALIGNMENT_BOTTOM);\r
+\r
+                    if (align) {\r
+                        ((AlignmentHandler) newLayout).setComponentAlignment(\r
+                                tf, OrderedLayout.ALIGNMENT_LEFT,\r
+                                OrderedLayout.ALIGNMENT_BOTTOM);\r
+                    }\r
                 }\r
             }\r
         }\r
@@ -211,6 +235,61 @@ public class Ticket1878 extends Application {
 \r
     }\r
 \r
+    // private static void createGridLayout(GridLayout parentLayout, int dir,\r
+    // String w, String h) {\r
+    // createGridLayout(parentLayout, dir, w, h, null, null);\r
+    // }\r
+\r
+    // private static void createGridLayout(GridLayout parentLayout, int dir,\r
+    // String w, String h, String componentWidth, String componentHeight) {\r
+    // GridLayout gl;\r
+    // if (dir == OrderedLayout.ORIENTATION_HORIZONTAL) {\r
+    // gl = new GridLayout(8, 1);\r
+    // } else {\r
+    // gl = new GridLayout(1, 8);\r
+    // }\r
+    //\r
+    // String dirText = (dir == OrderedLayout.ORIENTATION_HORIZONTAL ? "H"\r
+    // : "V");\r
+    // String cWidth = componentWidth == null ? "" : " - " + componentWidth;\r
+    // Panel p = new Panel("GL/" + dirText + " " + w + "x" + h + cWidth, gl);\r
+    //\r
+    // p.setWidth(w);\r
+    // p.setHeight(h);\r
+    //\r
+    // gl.setSizeFull();\r
+    //\r
+    // String captions[] = new String[] { "TextField with caption", null };\r
+    // Resource icons[] = new Resource[] {\r
+    // new ThemeResource("icons/16/document-delete.png"), null };\r
+    // boolean required[] = new boolean[] { true, false };\r
+    // TextField fields[][] = new TextField[captions.length][icons.length];\r
+    // for (int caption = 0; caption < captions.length; caption++) {\r
+    // for (int icon = 0; icon < icons.length; icon++) {\r
+    // for (int req = 0; req < required.length; req++) {\r
+    // TextField tf = createTextFieldWithError(captions[caption],\r
+    // icons[icon], required[req]);\r
+    //\r
+    // fields[caption][icon] = tf;\r
+    // if (componentWidth != null) {\r
+    // tf.setWidth(componentWidth);\r
+    // }\r
+    //\r
+    // if (componentHeight != null) {\r
+    // tf.setHeight(componentWidth);\r
+    // }\r
+    //\r
+    // p.addComponent(tf);\r
+    // gl.setComponentAlignment(tf, OrderedLayout.ALIGNMENT_LEFT,\r
+    // OrderedLayout.ALIGNMENT_BOTTOM);\r
+    // }\r
+    // }\r
+    // }\r
+    //\r
+    // parentLayout.addComponent(p);\r
+    //\r
+    // }\r
+\r
     private static TextField createTextFieldWithError(String caption,\r
             Resource icon, boolean required) {\r
         TextField tf = new TextField();\r
@@ -218,7 +297,6 @@ public class Ticket1878 extends Application {
         tf.setIcon(icon);\r
         tf.setRequired(required);\r
         tf.setComponentError(new UserError("Test error message"));\r
-\r
         return tf;\r
     }\r
 }\r