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.

AbstractLayoutTest.java 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.vaadin.tests.components;
  2. import java.util.LinkedHashMap;
  3. import com.vaadin.shared.ui.MarginInfo;
  4. import com.vaadin.ui.AbstractLayout;
  5. import com.vaadin.ui.Alignment;
  6. import com.vaadin.ui.Component;
  7. import com.vaadin.ui.Layout.AlignmentHandler;
  8. import com.vaadin.ui.Layout.MarginHandler;
  9. import com.vaadin.ui.Layout.SpacingHandler;
  10. public abstract class AbstractLayoutTest<T extends AbstractLayout>
  11. extends AbstractComponentContainerTest<T> {
  12. protected static final String CATEGORY_LAYOUT_FEATURES = "Layout features";
  13. private Command<T, MarginInfo> marginCommand = new Command<T, MarginInfo>() {
  14. @Override
  15. public void execute(T c, MarginInfo value, Object data) {
  16. ((MarginHandler) c).setMargin(value);
  17. }
  18. };
  19. protected Command<T, Boolean> spacingCommand = new Command<T, Boolean>() {
  20. @Override
  21. public void execute(T c, Boolean value, Object data) {
  22. ((SpacingHandler) c).setSpacing(value);
  23. }
  24. };
  25. private Command<T, Integer> setComponentAlignment = new Command<T, Integer>() {
  26. @Override
  27. public void execute(T c, Integer value, Object alignment) {
  28. Component child = getComponentAtIndex(c, value);
  29. ((AlignmentHandler) c).setComponentAlignment(child,
  30. (Alignment) alignment);
  31. }
  32. };
  33. @Override
  34. protected void createActions() {
  35. super.createActions();
  36. if (MarginHandler.class.isAssignableFrom(getTestClass())) {
  37. createMarginsSelect(CATEGORY_LAYOUT_FEATURES);
  38. }
  39. if (SpacingHandler.class.isAssignableFrom(getTestClass())) {
  40. createSpacingSelect(CATEGORY_LAYOUT_FEATURES);
  41. }
  42. if (AlignmentHandler.class.isAssignableFrom(getTestClass())) {
  43. createChangeComponentAlignmentAction(CATEGORY_LAYOUT_FEATURES);
  44. }
  45. }
  46. private void createMarginsSelect(String category) {
  47. LinkedHashMap<String, MarginInfo> options = new LinkedHashMap<>();
  48. options.put("off", new MarginInfo(false));
  49. options.put("all", new MarginInfo(true));
  50. options.put("left", new MarginInfo(false, false, false, true));
  51. options.put("right", new MarginInfo(false, true, false, false));
  52. options.put("top", new MarginInfo(true, false, false, false));
  53. options.put("bottom", new MarginInfo(false, false, true, false));
  54. options.put("left-right", new MarginInfo(false, true));
  55. options.put("top-bottom", new MarginInfo(true, false));
  56. createSelectAction("Margins", category, options, "off", marginCommand);
  57. }
  58. private void createSpacingSelect(String category) {
  59. createBooleanAction("Spacing", category, false, spacingCommand);
  60. }
  61. private void createChangeComponentAlignmentAction(String category) {
  62. String alignmentCategory = "Component alignment";
  63. createCategory(alignmentCategory, category);
  64. LinkedHashMap<String, Alignment> options = new LinkedHashMap<>();
  65. options.put("Top left", Alignment.TOP_LEFT);
  66. options.put("Top center", Alignment.TOP_CENTER);
  67. options.put("Top right", Alignment.TOP_RIGHT);
  68. options.put("Middle left", Alignment.MIDDLE_LEFT);
  69. options.put("Middle center", Alignment.MIDDLE_CENTER);
  70. options.put("Middle right", Alignment.MIDDLE_RIGHT);
  71. options.put("Bottom left", Alignment.BOTTOM_LEFT);
  72. options.put("Bottom center", Alignment.BOTTOM_CENTER);
  73. options.put("Bottom right", Alignment.BOTTOM_RIGHT);
  74. for (int i = 0; i < 20; i++) {
  75. String componentAlignmentCategory = "Component " + i + " alignment";
  76. createCategory(componentAlignmentCategory, alignmentCategory);
  77. for (String option : options.keySet()) {
  78. createClickAction(option, componentAlignmentCategory,
  79. setComponentAlignment, Integer.valueOf(i),
  80. options.get(option));
  81. }
  82. }
  83. }
  84. }