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.

AbstractOrderedLayoutTest.java 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.vaadin.tests.components;
  2. import java.util.LinkedHashMap;
  3. import com.vaadin.event.LayoutEvents.LayoutClickEvent;
  4. import com.vaadin.event.LayoutEvents.LayoutClickListener;
  5. import com.vaadin.ui.AbstractOrderedLayout;
  6. import com.vaadin.ui.Component;
  7. public abstract class AbstractOrderedLayoutTest<T extends AbstractOrderedLayout>
  8. extends AbstractLayoutTest<T> implements LayoutClickListener {
  9. private Command<T, Boolean> layoutClickListenerCommand = new Command<T, Boolean>() {
  10. @Override
  11. public void execute(T c, Boolean value, Object data) {
  12. if (value) {
  13. c.addListener(
  14. (LayoutClickListener) AbstractOrderedLayoutTest.this);
  15. } else {
  16. }
  17. }
  18. };
  19. private Command<T, Integer> setComponentExpandRatio = new Command<T, Integer>() {
  20. @Override
  21. public void execute(T c, Integer value, Object ratio) {
  22. Component child = getComponentAtIndex(c, value);
  23. c.setExpandRatio(child, (Float) ratio);
  24. }
  25. };
  26. @Override
  27. protected void createActions() {
  28. super.createActions();
  29. createLayoutClickListenerAction(CATEGORY_LISTENERS);
  30. createChangeComponentExpandRatioAction(CATEGORY_LAYOUT_FEATURES);
  31. // Set a root style so we can see the component. Can be overridden by
  32. // setting the style name in the UI
  33. for (T c : getTestComponents()) {
  34. c.setStyleName("background-lightblue");
  35. }
  36. }
  37. private void createLayoutClickListenerAction(String category) {
  38. createBooleanAction("Layout click listener", category, false,
  39. layoutClickListenerCommand);
  40. }
  41. private void createChangeComponentExpandRatioAction(String category) {
  42. String expandRatioCategory = "Component expand ratio";
  43. createCategory(expandRatioCategory, category);
  44. LinkedHashMap<String, Float> options = new LinkedHashMap<String, Float>();
  45. options.put("0", 0f);
  46. options.put("0.5", 0.5f);
  47. for (float f = 1; f <= 5; f++) {
  48. options.put(String.valueOf(f), f);
  49. }
  50. for (int i = 0; i < 20; i++) {
  51. String componentExpandRatioCategory = "Component " + i
  52. + " expand ratio";
  53. createCategory(componentExpandRatioCategory, expandRatioCategory);
  54. for (String option : options.keySet()) {
  55. createClickAction(option, componentExpandRatioCategory,
  56. setComponentExpandRatio, Integer.valueOf(i),
  57. options.get(option));
  58. }
  59. }
  60. }
  61. @Override
  62. public void layoutClick(LayoutClickEvent event) {
  63. log(event.getClass().getSimpleName() + ": button="
  64. + event.getButtonName() + ", childComponent="
  65. + event.getChildComponent().getClass().getSimpleName()
  66. + ", relativeX=" + event.getRelativeX() + ", relativeY="
  67. + event.getRelativeY());
  68. }
  69. }