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 interfaceProvider interface for classes that are responsible for supplying the contents of the tooltip.protected classManage registrations of listener widgets, their tooltip providers and the corresponding event handlers.Nested classes/interfaces inherited from class UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface HasDirection
HasDirection.DirectionNested classes/interfaces inherited from interface HasHorizontalAlignment
HasHorizontalAlignment.AutoHorizontalAlignmentConstant, HasHorizontalAlignment.HorizontalAlignmentConstant -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Tooltip.RegistrationReference to current provider of tooltips andnullif no provider available.private static final intDefault horizontal offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).private static final intDefault vertical offset of tooltip relative to the coordinates of the pointer (or the tap that triggered the tooltip).private intTime until tooltip expires and closes (in milliseconds).private TimerTimer for handling the timeout after which the tooltip is closed.private intDelay before showing the tooltip (in milliseconds) after the pointer started to hover over (part of) element that supplies tooltip.private TimerTimer for handling the delay in showing tooltips.(package private) HandlerRegistrationReference to fullscreen change handler.private intHorizontal offset of tooltip relative to coordinates of pointer or the location of the tap triggering the tooltip, respectively.private intVertical 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 StyleReference to style of tooltip.protected static TooltipShared instance of tooltip.private static final intDefault time until tooltip expires and closes (in milliseconds).private static final intDefault delay before showing the tooltip (in milliseconds) after the pointer started to hover over (part of) element that supplies tooltip.protected static final intHorizontal offset for tooltip placement relative to tap that triggered it.protected static final intVertical offset for tooltip placement relative to tap that triggered it.protected booleantrueif touch events are processed.private intCoordinates of current tooltip location (relative tolistenerwidget.private intCoordinates of current tooltip location (relative tolistenerwidget.Fields inherited from class Label
DEFAULT_DIRECTION_ESTIMATORFields inherited from class UIObject
DEBUG_ID_PREFIXFields inherited from interface HasAutoHorizontalAlignment
ALIGN_CONTENT_END, ALIGN_CONTENT_STARTFields 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.voidadd(FocusPanel listener, Tooltip.Provider provider) Register a newlistenerwidget for tooltips and associate with theproviderof the tooltip.Adds aFullscreenChangeEventhandler.voidclose()Close tooltip now.voidCalled when aFullscreenChangeEventis fired.voidonMouseMove(MouseMoveEvent event) voidonMouseOut(MouseOutEvent event) voidonMouseOver(MouseOverEvent event) voidonMouseWheel(MouseWheelEvent event) voidonTouchEnd(TouchEndEvent event) voidonTouchMove(TouchMoveEvent event) voidonTouchStart(TouchStartEvent event) protected voidprocessMouseEvent(MouseEvent<?> event) Update tooltip and save pointer locations.voidsetDelays(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).voidsetOffset(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.voidsetPosition(int x, int y) Set position(x, y)of tooltip relative to browser window.static TooltipThe tooltip is added to theRootPanelof the GWT application and shared among all elements that sport tooltips.voidshow()Show tooltip.voidupdate()Update tooltip if visible.private booleanHelper 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, setTextMethods inherited from class LabelBase
getAutoHorizontalAlignment, getDirectionEstimator, getHorizontalAlignment, getWordWrap, setAutoHorizontalAlignment, setDirectionEstimator, setDirectionEstimator, setHorizontalAlignment, setWordWrap, updateHorizontalAlignmentMethods 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, unsinkEventsMethods 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, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface HasDirectionalText
getTextDirection, setTextMethods 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 touchEventtrueif touch events are processed. -
x
private int xCoordinates of current tooltip location (relative tolistenerwidget. 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 tolistenerwidget. 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 theRootPanelto 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 andnullif 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 newlistenerwidget for tooltips and associate with theproviderof 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:
trueif 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==0tooltips are shown immediately and ifhide==0they 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:
onMouseOverin interfaceMouseOverHandler
-
onMouseOut
Pointer exited listener widget. Close tooltip.
- Specified by:
onMouseOutin interfaceMouseOutHandler
-
onMouseMove
Pointer moved on listener widget. Update tooltip.
- Specified by:
onMouseMovein interfaceMouseMoveHandler
-
onMouseWheel
Mouse wheel event on listener widget. Update tooltip.
- Specified by:
onMouseWheelin 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:
onTouchStartin interfaceTouchStartHandler
-
onTouchMove
Hide tooltip when moving finger across listener widget.
- Specified by:
onTouchMovein interfaceTouchMoveHandler
-
onTouchEnd
Hide tooltip when one or more touches ended.
- Specified by:
onTouchEndin interfaceTouchEndHandler
-
addFullscreenChangeHandler
Description copied from interface:HasFullscreenChangeHandlersAdds aFullscreenChangeEventhandler.- Specified by:
addFullscreenChangeHandlerin interfaceHasFullscreenChangeHandlers- Parameters:
handler- the fullscreenchange handler- Returns:
HandlerRegistrationused to remove this handler
-
onFullscreenChange
Called when aFullscreenChangeEventis fired.Placement of shared tooltip element in the DOM needs to be adjusted when entering or exiting fullscreen mode.
- Specified by:
onFullscreenChangein interfaceFullscreenChangeHandler- Parameters:
event- theFullscreenChangeEventthat was fired