javax.swing
Class ToolTipManager

java.lang.Object
  |
  +--java.awt.event.MouseAdapter
        |
        +--javax.swing.ToolTipManager
All Implemented Interfaces:
EventListener, MouseListener, MouseMotionListener

public class ToolTipManager
extends MouseAdapter
implements MouseMotionListener

Safe: Manages all the ToolTips in the system.

ToolTipManager contains numerous properties for configuring how long it will take for the tooltips to become visible, and how long till they hide. Consider a component that has a different tooltip based on where the mouse is, such as JTree. When the mouse moves into the JTree and over a region that has a valid tooltip, the tooltip will become visibile after initialDelay milliseconds. After dismissDelay milliseconds the tooltip will be hidden. If the mouse is over a region that has a valid tooltip, and the tooltip is currently visible, when the mouse moves to a region that doesn't have a valid tooltip the tooltip will be hidden. If the mouse then moves back into a region that has a valid tooltip within reshowDelay milliseconds, the tooltip will immediately be shown, otherwise the tooltip will be shown again after initialDelay milliseconds.

Version:
1.63 04/23/02
Author:
Dave Moore, Rich Schiavi
See Also:
JComponent.createToolTip()

Field Summary
(package private)  boolean enabled
           
(package private)  Timer enterTimer
           
(package private)  Timer exitTimer
           
private  FocusListener focusChangeListener
           
protected  boolean heavyWeightPopupEnabled
           
private  KeyStroke hideTip
           
private  Action hideTipAction
           
(package private)  JComponent insideComponent
           
(package private)  Timer insideTimer
           
protected  boolean lightWeightPopupEnabled
           
(package private)  MouseEvent mouseEvent
           
private  MouseMotionListener moveBeforeEnterListener
           
private  Rectangle popupFrameRect
           
private  Rectangle popupRect
           
private  KeyStroke postTip
           
private  Action postTipAction
           
(package private)  Point preferredLocation
           
(package private) static ToolTipManager sharedInstance
           
(package private)  boolean showImmediately
           
(package private)  JToolTip tip
           
private  boolean tipShowing
           
(package private)  Popup tipWindow
           
(package private)  String toolTipText
           
private  Window window
          The Window tip is being displayed in.
 
Constructor Summary
(package private) ToolTipManager()
           
 
Method Summary
private  void checkForTipChange(MouseEvent event)
          Checks to see if the tooltip needs to be changed in response to the MouseMoved event event.
private  FocusListener createFocusChangeListener()
           
(package private) static Frame frameForComponent(Component component)
           
 int getDismissDelay()
          Enabled: Returns the dismissal delay value.
private  int getHeightAdjust(Rectangle a, Rectangle b)
           
 int getInitialDelay()
          Enabled: Returns the initial delay value.
private  int getPopupFitHeight(Rectangle popupRectInScreen, Component invoker)
           
private  int getPopupFitWidth(Rectangle popupRectInScreen, Component invoker)
           
 int getReshowDelay()
          Enabled: Returns the reshow delay property.
private  int getWidthAdjust(Rectangle a, Rectangle b)
           
(package private)  void hideTipWindow()
           
private  void initiateToolTip(MouseEvent event)
           
 boolean isEnabled()
          Enabled: Returns true if this object is enabled.
 boolean isLightWeightPopupEnabled()
          Suppressed: Returns true if lightweight (all-Java) Tooltips are in use, or false if heavyweight (native peer) Tooltips are being used.
 void mouseDragged(MouseEvent event)
          Suppressed: Called when the mouse is pressed and dragged.
 void mouseEntered(MouseEvent event)
          Suppressed: Called when the mouse enters the region of a component.
 void mouseExited(MouseEvent event)
          Suppressed: Called when the mouse exits the region of a component.
 void mouseMoved(MouseEvent event)
          Suppressed: Called when the mouse is moved.
 void mousePressed(MouseEvent event)
          Suppressed: Called when the mouse is pressed.
 void registerComponent(JComponent component)
          Suppressed: Registers a component for tooltip management.
 void setDismissDelay(int milliseconds)
          Enabled: Specifies the dismissal delay value.
 void setEnabled(boolean flag)
          Enabled: Enables or disables the tooltip.
 void setInitialDelay(int milliseconds)
          Enabled: Specifies the initial delay value.
 void setLightWeightPopupEnabled(boolean aFlag)
          Suppressed: When displaying the JToolTip, the ToolTipManager chooses to use a lightweight JPanel if it fits.
 void setReshowDelay(int milliseconds)
          Enabled: Used to specify the amount of time before the user has to wait initialDelay milliseconds before a tooltip will be shown.
