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.

VCaption.java 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*
  2. * Copyright 2000-2016 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;
  17. import java.util.logging.Logger;
  18. import com.google.gwt.aria.client.Roles;
  19. import com.google.gwt.dom.client.Element;
  20. import com.google.gwt.dom.client.Style.Unit;
  21. import com.google.gwt.user.client.DOM;
  22. import com.google.gwt.user.client.Event;
  23. import com.google.gwt.user.client.ui.HTML;
  24. import com.google.gwt.user.client.ui.HasHTML;
  25. import com.vaadin.client.communication.StateChangeEvent;
  26. import com.vaadin.client.ui.AbstractFieldConnector;
  27. import com.vaadin.client.ui.Icon;
  28. import com.vaadin.client.ui.ImageIcon;
  29. import com.vaadin.client.ui.aria.AriaHelper;
  30. import com.vaadin.shared.AbstractComponentState;
  31. import com.vaadin.shared.AbstractFieldState;
  32. import com.vaadin.shared.ComponentConstants;
  33. import com.vaadin.shared.ui.ComponentStateUtil;
  34. public class VCaption extends HTML {
  35. public static final String CLASSNAME = "v-caption";
  36. private final ComponentConnector owner;
  37. private Element errorIndicatorElement;
  38. private Element requiredFieldIndicator;
  39. private Icon icon;
  40. private String iconAltText = "";
  41. private Element captionText;
  42. private final ApplicationConnection client;
  43. private boolean placedAfterComponent = false;
  44. private int maxWidth = -1;
  45. private enum InsertPosition {
  46. ICON, CAPTION, REQUIRED, ERROR
  47. }
  48. private TooltipInfo tooltipInfo = null;
  49. private boolean captionAsHtml = false;
  50. /**
  51. * Creates a caption that is not linked to a {@link ComponentConnector}.
  52. *
  53. * When using this constructor, {@link #getOwner()} returns null.
  54. *
  55. * @param client
  56. * ApplicationConnection
  57. * @deprecated all captions should be associated with a paintable widget and
  58. * be updated from shared state, not UIDL
  59. */
  60. @Deprecated
  61. public VCaption(ApplicationConnection client) {
  62. super();
  63. this.client = client;
  64. owner = null;
  65. setStyleName(CLASSNAME);
  66. sinkEvents(VTooltip.TOOLTIP_EVENTS);
  67. }
  68. /**
  69. * Creates a caption for a {@link ComponentConnector}.
  70. *
  71. * @param component
  72. * owner of caption, not null
  73. * @param client
  74. * ApplicationConnection
  75. */
  76. public VCaption(ComponentConnector component,
  77. ApplicationConnection client) {
  78. super();
  79. this.client = client;
  80. owner = component;
  81. if (client != null && owner != null) {
  82. setOwnerPid(getElement(), owner.getConnectorId());
  83. }
  84. setStyleName(CLASSNAME);
  85. }
  86. @Override
  87. protected void onAttach() {
  88. super.onAttach();
  89. if (null != owner) {
  90. AriaHelper.bindCaption(owner.getWidget(), getElement());
  91. }
  92. }
  93. @Override
  94. protected void onDetach() {
  95. super.onDetach();
  96. if (null != owner) {
  97. AriaHelper.bindCaption(owner.getWidget(), null);
  98. AriaHelper.handleInputInvalid(owner.getWidget(), false);
  99. AriaHelper.handleInputRequired(owner.getWidget(), false);
  100. }
  101. }
  102. /**
  103. * Updates the caption from UIDL.
  104. *
  105. * This method may only be called when the caption has an owner - otherwise,
  106. * use {@link #updateCaptionWithoutOwner(UIDL, String, boolean, boolean)}.
  107. *
  108. * @return true if the position where the caption should be placed has
  109. * changed
  110. */
  111. public boolean updateCaption() {
  112. boolean wasPlacedAfterComponent = placedAfterComponent;
  113. // Caption is placed after component unless there is some part which
  114. // moves it above.
  115. placedAfterComponent = true;
  116. String style = CLASSNAME;
  117. if (ComponentStateUtil.hasStyles(owner.getState())) {
  118. for (String customStyle : owner.getState().styles) {
  119. style += " " + CLASSNAME + "-" + customStyle;
  120. }
  121. }
  122. if (!owner.isEnabled()) {
  123. style += " " + StyleConstants.DISABLED;
  124. }
  125. setStyleName(style);
  126. boolean hasIcon = owner.getState().resources
  127. .containsKey(ComponentConstants.ICON_RESOURCE);
  128. boolean showRequired = false;
  129. boolean showError = owner.getState().errorMessage != null;
  130. if (owner.getState() instanceof AbstractFieldState) {
  131. AbstractFieldState abstractFieldState = (AbstractFieldState) owner
  132. .getState();
  133. showError = showError && !abstractFieldState.hideErrors;
  134. }
  135. if (owner instanceof AbstractFieldConnector) {
  136. showRequired = ((AbstractFieldConnector) owner).isRequired();
  137. }
  138. if (icon != null) {
  139. getElement().removeChild(icon.getElement());
  140. icon = null;
  141. }
  142. if (hasIcon) {
  143. String uri = owner.getState().resources
  144. .get(ComponentConstants.ICON_RESOURCE).getURL();
  145. icon = client.getIcon(uri);
  146. if (icon instanceof ImageIcon) {
  147. // onload will set appropriate size later
  148. icon.setWidth("0");
  149. icon.setHeight("0");
  150. }
  151. DOM.insertChild(getElement(), icon.getElement(),
  152. getInsertPosition(InsertPosition.ICON));
  153. // Icon forces the caption to be above the component
  154. placedAfterComponent = false;
  155. }
  156. if (owner.getState().caption != null) {
  157. // A caption text should be shown if the attribute is set
  158. // If the caption is null the ATTRIBUTE_CAPTION should not be set to
  159. // avoid ending up here.
  160. if (captionText == null) {
  161. captionText = DOM.createDiv();
  162. captionText.setClassName("v-captiontext");
  163. DOM.insertChild(getElement(), captionText,
  164. getInsertPosition(InsertPosition.CAPTION));
  165. }
  166. // Update caption text
  167. String c = owner.getState().caption;
  168. // A text forces the caption to be above the component.
  169. placedAfterComponent = false;
  170. if (c == null || c.trim().equals("")) {
  171. // Not sure if c even can be null. Should not.
  172. // This is required to ensure that the caption uses space in all
  173. // browsers when it is set to the empty string. If there is an
  174. // icon, error indicator or required indicator they will ensure
  175. // that space is reserved.
  176. if (!hasIcon && !showRequired && !showError) {
  177. captionText.setInnerHTML(" ");
  178. }
  179. } else {
  180. setCaptionText(captionText, owner.getState());
  181. }
  182. } else if (captionText != null) {
  183. // Remove existing
  184. DOM.removeChild(getElement(), captionText);
  185. captionText = null;
  186. }
  187. if (ComponentStateUtil.hasDescription(owner.getState())
  188. && captionText != null) {
  189. addStyleDependentName("hasdescription");
  190. } else {
  191. removeStyleDependentName("hasdescription");
  192. }
  193. AriaHelper.handleInputRequired(owner.getWidget(), showRequired);
  194. if (showRequired) {
  195. if (requiredFieldIndicator == null) {
  196. requiredFieldIndicator = DOM.createDiv();
  197. requiredFieldIndicator
  198. .setClassName("v-required-field-indicator");
  199. DOM.setInnerText(requiredFieldIndicator, "*");
  200. DOM.insertChild(getElement(), requiredFieldIndicator,
  201. getInsertPosition(InsertPosition.REQUIRED));
  202. // Hide the required indicator from assistive device
  203. Roles.getTextboxRole()
  204. .setAriaHiddenState(requiredFieldIndicator, true);
  205. }
  206. } else if (requiredFieldIndicator != null) {
  207. // Remove existing
  208. DOM.removeChild(getElement(), requiredFieldIndicator);
  209. requiredFieldIndicator = null;
  210. }
  211. AriaHelper.handleInputInvalid(owner.getWidget(), showError);
  212. if (showError) {
  213. if (errorIndicatorElement == null) {
  214. errorIndicatorElement = DOM.createDiv();
  215. DOM.setInnerHTML(errorIndicatorElement, " ");
  216. DOM.setElementProperty(errorIndicatorElement, "className",
  217. "v-errorindicator");
  218. DOM.insertChild(getElement(), errorIndicatorElement,
  219. getInsertPosition(InsertPosition.ERROR));
  220. // Hide error indicator from assistive devices
  221. Roles.getTextboxRole().setAriaHiddenState(errorIndicatorElement,
  222. true);
  223. }
  224. } else if (errorIndicatorElement != null) {
  225. // Remove existing
  226. getElement().removeChild(errorIndicatorElement);
  227. errorIndicatorElement = null;
  228. }
  229. return (wasPlacedAfterComponent != placedAfterComponent);
  230. }
  231. private int getInsertPosition(InsertPosition element) {
  232. int pos = 0;
  233. if (InsertPosition.ICON.equals(element)) {
  234. return pos;
  235. }
  236. if (icon != null) {
  237. pos++;
  238. }
  239. if (InsertPosition.CAPTION.equals(element)) {
  240. return pos;
  241. }
  242. if (captionText != null) {
  243. pos++;
  244. }
  245. if (InsertPosition.REQUIRED.equals(element)) {
  246. return pos;
  247. }
  248. if (requiredFieldIndicator != null) {
  249. pos++;
  250. }
  251. // if (InsertPosition.ERROR.equals(element)) {
  252. // }
  253. return pos;
  254. }
  255. @Deprecated
  256. public boolean updateCaptionWithoutOwner(String caption, boolean disabled,
  257. boolean hasDescription, boolean hasError, String iconURL) {
  258. return updateCaptionWithoutOwner(caption, disabled, hasDescription,
  259. hasError, iconURL, "");
  260. }
  261. @Deprecated
  262. public boolean updateCaptionWithoutOwner(String caption, boolean disabled,
  263. boolean hasDescription, boolean hasError, String iconURL,
  264. String iconAltText) {
  265. boolean wasPlacedAfterComponent = placedAfterComponent;
  266. // Caption is placed after component unless there is some part which
  267. // moves it above.
  268. placedAfterComponent = true;
  269. String style = VCaption.CLASSNAME;
  270. if (disabled) {
  271. style += " " + StyleConstants.DISABLED;
  272. }
  273. setStyleName(style);
  274. if (hasDescription) {
  275. if (captionText != null) {
  276. addStyleDependentName("hasdescription");
  277. } else {
  278. removeStyleDependentName("hasdescription");
  279. }
  280. }
  281. boolean hasIcon = iconURL != null;
  282. if (icon != null) {
  283. getElement().removeChild(icon.getElement());
  284. icon = null;
  285. }
  286. if (hasIcon) {
  287. icon = client.getIcon(iconURL);
  288. if (icon instanceof ImageIcon) {
  289. // onload sets appropriate size later
  290. icon.setWidth("0");
  291. icon.setHeight("0");
  292. }
  293. icon.setAlternateText(iconAltText);
  294. DOM.insertChild(getElement(), icon.getElement(),
  295. getInsertPosition(InsertPosition.ICON));
  296. // Icon forces the caption to be above the component
  297. placedAfterComponent = false;
  298. }
  299. if (caption != null) {
  300. // A caption text should be shown if the attribute is set
  301. // If the caption is null the ATTRIBUTE_CAPTION should not be set to
  302. // avoid ending up here.
  303. if (captionText == null) {
  304. captionText = DOM.createDiv();
  305. captionText.setClassName("v-captiontext");
  306. DOM.insertChild(getElement(), captionText,
  307. getInsertPosition(InsertPosition.CAPTION));
  308. }
  309. // Update caption text
  310. // A text forces the caption to be above the component.
  311. placedAfterComponent = false;
  312. if (caption.trim().equals("")) {
  313. // This is required to ensure that the caption uses space in all
  314. // browsers when it is set to the empty string. If there is an
  315. // icon, error indicator or required indicator they will ensure
  316. // that space is reserved.
  317. if (!hasIcon && !hasError) {
  318. captionText.setInnerHTML(" ");
  319. }
  320. } else {
  321. if (captionAsHtml) {
  322. captionText.setInnerHTML(caption);
  323. } else {
  324. captionText.setInnerText(caption);
  325. }
  326. }
  327. } else if (captionText != null) {
  328. // Remove existing
  329. DOM.removeChild(getElement(), captionText);
  330. captionText = null;
  331. }
  332. if (hasError) {
  333. if (errorIndicatorElement == null) {
  334. errorIndicatorElement = DOM.createDiv();
  335. DOM.setInnerHTML(errorIndicatorElement, " ");
  336. DOM.setElementProperty(errorIndicatorElement, "className",
  337. "v-errorindicator");
  338. DOM.insertChild(getElement(), errorIndicatorElement,
  339. getInsertPosition(InsertPosition.ERROR));
  340. }
  341. } else if (errorIndicatorElement != null) {
  342. // Remove existing
  343. getElement().removeChild(errorIndicatorElement);
  344. errorIndicatorElement = null;
  345. }
  346. return (wasPlacedAfterComponent != placedAfterComponent);
  347. }
  348. @Override
  349. public void onBrowserEvent(Event event) {
  350. super.onBrowserEvent(event);
  351. final Element target = DOM.eventGetTarget(event);
  352. if (DOM.eventGetType(event) == Event.ONLOAD
  353. && icon.getElement() == target) {
  354. icon.setWidth("");
  355. icon.setHeight("");
  356. // if max width defined, recalculate
  357. if (maxWidth != -1) {
  358. setMaxWidth(maxWidth);
  359. } else {
  360. String width = getElement().getStyle().getProperty("width");
  361. if (width != null && !width.equals("")) {
  362. setWidth(getRequiredWidth() + "px");
  363. }
  364. }
  365. /*
  366. * The size of the icon might affect the size of the component so we
  367. * must report the size change to the parent TODO consider moving
  368. * the responsibility of reacting to ONLOAD from VCaption to layouts
  369. */
  370. if (owner != null) {
  371. Util.notifyParentOfSizeChange(owner.getWidget(), true);
  372. } else {
  373. getLogger().warning(
  374. "Warning: Icon load event was not propagated because VCaption owner is unknown.");
  375. }
  376. }
  377. }
  378. public static boolean isNeeded(AbstractComponentState state) {
  379. if (state.caption != null) {
  380. return true;
  381. }
  382. if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) {
  383. return true;
  384. }
  385. if (state.errorMessage != null) {
  386. return true;
  387. }
  388. if (state instanceof AbstractFieldState) {
  389. if (((AbstractFieldState) state).required) {
  390. return true;
  391. }
  392. }
  393. return false;
  394. }
  395. /**
  396. * Checks whether anything in a given state change might cause the caption
  397. * to change.
  398. *
  399. * @param event
  400. * the state change event to check
  401. * @return <code>true</code> if the caption might have changed; otherwise
  402. * <code>false</code>
  403. */
  404. public static boolean mightChange(StateChangeEvent event) {
  405. if (event.hasPropertyChanged("caption")) {
  406. return true;
  407. }
  408. if (event.hasPropertyChanged("resources")) {
  409. return true;
  410. }
  411. if (event.hasPropertyChanged("errorMessage")) {
  412. return true;
  413. }
  414. return false;
  415. }
  416. /**
  417. * Returns Paintable for which this Caption belongs to.
  418. *
  419. * @return owner Widget
  420. */
  421. public ComponentConnector getOwner() {
  422. return owner;
  423. }
  424. public boolean shouldBePlacedAfterComponent() {
  425. return placedAfterComponent;
  426. }
  427. public int getRenderedWidth() {
  428. int width = 0;
  429. if (icon != null) {
  430. width += WidgetUtil.getRequiredWidth(icon.getElement());
  431. }
  432. if (captionText != null) {
  433. width += WidgetUtil.getRequiredWidth(captionText);
  434. }
  435. if (requiredFieldIndicator != null) {
  436. width += WidgetUtil.getRequiredWidth(requiredFieldIndicator);
  437. }
  438. if (errorIndicatorElement != null) {
  439. width += WidgetUtil.getRequiredWidth(errorIndicatorElement);
  440. }
  441. return width;
  442. }
  443. public int getRequiredWidth() {
  444. int width = 0;
  445. if (icon != null) {
  446. width += WidgetUtil.getRequiredWidth(icon.getElement());
  447. }
  448. if (captionText != null) {
  449. int textWidth = captionText.getScrollWidth();
  450. if (BrowserInfo.get().isFirefox()) {
  451. /*
  452. * In Firefox3 the caption might require more space than the
  453. * scrollWidth returns as scrollWidth is rounded down.
  454. */
  455. int requiredWidth = WidgetUtil.getRequiredWidth(captionText);
  456. if (requiredWidth > textWidth) {
  457. textWidth = requiredWidth;
  458. }
  459. }
  460. width += textWidth;
  461. }
  462. if (requiredFieldIndicator != null) {
  463. width += WidgetUtil.getRequiredWidth(requiredFieldIndicator);
  464. }
  465. if (errorIndicatorElement != null) {
  466. width += WidgetUtil.getRequiredWidth(errorIndicatorElement);
  467. }
  468. return width;
  469. }
  470. public int getHeight() {
  471. int height = 0;
  472. int h;
  473. if (icon != null) {
  474. h = WidgetUtil.getRequiredHeight(icon.getElement());
  475. if (h > height) {
  476. height = h;
  477. }
  478. }
  479. if (captionText != null) {
  480. h = WidgetUtil.getRequiredHeight(captionText);
  481. if (h > height) {
  482. height = h;
  483. }
  484. }
  485. if (requiredFieldIndicator != null) {
  486. h = WidgetUtil.getRequiredHeight(requiredFieldIndicator);
  487. if (h > height) {
  488. height = h;
  489. }
  490. }
  491. if (errorIndicatorElement != null) {
  492. h = WidgetUtil.getRequiredHeight(errorIndicatorElement);
  493. if (h > height) {
  494. height = h;
  495. }
  496. }
  497. return height;
  498. }
  499. public void setAlignment(String alignment) {
  500. getElement().getStyle().setProperty("textAlign", alignment);
  501. }
  502. public void setMaxWidth(int maxWidth) {
  503. this.maxWidth = maxWidth;
  504. getElement().getStyle().setWidth(maxWidth, Unit.PX);
  505. if (icon != null) {
  506. icon.getElement().getStyle().clearWidth();
  507. }
  508. if (captionText != null) {
  509. captionText.getStyle().clearWidth();
  510. }
  511. int requiredWidth = getRequiredWidth();
  512. /*
  513. * ApplicationConnection.getConsole().log( "Caption maxWidth: " +
  514. * maxWidth + ", requiredWidth: " + requiredWidth);
  515. */
  516. if (requiredWidth > maxWidth) {
  517. // Needs to truncate and clip
  518. int availableWidth = maxWidth;
  519. // DOM.setStyleAttribute(getElement(), "width", maxWidth + "px");
  520. if (requiredFieldIndicator != null) {
  521. availableWidth -= WidgetUtil
  522. .getRequiredWidth(requiredFieldIndicator);
  523. }
  524. if (errorIndicatorElement != null) {
  525. availableWidth -= WidgetUtil
  526. .getRequiredWidth(errorIndicatorElement);
  527. }
  528. if (availableWidth < 0) {
  529. availableWidth = 0;
  530. }
  531. if (icon != null) {
  532. int iconRequiredWidth = WidgetUtil
  533. .getRequiredWidth(icon.getElement());
  534. if (availableWidth > iconRequiredWidth) {
  535. availableWidth -= iconRequiredWidth;
  536. } else {
  537. icon.getElement().getStyle().setWidth(availableWidth,
  538. Unit.PX);
  539. availableWidth = 0;
  540. }
  541. }
  542. if (captionText != null) {
  543. int captionWidth = WidgetUtil.getRequiredWidth(captionText);
  544. if (availableWidth > captionWidth) {
  545. availableWidth -= captionWidth;
  546. } else {
  547. captionText.getStyle().setWidth(availableWidth, Unit.PX);
  548. availableWidth = 0;
  549. }
  550. }
  551. }
  552. }
  553. /**
  554. * Sets the tooltip that should be shown for the caption
  555. *
  556. * @param tooltipInfo
  557. * The tooltip that should be shown or null if no tooltip should
  558. * be shown
  559. */
  560. public void setTooltipInfo(TooltipInfo tooltipInfo) {
  561. this.tooltipInfo = tooltipInfo;
  562. }
  563. /**
  564. * Returns the tooltip that should be shown for the caption
  565. *
  566. * @return The tooltip to show or null if no tooltip should be shown
  567. */
  568. public TooltipInfo getTooltipInfo() {
  569. return tooltipInfo;
  570. }
  571. protected com.google.gwt.user.client.Element getTextElement() {
  572. return DOM.asOld(captionText);
  573. }
  574. public static String getCaptionOwnerPid(Element e) {
  575. return getOwnerPid(e);
  576. }
  577. private native static void setOwnerPid(Element el, String pid)
  578. /*-{
  579. el.vOwnerPid = pid;
  580. }-*/;
  581. public native static String getOwnerPid(Element el)
  582. /*-{
  583. return el.vOwnerPid;
  584. }-*/;
  585. /**
  586. * Sets whether the caption is rendered as HTML.
  587. * <p>
  588. * Default is false
  589. *
  590. * @param captionAsHtml
  591. * true if the captions are rendered as HTML, false if rendered
  592. * as plain text
  593. */
  594. public void setCaptionAsHtml(boolean captionAsHtml) {
  595. this.captionAsHtml = captionAsHtml;
  596. }
  597. /**
  598. * Checks whether captions are rendered as HTML.
  599. * <p>
  600. * Default is false
  601. *
  602. * @return true if the captions are rendered as HTML, false if rendered as
  603. * plain text
  604. */
  605. public boolean isCaptionAsHtml() {
  606. return captionAsHtml;
  607. }
  608. /**
  609. * Sets the text of the given caption element to the caption found in the
  610. * state.
  611. * <p>
  612. * Uses {@link AbstractComponentState#captionAsHtml} to determine whether to
  613. * set the caption as html or plain text
  614. *
  615. * @since 7.4
  616. * @param captionElement
  617. * the target element
  618. * @param state
  619. * the state from which to read the caption text and mode
  620. */
  621. public static void setCaptionText(Element captionElement,
  622. AbstractComponentState state) {
  623. if (state.captionAsHtml) {
  624. captionElement.setInnerHTML(state.caption);
  625. } else {
  626. captionElement.setInnerText(state.caption);
  627. }
  628. }
  629. /**
  630. * Sets the text of the given widget to the caption found in the state.
  631. * <p>
  632. * Uses {@link AbstractComponentState#captionAsHtml} to determine whether to
  633. * set the caption as html or plain text
  634. *
  635. * @since 7.4
  636. * @param widget
  637. * the target widget
  638. * @param state
  639. * the state from which to read the caption text and mode
  640. */
  641. public static void setCaptionText(HasHTML widget,
  642. AbstractComponentState state) {
  643. if (state.captionAsHtml) {
  644. widget.setHTML(state.caption);
  645. } else {
  646. widget.setText(state.caption);
  647. }
  648. }
  649. private static Logger getLogger() {
  650. return Logger.getLogger(VCaption.class.getName());
  651. }
  652. }