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-2014 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, ApplicationConnection client) {
  77. super();
  78. this.client = client;
  79. owner = component;
  80. if (client != null && owner != null) {
  81. setOwnerPid(getElement(), owner.getConnectorId());
  82. }
  83. setStyleName(CLASSNAME);
  84. }
  85. @Override
  86. protected void onAttach() {
  87. super.onAttach();
  88. if (null != owner) {
  89. AriaHelper.bindCaption(owner.getWidget(), getElement());
  90. }
  91. }
  92. @Override
  93. protected void onDetach() {
  94. super.onDetach();
  95. if (null != owner) {
  96. AriaHelper.bindCaption(owner.getWidget(), null);
  97. AriaHelper.handleInputInvalid(owner.getWidget(), false);
  98. AriaHelper.handleInputRequired(owner.getWidget(), false);
  99. }
  100. }
  101. /**
  102. * Updates the caption from UIDL.
  103. *
  104. * This method may only be called when the caption has an owner - otherwise,
  105. * use {@link #updateCaptionWithoutOwner(UIDL, String, boolean, boolean)}.
  106. *
  107. * @return true if the position where the caption should be placed has
  108. * changed
  109. */
  110. public boolean updateCaption() {
  111. boolean wasPlacedAfterComponent = placedAfterComponent;
  112. // Caption is placed after component unless there is some part which
  113. // moves it above.
  114. placedAfterComponent = true;
  115. String style = CLASSNAME;
  116. if (ComponentStateUtil.hasStyles(owner.getState())) {
  117. for (String customStyle : owner.getState().styles) {
  118. style += " " + CLASSNAME + "-" + customStyle;
  119. }
  120. }
  121. if (!owner.isEnabled()) {
  122. style += " " + StyleConstants.DISABLED;
  123. }
  124. setStyleName(style);
  125. boolean hasIcon = owner.getState().resources
  126. .containsKey(ComponentConstants.ICON_RESOURCE);
  127. boolean showRequired = false;
  128. boolean showError = owner.getState().errorMessage != null;
  129. if (owner.getState() instanceof AbstractFieldState) {
  130. AbstractFieldState abstractFieldState = (AbstractFieldState) owner
  131. .getState();
  132. showError = showError && !abstractFieldState.hideErrors;
  133. }
  134. if (owner instanceof AbstractFieldConnector) {
  135. showRequired = ((AbstractFieldConnector) owner).isRequired();
  136. }
  137. if (icon != null) {
  138. getElement().removeChild(icon.getElement());
  139. icon = null;
  140. }
  141. if (hasIcon) {
  142. String uri = owner.getState().resources.get(
  143. ComponentConstants.ICON_RESOURCE).getURL();
  144. icon = client.getIcon(uri);
  145. if (icon instanceof ImageIcon) {
  146. // onload will set appropriate size later
  147. icon.setWidth("0");
  148. icon.setHeight("0");
  149. }
  150. DOM.insertChild(getElement(), icon.getElement(),
  151. getInsertPosition(InsertPosition.ICON));
  152. // Icon forces the caption to be above the component
  153. placedAfterComponent = false;
  154. }
  155. if (owner.getState().caption != null) {
  156. // A caption text should be shown if the attribute is set
  157. // If the caption is null the ATTRIBUTE_CAPTION should not be set to
  158. // avoid ending up here.
  159. if (captionText == null) {
  160. captionText = DOM.createDiv();
  161. captionText.setClassName("v-captiontext");
  162. DOM.insertChild(getElement(), captionText,
  163. getInsertPosition(InsertPosition.CAPTION));
  164. }
  165. // Update caption text
  166. String c = owner.getState().caption;
  167. // A text forces the caption to be above the component.
  168. placedAfterComponent = false;
  169. if (c == null || c.trim().equals("")) {
  170. // Not sure if c even can be null. Should not.
  171. // This is required to ensure that the caption uses space in all
  172. // browsers when it is set to the empty string. If there is an
  173. // icon, error indicator or required indicator they will ensure
  174. // that space is reserved.
  175. if (!hasIcon && !showRequired && !showError) {
  176. captionText.setInnerHTML(" ");
  177. }
  178. } else {
  179. setCaptionText(captionText, owner.getState());
  180. }
  181. } else if (captionText != null) {
  182. // Remove existing
  183. DOM.removeChild(getElement(), captionText);
  184. captionText = null;
  185. }
  186. if (ComponentStateUtil.hasDescription(owner.getState())
  187. && captionText != null) {
  188. addStyleDependentName("hasdescription");
  189. } else {
  190. removeStyleDependentName("hasdescription");
  191. }
  192. AriaHelper.handleInputRequired(owner.getWidget(), showRequired);
  193. if (showRequired) {
  194. if (requiredFieldIndicator == null) {
  195. requiredFieldIndicator = DOM.createDiv();
  196. requiredFieldIndicator
  197. .setClassName("v-required-field-indicator");
  198. DOM.setInnerText(requiredFieldIndicator, "*");
  199. DOM.insertChild(getElement(), requiredFieldIndicator,
  200. getInsertPosition(InsertPosition.REQUIRED));
  201. // Hide the required indicator from assistive device
  202. Roles.getTextboxRole().setAriaHiddenState(
  203. requiredFieldIndicator, true);
  204. }
  205. } else if (requiredFieldIndicator != null) {
  206. // Remove existing
  207. DOM.removeChild(getElement(), requiredFieldIndicator);
  208. requiredFieldIndicator = null;
  209. }
  210. AriaHelper.handleInputInvalid(owner.getWidget(), showError);
  211. if (showError) {
  212. if (errorIndicatorElement == null) {
  213. errorIndicatorElement = DOM.createDiv();
  214. DOM.setInnerHTML(errorIndicatorElement, " ");
  215. DOM.setElementProperty(errorIndicatorElement, "className",
  216. "v-errorindicator");
  217. DOM.insertChild(getElement(), errorIndicatorElement,
  218. getInsertPosition(InsertPosition.ERROR));
  219. // Hide error indicator from assistive devices
  220. Roles.getTextboxRole().setAriaHiddenState(
  221. errorIndicatorElement, true);
  222. }
  223. } else if (errorIndicatorElement != null) {
  224. // Remove existing
  225. getElement().removeChild(errorIndicatorElement);
  226. errorIndicatorElement = null;
  227. }
  228. return (wasPlacedAfterComponent != placedAfterComponent);
  229. }
  230. private int getInsertPosition(InsertPosition element) {
  231. int pos = 0;
  232. if (InsertPosition.ICON.equals(element)) {
  233. return pos;
  234. }
  235. if (icon != null) {
  236. pos++;
  237. }
  238. if (InsertPosition.CAPTION.equals(element)) {
  239. return pos;
  240. }
  241. if (captionText != null) {
  242. pos++;
  243. }
  244. if (InsertPosition.REQUIRED.equals(element)) {
  245. return pos;
  246. }
  247. if (requiredFieldIndicator != null) {
  248. pos++;
  249. }
  250. // if (InsertPosition.ERROR.equals(element)) {
  251. // }
  252. return pos;
  253. }
  254. @Deprecated
  255. public boolean updateCaptionWithoutOwner(String caption, boolean disabled,
  256. boolean hasDescription, boolean hasError, String iconURL) {
  257. return updateCaptionWithoutOwner(caption, disabled, hasDescription,
  258. hasError, iconURL, "");
  259. }
  260. @Deprecated
  261. public boolean updateCaptionWithoutOwner(String caption, boolean disabled,
  262. boolean hasDescription, boolean hasError, String iconURL,
  263. String iconAltText) {
  264. boolean wasPlacedAfterComponent = placedAfterComponent;
  265. // Caption is placed after component unless there is some part which
  266. // moves it above.
  267. placedAfterComponent = true;
  268. String style = VCaption.CLASSNAME;
  269. if (disabled) {
  270. style += " " + StyleConstants.DISABLED;
  271. }
  272. setStyleName(style);
  273. if (hasDescription) {
  274. if (captionText != null) {
  275. addStyleDependentName("hasdescription");
  276. } else {
  277. removeStyleDependentName("hasdescription");
  278. }
  279. }
  280. boolean hasIcon = iconURL != null;
  281. if (icon != null) {
  282. getElement().removeChild(icon.getElement());
  283. icon = null;
  284. }
  285. if (hasIcon) {
  286. icon = client.getIcon(iconURL);
  287. if (icon instanceof ImageIcon) {
  288. // onload sets appropriate size later
  289. icon.setWidth("0");
  290. icon.setHeight("0");
  291. }
  292. icon.setAlternateText(iconAltText);
  293. DOM.insertChild(getElement(), icon.getElement(),
  294. getInsertPosition(InsertPosition.ICON));
  295. // Icon forces the caption to be above the component
  296. placedAfterComponent = false;
  297. }
  298. if (caption != null) {
  299. // A caption text should be shown if the attribute is set
  300. // If the caption is null the ATTRIBUTE_CAPTION should not be set to
  301. // avoid ending up here.
  302. if (captionText == null) {
  303. captionText = DOM.createDiv();
  304. captionText.setClassName("v-captiontext");
  305. DOM.insertChild(getElement(), captionText,
  306. getInsertPosition(InsertPosition.CAPTION));
  307. }
  308. // Update caption text
  309. // A text forces the caption to be above the component.
  310. placedAfterComponent = false;
  311. if (caption.trim().equals("")) {
  312. // This is required to ensure that the caption uses space in all
  313. // browsers when it is set to the empty string. If there is an
  314. // icon, error indicator or required indicator they will ensure
  315. // that space is reserved.
  316. if (!hasIcon && !hasError) {
  317. captionText.setInnerHTML(" ");
  318. }
  319. } else {
  320. if (captionAsHtml) {
  321. captionText.setInnerHTML(caption);
  322. } else {
  323. captionText.setInnerText(caption);
  324. }
  325. }
  326. } else if (captionText != null) {
  327. // Remove existing
  328. DOM.removeChild(getElement(), captionText);
  329. captionText = null;
  330. }
  331. if (hasError) {
  332. if (errorIndicatorElement == null) {
  333. errorIndicatorElement = DOM.createDiv();
  334. DOM.setInnerHTML(errorIndicatorElement, " ");
  335. DOM.setElementProperty(errorIndicatorElement, "className",
  336. "v-errorindicator");
  337. DOM.insertChild(getElement(), errorIndicatorElement,
  338. getInsertPosition(InsertPosition.ERROR));
  339. }
  340. } else if (errorIndicatorElement != null) {
  341. // Remove existing
  342. getElement().removeChild(errorIndicatorElement);
  343. errorIndicatorElement = null;
  344. }
  345. return (wasPlacedAfterComponent != placedAfterComponent);
  346. }
  347. @Override
  348. public void onBrowserEvent(Event event) {
  349. super.onBrowserEvent(event);
  350. final Element target = DOM.eventGetTarget(event);
  351. if (DOM.eventGetType(event) == Event.ONLOAD
  352. && icon.getElement() == target) {
  353. icon.setWidth("");
  354. icon.setHeight("");
  355. // if max width defined, recalculate
  356. if (maxWidth != -1) {
  357. setMaxWidth(maxWidth);
  358. } else {
  359. String width = getElement().getStyle().getProperty("width");
  360. if (width != null && !width.equals("")) {
  361. setWidth(getRequiredWidth() + "px");
  362. }
  363. }
  364. /*
  365. * The size of the icon might affect the size of the component so we
  366. * must report the size change to the parent TODO consider moving
  367. * the responsibility of reacting to ONLOAD from VCaption to layouts
  368. */
  369. if (owner != null) {
  370. Util.notifyParentOfSizeChange(owner.getWidget(), true);
  371. } else {
  372. getLogger()
  373. .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.getRequiredWidth(icon
  533. .getElement());
  534. if (availableWidth > iconRequiredWidth) {
  535. availableWidth -= iconRequiredWidth;
  536. } else {
  537. icon.getElement().getStyle()
  538. .setWidth(availableWidth, 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. }