static ToolTipManager sharedInstance()
          Suppressed: Returns a shared ToolTipManager instance.
private  boolean shouldRegisterBindings(JComponent component)
          Returns whether or not bindings should be registered on the given JComponent.
(package private)  void showTipWindow()
           
 void unregisterComponent(JComponent component)
          Suppressed: Removes a component from tooltip control.
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseReleased
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enterTimer

Timer enterTimer

exitTimer

Timer exitTimer

insideTimer

Timer insideTimer

toolTipText

String toolTipText

preferredLocation

Point preferredLocation

insideComponent

JComponent insideComponent

mouseEvent

MouseEvent mouseEvent

showImmediately

boolean showImmediately

sharedInstance

static final ToolTipManager sharedInstance

tipWindow

transient Popup tipWindow

window

private Window window
The Window tip is being displayed in. This will be non-null if the Window tip is in differs from that of insideComponent's Window.


tip

JToolTip tip

popupRect

private Rectangle popupRect

popupFrameRect

private Rectangle popupFrameRect

enabled

boolean enabled

tipShowing

private boolean tipShowing

postTip

private KeyStroke postTip

hideTip

private KeyStroke hideTip

postTipAction

private Action postTipAction

hideTipAction

private Action hideTipAction

focusChangeListener

private FocusListener focusChangeListener

moveBeforeEnterListener

private MouseMotionListener moveBeforeEnterListener

lightWeightPopupEnabled

protected boolean lightWeightPopupEnabled

heavyWeightPopupEnabled

protected boolean heavyWeightPopupEnabled
Constructor Detail

ToolTipManager

ToolTipManager()
Method Detail

setEnabled

public void setEnabled(boolean flag)
Enabled: Enables or disables the tooltip.

Parameters:
flag - true to enable the tip, false otherwise

isEnabled

public boolean isEnabled()
Enabled: Returns true if this object is enabled.

Returns:
true if this object is enabled, false otherwise

setLightWeightPopupEnabled

public void setLightWeightPopupEnabled(boolean aFlag)
Suppressed: When displaying the JToolTip, the ToolTipManager chooses to use a lightweight JPanel if it fits. This method allows you to disable this feature. You have to do disable it if your application mixes light weight and heavy weights components.

Parameters:
aFlag - true if a lightweight panel is desired, false otherwise

isLightWeightPopupEnabled

public boolean isLightWeightPopupEnabled()
Suppressed: Returns true if lightweight (all-Java) Tooltips are in use, or false if heavyweight (native peer) Tooltips are being used.

Returns:
true if lightweight ToolTips are in use

setInitialDelay

public void setInitialDelay(int milliseconds)
Enabled: Specifies the initial delay value.

Parameters:
milliseconds - the number of milliseconds to delay (after the cursor has paused) before displaying the tooltip
See Also:
getInitialDelay()

getInitialDelay

public int getInitialDelay()
Enabled: Returns the initial delay value.

Returns:
an integer representing the initial delay value, in milliseconds
See Also:
setInitialDelay(int)

setDismissDelay

public void setDismissDelay(int milliseconds)
Enabled: Specifies the dismissal delay value.

Parameters:
milliseconds - the number of milliseconds to delay before taking away the tooltip
See Also:
getDismissDelay()

getDismissDelay

public int getDismissDelay()
Enabled: Returns the dismissal delay value.

