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.

ComponentConnectorLayoutSlot.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright 2000-2021 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.client.ui.layout;
  17. import com.vaadin.client.ComponentConnector;
  18. import com.vaadin.client.LayoutManager;
  19. import com.vaadin.client.VCaption;
  20. import com.vaadin.client.ui.ManagedLayout;
  21. /**
  22. * A slot class implementation for ManagedLayout cells.
  23. *
  24. * @author Vaadin Ltd
  25. */
  26. public class ComponentConnectorLayoutSlot extends VLayoutSlot {
  27. final ComponentConnector child;
  28. final ManagedLayout layout;
  29. /**
  30. * Constructs a slot instance for a ManagedLayout cell.
  31. *
  32. * @param baseClassName
  33. * the base class name of the layout
  34. * @param child
  35. * the connector of the child component whose widget should be
  36. * set to this slot, should not be {@code null}
  37. * @param layout
  38. * the managed layout that contains this slot
  39. */
  40. public ComponentConnectorLayoutSlot(String baseClassName,
  41. ComponentConnector child, ManagedLayout layout) {
  42. super(baseClassName, child.getWidget());
  43. this.child = child;
  44. this.layout = layout;
  45. }
  46. /**
  47. * Returns the connector of the child component that has been assigned to
  48. * this slot.
  49. *
  50. * @return the content connector
  51. */
  52. public ComponentConnector getChild() {
  53. return child;
  54. }
  55. @Override
  56. protected int getCaptionHeight() {
  57. VCaption caption = getCaption();
  58. return caption != null
  59. ? getLayoutManager().getOuterHeight(caption.getElement())
  60. : 0;
  61. }
  62. @Override
  63. protected int getCaptionWidth() {
  64. VCaption caption = getCaption();
  65. return caption != null
  66. ? getLayoutManager().getOuterWidth(caption.getElement())
  67. : 0;
  68. }
  69. /**
  70. * Returns the layout manager for the managed layout.
  71. *
  72. * @return layout manager
  73. */
  74. public LayoutManager getLayoutManager() {
  75. return layout.getLayoutManager();
  76. }
  77. @Override
  78. public void setCaption(VCaption caption) {
  79. VCaption oldCaption = getCaption();
  80. if (oldCaption != null) {
  81. getLayoutManager().unregisterDependency(layout,
  82. oldCaption.getElement());
  83. }
  84. super.setCaption(caption);
  85. if (caption != null) {
  86. getLayoutManager().registerDependency(
  87. (ManagedLayout) child.getParent(), caption.getElement());
  88. }
  89. }
  90. /**
  91. * Reports the expected outer height to the LayoutManager.
  92. *
  93. * @param allocatedHeight
  94. * the height to set (including margins, borders and paddings) in
  95. * pixels
  96. */
  97. @Override
  98. protected void reportActualRelativeHeight(int allocatedHeight) {
  99. getLayoutManager().reportOuterHeight(child, allocatedHeight);
  100. }
  101. /**
  102. * Reports the expected outer width to the LayoutManager.
  103. *
  104. * @param allocatedWidth
  105. * the width to set (including margins, borders and paddings) in
  106. * pixels
  107. */
  108. @Override
  109. protected void reportActualRelativeWidth(int allocatedWidth) {
  110. getLayoutManager().reportOuterWidth(child, allocatedWidth);
  111. }
  112. @Override
  113. public int getWidgetHeight() {
  114. return getLayoutManager()
  115. .getOuterHeight(child.getWidget().getElement());
  116. }
  117. @Override
  118. public int getWidgetWidth() {
  119. return getLayoutManager().getOuterWidth(child.getWidget().getElement());
  120. }
  121. @Override
  122. public boolean isUndefinedHeight() {
  123. return child.isUndefinedHeight();
  124. }
  125. @Override
  126. public boolean isUndefinedWidth() {
  127. return child.isUndefinedWidth();
  128. }
  129. @Override
  130. public boolean isRelativeHeight() {
  131. return child.isRelativeHeight();
  132. }
  133. @Override
  134. public boolean isRelativeWidth() {
  135. return child.isRelativeWidth();
  136. }
  137. }