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.

AbsoluteLayoutResizeComponents.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package com.vaadin.tests.components.absolutelayout;
  2. import com.vaadin.server.VaadinRequest;
  3. import com.vaadin.tests.components.AbstractReindeerTestUI;
  4. import com.vaadin.ui.AbsoluteLayout;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Component;
  7. import com.vaadin.ui.CssLayout;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.Panel;
  10. /**
  11. * Test UI with different cases for component size changes
  12. */
  13. public class AbsoluteLayoutResizeComponents extends AbstractReindeerTestUI {
  14. @Override
  15. protected void setup(VaadinRequest request) {
  16. AbsoluteLayout layout = new AbsoluteLayout();
  17. addStartWithFullWidth(layout);
  18. addStartWithDefinedWidth(layout);
  19. addStartWithDefinedWidthAbsoluteLayout(layout);
  20. setContent(layout);
  21. }
  22. /**
  23. * Build test layout for #8255
  24. */
  25. private void addStartWithFullWidth(AbsoluteLayout layout) {
  26. final Panel full = new Panel(
  27. new CssLayout(new Label("Start Width 100%")));
  28. full.setWidth("100%");
  29. full.setId("expanding-panel");
  30. layout.addComponent(full, "right:0;top:10px;");
  31. layout.addComponent(expandButton(full), "left: 10x; top: 50px;");
  32. }
  33. /**
  34. * Build test layout for #8256
  35. */
  36. private void addStartWithDefinedWidth(AbsoluteLayout layout) {
  37. final Panel small = new Panel(
  38. new CssLayout(new Label("Start Width 250px")));
  39. small.setWidth("250px");
  40. small.setId("small-panel");
  41. layout.addComponent(small, "right:0;top:100px;");
  42. layout.addComponent(expandButton(small), "left: 10x; top: 150px;");
  43. }
  44. /**
  45. * Build test layout for #8257
  46. */
  47. private void addStartWithDefinedWidthAbsoluteLayout(AbsoluteLayout layout) {
  48. AbsoluteLayout layoutExpading = new AbsoluteLayout();
  49. layoutExpading.setWidth("250px");
  50. layoutExpading.addComponent(
  51. new Panel(new CssLayout(new Label("Start Width 250px"))));
  52. layoutExpading.setId("absolute-expanding");
  53. layout.addComponent(layoutExpading, "right:0;top:200px;");
  54. layout.addComponent(expandButton(layoutExpading),
  55. "left: 10x; top: 250px;");
  56. }
  57. /**
  58. * Create size change button for component
  59. *
  60. * @param component Component to controll with button
  61. * @return Created Expand Button
  62. */
  63. private Button expandButton(Component component) {
  64. Button button = new Button("Change Size",
  65. clickEvent -> resizeComponent(component));
  66. button.setId(component.getId() + "-button");
  67. return button;
  68. }
  69. private void resizeComponent(Component component) {
  70. if (component.getWidthUnits().equals(Unit.PERCENTAGE)) {
  71. component.setWidth("250px");
  72. } else {
  73. component.setWidth("100%");
  74. }
  75. }
  76. }