]> source.dussan.org Git - vaadin-framework.git/commitdiff
added simple layout performance test
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 1 Sep 2009 11:58:47 +0000 (11:58 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 1 Sep 2009 11:58:47 +0000 (11:58 +0000)
svn changeset:8616/svn branch:6.1

src/com/vaadin/tests/layouts/TestLayoutPerformance.java [new file with mode: 0644]

diff --git a/src/com/vaadin/tests/layouts/TestLayoutPerformance.java b/src/com/vaadin/tests/layouts/TestLayoutPerformance.java
new file mode 100644 (file)
index 0000000..896581c
--- /dev/null
@@ -0,0 +1,133 @@
+package com.vaadin.tests.layouts;\r
+\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.ui.AbstractComponent;\r
+import com.vaadin.ui.Button;\r
+import com.vaadin.ui.CheckBox;\r
+import com.vaadin.ui.Component;\r
+import com.vaadin.ui.CssLayout;\r
+import com.vaadin.ui.GridLayout;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.Layout;\r
+import com.vaadin.ui.NativeSelect;\r
+import com.vaadin.ui.TextField;\r
+import com.vaadin.ui.VerticalLayout;\r
+import com.vaadin.ui.Button.ClickEvent;\r
+\r
+public class TestLayoutPerformance extends TestBase {\r
+    private NativeSelect ns;\r
+    private int i;\r
+    private NativeSelect ns2;\r
+    private VerticalLayout testarea = new VerticalLayout();\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "Test app to test simple rendering to various layouts.";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    protected void setup() {\r
+        Label label = new Label("<h1>CssLayout performance test.</h1>",\r
+                Label.CONTENT_XHTML);\r
+        getLayout().addComponent(label);\r
+\r
+        label = new Label(\r
+                "<em>Hint</em>. Use debug dialog to measure rendering times TODO: extend with size settings (to both layout and content).",\r
+                Label.CONTENT_XHTML);\r
+        getLayout().addComponent(label);\r
+\r
+        ns = new NativeSelect("Select component to test");\r
+        ns.addItem(CssLayout.class);\r
+        ns.addItem(GridLayout.class);\r
+        ns.addItem(VerticalLayout.class);\r
+        ns.setNullSelectionAllowed(false);\r
+        ns.setValue(CssLayout.class);\r
+\r
+        ns2 = new NativeSelect("Select component to render inside layout.");\r
+        ns2.addItem(Label.class);\r
+        ns2.addItem(Button.class);\r
+        ns2.setNullSelectionAllowed(false);\r
+        ns2.setValue(Label.class);\r
+\r
+        final TextField n = new TextField("Number of components");\r
+\r
+        n.setValue("1000");\r
+\r
+        final CheckBox cb = new CheckBox("Generate captions", false);\r
+\r
+        Button b = new Button("Render component");\r
+\r
+        b.addListener(new Button.ClickListener() {\r
+\r
+            public void buttonClick(ClickEvent event) {\r
+                int components = Integer.parseInt((String) n.getValue());\r
+                Layout layout = getCurrentLayout();\r
+                for (int i = 0; i < components; i++) {\r
+                    Component component = newTestComponent();\r
+                    if (cb.booleanValue()) {\r
+                        component.setCaption("caption " + i);\r
+                    }\r
+                    layout.addComponent(component);\r
+                }\r
+\r
+                testarea.removeAllComponents();\r
+                testarea.addComponent(layout);\r
+            }\r
+\r
+        });\r
+\r
+        getLayout().addComponent(ns);\r
+        getLayout().addComponent(ns2);\r
+        getLayout().addComponent(n);\r
+        getLayout().addComponent(cb);\r
+        getLayout().addComponent(b);\r
+        getLayout().addComponent(testarea);\r
+\r
+    }\r
+\r
+    private Layout getCurrentLayout() {\r
+        Class value = (Class) ns.getValue();\r
+        if (value == GridLayout.class) {\r
+            return new GridLayout(10, 1);\r
+        }\r
+\r
+        try {\r
+            return (Layout) value.newInstance();\r
+        } catch (InstantiationException e) {\r
+            // TODO Auto-generated catch block\r
+            e.printStackTrace();\r
+        } catch (IllegalAccessException e) {\r
+            // TODO Auto-generated catch block\r
+            e.printStackTrace();\r
+        }\r
+        return null;\r
+\r
+    }\r
+\r
+    private Component newTestComponent() {\r
+        Class componentClass = (Class) ns2.getValue();\r
+        AbstractComponent newInstance = null;\r
+        try {\r
+            newInstance = (AbstractComponent) componentClass.newInstance();\r
+        } catch (InstantiationException e) {\r
+            // TODO Auto-generated catch block\r
+            e.printStackTrace();\r
+        } catch (IllegalAccessException e) {\r
+            // TODO Auto-generated catch block\r
+            e.printStackTrace();\r
+        }\r
+        if (componentClass == Label.class) {\r
+            ((Label) newInstance).setValue("Test l " + (i++));\r
+            ((Label) newInstance).setSizeUndefined();\r
+        } else {\r
+            newInstance.setCaption("Test l " + (i++));\r
+        }\r
+        return newInstance;\r
+    }\r
+\r
+}\r