summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2007-08-10 06:26:56 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2007-08-10 06:26:56 +0000
commit7b7b8dea5f4cdbcef9c91c3aad362587a14a5d79 (patch)
tree5d61e888f55acbbca4ec9309e765d778fda236ea
parentf776d9e9a189ab485725af9b000920331ddc3516 (diff)
downloadvaadin-framework-7b7b8dea5f4cdbcef9c91c3aad362587a14a5d79.tar.gz
vaadin-framework-7b7b8dea5f4cdbcef9c91c3aad362587a14a5d79.zip
evolved IGridLayout's rendering + added test
svn changeset:1977/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java12
-rw-r--r--src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java101
2 files changed, 110 insertions, 3 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
index 7cf0c64fb0..ab91f7f0ff 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
@@ -35,11 +35,16 @@ public class IGridLayout extends FlexTable implements Paintable, Layout {
UIDL c = (UIDL) j.next();
if ("gc".equals(c.getTag())) {
column++;
+ int w;
if (c.hasAttribute("w")) {
- int w = c.getIntAttribute("w");
- ((FlexCellFormatter) getCellFormatter())
- .setColSpan(row, column, w);
+ w = c.getIntAttribute("w");
}
+ else
+ w = 1;
+ ((FlexCellFormatter) getCellFormatter())
+ .setColSpan(row, column, w);
+
+
UIDL u = c.getChildUIDL(0);
if (u != null) {
Widget child = client.getWidget(u);
@@ -57,6 +62,7 @@ public class IGridLayout extends FlexTable implements Paintable, Layout {
}
((Paintable) child).updateFromUIDL(u, client);
}
+ column += w -1;
}
}
}
diff --git a/src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java b/src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java
new file mode 100644
index 0000000000..23f9f47b32
--- /dev/null
+++ b/src/com/itmill/toolkit/tests/TestForGridLayoutChildComponentRendering.java
@@ -0,0 +1,101 @@
+package com.itmill.toolkit.tests;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.itmill.toolkit.terminal.ExternalResource;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.Component;
+import com.itmill.toolkit.ui.CustomComponent;
+import com.itmill.toolkit.ui.GridLayout;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Link;
+import com.itmill.toolkit.ui.OrderedLayout;
+import com.itmill.toolkit.ui.Select;
+
+/**
+ *
+ * This Component contains some simple test to see that component
+ * updates its contents propertly.
+ *
+ * @author IT Mill Ltd.
+ */
+public class TestForGridLayoutChildComponentRendering extends CustomComponent {
+
+
+ private GridLayout main = new GridLayout(2,3);
+
+ public TestForGridLayoutChildComponentRendering() {
+
+ setCompositionRoot(main);
+ createNewView();
+ }
+
+ public void createNewView() {
+ main.removeAllComponents();
+ main.addComponent(new Label("SDFGFHFHGJGFDSDSSSGFDD"));
+
+ Link l = new Link();
+ l.setCaption("Siirry ITMILLIIN");
+ l.setResource(new ExternalResource("http://www.itmill.com/"));
+ l.setTargetHeight(200);
+ l.setTargetWidth(500);
+ l.setTargetBorder(Link.TARGET_BORDER_MINIMAL);
+ main.addComponent(l);
+
+
+ Select se = new Select("Tästä valitaan");
+ se.setCaption("Whattaa select");
+ se.addItem("valinta1");
+ se.addItem("Valinta 2");
+
+ main.addComponent(se, 0, 1, 1, 1);
+
+
+ Button b = new Button("refresh view", this, "createNewView");
+ main.addComponent(b);
+
+ b = new Button("reorder view", this, "randomReorder");
+ main.addComponent(b);
+
+ b = new Button("remove randomly one component", this, "removeRandomComponent");
+ main.addComponent(b);
+
+ }
+
+ public void randomReorder() {
+ Iterator it = main.getComponentIterator();
+ ArrayList components = new ArrayList();
+ while(it.hasNext())
+ components.add(it.next());
+
+ main.removeAllComponents();
+
+ int size = components.size();
+ int colspanIndex = ((int) (Math.random()*size)/2)*2 + 2;
+
+ for(int i = components.size(); i > 0; i--) {
+ int index = (int) (Math.random()*i);
+ if(i == colspanIndex)
+ main.addComponent((Component) components.get(index), 0, (size - i )/2, 1, (size - i)/2);
+ else
+ main.addComponent((Component) components.get(index));
+ components.remove(index);
+ }
+ }
+
+ public void removeRandomComponent() {
+ Iterator it = main.getComponentIterator();
+ ArrayList components = new ArrayList();
+ while(it.hasNext())
+ components.add(it.next());
+ int size = components.size();
+ int index = (int) (Math.random()*size);
+ main.removeComponent((Component) components.get(index));
+
+ }
+
+
+}
+
+