Package totalcross.ui
Class ToolTip
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Label
-
- totalcross.ui.ToolTip
-
- All Implemented Interfaces:
MouseListener,PenListener,TextControl
public class ToolTip extends Label implements PenListener, MouseListener
Displays a tooltip when user holds the pen in the control. On Windows and Linux desktop, the tooltip is also shown when the mouse stays over a control.
The default popup delay is 1000ms and the amount of time it will be displayed is 2000 ms; a pen up also hides the tip.You can change some properties of the tooltip: borderColor, insideGap, distX, distY, millisDelay, millisDisplay. See their javadocs for details.
Example:
ToolTip.distX = 10; // 0 by default ToolTip.distY = 4; // 0 by default ToolTip.insideGap = 8; // 4 by default Button b; add(b = new Button("Hello Tooltip!"),CENTER,BOTTOM);The tooltip can have multiple lines, just split them using the char '\n' in your message.
ToolTip t = new ToolTip(b, "Hi, this is a button");
t.borderColor = 0x00FF00; // -1 (none) by default t.millisDelay = 500; // 1000 by default t.millisDisplay = 4000; // 2000 by default t.setBackColor(Color.getRGB(250,0,0)); // same as control's container by default
Example :ToolTip t = new ToolTip(control, "Hi!\nIt's Me");
A ControlEvent.PRESSED event will be dispatched to the attached control right before the text is shown. You can then set the tip to a new value using setText; setting to an empty string will disable the tooltip at that moment. Calling setControlRect also changes the rectangle around which the tooltip will be displayed. In Android UI, the ToolTip is displayed with a round border.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description intborderColorThe border color.static intdistXThe x distance between the tip and the control, 0 by default.static intdistYThe y distance between the tip and the control, 0 by default.static intinsideGapThe gap between the border and the text.intmillisDelayThe amount of time that the pen must be down until the tip pops up (by default, 1000ms)intmillisDisplayThe amount of time that the tip will be shown (by default, 2000ms)-
Fields inherited from class totalcross.ui.Label
align, autoSplit, backgroundType, firstGradientColor, HORIZONTAL_GRADIENT_BACKGROUND, lines, pageScroll, preferredWidthText, secondGradientColor, SOLID_BACKGROUND, text, useFillAsPreferred, vAlign, VERTICAL_GRADIENT_BACKGROUND
-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voiddontShowTipOnMouseEvents()Stop using mouse events to show the tooltip.voidhide()Hides the tooltip.voidmouseIn(MouseEvent e)A MOUSE_IN event was dispatched when the mouse was going into a control.voidmouseMove(MouseEvent e)A MOUSE_MOVE event was dispatched.voidmouseOut(MouseEvent e)A MOUSE_OUT event was dispatched when the mouse was going out of a control.voidmouseWheel(MouseEvent e)The event type for a mouse wheel moving down.voidonEvent(Event e)Called to process key, pen, control and other posted events.voidonPaint(Graphics g)Called by the system to draw the button.voidpenDown(PenEvent e)A PEN_DOWN event was dispatched.voidpenDrag(DragEvent e)A PEN_DRAG event was dispatched.voidpenDragEnd(DragEvent e)A PEN_DRAG_END event was dispatched.voidpenDragStart(DragEvent e)A PEN_DRAG_START event was dispatched.voidpenUp(PenEvent e)A PEN_UP event was dispatched.voidreposition()Reposition this control, calling again setRect with the original parameters.voidsetControlRect(Rect r)Change the control rect to the given one.voidshow()Shows the tooltip.static java.lang.Stringsplit(java.lang.String msg, FontMetrics fm)Deprecated.The split is done automatically-
Methods inherited from class totalcross.ui.Label
canScroll, clear, getLineCount, getLinesPerPage, getMaxTextWidth, getPreferredHeight, getPreferredWidth, getText, isMarqueeRunning, onBoundsChanged, onColorsChanged, onFontChanged, scroll, scrollTo, scrollToBegin, scrollToEnd, set3d, setHighlighted, setHighlightedColor, setInsets, setInvert, setMarqueeText, setText, split, stopMarquee
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
insideGap
public static int insideGap
The gap between the border and the text. Common to all tooltips.
-
distX
public static int distX
The x distance between the tip and the control, 0 by default. Common to all tooltips.
-
distY
public static int distY
The y distance between the tip and the control, 0 by default. Common to all tooltips.
-
millisDelay
public int millisDelay
The amount of time that the pen must be down until the tip pops up (by default, 1000ms)
-
millisDisplay
public int millisDisplay
The amount of time that the tip will be shown (by default, 2000ms)
-
borderColor
public int borderColor
The border color. By default, it is -1 and no border is shown
-
-
Constructor Detail
-
ToolTip
public ToolTip(Control control, java.lang.String message)
Constructor- Parameters:
control- the control which supports the tip. If null, you must callsetControlRectandshowby your own.message- the message which will be written in the tip. You can make multiLine, using \n character like in the Label control.
-
-
Method Detail
-
dontShowTipOnMouseEvents
public void dontShowTipOnMouseEvents()
Stop using mouse events to show the tooltip.- Since:
- TotalCross 1.27
-
split
@Deprecated public static java.lang.String split(java.lang.String msg, FontMetrics fm)Deprecated.The split is done automaticallyUse this handy method to split the text in order to correctly fit the window. Here's a sample:String msg = "a very long text that will be split to fit in the window"; new ToolTip(control, ToolTip.split(msg, fm));
Make sure that fm will be the font's FontMetrics (if you plan to change the font after calling the constructor).- Since:
- TotalCross 1.2
-
setControlRect
public void setControlRect(Rect r)
Change the control rect to the given one. By default, its used the absolute rectangle of the control passed in the constructor. The placement of the tooltip will be defined based on it, in a way that the control is not obscured.
-
onEvent
public void onEvent(Event e)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
show
public void show()
Shows the tooltip. If you want to show the tooltip programatically, you must do something like:toolTip.setText(msg); toolTip.setControlRect(lbCompany.getAbsoluteRect()); toolTip.show();
-
hide
public void hide()
Hides the tooltip.
-
mouseMove
public void mouseMove(MouseEvent e)
Description copied from interface:MouseListenerA MOUSE_MOVE event was dispatched.- Specified by:
mouseMovein interfaceMouseListener- See Also:
PenEvent
-
mouseIn
public void mouseIn(MouseEvent e)
Description copied from interface:MouseListenerA MOUSE_IN event was dispatched when the mouse was going into a control.- Specified by:
mouseInin interfaceMouseListener- See Also:
PenEvent
-
mouseOut
public void mouseOut(MouseEvent e)
Description copied from interface:MouseListenerA MOUSE_OUT event was dispatched when the mouse was going out of a control.- Specified by:
mouseOutin interfaceMouseListener- See Also:
PenEvent
-
penDown
public void penDown(PenEvent e)
Description copied from interface:PenListenerA PEN_DOWN event was dispatched.- Specified by:
penDownin interfacePenListener- See Also:
PenEvent
-
penUp
public void penUp(PenEvent e)
Description copied from interface:PenListenerA PEN_UP event was dispatched.- Specified by:
penUpin interfacePenListener- See Also:
PenEvent
-
onPaint
public void onPaint(Graphics g)
Description copied from class:LabelCalled by the system to draw the button.
-
penDrag
public void penDrag(DragEvent e)
Description copied from interface:PenListenerA PEN_DRAG event was dispatched.- Specified by:
penDragin interfacePenListener- See Also:
PenEvent
-
penDragEnd
public void penDragEnd(DragEvent e)
Description copied from interface:PenListenerA PEN_DRAG_END event was dispatched.- Specified by:
penDragEndin interfacePenListener- See Also:
PenEvent
-
penDragStart
public void penDragStart(DragEvent e)
Description copied from interface:PenListenerA PEN_DRAG_START event was dispatched.- Specified by:
penDragStartin interfacePenListener- See Also:
PenEvent
-
reposition
public void reposition()
Description copied from class:ControlReposition this control, calling again setRect with the original parameters.- Overrides:
repositionin classControl
-
mouseWheel
public void mouseWheel(MouseEvent e)
Description copied from interface:MouseListenerThe event type for a mouse wheel moving down. This is a hardware event.- Specified by:
mouseWheelin interfaceMouseListener
-
-