--- /dev/null
+package com.itmill.toolkit.tests.tickets;\r
+\r
+import com.itmill.toolkit.Application;\r
+import com.itmill.toolkit.terminal.Resource;\r
+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.GridLayout;\r
+import com.itmill.toolkit.ui.Layout;\r
+import com.itmill.toolkit.ui.OrderedLayout;\r
+import com.itmill.toolkit.ui.Panel;\r
+import com.itmill.toolkit.ui.TextField;\r
+import com.itmill.toolkit.ui.Window;\r
+import com.itmill.toolkit.ui.Button.ClickEvent;\r
+import com.itmill.toolkit.ui.Button.ClickListener;\r
+\r
+public class Ticket1878 extends Application {\r
+\r
+ private Layout orderedLayout;\r
+ private Layout gridLayout;\r
+ private GridLayout mainLayout;\r
+ private Button switchButton;\r
+\r
+ public void init() {\r
+ Window w = new Window(getClass().getSimpleName());\r
+ setMainWindow(w);\r
+ // setTheme("tests-tickets");\r
+\r
+ mainLayout = new GridLayout(1, 2);\r
+ w.setLayout(mainLayout);\r
+ orderedLayout = createOL();\r
+ gridLayout = createGL();\r
+ switchButton = new Button("Switch to GridLayout", new ClickListener() {\r
+\r
+ public void buttonClick(ClickEvent event) {\r
+ changeLayout();\r
+ }\r
+\r
+ });\r
+ mainLayout.addComponent(switchButton);\r
+ mainLayout.addComponent(orderedLayout);\r
+ // w.setLayout(orderedLayout);\r
+ }\r
+\r
+ private static Layout createOL() {\r
+ GridLayout layout = new GridLayout(1, 5);\r
+\r
+ GridLayout l1 = new GridLayout(1, 3);\r
+ createOrderedLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
+ "150");\r
+ createOrderedLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
+ "100");\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
+ layout.addComponent(l1);\r
+ layout.addComponent(l2);\r
+\r
+ return layout;\r
+ }\r
+\r
+ private static Layout createGL() {\r
+ GridLayout layout = new GridLayout(1, 5);\r
+\r
+ GridLayout l1 = new GridLayout(1, 3);\r
+ createGridLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
+ "150");\r
+ createGridLayout(l1, OrderedLayout.ORIENTATION_HORIZONTAL, "1000",\r
+ "100");\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
+ 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
+\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
+ ol.setComponentAlignment(tf, OrderedLayout.ALIGNMENT_LEFT,\r
+ OrderedLayout.ALIGNMENT_BOTTOM);\r
+ }\r
+ }\r
+ }\r
+\r
+ parentLayout.addComponent(p);\r
+\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
+ tf.setCaption(caption);\r
+ tf.setIcon(icon);\r
+ tf.setRequired(required);\r
+ tf.setComponentError(new UserError("Test error message"));\r
+\r
+ return tf;\r
+ }\r
+}\r