Class Tooltip

All Implemented Interfaces:
IsEditor<LeafValueEditor<String>>, HasAllDragAndDropHandlers, HasAllGestureHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, MouseMoveHandler, MouseOutHandler, MouseOverHandler, MouseWheelHandler, TouchEndHandler, TouchMoveHandler, TouchStartHandler, HasAttachHandlers, EventHandler, HasHandlers, HasDirection, HasDirectionEstimator, HasSafeHtml, EventListener, HasAutoHorizontalAlignment, HasDirectionalHtml, HasDirectionalSafeHtml, HasDirectionalText, HasHorizontalAlignment, HasHTML, HasText, HasVisibility, HasWordWrap, IsWidget, SourcesClickEvents, SourcesMouseEvents, FullscreenChangeHandler, HasFullscreenChangeHandlers

Tooltip extension to GWT's user interface.

Add customizable tooltips to GWT applications. Tooltips work through a shared instance (like ContextMenu's). Each widget that sports tooltips (the listener widget) must be associated with a tooltip provider.

The tooltip is displayed when the pointer hovers over the listener widget and the tooltip provider returns a non-null string. For devices without pointers the tooltip display is triggered by a one-finger tap. Another tap re-positions or closes the tooltip. The delay for opening the tooltip as well as the timeout for showing it can be configured. The tooltip closes when the ContextMenu opens.

CSS Style Rules

.gwt-Tooltip
the tooltip element.
Author:
Christoph Hauert
  • Field Details

    • DEFAULT_OFFSET_X

      private static final int DEFAULT_OFFSET_X
      Default horizontal offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).
      See Also:
    • offsetX

      private int offsetX
      Horizontal offset of tooltip relative to coordinates of pointer or the location of the tap triggering the tooltip, respectively. Negative offsets shift to the left. In general, this should be a non-negative number such that the pointer location is not obscured by the tooltip.
      See Also:
    • DEFAULT_OFFSET_Y

      private static final int DEFAULT_OFFSET_Y
      Default vertical offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).
      See Also:
    • offsetY

      private int offsetY
      Vertical offset of tooltip relative to coordinates of pointer or the location of the tap triggering the tooltip, respectively. Negative offsets shift to the top. In general, this should be a non-negative number such that the pointer location is not obscured by the tooltip.
      See Also:
    • TOOLTIP_DEFAULT_DELAY_SHOW

      private static final int TOOLTIP_DEFAULT_DELAY_SHOW
      Default delay before showing the tooltip (in milliseconds) after the pointer started to hover over (part of) element that supplies tooltip.
      See Also:
    • delayShow

      private int delayShow
      Delay before showing the tooltip (in milliseconds) after the pointer started to hover over (part of) element that supplies tooltip. Does not apply to tooltips triggered by taps.
      See Also:
    • TOOLTIP_DEFAULT_DELAY_HIDE

      private static final int TOOLTIP_DEFAULT_DELAY_HIDE
      Default time until tooltip expires and closes (in milliseconds).
      See Also:
    • delayHide

      private int delayHide
      Time until tooltip expires and closes (in milliseconds).
      See Also:
    • TOUCH_SHIFT_X

      protected static final int TOUCH_SHIFT_X
      Horizontal offset for tooltip placement relative to tap that triggered it. Negative offsets shift to the left.
      See Also:
    • TOUCH_SHIFT_Y

      protected static final int TOUCH_SHIFT_Y
      Vertical offset for tooltip placement relative to tap that triggered it. Negative offsets shift to the top.
      See Also:
    • touchEvent

      protected boolean touchEvent
      true if touch events are processed.
    • x

      private int x
      Coordinates of current tooltip location (relative to listener widget. This allows to update the tooltip without user interaction. For example while hovering over an item that changes over time.
    • y

      private int y
      Coordinates of current tooltip location (relative to listener widget. This allows to update the tooltip without user interaction. For example while hovering over an item that changes over time.
    • style

      protected Style style
      Reference to style of tooltip. Most important to control positioning of tooltip.
    • fullscreenHandler

      HandlerRegistration fullscreenHandler
      Reference to fullscreen change handler. When entering fullscreen the tooltip needs to be moved from the RootPanel to the fullscreen element and vice versa.
    • participants

      protected HashMap<FocusPanel,Tooltip.Registration> participants
      Lookup table of listener widgets sporting tooltips and their corresponding providers of the tooltip contents.
    • current

      protected Tooltip.Registration current
      Reference to current provider of tooltips and null if no provider available.
    • tooltip

      protected static Tooltip tooltip
      Shared instance of tooltip.
    • delayShowTimer

      private Timer delayShowTimer
      Timer for handling the delay in showing tooltips.
    • delayHideTimer

      private Timer delayHideTimer
      Timer for handling the timeout after which the tooltip is closed.
  • Constructor Details

    • Tooltip

      protected Tooltip()
      Create new tooltip. Use shared instance to create tooltips, sharedTooltip().
  • Method Details

    • sharedTooltip

      public static Tooltip sharedTooltip()
      The tooltip is added to the RootPanel of the GWT application and shared among all elements that sport tooltips. Always use this shared instance to implement tooltips.
      Returns:
      shared instance of tooltip.
    • add

      public void add(FocusPanel listener, Tooltip.Provider provider)
      Register a new listener widget for tooltips and associate with the provider of the tooltip.
      Parameters:
      listener - widget sporting tooltips
      provider - provides tooltip
    • show

      public void show()
      Show tooltip. Set timer to show tooltip after delay delayShow. If already visible the location is updated.
    • _show

      private void _show()
      Helper method: show tooltip now and set timeout timer.
    • close

      public void close()
      Close tooltip now.
    • update

      public void update()
      Update tooltip if visible.
    • _update

      private void _update(FocusPanel origin)
      Helper method: remember current provider of tooltips for future use and update tooltip.
      Parameters:
      origin - the FocusPanel with tooltips.
    • updateTooltip

      private boolean updateTooltip()
      Helper method: update contents and visibility of tooltip.
      Returns:
      true if tooltip is visible.
    • setPosition

      public void setPosition(int x, int y)
      Set position (x, y) of tooltip relative to browser window.
      Parameters:
      x - horizontal position of tooltip
      y - vertical position of tooltip
    • setOffset

      public void setOffset(int ox, int oy)
      Sets the horizontal and vertical offset between the location where the tooltip was triggered and the position of the top left corner of the tooltip. Typically the offset should be non-negative in both directions to ensure that the tooltip does not obscure the location under the pointer.
      Parameters:
      ox - horizontal offset
      oy - vertical offset
      See Also:
    • setDelays

      public void setDelays(int show, int hide)
      Set delay before showing the tooltip as well as the timeout after which the tooltip is hidden again (both in milliseconds). If show==0 tooltips are shown immediately and if hide==0 they never time out.
      Parameters:
      show - the delay for showing the tooltip
      hide - the timeout to hide tooltips again
      See Also:
    • onMouseOver

      public void onMouseOver(MouseOverEvent event)

      Pointer entered a listener widget. Process (potential) tooltip.

      Specified by:
      onMouseOver in interface MouseOverHandler
    • onMouseOut

      public void onMouseOut(MouseOutEvent event)

      Pointer exited listener widget. Close tooltip.

      Specified by:
      onMouseOut in interface MouseOutHandler
    • onMouseMove

      public void onMouseMove(MouseMoveEvent event)

      Pointer moved on listener widget. Update tooltip.

      Specified by:
      onMouseMove in interface MouseMoveHandler
    • onMouseWheel

      public void onMouseWheel(MouseWheelEvent event)

      Mouse wheel event on listener widget. Update tooltip.

      Specified by:
      onMouseWheel in interface MouseWheelHandler
    • processMouseEvent

      protected void processMouseEvent(MouseEvent<?> event)
      Update tooltip and save pointer locations.
      Parameters:
      event - the mouse even that fired
    • onTouchStart

      public void onTouchStart(TouchStartEvent event)

      Show tooltip with single, one-finger on tap listener widget.

      Specified by:
      onTouchStart in interface TouchStartHandler
    • onTouchMove

      public void onTouchMove(TouchMoveEvent event)

      Hide tooltip when moving finger across listener widget.

      Specified by:
      onTouchMove in interface TouchMoveHandler
    • onTouchEnd

      public void onTouchEnd(TouchEndEvent event)

      Hide tooltip when one or more touches ended.

      Specified by:
      onTouchEnd in interface TouchEndHandler
    • addFullscreenChangeHandler

      public HandlerRegistration addFullscreenChangeHandler(FullscreenChangeHandler handler)
      Description copied from interface: HasFullscreenChangeHandlers
      Adds a FullscreenChangeEvent handler.
      Specified by:
      addFullscreenChangeHandler in interface HasFullscreenChangeHandlers
      Parameters:
      handler - the fullscreenchange handler
      Returns:
      HandlerRegistration used to remove this handler
    • onFullscreenChange

      public void onFullscreenChange(FullscreenChangeEvent event)
      Called when a FullscreenChangeEvent is fired.

      Placement of shared tooltip element in the DOM needs to be adjusted when entering or exiting fullscreen mode.

      Specified by:
      onFullscreenChange in interface FullscreenChangeHandler
      Parameters:
      event - the FullscreenChangeEvent that was fired