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