com.miginfocom.util.states
Class ToolTipProvider

java.lang.Object
  extended by com.miginfocom.util.states.ToolTipProvider

public abstract class ToolTipProvider
extends java.lang.Object

An abstract base class to extend if you want to provide dynamic tooltips. For instance DefaultDateArea uses this if one is registered.

Default implementations has been provided for methods with values from ToolTipManager.

Only one abstract method that need to be implemented to make this class work. Here's an example on how that method could look like to show the summary of a mouse overed activity in a very way that is exactly like a normal tooltip.

 public int configureToolTip(JToolTip toolTip, MouseEvent e, Object source)
 {
   if (e.getID() == MouseEvent.MOUSE_MOVED && source instanceof ActivityView) {
     toolTip.setForeground(Color.DARK_GRAY);
     toolTip.setTipText(((ActivityView) source).getModel().getSummary());
     return ToolTipProvider.SHOW_TOOLTIP;
   } else {
     return ToolTipProvider.HIDE_TOOLTIP;
   }
 }
 


Field Summary
static int HIDE_TOOLTIP
          The tooltip will be hidden if showing.
static int SHOW_TOOLTIP
          The tooltip will be shown if not already shown in which case nothing is done.
 
Constructor Summary
ToolTipProvider()
           
 
Method Summary
abstract  int configureToolTip(javax.swing.JToolTip toolTip, java.awt.event.MouseEvent e, java.lang.Object source)
          Configure the tooltip.
 int getDismissDelay()
          Returns the number of milliseconds that the tooltip will be visible.
 int getInitialDelay()
          Returns the number of milliseconds that the mouse has to be still for the tooltop to show.
 int getPositionAdjustX()
          Returns the x-position relative to the mouse hot spot to show the upper left corner of the tooltip.
 int getPositionAdjustY()
          Returns the y-position relative to the mouse hot spot to show the upper left corner of the tooltip.
 int getReshowDelay()
          Returns the number of milliseconds that should pass to reset to the initial delay again.
 java.awt.Insets getScreenInsets()
          Deprecated. Replaced with getScreenInsets(java.awt.GraphicsConfiguration).
 java.awt.Insets getScreenInsets(java.awt.GraphicsConfiguration gc)
          Returns the insets around the indicated screen to show the tooltip inside.
 java.awt.Insets getWindowInsets(java.awt.Window window)
          Returns the insets around the window to show the tooltip inside.
 boolean isFollowMouse()
          Returns if the tooltip should be continuously following the mouse movements when shown.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HIDE_TOOLTIP

public static final int HIDE_TOOLTIP
The tooltip will be hidden if showing.

See Also:
Constant Field Values

SHOW_TOOLTIP

public static final int SHOW_TOOLTIP
The tooltip will be shown if not already shown in which case nothing is done.

See Also:
Constant Field Values
Constructor Detail

ToolTipProvider

public ToolTipProvider()
Method Detail

configureToolTip

public abstract int configureToolTip(javax.swing.JToolTip toolTip,
                                     java.awt.event.MouseEvent e,
                                     java.lang.Object source)
Configure the tooltip. This method may be called at any time and even quite often so it shouldn't do too much. It normally sets the tooltip text.

Setting background and foreground color (even translucent/transparent is possible) and changeing the border and font can be done here.

Parameters:
toolTip - The tooltip that can be configured.
e - The mouse event that started this. Note that normally null should be returned for any event type (e.getID()) that isn't equal to MouseEvent.MOUSE_MOVED.
source - The source. Might be an Activity or the Component instance itself. It is up to the object that will call this method to set the source and implementations should be programmed defensively.
Returns:
The show state of the tooltip. E.g. ToolTipProviderI.RESHOW_TOOLTIP_NOW.

getInitialDelay

public int getInitialDelay()
Returns the number of milliseconds that the mouse has to be still for the tooltop to show.

Returns:
The number of milliseconds that the mouse has to be still for the tooltop to show.
See Also:
ToolTipManager.getInitialDelay()

getDismissDelay

public int getDismissDelay()
Returns the number of milliseconds that the tooltip will be visible.

Returns:
The number of milliseconds that the tooltip will be visible.
See Also:
ToolTipManager.getDismissDelay()

getReshowDelay

public int getReshowDelay()
Returns the number of milliseconds that should pass to reset to the initial delay again.

This value is currently not used by may be later on.

Returns:
The number of milliseconds that should pass to reset to the initial delay again.
See Also:
ToolTipManager.getReshowDelay()

getPositionAdjustX

public int getPositionAdjustX()
Returns the x-position relative to the mouse hot spot to show the upper left corner of the tooltip.

Default is 0.

Returns:
The x-position relative to the mouse hot spot to show the upper left corner of the tooltip.

getPositionAdjustY

public int getPositionAdjustY()
Returns the y-position relative to the mouse hot spot to show the upper left corner of the tooltip.

Default is 18.

Returns:
The y-position relative to the mouse hot spot to show the upper left corner of the tooltip.

isFollowMouse

public boolean isFollowMouse()
Returns if the tooltip should be continuously following the mouse movements when shown.

Default is true.

Returns:
If the tooltip should be continuously following the mouse movements when shown.

getScreenInsets

public java.awt.Insets getScreenInsets()
Deprecated. Replaced with getScreenInsets(java.awt.GraphicsConfiguration).

Returns the insets around the main screen to show the tooltip inside. If null the tooltip will always be showed at the mouse point even if that means it will show parts outside the screen.

Returns:
The insets. Default to Toolkit.getDefaultToolkit().getScreenInsets(GfxUtil.getDefaultConfiguration()).

getScreenInsets

public java.awt.Insets getScreenInsets(java.awt.GraphicsConfiguration gc)
Returns the insets around the indicated screen to show the tooltip inside. If null the tooltip will always be showed at the mouse point even if that means it will show parts outside the screen.

Returns:
The insets. Default to Toolkit.getDefaultToolkit().getScreenInsets(gc).

getWindowInsets

public java.awt.Insets getWindowInsets(java.awt.Window window)
Returns the insets around the window to show the tooltip inside. If null the tooltip will always be showed at the mouse pointed even if that means it will show parts outside the current frame (and thus will flicker sice a heavyweight Window is needed from the native platform).

Parameters:
window - The window in question. Never null.
Returns:
The insets. Default to window.getInsets().


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.