package com.itmill.toolkit.tests.tickets;\r
\r
+import java.util.Iterator;\r
import java.util.LinkedList;\r
\r
+import com.itmill.toolkit.data.Property;\r
+import com.itmill.toolkit.data.Property.ValueChangeEvent;\r
+import com.itmill.toolkit.data.util.MethodProperty;\r
import com.itmill.toolkit.terminal.Sizeable;\r
import com.itmill.toolkit.terminal.SystemError;\r
import com.itmill.toolkit.terminal.ThemeResource;\r
+import com.itmill.toolkit.ui.AbstractComponent;\r
import com.itmill.toolkit.ui.Button;\r
import com.itmill.toolkit.ui.Component;\r
import com.itmill.toolkit.ui.ComponentContainer;\r
import com.itmill.toolkit.ui.Form;\r
import com.itmill.toolkit.ui.GridLayout;\r
import com.itmill.toolkit.ui.Label;\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
\r
public void init() {\r
\r
+ setTheme("tests-tickets");\r
+\r
OrderedLayout lo = new OrderedLayout();\r
setMainWindow(new Window("#1710", lo));\r
lo.setMargin(true);\r
\r
// OrderedLayout\r
OrderedLayout orderedVertical = new OrderedLayout();\r
- lo.addComponent(new Panel("OrderedLayout Vertical", orderedVertical));\r
+ lo.addComponent(new LayoutTestingPanel("OrderedLayout Vertical",\r
+ orderedVertical));\r
orderedVertical.setSpacing(true);\r
addFields(orderedVertical);\r
OrderedLayout orderedHorizontal = new OrderedLayout(\r
OrderedLayout.ORIENTATION_HORIZONTAL);\r
- lo\r
- .addComponent(new Panel("OrderedLayout Horizontal",\r
- orderedHorizontal));\r
+ lo.addComponent(new LayoutTestingPanel("OrderedLayout Horizontal",\r
+ orderedHorizontal));\r
orderedHorizontal.setSpacing(true);\r
addFields(orderedHorizontal);\r
\r
// GridLayout\r
GridLayout grid = new GridLayout(1, 1);\r
- lo.addComponent(new Panel("Gridlayout with 1 column", grid));\r
+ lo\r
+ .addComponent(new LayoutTestingPanel(\r
+ "Gridlayout with 1 column", grid));\r
grid.setSpacing(true);\r
addFields(grid);\r
-\r
- // GridLayout\r
GridLayout grid2 = new GridLayout(2, 1);\r
- lo.addComponent(new Panel("Gridlayout with 2 columns", grid2));\r
+ lo.addComponent(new LayoutTestingPanel("Gridlayout with 2 columns",\r
+ grid2));\r
grid2.setSpacing(true);\r
addFields(grid2);\r
\r
// ExpandLayout\r
ExpandLayout el = new ExpandLayout();\r
- Panel elp = new Panel("ExpandLayout width first component expanded", el);\r
+ Panel elp = new LayoutTestingPanel(\r
+ "ExpandLayout width first component expanded", el);\r
el.setHeight(700);\r
addFields(el);\r
Component firstComponent = (Component) el.getComponentIterator().next();\r
el.expand(firstComponent);\r
lo.addComponent(elp);\r
ExpandLayout elh = new ExpandLayout(ExpandLayout.ORIENTATION_HORIZONTAL);\r
- Panel elhp = new Panel(\r
+ Panel elhp = new LayoutTestingPanel(\r
"ExpandLayout width first component expanded; horizontal", elh);\r
elhp.setScrollable(true);\r
elh.setWidth(2000);\r
lo.addComponent(elhp);\r
\r
// CustomLayout\r
- Panel clp = new Panel("CustomLayout");\r
+ OrderedLayout cl = new OrderedLayout();\r
+ Panel clp = new LayoutTestingPanel("CustomLayout", cl);\r
lo.addComponent(clp);\r
- clp.addComponent(new Label("<<< Add customlayout testcase here >>>"));\r
+ cl.addComponent(new Label("<<< Add customlayout testcase here >>>"));\r
\r
// Form\r
Panel formPanel = new Panel("Form");\r
Button fb1 = new Button("Test button");\r
fb1.setComponentError(new SystemError("Test error"));\r
f.addField("fb1", fb1);\r
- Button fb2 = new Button("Test button");\r
+ Button fb2 = new Button("Test button", true);\r
fb2.setComponentError(new SystemError("Test error"));\r
- fb2.setSwitchMode(true);\r
f.addField("fb2", fb2);\r
TextField ft1 = new TextField("With caption");\r
ft1.setComponentError(new SystemError("Error"));\r
lo.addComponent(t2);\r
\r
TextField t3 = new TextField();\r
- t3.setValue("With caption");\r
+ t3.setValue("Without caption");\r
t3.setComponentError(new SystemError("Error"));\r
lo.addComponent(t3);\r
\r
TextField t4 = new TextField();\r
- t4.setValue("With caption and required");\r
+ t4.setValue("Without caption, With required");\r
t4.setComponentError(new SystemError("Error"));\r
t4.setRequired(true);\r
lo.addComponent(t4);\r
\r
TextField t5 = new TextField();\r
- t5.setValue("With caption - WIDE");\r
+ t5.setValue("Without caption, WIDE");\r
t5.setComponentError(new SystemError("Error"));\r
t5.setWidth(100);\r
t5.setWidthUnits(Sizeable.UNITS_PERCENTAGE);\r
lo.addComponent(t5);\r
\r
TextField t6 = new TextField();\r
- t6.setValue("With caption and required - WIDE");\r
+ t6.setValue("Without caption, With required, WIDE");\r
t6.setComponentError(new SystemError("Error"));\r
t6.setRequired(true);\r
t6.setWidth(100);\r
lo.addComponent(t6);\r
\r
TextField t7 = new TextField();\r
- t7.setValue("With caption and required and icon");\r
+ t7.setValue("With icon and required and icon");\r
t7.setComponentError(new SystemError("Error"));\r
t7.setRequired(true);\r
t7.setIcon(new ThemeResource("icons/16/ok.png"));\r
lo.addComponent(t7);\r
}\r
+\r
+ public class LayoutTestingPanel extends Panel {\r
+\r
+ Layout testedLayout;\r
+ OrderedLayout internalLayout = new OrderedLayout();\r
+ OrderedLayout controls = new OrderedLayout(\r
+ OrderedLayout.ORIENTATION_HORIZONTAL);\r
+ Button marginLeft = new Button("m-left", false);\r
+ Button marginRight = new Button("m-right", false);\r
+ Button marginTop = new Button("m-top", false);\r
+ Button marginBottom = new Button("m-bottom", false);\r
+ Button spacing = new Button("spacing", false);\r
+\r
+ LayoutTestingPanel(String caption, Layout layout) {\r
+ super(caption);\r
+ setLayout(internalLayout);\r
+ testedLayout = layout;\r
+ internalLayout.addComponent(controls);\r
+ internalLayout.addComponent(testedLayout);\r
+\r
+ controls.setWidth(100, OrderedLayout.UNITS_PERCENTAGE);\r
+ controls.setStyleName("controls");\r
+ controls.setSpacing(true);\r
+ controls.setMargin(true);\r
+ controls.addComponent(new Label("width"));\r
+ controls.addComponent(new TextField(new MethodProperty(\r
+ testedLayout, "width")));\r
+ controls.addComponent(new Button("%", new MethodProperty(this,\r
+ "widthPercents")));\r
+ controls.addComponent(new Label("height"));\r
+ controls.addComponent(new TextField(new MethodProperty(\r
+ testedLayout, "height")));\r
+ controls.addComponent(new Button("%", new MethodProperty(this,\r
+ "heightPercents")));\r
+ controls.addComponent(marginLeft);\r
+ controls.addComponent(marginRight);\r
+ controls.addComponent(marginTop);\r
+ controls.addComponent(marginBottom);\r
+ controls.addComponent(spacing);\r
+ for (Iterator i = controls.getComponentIterator(); i.hasNext();) {\r
+ ((AbstractComponent) i.next()).setImmediate(true);\r
+ }\r
+\r
+ Property.ValueChangeListener marginSpacingListener = new Property.ValueChangeListener() {\r
+ public void valueChange(ValueChangeEvent event) {\r
+ updateMarginsAndSpacing();\r
+ }\r
+ };\r
+\r
+ marginBottom.addListener(marginSpacingListener);\r
+ marginTop.addListener(marginSpacingListener);\r
+ marginLeft.addListener(marginSpacingListener);\r
+ marginRight.addListener(marginSpacingListener);\r
+ spacing.addListener(marginSpacingListener);\r
+ updateMarginsAndSpacing();\r
+\r
+ testedLayout.setStyleName("tested-layout");\r
+ setStyleName("layout-testing-panel");\r
+ }\r
+\r
+ private void updateMarginsAndSpacing() {\r
+ testedLayout.setMargin(((Boolean) marginTop.getValue())\r
+ .booleanValue(), ((Boolean) marginRight.getValue())\r
+ .booleanValue(), ((Boolean) marginBottom.getValue())\r
+ .booleanValue(), ((Boolean) marginLeft.getValue())\r
+ .booleanValue());\r
+ if (testedLayout instanceof OrderedLayout) {\r
+ ((OrderedLayout) testedLayout).setSpacing(((Boolean) spacing\r
+ .getValue()).booleanValue());\r
+ } else if (testedLayout instanceof GridLayout) {\r
+ ((GridLayout) testedLayout).setSpacing(((Boolean) spacing\r
+ .getValue()).booleanValue());\r
+ }\r
+ }\r
+\r
+ public boolean getWidthPercents() {\r
+ return testedLayout.getWidthUnits() == testedLayout.UNITS_PERCENTAGE;\r
+ }\r
+\r
+ public void setWidthPercents(boolean b) {\r
+ testedLayout.setWidthUnits(b ? testedLayout.UNITS_PERCENTAGE\r
+ : testedLayout.UNITS_PIXELS);\r
+ }\r
+\r
+ public boolean getHeightPercents() {\r
+ return testedLayout.getHeightUnits() == testedLayout.UNITS_PERCENTAGE;\r
+ }\r
+\r
+ public void setHeightPercents(boolean b) {\r
+ testedLayout.setHeightUnits(b ? testedLayout.UNITS_PERCENTAGE\r
+ : testedLayout.UNITS_PIXELS);\r
+ }\r
+ }\r
}\r