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.

GridLayoutHideMiddleCells.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package com.vaadin.tests.components.gridlayout;
  2. import java.util.Random;
  3. import com.vaadin.server.VaadinRequest;
  4. import com.vaadin.tests.components.AbstractReindeerTestUI;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.GridLayout;
  7. import com.vaadin.ui.HorizontalLayout;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.VerticalLayout;
  10. public class GridLayoutHideMiddleCells extends AbstractReindeerTestUI {
  11. GridLayout gridLayout;
  12. GridLayout gridLayout2;
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. final int ROWS = 5;
  16. final int COLS = 5;
  17. final Label[][] labels = new Label[ROWS][COLS];
  18. VerticalLayout mainLayout = new VerticalLayout();
  19. HorizontalLayout horLayout = new HorizontalLayout();
  20. gridLayout = new GridLayout(ROWS, COLS);
  21. gridLayout.setHideEmptyRowsAndColumns(true);
  22. gridLayout2 = new GridLayout(4, 4);
  23. gridLayout2.setHideEmptyRowsAndColumns(true);
  24. for (int i = 0; i < 5; i++) {
  25. for (int j = 0; j < 5; j++) {
  26. Label label = new Label("Slot " + i + " " + j);
  27. labels[i][j] = label;
  28. gridLayout.addComponent(label);
  29. if (!(i == 2 || j == 2)) {
  30. Label label2 = new Label("Slot " + i + " " + j);
  31. gridLayout2.addComponent(label2);
  32. }
  33. }
  34. }
  35. setContent(mainLayout);
  36. gridLayout.setHeight("500px");
  37. gridLayout.setWidth("500px");
  38. gridLayout.setSpacing(true);
  39. addComponent(gridLayout);
  40. addComponent(gridLayout2);
  41. mainLayout.addComponent(horLayout);
  42. gridLayout2.setHeight("500px");
  43. gridLayout2.setWidth("500px");
  44. gridLayout2.setSpacing(true);
  45. horLayout.addComponent(gridLayout);
  46. horLayout.addComponent(gridLayout2);
  47. mainLayout.addComponent(
  48. new Button("Hide/show both middle Column and row", event -> {
  49. for (int i = 0; i < ROWS; i++) {
  50. for (int j = 0; j < COLS; j++) {
  51. if (j == 2 || i == 2) {
  52. if (labels[i][j].isVisible()) {
  53. labels[i][j].setVisible(false);
  54. } else {
  55. labels[i][j].setVisible(true);
  56. }
  57. }
  58. }
  59. }
  60. }));
  61. mainLayout.addComponent(new Button("Hide/show middle Column", event -> {
  62. for (int i = 0; i < ROWS; i++) {
  63. if (labels[i][2].isVisible()) {
  64. labels[i][2].setVisible(false);
  65. } else {
  66. labels[i][2].setVisible(true);
  67. }
  68. }
  69. }));
  70. mainLayout.addComponent(new Button("Hide/show middle Row", event -> {
  71. for (int j = 0; j < COLS; j++) {
  72. if (labels[2][j].isVisible()) {
  73. labels[2][j].setVisible(false);
  74. } else {
  75. labels[2][j].setVisible(true);
  76. }
  77. }
  78. }));
  79. mainLayout.addComponent(new Button("Hide Random button", event -> {
  80. // TODO Auto-generated method stub
  81. Random rand = new Random();
  82. int i = rand.nextInt(ROWS);
  83. int j = rand.nextInt(COLS);
  84. if (labels[i][j].isVisible()) {
  85. labels[i][j].setVisible(false);
  86. } else {
  87. labels[i][j].setVisible(true);
  88. }
  89. }));
  90. }
  91. @Override
  92. protected Integer getTicketNumber() {
  93. return 8855;
  94. }
  95. /*
  96. * (non-Javadoc)
  97. *
  98. * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
  99. */
  100. @Override
  101. protected String getTestDescription() {
  102. return "Changing the number of visible fields a GridLayout with spacing should not cause additional empty space on the place of invisible fields";
  103. }
  104. }