uk.co.keang.swingaddons
Class HoverDetector

java.lang.Object
  extended by java.awt.event.MouseAdapter
      extended by uk.co.keang.swingaddons.HoverDetector
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.util.EventListener

public class HoverDetector
extends java.awt.event.MouseAdapter

A mouse listener to determine if a mouse is hovering over a component and if so to perform an action such as popping a dialog.
Hovering is defined as the mouse entering a component and staying still for a predetermined amount of time. Once the hover has been detected this detector will not trigger again until the mouse has exited from the component and re-entered it.
This instance will register itself with the appropriate mouse listeners on the owning component. To de-register this hover detector from the owning component call the remove() method. Once removed this hover detector can't be used again.
The action taken when a hover is detected is defined in the Callable object. If a window is displayed then returning a reference to the window from the Callable object will allow this hover detector to spot when this window no longer has focus and to close the window and reset the hover detector appropriately. If this functionality is not required return null, if an alternative functionality is required override the handleObject(Object obj) method.

Author:
A.G.Docherty

Constructor Summary
HoverDetector(java.awt.Component parent, java.util.concurrent.Callable<java.awt.Component> r)
          Creates a hover detector and registers it with component.
HoverDetector(java.awt.Component parent, java.util.concurrent.Callable<java.awt.Component> r, int time)
          Creates a hover detector and registers it with the component.
 
Method Summary
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void remove()
          De-registers the hover detector from the component.
 void reset()
          Forcibly resets the trigger mechanism.
 
Methods inherited from class java.awt.event.MouseAdapter
mouseClicked, mouseDragged, mousePressed, mouseReleased, mouseWheelMoved
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HoverDetector

public HoverDetector(java.awt.Component parent,
                     java.util.concurrent.Callable<java.awt.Component> r)
Creates a hover detector and registers it with component. The trigger delay time is the constant TIME_BEFORE_TRIGGER.

Parameters:
parent - - the component to register for hover detection
r - - the command to run on hover detection

HoverDetector

public HoverDetector(java.awt.Component parent,
                     java.util.concurrent.Callable<java.awt.Component> r,
                     int time)
Creates a hover detector and registers it with the component.

Parameters:
parent - - the component to register for hover detection
r - - the command to run on hover detection
time - - the delay time before triggering a hover
Method Detail

remove

public void remove()
De-registers the hover detector from the component. Once called the detector can not be used again.


reset

public void reset()
Forcibly resets the trigger mechanism. This is required if the trigger causes some without generating a mouseExited event.


mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Overrides:
mouseEntered in class java.awt.event.MouseAdapter

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Overrides:
mouseMoved in class java.awt.event.MouseAdapter

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class java.awt.event.MouseAdapter