From: Matti Tahvonen Date: Tue, 1 Sep 2009 11:58:47 +0000 (+0000) Subject: added simple layout performance test X-Git-Tag: 6.7.0.beta1~2548 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f5f093815e01f073d91063ce06b86bbbd9deae1d;p=vaadin-framework.git added simple layout performance test svn changeset:8616/svn branch:6.1 --- diff --git a/src/com/vaadin/tests/layouts/TestLayoutPerformance.java b/src/com/vaadin/tests/layouts/TestLayoutPerformance.java new file mode 100644 index 0000000000..896581ce3d --- /dev/null +++ b/src/com/vaadin/tests/layouts/TestLayoutPerformance.java @@ -0,0 +1,133 @@ +package com.vaadin.tests.layouts; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Button; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.Layout; +import com.vaadin.ui.NativeSelect; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Button.ClickEvent; + +public class TestLayoutPerformance extends TestBase { + private NativeSelect ns; + private int i; + private NativeSelect ns2; + private VerticalLayout testarea = new VerticalLayout(); + + @Override + protected String getDescription() { + return "Test app to test simple rendering to various layouts."; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + @Override + protected void setup() { + Label label = new Label("

CssLayout performance test.

", + Label.CONTENT_XHTML); + getLayout().addComponent(label); + + label = new Label( + "Hint. Use debug dialog to measure rendering times TODO: extend with size settings (to both layout and content).", + Label.CONTENT_XHTML); + getLayout().addComponent(label); + + ns = new NativeSelect("Select component to test"); + ns.addItem(CssLayout.class); + ns.addItem(GridLayout.class); + ns.addItem(VerticalLayout.class); + ns.setNullSelectionAllowed(false); + ns.setValue(CssLayout.class); + + ns2 = new NativeSelect("Select component to render inside layout."); + ns2.addItem(Label.class); + ns2.addItem(Button.class); + ns2.setNullSelectionAllowed(false); + ns2.setValue(Label.class); + + final TextField n = new TextField("Number of components"); + + n.setValue("1000"); + + final CheckBox cb = new CheckBox("Generate captions", false); + + Button b = new Button("Render component"); + + b.addListener(new Button.ClickListener() { + + public void buttonClick(ClickEvent event) { + int components = Integer.parseInt((String) n.getValue()); + Layout layout = getCurrentLayout(); + for (int i = 0; i < components; i++) { + Component component = newTestComponent(); + if (cb.booleanValue()) { + component.setCaption("caption " + i); + } + layout.addComponent(component); + } + + testarea.removeAllComponents(); + testarea.addComponent(layout); + } + + }); + + getLayout().addComponent(ns); + getLayout().addComponent(ns2); + getLayout().addComponent(n); + getLayout().addComponent(cb); + getLayout().addComponent(b); + getLayout().addComponent(testarea); + + } + + private Layout getCurrentLayout() { + Class value = (Class) ns.getValue(); + if (value == GridLayout.class) { + return new GridLayout(10, 1); + } + + try { + return (Layout) value.newInstance(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + + } + + private Component newTestComponent() { + Class componentClass = (Class) ns2.getValue(); + AbstractComponent newInstance = null; + try { + newInstance = (AbstractComponent) componentClass.newInstance(); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (componentClass == Label.class) { + ((Label) newInstance).setValue("Test l " + (i++)); + ((Label) newInstance).setSizeUndefined(); + } else { + newInstance.setCaption("Test l " + (i++)); + } + return newInstance; + } + +}