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.

BaseLayoutForSpacingMargin.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.layouts.layouttester;
  17. import com.vaadin.server.VaadinRequest;
  18. import com.vaadin.shared.ui.label.ContentMode;
  19. import com.vaadin.ui.AbstractLayout;
  20. import com.vaadin.ui.Button;
  21. import com.vaadin.ui.Button.ClickEvent;
  22. import com.vaadin.ui.Button.ClickListener;
  23. import com.vaadin.ui.Label;
  24. import com.vaadin.ui.Table;
  25. /**
  26. *
  27. * @since
  28. * @author Vaadin Ltd
  29. */
  30. public class BaseLayoutForSpacingMargin extends BaseLayoutTestUI {
  31. /**
  32. * @param layoutClass
  33. */
  34. public BaseLayoutForSpacingMargin(
  35. Class<? extends AbstractLayout> layoutClass) {
  36. super(layoutClass);
  37. }
  38. @Override
  39. protected void setup(VaadinRequest request) {
  40. init();
  41. buildLayout();
  42. super.setup(request);
  43. }
  44. private void buildLayout() {
  45. Table t1 = getTestTable();
  46. Table t2 = getTestTable();
  47. l2.addComponent(t1);
  48. l2.setMargin(false);
  49. l2.setSpacing(false);
  50. // Must add something around the hr to avoid the margins collapsing
  51. l2.addComponent(new Label(
  52. "<div style='height: 1px'></div><hr /><div style='height: 1px'></div>",
  53. ContentMode.HTML));
  54. l2.addComponent(t2);
  55. final Button btn1 = new Button("Toggle margin on/off");
  56. btn1.addClickListener(new ClickListener() {
  57. @Override
  58. public void buttonClick(ClickEvent event) {
  59. boolean margin = l2.getMargin().hasLeft();
  60. l2.setMargin(!margin);
  61. }
  62. });
  63. final Button btn2 = new Button("Toggle spacing on/off");
  64. btn2.addClickListener(new ClickListener() {
  65. @Override
  66. public void buttonClick(ClickEvent event) {
  67. l2.setSpacing(!l2.isSpacing());
  68. }
  69. });
  70. l1.addComponent(btn1);
  71. l1.addComponent(btn2);
  72. }
  73. }