You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestLayoutPerformance.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package com.vaadin.tests.layouts;
  2. import com.vaadin.shared.ui.ContentMode;
  3. import com.vaadin.tests.components.TestBase;
  4. import com.vaadin.ui.AbstractComponent;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Button.ClickEvent;
  7. import com.vaadin.ui.CheckBox;
  8. import com.vaadin.ui.Component;
  9. import com.vaadin.ui.CssLayout;
  10. import com.vaadin.ui.GridLayout;
  11. import com.vaadin.ui.Label;
  12. import com.vaadin.ui.Layout;
  13. import com.vaadin.ui.VerticalLayout;
  14. import com.vaadin.v7.ui.NativeSelect;
  15. import com.vaadin.v7.ui.TextField;
  16. public class TestLayoutPerformance extends TestBase {
  17. private NativeSelect ns;
  18. private int i;
  19. private NativeSelect ns2;
  20. private VerticalLayout testarea = new VerticalLayout();
  21. @Override
  22. protected String getDescription() {
  23. return "Test app to test simple rendering to various layouts.";
  24. }
  25. @Override
  26. protected Integer getTicketNumber() {
  27. return null;
  28. }
  29. @Override
  30. protected void setup() {
  31. Label label = new Label("<h1>CssLayout performance test.</h1>",
  32. ContentMode.HTML);
  33. getLayout().addComponent(label);
  34. label = new Label(
  35. "<em>Hint</em>. Use debug dialog to measure rendering times TODO: extend with size settings (to both layout and content).",
  36. ContentMode.HTML);
  37. getLayout().addComponent(label);
  38. ns = new NativeSelect("Select component to test");
  39. ns.addItem(CssLayout.class);
  40. ns.addItem(GridLayout.class);
  41. ns.addItem(VerticalLayout.class);
  42. ns.setNullSelectionAllowed(false);
  43. ns.setValue(CssLayout.class);
  44. ns2 = new NativeSelect("Select component to render inside layout.");
  45. ns2.addItem(Label.class);
  46. ns2.addItem(Button.class);
  47. ns2.setNullSelectionAllowed(false);
  48. ns2.setValue(Label.class);
  49. final TextField n = new TextField("Number of components");
  50. n.setValue("1000");
  51. final CheckBox cb = new CheckBox("Generate captions", false);
  52. Button b = new Button("Render component");
  53. b.addClickListener(new Button.ClickListener() {
  54. @Override
  55. public void buttonClick(ClickEvent event) {
  56. int components = Integer.parseInt(n.getValue());
  57. Layout layout = getCurrentLayout();
  58. for (int i = 0; i < components; i++) {
  59. Component component = newTestComponent();
  60. if (cb.getValue()) {
  61. component.setCaption("caption " + i);
  62. }
  63. layout.addComponent(component);
  64. }
  65. testarea.removeAllComponents();
  66. testarea.addComponent(layout);
  67. }
  68. });
  69. getLayout().addComponent(ns);
  70. getLayout().addComponent(ns2);
  71. getLayout().addComponent(n);
  72. getLayout().addComponent(cb);
  73. getLayout().addComponent(b);
  74. getLayout().addComponent(testarea);
  75. }
  76. private Layout getCurrentLayout() {
  77. Class<?> value = (Class<?>) ns.getValue();
  78. if (value == GridLayout.class) {
  79. return new GridLayout(10, 1);
  80. }
  81. try {
  82. return (Layout) value.newInstance();
  83. } catch (InstantiationException e) {
  84. // TODO Auto-generated catch block
  85. e.printStackTrace();
  86. } catch (IllegalAccessException e) {
  87. // TODO Auto-generated catch block
  88. e.printStackTrace();
  89. }
  90. return null;
  91. }
  92. private Component newTestComponent() {
  93. Class<?> componentClass = (Class<?>) ns2.getValue();
  94. AbstractComponent newInstance = null;
  95. try {
  96. newInstance = (AbstractComponent) componentClass.newInstance();
  97. } catch (InstantiationException e) {
  98. // TODO Auto-generated catch block
  99. e.printStackTrace();
  100. } catch (IllegalAccessException e) {
  101. // TODO Auto-generated catch block
  102. e.printStackTrace();
  103. }
  104. if (componentClass == Label.class) {
  105. ((Label) newInstance).setValue("Test l " + (i++));
  106. ((Label) newInstance).setSizeUndefined();
  107. } else {
  108. newInstance.setCaption("Test l " + (i++));
  109. }
  110. return newInstance;
  111. }
  112. }