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.

VTooltip.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  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 com.google.gwt.aria.client.LiveValue;
  18. import com.google.gwt.aria.client.RelevantValue;
  19. import com.google.gwt.aria.client.Roles;
  20. import com.google.gwt.dom.client.Element;
  21. import com.google.gwt.dom.client.Style.Display;
  22. import com.google.gwt.event.dom.client.*;
  23. import com.google.gwt.user.client.DOM;
  24. import com.google.gwt.user.client.Event;
  25. import com.google.gwt.user.client.Timer;
  26. import com.google.gwt.user.client.Window;
  27. import com.google.gwt.user.client.ui.FlowPanel;
  28. import com.google.gwt.user.client.ui.RootPanel;
  29. import com.google.gwt.user.client.ui.Widget;
  30. import com.vaadin.client.ui.VOverlay;
  31. /**
  32. * TODO open for extension
  33. */
  34. public class VTooltip extends VOverlay {
  35. private static final String CLASSNAME = "v-tooltip";
  36. private static final int MARGIN = 4;
  37. public static final int TOOLTIP_EVENTS = Event.ONKEYDOWN
  38. | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONMOUSEMOVE
  39. | Event.ONCLICK;
  40. VErrorMessage em = new VErrorMessage();
  41. Element description = DOM.createDiv();
  42. private TooltipInfo currentTooltipInfo = new TooltipInfo(" ");
  43. private boolean closing = false;
  44. private boolean opening = false;
  45. // Open next tooltip faster. Disabled after 2 sec of showTooltip-silence.
  46. private boolean justClosed = false;
  47. private String uniqueId = DOM.createUniqueId();
  48. private int maxWidth;
  49. // Delays for the tooltip, configurable on the server side
  50. private int openDelay;
  51. private int quickOpenDelay;
  52. private int quickOpenTimeout;
  53. private int closeTimeout;
  54. /**
  55. * Current element hovered
  56. */
  57. private com.google.gwt.dom.client.Element currentElement = null;
  58. /**
  59. * Used to show tooltips; usually used via the singleton in
  60. * {@link ApplicationConnection}. NOTE that #setOwner(Widget)} should be
  61. * called after instantiating.
  62. *
  63. * @see ApplicationConnection#getVTooltip()
  64. */
  65. public VTooltip() {
  66. super(false, false, true);
  67. setStyleName(CLASSNAME);
  68. FlowPanel layout = new FlowPanel();
  69. setWidget(layout);
  70. layout.add(em);
  71. DOM.setElementProperty(description, "className", CLASSNAME + "-text");
  72. DOM.appendChild(layout.getElement(), description);
  73. setSinkShadowEvents(true);
  74. // When a tooltip is shown, the content of the tooltip changes. With a
  75. // tooltip being a live-area, this change is notified to a assistive
  76. // device.
  77. Roles.getTooltipRole().set(getElement());
  78. Roles.getTooltipRole().setAriaLiveProperty(getElement(),
  79. LiveValue.ASSERTIVE);
  80. Roles.getTooltipRole().setAriaRelevantProperty(getElement(),
  81. RelevantValue.ADDITIONS);
  82. // Tooltip needs to be on top of other VOverlay elements.
  83. setZIndex(VOverlay.Z_INDEX + 1);
  84. }
  85. /**
  86. * Show the tooltip with the provided info for assistive devices.
  87. *
  88. * @param info
  89. * with the content of the tooltip
  90. */
  91. public void showAssistive(TooltipInfo info) {
  92. updatePosition(null, true);
  93. setTooltipText(info);
  94. showTooltip();
  95. }
  96. /**
  97. * Initialize the tooltip overlay for assistive devices.
  98. *
  99. * @param info
  100. * with the content of the tooltip
  101. * @since 7.2.4
  102. */
  103. public void initializeAssistiveTooltips() {
  104. updatePosition(null, true);
  105. setTooltipText(new TooltipInfo(" "));
  106. showTooltip();
  107. hideTooltip();
  108. description.getParentElement().getStyle().clearWidth();
  109. }
  110. private void setTooltipText(TooltipInfo info) {
  111. if (info.getErrorMessage() != null && !info.getErrorMessage().isEmpty()) {
  112. em.setVisible(true);
  113. em.updateMessage(info.getErrorMessage());
  114. } else {
  115. em.setVisible(false);
  116. }
  117. if (info.getTitle() != null && !info.getTitle().isEmpty()) {
  118. description.setInnerHTML(info.getTitle());
  119. /*
  120. * Issue #11871: to correctly update the offsetWidth of description
  121. * element we need to clear style width of its parent DIV from old
  122. * value (in some strange cases this width=[tooltip MAX_WIDTH] after
  123. * tooltip text has been already updated to new shortly value:
  124. *
  125. * <div class="popupContent"> <div style="width:500px;"> <div
  126. * class="v-errormessage" aria-hidden="true" style="display: none;">
  127. * <div class="gwt-HTML"> </div> </div> <div
  128. * class="v-tooltip-text">This is a short tooltip</div> </div>
  129. *
  130. * and it leads to error during calculation offsetWidth (it is
  131. * native GWT method getSubPixelOffsetWidth()) of description
  132. * element")
  133. */
  134. description.getParentElement().getStyle().clearWidth();
  135. description.getStyle().clearDisplay();
  136. } else {
  137. description.setInnerHTML("");
  138. description.getStyle().setDisplay(Display.NONE);
  139. }
  140. currentTooltipInfo = info;
  141. }
  142. /**
  143. * Show a popup containing the currentTooltipInfo
  144. *
  145. */
  146. private void showTooltip() {
  147. if (currentTooltipInfo.hasMessage()) {
  148. // Issue #8454: With IE7 the tooltips size is calculated based on
  149. // the last tooltip's position, causing problems if the last one was
  150. // in the right or bottom edge. For this reason the tooltip is moved
  151. // first to 0,0 position so that the calculation goes correctly.
  152. setPopupPosition(0, 0);
  153. setPopupPositionAndShow(new PositionCallback() {
  154. @Override
  155. public void setPosition(int offsetWidth, int offsetHeight) {
  156. if (offsetWidth > getMaxWidth()) {
  157. setWidth(getMaxWidth() + "px");
  158. // Check new height and width with reflowed content
  159. offsetWidth = getOffsetWidth();
  160. offsetHeight = getOffsetHeight();
  161. }
  162. int x = 0;
  163. int y = 0;
  164. if (BrowserInfo.get().isTouchDevice()) {
  165. setMaxWidth(Window.getClientWidth());
  166. offsetWidth = getOffsetWidth();
  167. offsetHeight = getOffsetHeight();
  168. x = getFinalTouchX(offsetWidth);
  169. y = getFinalTouchY(offsetHeight);
  170. } else {
  171. x = getFinalX(offsetWidth);
  172. y = getFinalY(offsetHeight);
  173. }
  174. setPopupPosition(x, y);
  175. sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT);
  176. }
  177. /**
  178. * Return the final X-coordinate of the tooltip based on cursor
  179. * position, size of the tooltip, size of the page and necessary
  180. * margins.
  181. *
  182. * @param offsetWidth
  183. * @return The final X-coordinate
  184. */
  185. private int getFinalX(int offsetWidth) {
  186. int x = 0;
  187. int widthNeeded = 10 + MARGIN + offsetWidth;
  188. int roomLeft = tooltipEventMouseX;
  189. int roomRight = Window.getClientWidth() - roomLeft;
  190. if (roomRight > widthNeeded) {
  191. x = tooltipEventMouseX + 10 + Window.getScrollLeft();
  192. } else {
  193. x = tooltipEventMouseX + Window.getScrollLeft() - 10
  194. - offsetWidth;
  195. }
  196. if (x + offsetWidth + MARGIN - Window.getScrollLeft() > Window
  197. .getClientWidth()) {
  198. x = Window.getClientWidth() - offsetWidth - MARGIN
  199. + Window.getScrollLeft();
  200. }
  201. if (tooltipEventMouseX != EVENT_XY_POSITION_OUTSIDE) {
  202. // Do not allow x to be zero, for otherwise the tooltip
  203. // does not close when the mouse is moved (see
  204. // isTooltipOpen()). #15129
  205. int minX = Window.getScrollLeft() + MARGIN;
  206. x = Math.max(x, minX);
  207. }
  208. return x;
  209. }
  210. /**
  211. * Return the final X-coordinate of the tooltip based on cursor
  212. * position, size of the tooltip, size of the page and necessary
  213. * margins.
  214. *
  215. * @param offsetWidth
  216. * @return The final X-coordinate
  217. */
  218. private int getFinalTouchX(int offsetWidth) {
  219. int x = 0;
  220. int widthNeeded = 10 + offsetWidth;
  221. int roomLeft = currentElement != null ? currentElement
  222. .getAbsoluteLeft() : EVENT_XY_POSITION_OUTSIDE;
  223. int viewPortWidth = Window.getClientWidth();
  224. int roomRight = viewPortWidth - roomLeft;
  225. if (roomRight > widthNeeded) {
  226. x = roomLeft;
  227. } else {
  228. x = roomLeft - offsetWidth;
  229. }
  230. if (x + offsetWidth - Window.getScrollLeft() > viewPortWidth) {
  231. x = viewPortWidth - offsetWidth
  232. + Window.getScrollLeft();
  233. }
  234. if (roomLeft != EVENT_XY_POSITION_OUTSIDE) {
  235. // Do not allow x to be zero, for otherwise the tooltip
  236. // does not close when the mouse is moved (see
  237. // isTooltipOpen()). #15129
  238. int minX = Window.getScrollLeft();
  239. x = Math.max(x, minX);
  240. }
  241. return x;
  242. }
  243. /**
  244. * Return the final Y-coordinate of the tooltip based on cursor
  245. * position, size of the tooltip, size of the page and necessary
  246. * margins.
  247. *
  248. * @param offsetHeight
  249. * @return The final y-coordinate
  250. *
  251. */
  252. private int getFinalY(int offsetHeight) {
  253. int y = 0;
  254. int heightNeeded = 10 + offsetHeight;
  255. int roomAbove = tooltipEventMouseY;
  256. int roomBelow = Window.getClientHeight() - roomAbove;
  257. if (roomBelow > heightNeeded) {
  258. y = tooltipEventMouseY + 10 + Window.getScrollTop();
  259. } else {
  260. y = tooltipEventMouseY + Window.getScrollTop() - 10
  261. - offsetHeight;
  262. }
  263. if (y + offsetHeight + MARGIN - Window.getScrollTop() > Window
  264. .getClientHeight()) {
  265. y = tooltipEventMouseY - 5 - offsetHeight
  266. + Window.getScrollTop();
  267. if (y - Window.getScrollTop() < 0) {
  268. // tooltip does not fit on top of the mouse either,
  269. // put it at the top of the screen
  270. y = Window.getScrollTop();
  271. }
  272. }
  273. if (tooltipEventMouseY != EVENT_XY_POSITION_OUTSIDE) {
  274. // Do not allow y to be zero, for otherwise the tooltip
  275. // does not close when the mouse is moved (see
  276. // isTooltipOpen()). #15129
  277. int minY = Window.getScrollTop() + MARGIN;
  278. y = Math.max(y, minY);
  279. }
  280. return y;
  281. }
  282. /**
  283. * Return the final Y-coordinate of the tooltip based on cursor
  284. * position, size of the tooltip, size of the page and necessary
  285. * margins.
  286. *
  287. * @param offsetHeight
  288. * @return The final y-coordinate
  289. *
  290. */
  291. private int getFinalTouchY(int offsetHeight) {
  292. int y = 0;
  293. int heightNeeded = 10 + offsetHeight;
  294. int roomAbove = currentElement != null ? currentElement
  295. .getAbsoluteTop()
  296. + currentElement.getOffsetHeight()
  297. : EVENT_XY_POSITION_OUTSIDE;
  298. int roomBelow = Window.getClientHeight() - roomAbove;
  299. if (roomBelow > heightNeeded) {
  300. y = roomAbove;
  301. } else {
  302. y = roomAbove
  303. - offsetHeight
  304. - (currentElement != null ? currentElement
  305. .getOffsetHeight() : 0);
  306. }
  307. if (y + offsetHeight - Window.getScrollTop() > Window
  308. .getClientHeight()) {
  309. y = roomAbove - 5 - offsetHeight
  310. + Window.getScrollTop();
  311. if (y - Window.getScrollTop() < 0) {
  312. // tooltip does not fit on top of the mouse either,
  313. // put it at the top of the screen
  314. y = Window.getScrollTop();
  315. }
  316. }
  317. if (roomAbove != EVENT_XY_POSITION_OUTSIDE) {
  318. // Do not allow y to be zero, for otherwise the tooltip
  319. // does not close when the mouse is moved (see
  320. // isTooltipOpen()). #15129
  321. int minY = Window.getScrollTop();
  322. y = Math.max(y, minY);
  323. }
  324. return y;
  325. }
  326. });
  327. } else {
  328. hide();
  329. }
  330. }
  331. /**
  332. * For assistive tooltips to work correctly we must have the tooltip visible
  333. * and attached to the DOM well in advance. For this reason both isShowing
  334. * and isVisible return false positives. We can't override either of them as
  335. * external code may depend on this behavior.
  336. *
  337. * @return boolean
  338. */
  339. public boolean isTooltipOpen() {
  340. return super.isShowing() && super.isVisible() && getPopupLeft() > 0
  341. && getPopupTop() > 0;
  342. }
  343. private void closeNow() {
  344. hide();
  345. setWidth("");
  346. closing = false;
  347. justClosedTimer.schedule(getQuickOpenTimeout());
  348. justClosed = true;
  349. }
  350. private Timer showTimer = new Timer() {
  351. @Override
  352. public void run() {
  353. opening = false;
  354. showTooltip();
  355. }
  356. };
  357. private Timer closeTimer = new Timer() {
  358. @Override
  359. public void run() {
  360. closeNow();
  361. }
  362. };
  363. private Timer justClosedTimer = new Timer() {
  364. @Override
  365. public void run() {
  366. justClosed = false;
  367. }
  368. };
  369. public void hideTooltip() {
  370. if (opening) {
  371. showTimer.cancel();
  372. opening = false;
  373. }
  374. if (!isAttached()) {
  375. return;
  376. }
  377. if (closing) {
  378. // already about to close
  379. return;
  380. }
  381. if (isTooltipOpen()) {
  382. closeTimer.schedule(getCloseTimeout());
  383. closing = true;
  384. }
  385. }
  386. @Override
  387. public void hide() {
  388. em.updateMessage("");
  389. description.setInnerHTML("");
  390. updatePosition(null, true);
  391. setPopupPosition(tooltipEventMouseX, tooltipEventMouseY);
  392. }
  393. private int EVENT_XY_POSITION_OUTSIDE = -5000;
  394. private int tooltipEventMouseX;
  395. private int tooltipEventMouseY;
  396. public void updatePosition(Event event, boolean isFocused) {
  397. tooltipEventMouseX = getEventX(event, isFocused);
  398. tooltipEventMouseY = getEventY(event, isFocused);
  399. }
  400. private int getEventX(Event event, boolean isFocused) {
  401. return isFocused ? EVENT_XY_POSITION_OUTSIDE : DOM
  402. .eventGetClientX(event);
  403. }
  404. private int getEventY(Event event, boolean isFocused) {
  405. return isFocused ? EVENT_XY_POSITION_OUTSIDE : DOM
  406. .eventGetClientY(event);
  407. }
  408. @Override
  409. public void onBrowserEvent(Event event) {
  410. final int type = DOM.eventGetType(event);
  411. // cancel closing event if tooltip is mouseovered; the user might want
  412. // to scroll of cut&paste
  413. if (type == Event.ONMOUSEOVER) {
  414. // Cancel closing so tooltip stays open and user can copy paste the
  415. // tooltip
  416. closeTimer.cancel();
  417. closing = false;
  418. }
  419. }
  420. /**
  421. * Replace current open tooltip with new content
  422. */
  423. public void replaceCurrentTooltip() {
  424. if (closing) {
  425. closeTimer.cancel();
  426. closeNow();
  427. justClosedTimer.cancel();
  428. justClosed = false;
  429. }
  430. showTooltip();
  431. opening = false;
  432. }
  433. private class TooltipEventHandler implements MouseMoveHandler,
  434. KeyDownHandler, FocusHandler, BlurHandler, MouseDownHandler {
  435. /**
  436. * Marker for handling of tooltip through focus
  437. */
  438. private boolean handledByFocus;
  439. /**
  440. * Locate the tooltip for given element
  441. *
  442. * @param element
  443. * Element used in search
  444. * @return TooltipInfo if connector and tooltip found, null if not
  445. */
  446. private TooltipInfo getTooltipFor(Element element) {
  447. ApplicationConnection ac = getApplicationConnection();
  448. ComponentConnector connector = Util.getConnectorForElement(ac,
  449. RootPanel.get(), element);
  450. // Try to find first connector with proper tooltip info
  451. TooltipInfo info = null;
  452. while (connector != null) {
  453. info = connector.getTooltipInfo(element);
  454. if (info != null && info.hasMessage()) {
  455. break;
  456. }
  457. if (!(connector.getParent() instanceof ComponentConnector)) {
  458. connector = null;
  459. info = null;
  460. break;
  461. }
  462. connector = (ComponentConnector) connector.getParent();
  463. }
  464. if (connector != null && info != null) {
  465. assert connector.hasTooltip() : "getTooltipInfo for "
  466. + Util.getConnectorString(connector)
  467. + " returned a tooltip even though hasTooltip claims there are no tooltips for the connector.";
  468. return info;
  469. }
  470. return null;
  471. }
  472. /**
  473. * Handle hide event
  474. *
  475. */
  476. private void handleHideEvent() {
  477. hideTooltip();
  478. }
  479. @Override
  480. public void onMouseMove(MouseMoveEvent mme) {
  481. handleShowHide(mme, false);
  482. }
  483. @Override
  484. public void onMouseDown(MouseDownEvent event) {
  485. handleHideEvent();
  486. }
  487. @Override
  488. public void onKeyDown(KeyDownEvent event) {
  489. handleHideEvent();
  490. }
  491. /**
  492. * Displays Tooltip when page is navigated with the keyboard.
  493. *
  494. * Tooltip is not visible. This makes it possible for assistive devices
  495. * to recognize the tooltip.
  496. */
  497. @Override
  498. public void onFocus(FocusEvent fe) {
  499. handleShowHide(fe, true);
  500. }
  501. /**
  502. * Hides Tooltip when the page is navigated with the keyboard.
  503. *
  504. * Removes the Tooltip from page to make sure assistive devices don't
  505. * recognize it by accident.
  506. */
  507. @Override
  508. public void onBlur(BlurEvent be) {
  509. handledByFocus = false;
  510. handleHideEvent();
  511. }
  512. private void handleShowHide(DomEvent domEvent, boolean isFocused) {
  513. Event event = Event.as(domEvent.getNativeEvent());
  514. Element element = Element.as(event.getEventTarget());
  515. // We can ignore move event if it's handled by move or over already
  516. if (currentElement == element && handledByFocus == true) {
  517. return;
  518. }
  519. // If the parent (sub)component already has a tooltip open and it
  520. // hasn't changed, we ignore the event.
  521. // TooltipInfo contains a reference to the parent component that is
  522. // checked in it's equals-method.
  523. if (currentElement != null && isTooltipOpen()) {
  524. TooltipInfo newTooltip = getTooltipFor(element);
  525. if (currentTooltipInfo != null
  526. && currentTooltipInfo.equals(newTooltip)) {
  527. return;
  528. }
  529. }
  530. TooltipInfo info = getTooltipFor(element);
  531. if (info == null) {
  532. handleHideEvent();
  533. } else {
  534. if (closing) {
  535. closeTimer.cancel();
  536. closing = false;
  537. }
  538. if (isTooltipOpen()) {
  539. closeNow();
  540. }
  541. setTooltipText(info);
  542. updatePosition(event, isFocused);
  543. // Schedule timer for showing the tooltip according to if it
  544. // was recently closed or not.
  545. if (BrowserInfo.get().isIOS()) {
  546. element.focus();
  547. }
  548. int timeout = justClosed ? getQuickOpenDelay() : getOpenDelay();
  549. if (timeout == 0) {
  550. showTooltip();
  551. } else {
  552. showTimer.schedule(timeout);
  553. opening = true;
  554. }
  555. }
  556. handledByFocus = isFocused;
  557. currentElement = element;
  558. }
  559. }
  560. private final TooltipEventHandler tooltipEventHandler = new TooltipEventHandler();
  561. /**
  562. * Connects DOM handlers to widget that are needed for tooltip presentation.
  563. *
  564. * @param widget
  565. * Widget which DOM handlers are connected
  566. */
  567. public void connectHandlersToWidget(Widget widget) {
  568. Profiler.enter("VTooltip.connectHandlersToWidget");
  569. widget.addDomHandler(tooltipEventHandler, MouseMoveEvent.getType());
  570. widget.addDomHandler(tooltipEventHandler, MouseDownEvent.getType());
  571. widget.addDomHandler(tooltipEventHandler, KeyDownEvent.getType());
  572. widget.addDomHandler(tooltipEventHandler, FocusEvent.getType());
  573. widget.addDomHandler(tooltipEventHandler, BlurEvent.getType());
  574. Profiler.leave("VTooltip.connectHandlersToWidget");
  575. }
  576. /**
  577. * Returns the unique id of the tooltip element.
  578. *
  579. * @return String containing the unique id of the tooltip, which always has
  580. * a value
  581. */
  582. public String getUniqueId() {
  583. return uniqueId;
  584. }
  585. @Override
  586. public void setPopupPositionAndShow(PositionCallback callback) {
  587. if (isAttached()) {
  588. callback.setPosition(getOffsetWidth(), getOffsetHeight());
  589. } else {
  590. super.setPopupPositionAndShow(callback);
  591. }
  592. }
  593. /**
  594. * Returns the time (in ms) the tooltip should be displayed after an event
  595. * that will cause it to be closed (e.g. mouse click outside the component,
  596. * key down).
  597. *
  598. * @return The close timeout (in ms)
  599. */
  600. public int getCloseTimeout() {
  601. return closeTimeout;
  602. }
  603. /**
  604. * Sets the time (in ms) the tooltip should be displayed after an event that
  605. * will cause it to be closed (e.g. mouse click outside the component, key
  606. * down).
  607. *
  608. * @param closeTimeout
  609. * The close timeout (in ms)
  610. */
  611. public void setCloseTimeout(int closeTimeout) {
  612. this.closeTimeout = closeTimeout;
  613. }
  614. /**
  615. * Returns the time (in ms) during which {@link #getQuickOpenDelay()} should
  616. * be used instead of {@link #getOpenDelay()}. The quick open delay is used
  617. * when the tooltip has very recently been shown, is currently hidden but
  618. * about to be shown again.
  619. *
  620. * @return The quick open timeout (in ms)
  621. */
  622. public int getQuickOpenTimeout() {
  623. return quickOpenTimeout;
  624. }
  625. /**
  626. * Sets the time (in ms) that determines when {@link #getQuickOpenDelay()}
  627. * should be used instead of {@link #getOpenDelay()}. The quick open delay
  628. * is used when the tooltip has very recently been shown, is currently
  629. * hidden but about to be shown again.
  630. *
  631. * @param quickOpenTimeout
  632. * The quick open timeout (in ms)
  633. */
  634. public void setQuickOpenTimeout(int quickOpenTimeout) {
  635. this.quickOpenTimeout = quickOpenTimeout;
  636. }
  637. /**
  638. * Returns the time (in ms) that should elapse before a tooltip will be
  639. * shown, in the situation when a tooltip has very recently been shown
  640. * (within {@link #getQuickOpenDelay()} ms).
  641. *
  642. * @return The quick open delay (in ms)
  643. */
  644. public int getQuickOpenDelay() {
  645. return quickOpenDelay;
  646. }
  647. /**
  648. * Sets the time (in ms) that should elapse before a tooltip will be shown,
  649. * in the situation when a tooltip has very recently been shown (within
  650. * {@link #getQuickOpenDelay()} ms).
  651. *
  652. * @param quickOpenDelay
  653. * The quick open delay (in ms)
  654. */
  655. public void setQuickOpenDelay(int quickOpenDelay) {
  656. this.quickOpenDelay = quickOpenDelay;
  657. }
  658. /**
  659. * Returns the time (in ms) that should elapse after an event triggering
  660. * tooltip showing has occurred (e.g. mouse over) before the tooltip is
  661. * shown. If a tooltip has recently been shown, then
  662. * {@link #getQuickOpenDelay()} is used instead of this.
  663. *
  664. * @return The open delay (in ms)
  665. */
  666. public int getOpenDelay() {
  667. return openDelay;
  668. }
  669. /**
  670. * Sets the time (in ms) that should elapse after an event triggering
  671. * tooltip showing has occurred (e.g. mouse over) before the tooltip is
  672. * shown. If a tooltip has recently been shown, then
  673. * {@link #getQuickOpenDelay()} is used instead of this.
  674. *
  675. * @param openDelay
  676. * The open delay (in ms)
  677. */
  678. public void setOpenDelay(int openDelay) {
  679. this.openDelay = openDelay;
  680. }
  681. /**
  682. * Sets the maximum width of the tooltip popup.
  683. *
  684. * @param maxWidth
  685. * The maximum width the tooltip popup (in pixels)
  686. */
  687. public void setMaxWidth(int maxWidth) {
  688. this.maxWidth = maxWidth;
  689. }
  690. /**
  691. * Returns the maximum width of the tooltip popup.
  692. *
  693. * @return The maximum width the tooltip popup (in pixels)
  694. */
  695. public int getMaxWidth() {
  696. return maxWidth;
  697. }
  698. }