Returns:
an integer representing the dismissal delay value, in milliseconds
See Also:
setDismissDelay(int)

setReshowDelay

public void setReshowDelay(int milliseconds)
Enabled: Used to specify the amount of time before the user has to wait initialDelay milliseconds before a tooltip will be shown. That is, if the tooltip is hidden, and the user moves into a region of the same Component that has a valid tooltip within milliseconds milliseconds the tooltip will immediately be shown. Otherwise, if the user moves into a region with a valid tooltip after milliseconds milliseconds, the user will have to wait an additional initialDelay milliseconds before the tooltip is shown again.

Parameters:
milliseconds - time in milliseconds
See Also:
getReshowDelay()

getReshowDelay

public int getReshowDelay()
Enabled: Returns the reshow delay property.

Returns:
reshown delay property
See Also:
setReshowDelay(int)

showTipWindow

void showTipWindow()

hideTipWindow

void hideTipWindow()

sharedInstance

public static ToolTipManager sharedInstance()
Suppressed: Returns a shared ToolTipManager instance.

Returns:
a shared ToolTipManager object

registerComponent

public void registerComponent(JComponent component)
Suppressed: Registers a component for tooltip management.

This will register key bindings to show and hide the tooltip text only if component has focus bindings. This is done so that components that are not normally focus traversable, such as JLabel, are not made focus traversable as a result of invoking this method.

Parameters:
component - a JComponent object to add
See Also:
Component.isFocusTraversable()

unregisterComponent

public void unregisterComponent(JComponent component)
Suppressed: Removes a component from tooltip control.

Parameters:
component - a JComponent object to remove

shouldRegisterBindings

private boolean shouldRegisterBindings(JComponent component)
Returns whether or not bindings should be registered on the given JComponent. This is implemented to return true if the tool tip manager has a binding in any one of the InputMaps registered under the condition WHEN_FOCUSED.

This does not use isFocusTraversable as some components may override isFocusTraversable and base the return value on something other than bindings. For example, JButton bases its return value on its enabled state.

Parameters:
component - the JComponent in question

mouseEntered

public void mouseEntered(MouseEvent event)
Suppressed: Called when the mouse enters the region of a component. This determines whether the tool tip should be shown.

Specified by:
mouseEntered in interface MouseListener
Overrides:
mouseEntered in class MouseAdapter
Parameters:
event - the event in question

initiateToolTip

private void initiateToolTip(MouseEvent event)

mouseExited

public void mouseExited(MouseEvent event)
Suppressed: Called when the mouse exits the region of a component. Any tool tip showing should be hidden.

Specified by:
mouseExited in interface MouseListener
Overrides:
mouseExited in class MouseAdapter
Parameters:
event - the event in question

mousePressed

public void mousePressed(MouseEvent event)
Suppressed: Called when the mouse is pressed. Any tool tip showing should be hidden.

Specified by:
mousePressed in interface MouseListener
Overrides:
mousePressed in class MouseAdapter
Parameters:
event - the event in question

mouseDragged

public void mouseDragged(MouseEvent event)
Suppressed: Called when the mouse is pressed and dragged. Does nothing.

Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
event - the event in question

mouseMoved

public void mouseMoved(MouseEvent event)
Suppressed: Called when the mouse is moved. Determines whether the tool tip should be displayed.

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
event - the event in question

checkForTipChange

private void checkForTipChange(MouseEvent event)
Checks to see if the tooltip needs to be changed in response to the MouseMoved event event.


frameForComponent

static Frame frameForComponent(Component component)

createFocusChangeListener

private FocusListener createFocusChangeListener()

getPopupFitWidth

private int getPopupFitWidth(Rectangle popupRectInScreen,
                             Component invoker)

getPopupFitHeight

private int getPopupFitHeight(Rectangle popupRectInScreen,
                              Component invoker)

getHeightAdjust

private int getHeightAdjust(Rectangle a,
                            Rectangle b)

getWidthAdjust

private int getWidthAdjust(Rectangle a,
                           Rectangle b)


comments?