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.

VerticalLayout.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.ui;
  17. import com.vaadin.shared.ui.orderedlayout.VerticalLayoutState;
  18. /**
  19. * Vertical layout
  20. *
  21. * <code>VerticalLayout</code> is a component container, which shows the
  22. * subcomponents in the order of their addition (vertically). A vertical layout
  23. * is by default 100% wide.
  24. *
  25. * @author Vaadin Ltd.
  26. * @since 5.3
  27. */
  28. @SuppressWarnings("serial")
  29. public class VerticalLayout extends AbstractOrderedLayout {
  30. /**
  31. * Constructs an empty VerticalLayout.
  32. */
  33. public VerticalLayout() {
  34. setWidth("100%");
  35. setSpacing(true);
  36. setMargin(true);
  37. }
  38. /**
  39. * Constructs a VerticalLayout with the given components. The components are
  40. * added in the given order.
  41. *
  42. * @see AbstractOrderedLayout#addComponents(Component...)
  43. *
  44. * @param children
  45. * The components to add.
  46. */
  47. public VerticalLayout(Component... children) {
  48. this();
  49. addComponents(children);
  50. }
  51. @Override
  52. protected VerticalLayoutState getState() {
  53. return (VerticalLayoutState) super.getState();
  54. }
  55. @Override
  56. protected VerticalLayoutState getState(boolean markAsDirty) {
  57. return (VerticalLayoutState) super.getState(markAsDirty);
  58. }
  59. /**
  60. * Adds the given components to this layout and sets them as expanded. The
  61. * height of all added child components are set to 100% so that the
  62. * expansion will be effective. The height of this layout is also set to
  63. * 100% if it is currently undefined.
  64. * <p>
  65. * The components are added in the provided order to the end of this layout.
  66. * Any components that are already children of this layout will be moved to
  67. * new positions.
  68. *
  69. * @param components
  70. * the components to set, not <code>null</code>
  71. * @since 8.0
  72. */
  73. public void addComponentsAndExpand(Component... components) {
  74. addComponents(components);
  75. if (getHeight() < 0) {
  76. setHeight(100, Unit.PERCENTAGE);
  77. }
  78. for (Component child : components) {
  79. child.setHeight(100, Unit.PERCENTAGE);
  80. setExpandRatio(child, 1);
  81. }
  82. }
  83. }