public class HelpTooltip
extends java.lang.Object
UI design requires to have tooltips that contain detailed information about UI actions and controls. Embedded context help tooltip functionality is incorporated this class.
A simple example of the tooltip usage is the following:
new HelpTooltip().
setTitle("Title").
setShortcut("Shortcut").
setDescription("Description").
installOn(component);
If you're creating a tooltip with a shortcut then title is mandatory otherwise title, description, link are optional.
You can optionally set the tooltip relative location using setLocation(Alignment)
.
The Alignment
enum defines fixed relative locations according to the design document (see the link below).
More types of relative location will be added as needed but there won't be a way to choose the location on pixel basis.
No HTML tagging is allowed in title or shortcut, they are supposed to be simple text strings.
Description is can be html formatted. You can use all possible html tagging in description just without enclosing <html> and </html> tags themselves. In description it's allowed to have <p/> or <p> tags between paragraphs. Paragraphs will be rendered with the standard (10px) offset from the title, from one another and from the link. To force the line break in a paragraph use <br/>. Standard font coloring and styling is also available.
Single line tooltips autoclose in 10 seconds, multiline in 30 seconds. You can optionally disable autoclosing by
setting setNeverHideOnTimeout(boolean)
to true
. By default tooltips don't close after a timeout on help buttons
(those having a round icon with question mark). Before setting this option to true you should contact designers first.
System wide tooltip timeouts are set through the registry:
Some actions may open a popup menu. Current design is that the action's popup menu should take over the help tooltip.
This is partly implemented in AbstractPopup
class to track such cases. But this doesn't always work.
If help tooltip shows up over the component's popup menu you should make sure you set the master popup for the help tooltip.
This will prevent help tooltip from showing when the popup menu is opened. The best way to do it is to take source component
from an InputEvent
and pass the source component along with the popup menu reference to
setMasterPopup(Component, JBPopup)
static method.
If you're handling DumbAware.actionPerformed(AnActionEvent e)
, it has InputEvent
in AnActionEvent
which you can use to get the source.
ContextHelpLabel is a convenient JLabel
which contains a help icon and has a HelpTooltip installed on it.
You can create it using one of its static methods and pass title/description/link. This label can also be used in forms.
The UI designer will offer to create private void createUIComponents()
method where you can create the label with a static method.
Modifier and Type | Class and Description |
---|---|
static class |
HelpTooltip.Alignment
Location of the HelpTooltip relatively to the owner component.
|
Modifier and Type | Field and Description |
---|---|
protected java.awt.event.MouseAdapter |
myMouseListener |
Constructor and Description |
---|
HelpTooltip() |
Modifier and Type | Method and Description |
---|---|
protected void |
createMouseListeners() |
protected javax.swing.JPanel |
createTipPanel() |
static void |
dispose(java.awt.Component owner)
Hides and disposes the tooltip possibly installed on the mentioned component.
|
protected void |
getDismissDelay() |
static java.lang.String |
getShortcutAsHtml(java.lang.String shortcut) |
static void |
hide(java.awt.Component owner)
Hides the tooltip possibly installed on the mentioned component without disposing.
|
protected void |
hidePopup(boolean force) |
protected void |
initPopupBuilder(HelpTooltip instance) |
void |
installOn(javax.swing.JComponent component)
Installs the tooltip after the configuration has been completed on the specified owner component.
|
HelpTooltip |
setDescription(java.lang.String description)
Sets description text.
|
HelpTooltip |
setLink(java.lang.String linkText,
java.lang.Runnable linkAction)
Enables link in the tooltip below description and sets action for it.
|
HelpTooltip |
setLocation(HelpTooltip.Alignment alignment)
Sets location of the tooltip relatively to the owner component.
|
static void |
setMasterPopup(java.awt.Component owner,
JBPopup master)
Sets master popup for the current
HelpTooltip . |
static void |
setMasterPopupOpenCondition(java.awt.Component owner,
java.util.function.BooleanSupplier condition)
Sets master popup open condition supplier for the current
HelpTooltip . |
HelpTooltip |
setNeverHideOnTimeout(boolean neverHide)
Toggles whether to hide tooltip automatically on timeout.
|
HelpTooltip |
setShortcut(java.lang.String shortcut)
Sets text for the shortcut placeholder.
|
HelpTooltip |
setTitle(java.lang.String title)
Sets tooltip title.
|
public HelpTooltip setTitle(java.lang.String title)
title
- text for title.this
public HelpTooltip setShortcut(java.lang.String shortcut)
shortcut
- text for shortcut.this
public HelpTooltip setDescription(java.lang.String description)
description
- text for description.this
public HelpTooltip setLink(java.lang.String linkText, java.lang.Runnable linkAction)
linkText
- text to show in the link.linkAction
- action to execute when link is clicked.this
public HelpTooltip setNeverHideOnTimeout(boolean neverHide)
neverHide
- true
don't hide, false
otherwise.this
public HelpTooltip setLocation(HelpTooltip.Alignment alignment)
alignment
- is relative locationthis
public void installOn(javax.swing.JComponent component)
component
- is the owner component for the tooltip.protected final void getDismissDelay()
protected final void createMouseListeners()
protected void initPopupBuilder(HelpTooltip instance)
protected final javax.swing.JPanel createTipPanel()
public static void dispose(java.awt.Component owner)
HelpTooltip
specific listeners installed on the component.
If there is no tooltip installed on the component nothing happens.owner
- a possible HelpTooltip
owner.public static void hide(java.awt.Component owner)
owner
- a possible HelpTooltip
owner.public static void setMasterPopup(java.awt.Component owner, JBPopup master)
HelpTooltip
. Master popup takes over the help tooltip,
so when the master popup is about to be shown help tooltip hides.owner
- possible ownermaster
- master popuppublic static void setMasterPopupOpenCondition(java.awt.Component owner, java.util.function.BooleanSupplier condition)
HelpTooltip
.
This method is more general than setMasterPopup(Component, JBPopup)
so that
it's possible to create master popup condition for any types of popups such as JPopupMenu
owner
- possible ownercondition
- a BooleanSupplier
for open conditionprotected void hidePopup(boolean force)
public static java.lang.String getShortcutAsHtml(java.lang.String shortcut)