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.

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