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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Provider interface for classes that are responsible for supplying the contents of the tooltip.protected class
Manage registrations of listener widgets, their tooltip providers and the corresponding event handlers.Nested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
Nested classes/interfaces inherited from interface HasDirection
HasDirection.Direction
Nested classes/interfaces inherited from interface HasHorizontalAlignment
HasHorizontalAlignment.AutoHorizontalAlignmentConstant, HasHorizontalAlignment.HorizontalAlignmentConstant
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Tooltip.Registration
Reference to current provider of tooltips andnull
if no provider available.private static final int
Default horizontal offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).private static final int
Default vertical offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).private int
Time until tooltip expires and closes (in milliseconds).private Timer
Timer for handling the timeout after which the tooltip is closed.private int
Delay before showing the tooltip (in milliseconds) after the pointer started to hover over (part of) element that supplies tooltip.private Timer
Timer for handling the delay in showing tooltips.(package private) HandlerRegistration
Reference to fullscreen change handler.private int
Horizontal offset of tooltip relative to coordinates of pointer or the location of the tap triggering the tooltip, respectively.private int
Vertical offset of tooltip relative to coordinates of pointer or the location of the tap triggering the tooltip, respectively.protected HashMap
<FocusPanel, Tooltip.Registration> Lookup table of listener widgets sporting tooltips and their corresponding providers of the tooltip contents.protected Style
Reference to style of tooltip.protected static Tooltip
Shared instance of tooltip.private static final int
Default time until tooltip expires and closes (in milliseconds).private static final int
Default delay before showing the tooltip (in milliseconds) after the pointer started to hover over (part of) element that supplies tooltip.protected static final int
Horizontal offset for tooltip placement relative to tap that triggered it.protected static final int
Vertical offset for tooltip placement relative to tap that triggered it.protected boolean
true
if touch events are processed.private int
Coordinates of current tooltip location (relative tolistener
widget.private int
Coordinates of current tooltip location (relative tolistener
widget.Fields inherited from class Label
DEFAULT_DIRECTION_ESTIMATOR
Fields inherited from class UIObject
DEBUG_ID_PREFIX
Fields inherited from interface HasAutoHorizontalAlignment
ALIGN_CONTENT_END, ALIGN_CONTENT_START
Fields inherited from interface HasHorizontalAlignment
ALIGN_CENTER, ALIGN_DEFAULT, ALIGN_JUSTIFY, ALIGN_LEFT, ALIGN_LOCALE_END, ALIGN_LOCALE_START, ALIGN_RIGHT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
_show()
Helper method: show tooltip now and set timeout timer.private void
_update
(FocusPanel origin) Helper method: remember current provider of tooltips for future use and update tooltip.void
add
(FocusPanel listener, Tooltip.Provider provider) Register a newlistener
widget for tooltips and associate with theprovider
of the tooltip.Adds aFullscreenChangeEvent
handler.void
close()
Close tooltip now.void
Called when aFullscreenChangeEvent
is fired.void
onMouseMove
(MouseMoveEvent event) void
onMouseOut
(MouseOutEvent event) void
onMouseOver
(MouseOverEvent event) void
onMouseWheel
(MouseWheelEvent event) void
onTouchEnd
(TouchEndEvent event) void
onTouchMove
(TouchMoveEvent event) void
onTouchStart
(TouchStartEvent event) protected void
processMouseEvent
(MouseEvent<?> event) Update tooltip and save pointer locations.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).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.void
setPosition
(int x, int y) Set position(x, y)
of tooltip relative to browser window.static Tooltip
The tooltip is added to theRootPanel
of the GWT application and shared among all elements that sport tooltips.void
show()
Show tooltip.void
update()
Update tooltip if visible.private boolean
Helper method: update contents and visibility of tooltip.Methods inherited from class Label
addClickHandler, addClickListener, addDoubleClickHandler, addDragEndHandler, addDragEnterHandler, addDragHandler, addDragLeaveHandler, addDragOverHandler, addDragStartHandler, addDropHandler, addGestureChangeHandler, addGestureEndHandler, addGestureStartHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addMouseWheelListener, addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler, asEditor, getDirection, getText, getTextDirection, removeClickListener, removeMouseListener, removeMouseWheelListener, setDirection, setText, setText
Methods inherited from class LabelBase
getAutoHorizontalAlignment, getDirectionEstimator, getHorizontalAlignment, getWordWrap, setAutoHorizontalAlignment, setDirectionEstimator, setDirectionEstimator, setHorizontalAlignment, setWordWrap, updateHorizontalAlignment
Methods inherited from class Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
Methods inherited from class UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface HasDirectionalText
getTextDirection, setText
Methods inherited from interface HasHandlers
fireEvent
-
Field Details
-
DEFAULT_OFFSET_X
private static final int DEFAULT_OFFSET_XDefault horizontal offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).- See Also:
-
offsetX
private int offsetXHorizontal 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_YDefault vertical offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).- See Also:
-
offsetY
private int offsetYVertical 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_SHOWDefault 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 delayShowDelay 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_HIDEDefault time until tooltip expires and closes (in milliseconds).- See Also:
-
delayHide
private int delayHideTime until tooltip expires and closes (in milliseconds).- See Also:
-
TOUCH_SHIFT_X
protected static final int TOUCH_SHIFT_XHorizontal 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_YVertical offset for tooltip placement relative to tap that triggered it. Negative offsets shift to the top.- See Also:
-
touchEvent
protected boolean touchEventtrue
if touch events are processed. -
x
private int xCoordinates of current tooltip location (relative tolistener
widget. This allows to update the tooltip without user interaction. For example while hovering over an item that changes over time. -
y
private int yCoordinates of current tooltip location (relative tolistener
widget. This allows to update the tooltip without user interaction. For example while hovering over an item that changes over time. -
style
Reference to style of tooltip. Most important to control positioning of tooltip. -
fullscreenHandler
HandlerRegistration fullscreenHandlerReference to fullscreen change handler. When entering fullscreen the tooltip needs to be moved from theRootPanel
to the fullscreen element and vice versa. -
participants
Lookup table of listener widgets sporting tooltips and their corresponding providers of the tooltip contents. -
current
Reference to current provider of tooltips andnull
if no provider available. -
tooltip
Shared instance of tooltip. -
delayShowTimer
Timer for handling the delay in showing tooltips. -
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
-
add
Register a newlistener
widget for tooltips and associate with theprovider
of the tooltip.- Parameters:
listener
- widget sporting tooltipsprovider
- provides tooltip
-
show
public void show()Show tooltip. Set timer to show tooltip after delaydelayShow
. 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
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 tooltipy
- 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 offsetoy
- 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). Ifshow==0
tooltips are shown immediately and ifhide==0
they never time out.- Parameters:
show
- the delay for showing the tooltiphide
- the timeout to hide tooltips again- See Also:
-
onMouseOver
Pointer entered a listener widget. Process (potential) tooltip.
- Specified by:
onMouseOver
in interfaceMouseOverHandler
-
onMouseOut
Pointer exited listener widget. Close tooltip.
- Specified by:
onMouseOut
in interfaceMouseOutHandler
-
onMouseMove
Pointer moved on listener widget. Update tooltip.
- Specified by:
onMouseMove
in interfaceMouseMoveHandler
-
onMouseWheel
Mouse wheel event on listener widget. Update tooltip.
- Specified by:
onMouseWheel
in interfaceMouseWheelHandler
-
processMouseEvent
Update tooltip and save pointer locations.- Parameters:
event
- the mouse even that fired
-
onTouchStart
Show tooltip with single, one-finger on tap listener widget.
- Specified by:
onTouchStart
in interfaceTouchStartHandler
-
onTouchMove
Hide tooltip when moving finger across listener widget.
- Specified by:
onTouchMove
in interfaceTouchMoveHandler
-
onTouchEnd
Hide tooltip when one or more touches ended.
- Specified by:
onTouchEnd
in interfaceTouchEndHandler
-
addFullscreenChangeHandler
Description copied from interface:HasFullscreenChangeHandlers
Adds aFullscreenChangeEvent
handler.- Specified by:
addFullscreenChangeHandler
in interfaceHasFullscreenChangeHandlers
- Parameters:
handler
- the fullscreenchange handler- Returns:
HandlerRegistration
used to remove this handler
-
onFullscreenChange
Called when aFullscreenChangeEvent
is fired.Placement of shared tooltip element in the DOM needs to be adjusted when entering or exiting fullscreen mode.
- Specified by:
onFullscreenChange
in interfaceFullscreenChangeHandler
- Parameters:
event
- theFullscreenChangeEvent
that was fired