Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VAbstractOrderedLayout.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Copyright 2000-2013 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.orderedlayout;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import com.google.gwt.dom.client.Element;
  20. import com.google.gwt.dom.client.Node;
  21. import com.google.gwt.dom.client.Style;
  22. import com.google.gwt.dom.client.Style.Unit;
  23. import com.google.gwt.dom.client.Style.Visibility;
  24. import com.google.gwt.regexp.shared.MatchResult;
  25. import com.google.gwt.regexp.shared.RegExp;
  26. import com.google.gwt.user.client.DOM;
  27. import com.google.gwt.user.client.ui.FlowPanel;
  28. import com.google.gwt.user.client.ui.RequiresResize;
  29. import com.google.gwt.user.client.ui.Widget;
  30. import com.vaadin.client.BrowserInfo;
  31. import com.vaadin.client.LayoutManager;
  32. import com.vaadin.client.Profiler;
  33. import com.vaadin.client.Util;
  34. import com.vaadin.shared.ui.MarginInfo;
  35. /**
  36. * Base class for ordered layouts
  37. */
  38. public class VAbstractOrderedLayout extends FlowPanel {
  39. protected boolean spacing = false;
  40. /** For internal use only. May be removed or replaced in the future. */
  41. public boolean vertical = true;
  42. protected boolean definedHeight = false;
  43. private Map<Widget, Slot> widgetToSlot = new HashMap<Widget, Slot>();
  44. private Element expandWrapper;
  45. private LayoutManager layoutManager;
  46. /**
  47. * Keep track of the last allocated expand size to help detecting when it
  48. * changes.
  49. */
  50. private int lastExpandSize = -1;
  51. public VAbstractOrderedLayout(boolean vertical) {
  52. this.vertical = vertical;
  53. }
  54. /**
  55. * See the method {@link #addOrMoveSlot(Slot, int, boolean)}.
  56. *
  57. * <p>
  58. * This method always adjusts spacings for the whole layout.
  59. *
  60. * @param slot
  61. * The slot to move or add
  62. * @param index
  63. * The index where the slot should be placed.
  64. * @deprecated since 7.1.4, use {@link #addOrMoveSlot(Slot, int, boolean)}
  65. */
  66. @Deprecated
  67. public void addOrMoveSlot(Slot slot, int index) {
  68. addOrMoveSlot(slot, index, true);
  69. }
  70. /**
  71. * Add or move a slot to another index.
  72. * <p>
  73. * For internal use only. May be removed or replaced in the future.
  74. * <p>
  75. * You should note that the index does not refer to the DOM index if
  76. * spacings are used. If spacings are used then the index will be adjusted
  77. * to include the spacings when inserted.
  78. * <p>
  79. * For instance when using spacing the index converts to DOM index in the
  80. * following way:
  81. *
  82. * <pre>
  83. * index : 0 -> DOM index: 0
  84. * index : 1 -> DOM index: 1
  85. * index : 2 -> DOM index: 3
  86. * index : 3 -> DOM index: 5
  87. * index : 4 -> DOM index: 7
  88. * </pre>
  89. *
  90. * When using this method never account for spacings.
  91. * <p>
  92. * The caller should remove all spacings before calling this method and
  93. * re-add them (if necessary) after this method. This can be done before and
  94. * after all slots have been added/moved.
  95. * </p>
  96. *
  97. * @since 7.1.4
  98. *
  99. * @param slot
  100. * The slot to move or add
  101. * @param index
  102. * The index where the slot should be placed.
  103. * @param adjustSpacing
  104. * true to recalculate spacings for the whole layout after the
  105. * operation
  106. */
  107. public void addOrMoveSlot(Slot slot, int index, boolean adjustSpacing) {
  108. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  109. if (slot.getParent() == this) {
  110. int currentIndex = getWidgetIndex(slot);
  111. if (index == currentIndex) {
  112. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  113. return;
  114. }
  115. }
  116. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  117. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot insert");
  118. insert(slot, index);
  119. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot insert");
  120. if (adjustSpacing) {
  121. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot setSpacing");
  122. setSpacing(spacing);
  123. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot setSpacing");
  124. }
  125. }
  126. /**
  127. * {@inheritDoc}
  128. *
  129. * @deprecated As of 7.2, use or override
  130. * {@link #insert(Widget, Element, int, boolean)} instead.
  131. */
  132. @Override
  133. @Deprecated
  134. protected void insert(Widget child,
  135. com.google.gwt.user.client.Element container, int beforeIndex,
  136. boolean domInsert) {
  137. // Validate index; adjust if the widget is already a child of this
  138. // panel.
  139. beforeIndex = adjustIndex(child, beforeIndex);
  140. // Detach new child.
  141. child.removeFromParent();
  142. // Logical attach.
  143. getChildren().insert(child, beforeIndex);
  144. // Physical attach.
  145. container = expandWrapper != null ? DOM.asOld(expandWrapper)
  146. : getElement();
  147. if (domInsert) {
  148. if (spacing) {
  149. if (beforeIndex != 0) {
  150. /*
  151. * Since the spacing elements are located at the same DOM
  152. * level as the slots we need to take them into account when
  153. * calculating the slot position.
  154. *
  155. * The spacing elements are always located before the actual
  156. * slot except for the first slot which do not have a
  157. * spacing element like this
  158. *
  159. * |<slot1><spacing2><slot2><spacing3><slot3>...|
  160. */
  161. beforeIndex = beforeIndex * 2 - 1;
  162. }
  163. }
  164. DOM.insertChild(container, child.getElement(), beforeIndex);
  165. } else {
  166. DOM.appendChild(container, child.getElement());
  167. }
  168. // Adopt.
  169. adopt(child);
  170. }
  171. /**
  172. * {@inheritDoc}
  173. *
  174. * @since 7.2
  175. */
  176. @Override
  177. protected void insert(Widget child, Element container, int beforeIndex,
  178. boolean domInsert) {
  179. insert(child, DOM.asOld(container), beforeIndex, domInsert);
  180. }
  181. /**
  182. * Remove a slot from the layout
  183. *
  184. * @param widget
  185. * @return
  186. */
  187. public void removeWidget(Widget widget) {
  188. Slot slot = widgetToSlot.get(widget);
  189. remove(slot);
  190. widgetToSlot.remove(widget);
  191. }
  192. /**
  193. * Get the containing slot for a widget. If no slot is found a new slot is
  194. * created and returned.
  195. *
  196. * @param widget
  197. * The widget whose slot you want to get
  198. *
  199. * @return
  200. */
  201. public Slot getSlot(Widget widget) {
  202. Slot slot = widgetToSlot.get(widget);
  203. if (slot == null) {
  204. slot = new Slot(this, widget);
  205. widgetToSlot.put(widget, slot);
  206. }
  207. return slot;
  208. }
  209. /**
  210. * Gets a slot based on the widget element. If no slot is found then null is
  211. * returned.
  212. *
  213. * @param widgetElement
  214. * The element of the widget ( Same as getWidget().getElement() )
  215. * @return
  216. * @deprecated As of 7.2, call or override {@link #getSlot(Element)} instead
  217. */
  218. @Deprecated
  219. public Slot getSlot(com.google.gwt.user.client.Element widgetElement) {
  220. for (Map.Entry<Widget, Slot> entry : widgetToSlot.entrySet()) {
  221. if (entry.getKey().getElement() == widgetElement) {
  222. return entry.getValue();
  223. }
  224. }
  225. return null;
  226. }
  227. /**
  228. * Gets a slot based on the widget element. If no slot is found then null is
  229. * returned.
  230. *
  231. * @param widgetElement
  232. * The element of the widget ( Same as getWidget().getElement() )
  233. * @return
  234. *
  235. * @since 7.2
  236. */
  237. public Slot getSlot(Element widgetElement) {
  238. return getSlot(DOM.asOld(widgetElement));
  239. }
  240. /**
  241. * Set the layout manager for the layout
  242. *
  243. * @param manager
  244. * The layout manager to use
  245. */
  246. public void setLayoutManager(LayoutManager manager) {
  247. layoutManager = manager;
  248. }
  249. /**
  250. * Get the layout manager used by this layout
  251. *
  252. */
  253. public LayoutManager getLayoutManager() {
  254. return layoutManager;
  255. }
  256. /**
  257. * Deducts the caption position by examining the wrapping element.
  258. * <p>
  259. * For internal use only. May be removed or replaced in the future.
  260. *
  261. * @param captionWrap
  262. * The wrapping element
  263. *
  264. * @return The caption position
  265. * @deprecated As of 7.2, call or override
  266. * {@link #getCaptionPositionFromElement(Element)} instead
  267. */
  268. @Deprecated
  269. public CaptionPosition getCaptionPositionFromElement(
  270. com.google.gwt.user.client.Element captionWrap) {
  271. RegExp captionPositionRegexp = RegExp.compile("v-caption-on-(\\S+)");
  272. // Get caption position from the classname
  273. MatchResult matcher = captionPositionRegexp.exec(captionWrap
  274. .getClassName());
  275. if (matcher == null || matcher.getGroupCount() < 2) {
  276. return CaptionPosition.TOP;
  277. }
  278. String captionClass = matcher.getGroup(1);
  279. CaptionPosition captionPosition = CaptionPosition.valueOf(
  280. CaptionPosition.class, captionClass.toUpperCase());
  281. return captionPosition;
  282. }
  283. /**
  284. * Deducts the caption position by examining the wrapping element.
  285. * <p>
  286. * For internal use only. May be removed or replaced in the future.
  287. *
  288. * @param captionWrap
  289. * The wrapping element
  290. *
  291. * @return The caption position
  292. * @since 7.2
  293. */
  294. public CaptionPosition getCaptionPositionFromElement(Element captionWrap) {
  295. return getCaptionPositionFromElement(DOM.asOld(captionWrap));
  296. }
  297. /**
  298. * Update the offset off the caption relative to the slot
  299. * <p>
  300. * For internal use only. May be removed or replaced in the future.
  301. *
  302. * @param caption
  303. * The caption element
  304. * @deprecated As of 7.2, call or override
  305. * {@link #updateCaptionOffset(Element)} instead
  306. */
  307. @Deprecated
  308. public void updateCaptionOffset(com.google.gwt.user.client.Element caption) {
  309. Element captionWrap = caption.getParentElement();
  310. Style captionWrapStyle = captionWrap.getStyle();
  311. captionWrapStyle.clearPaddingTop();
  312. captionWrapStyle.clearPaddingRight();
  313. captionWrapStyle.clearPaddingBottom();
  314. captionWrapStyle.clearPaddingLeft();
  315. Style captionStyle = caption.getStyle();
  316. captionStyle.clearMarginTop();
  317. captionStyle.clearMarginRight();
  318. captionStyle.clearMarginBottom();
  319. captionStyle.clearMarginLeft();
  320. // Get caption position from the classname
  321. CaptionPosition captionPosition = getCaptionPositionFromElement(captionWrap);
  322. if (captionPosition == CaptionPosition.LEFT
  323. || captionPosition == CaptionPosition.RIGHT) {
  324. int captionWidth;
  325. if (layoutManager != null) {
  326. captionWidth = layoutManager.getOuterWidth(caption)
  327. - layoutManager.getMarginWidth(caption);
  328. } else {
  329. captionWidth = caption.getOffsetWidth();
  330. }
  331. if (captionWidth > 0) {
  332. if (captionPosition == CaptionPosition.LEFT) {
  333. captionWrapStyle.setPaddingLeft(captionWidth, Unit.PX);
  334. captionStyle.setMarginLeft(-captionWidth, Unit.PX);
  335. } else {
  336. captionWrapStyle.setPaddingRight(captionWidth, Unit.PX);
  337. captionStyle.setMarginRight(-captionWidth, Unit.PX);
  338. }
  339. }
  340. }
  341. if (captionPosition == CaptionPosition.TOP
  342. || captionPosition == CaptionPosition.BOTTOM) {
  343. int captionHeight;
  344. if (layoutManager != null) {
  345. captionHeight = layoutManager.getOuterHeight(caption)
  346. - layoutManager.getMarginHeight(caption);
  347. } else {
  348. captionHeight = caption.getOffsetHeight();
  349. }
  350. if (captionHeight > 0) {
  351. if (captionPosition == CaptionPosition.TOP) {
  352. captionWrapStyle.setPaddingTop(captionHeight, Unit.PX);
  353. captionStyle.setMarginTop(-captionHeight, Unit.PX);
  354. } else {
  355. captionWrapStyle.setPaddingBottom(captionHeight, Unit.PX);
  356. captionStyle.setMarginBottom(-captionHeight, Unit.PX);
  357. }
  358. }
  359. }
  360. }
  361. /**
  362. * Update the offset off the caption relative to the slot
  363. * <p>
  364. * For internal use only. May be removed or replaced in the future.
  365. *
  366. * @param caption
  367. * The caption element
  368. * @since 7.2
  369. */
  370. public void updateCaptionOffset(Element caption) {
  371. updateCaptionOffset(DOM.asOld(caption));
  372. }
  373. /**
  374. * Set the margin of the layout
  375. *
  376. * @param marginInfo
  377. * The margin information
  378. */
  379. public void setMargin(MarginInfo marginInfo) {
  380. if (marginInfo != null) {
  381. setStyleName("v-margin-top", marginInfo.hasTop());
  382. setStyleName("v-margin-right", marginInfo.hasRight());
  383. setStyleName("v-margin-bottom", marginInfo.hasBottom());
  384. setStyleName("v-margin-left", marginInfo.hasLeft());
  385. }
  386. }
  387. /**
  388. * Turn on or off spacing in the layout
  389. *
  390. * @param spacing
  391. * True if spacing should be used, false if not
  392. */
  393. public void setSpacing(boolean spacing) {
  394. Profiler.enter("VAOL.onConnectorHierarchyChange setSpacing");
  395. this.spacing = spacing;
  396. // first widget does not have spacing on
  397. // optimization to avoid looking up widget indices on every iteration
  398. Widget firstSlot = null;
  399. if (getWidgetCount() > 0) {
  400. firstSlot = getWidget(0);
  401. }
  402. for (Slot slot : widgetToSlot.values()) {
  403. slot.setSpacing(spacing && firstSlot != slot);
  404. }
  405. Profiler.leave("VAOL.onConnectorHierarchyChange setSpacing");
  406. }
  407. /**
  408. * Assigns relative sizes to the children that should expand based on their
  409. * expand ratios.
  410. */
  411. public void updateExpandedSizes() {
  412. // Ensure the expand wrapper is in place
  413. if (expandWrapper == null) {
  414. expandWrapper = DOM.createDiv();
  415. expandWrapper.setClassName("v-expand");
  416. // Detach all widgets before modifying DOM
  417. for (Widget widget : getChildren()) {
  418. orphan(widget);
  419. }
  420. while (getElement().getChildCount() > 0) {
  421. Node el = getElement().getChild(0);
  422. expandWrapper.appendChild(el);
  423. }
  424. getElement().appendChild(expandWrapper);
  425. // Attach all widgets again
  426. for (Widget widget : getChildren()) {
  427. adopt(widget);
  428. }
  429. }
  430. // Sum up expand ratios to get the denominator
  431. double total = 0;
  432. for (Slot slot : widgetToSlot.values()) {
  433. // FIXME expandRatio might be <0
  434. total += slot.getExpandRatio();
  435. }
  436. // Give each expanded child its own share
  437. for (Slot slot : widgetToSlot.values()) {
  438. Element slotElement = slot.getElement();
  439. slotElement.removeAttribute("aria-hidden");
  440. Style slotStyle = slotElement.getStyle();
  441. slotStyle.clearVisibility();
  442. slotStyle.clearMarginLeft();
  443. slotStyle.clearMarginTop();
  444. if (slot.getExpandRatio() != 0) {
  445. // FIXME expandRatio might be <0
  446. double size = 100 * (slot.getExpandRatio() / total);
  447. if (vertical) {
  448. slot.setHeight(size + "%");
  449. if (slot.hasRelativeHeight()) {
  450. Util.notifyParentOfSizeChange(this, true);
  451. }
  452. } else {
  453. slot.setWidth(size + "%");
  454. if (slot.hasRelativeWidth()) {
  455. Util.notifyParentOfSizeChange(this, true);
  456. }
  457. }
  458. } else if (slot.isRelativeInDirection(vertical)) {
  459. // Relative child without expansion gets no space at all
  460. if (vertical) {
  461. slot.setHeight("0");
  462. } else {
  463. slot.setWidth("0");
  464. }
  465. slotStyle.setVisibility(Visibility.HIDDEN);
  466. slotElement.setAttribute("aria-hidden", "true");
  467. } else {
  468. // Non-relative child without expansion should be unconstrained
  469. if (BrowserInfo.get().isIE8()) {
  470. // unconstrained in IE8 is auto
  471. if (vertical) {
  472. slot.setHeight("auto");
  473. } else {
  474. slot.setWidth("auto");
  475. }
  476. } else {
  477. if (vertical) {
  478. slotStyle.clearHeight();
  479. } else {
  480. slotStyle.clearWidth();
  481. }
  482. }
  483. }
  484. }
  485. }
  486. /**
  487. * Removes elements used to expand a slot.
  488. * <p>
  489. * For internal use only. May be removed or replaced in the future.
  490. */
  491. public void clearExpand() {
  492. if (expandWrapper != null) {
  493. // Detach all widgets before modifying DOM
  494. for (Widget widget : getChildren()) {
  495. orphan(widget);
  496. }
  497. lastExpandSize = -1;
  498. while (expandWrapper.getChildCount() > 0) {
  499. Element el = expandWrapper.getChild(0).cast();
  500. getElement().appendChild(el);
  501. if (vertical) {
  502. el.getStyle().clearHeight();
  503. el.getStyle().clearMarginTop();
  504. } else {
  505. el.getStyle().clearWidth();
  506. el.getStyle().clearMarginLeft();
  507. }
  508. }
  509. expandWrapper.removeFromParent();
  510. expandWrapper = null;
  511. // Attach children again
  512. for (Widget widget : getChildren()) {
  513. adopt(widget);
  514. }
  515. }
  516. }
  517. /**
  518. * Updates the expand compensation based on the measured sizes of children
  519. * without expand.
  520. */
  521. public void updateExpandCompensation() {
  522. boolean isExpanding = false;
  523. for (Widget slot : getChildren()) {
  524. // FIXME expandRatio might be <0
  525. if (((Slot) slot).getExpandRatio() != 0) {
  526. isExpanding = true;
  527. break;
  528. }
  529. }
  530. if (isExpanding) {
  531. /*
  532. * Expanded slots have relative sizes that together add up to 100%.
  533. * To make room for slots without expand, we will add padding that
  534. * is not considered for relative sizes and a corresponding negative
  535. * margin for the unexpanded slots. We calculate the size by summing
  536. * the size of all non-expanded non-relative slots.
  537. *
  538. * Relatively sized slots without expansion are considered to get
  539. * 0px, but we still keep them visible (causing overflows) to help
  540. * the developer see what's happening. Forcing them to only get 0px
  541. * would make them disappear which would avoid overflows but would
  542. * instead cause confusion as they would then just disappear without
  543. * any obvious reason.
  544. */
  545. int totalSize = 0;
  546. for (Widget w : getChildren()) {
  547. Slot slot = (Slot) w;
  548. if (slot.getExpandRatio() == 0
  549. && !slot.isRelativeInDirection(vertical)) {
  550. if (layoutManager != null) {
  551. // TODO check caption position
  552. if (vertical) {
  553. int size = layoutManager.getOuterHeight(slot
  554. .getWidget().getElement());
  555. if (slot.hasCaption()) {
  556. size += layoutManager.getOuterHeight(slot
  557. .getCaptionElement());
  558. }
  559. if (size > 0) {
  560. totalSize += size;
  561. }
  562. } else {
  563. int max = -1;
  564. max = layoutManager.getOuterWidth(slot.getWidget()
  565. .getElement());
  566. if (slot.hasCaption()) {
  567. int max2 = layoutManager.getOuterWidth(slot
  568. .getCaptionElement());
  569. max = Math.max(max, max2);
  570. }
  571. if (max > 0) {
  572. totalSize += max;
  573. }
  574. }
  575. } else {
  576. // FIXME expandRatio might be <0
  577. totalSize += vertical ? slot.getOffsetHeight() : slot
  578. .getOffsetWidth();
  579. }
  580. }
  581. // TODO fails in Opera, always returns 0
  582. int spacingSize = vertical ? slot.getVerticalSpacing() : slot
  583. .getHorizontalSpacing();
  584. if (spacingSize > 0) {
  585. totalSize += spacingSize;
  586. }
  587. }
  588. // When we set the margin to the first child, we don't need
  589. // overflow:hidden in the layout root element, since the wrapper
  590. // would otherwise be placed outside of the layout root element
  591. // and block events on elements below it.
  592. if (vertical) {
  593. expandWrapper.getStyle().setPaddingTop(totalSize, Unit.PX);
  594. expandWrapper.getFirstChildElement().getStyle()
  595. .setMarginTop(-totalSize, Unit.PX);
  596. } else {
  597. expandWrapper.getStyle().setPaddingLeft(totalSize, Unit.PX);
  598. expandWrapper.getFirstChildElement().getStyle()
  599. .setMarginLeft(-totalSize, Unit.PX);
  600. }
  601. // Measure expanded children again if their size might have changed
  602. if (totalSize != lastExpandSize) {
  603. lastExpandSize = totalSize;
  604. for (Widget w : getChildren()) {
  605. Slot slot = (Slot) w;
  606. // FIXME expandRatio might be <0
  607. if (slot.getExpandRatio() != 0) {
  608. if (layoutManager != null) {
  609. layoutManager.setNeedsMeasure(Util
  610. .findConnectorFor(slot.getWidget()));
  611. } else if (slot.getWidget() instanceof RequiresResize) {
  612. ((RequiresResize) slot.getWidget()).onResize();
  613. }
  614. }
  615. }
  616. }
  617. }
  618. }
  619. /**
  620. * {@inheritDoc}
  621. */
  622. @Override
  623. public void setHeight(String height) {
  624. super.setHeight(height);
  625. definedHeight = (height != null && !"".equals(height));
  626. }
  627. /**
  628. * Sets the slots style names. The style names will be prefixed with the
  629. * v-slot prefix.
  630. *
  631. * @param stylenames
  632. * The style names of the slot.
  633. */
  634. public void setSlotStyleNames(Widget widget, String... stylenames) {
  635. Slot slot = getSlot(widget);
  636. if (slot == null) {
  637. throw new IllegalArgumentException(
  638. "A slot for the widget could not be found. Has the widget been added to the layout?");
  639. }
  640. slot.setStyleNames(stylenames);
  641. }
  642. }