net.lucidviews.util.gui.event
Class MouseActivityNotifier

java.lang.Object
  extended by net.lucidviews.util.gui.event.MouseActivityNotifier
All Implemented Interfaces:
MouseMotionListener, EventListener

public class MouseActivityNotifier
extends Object
implements MouseMotionListener

Listens for mouse events and sends notification when the user is using or has stopped using the mouse.

For each mouse event, if the notifier is not already in an active state, an active event is published. A thread is then started which causes a delay before sending the dormant event. If another mouse event received within the delayed time period slot then another thread is started to re-start the delay.

Since:
1.0
Version:
$Revision: 1.3 $
Author:
Stephen Battey

Nested Class Summary
static class MouseActivityNotifier.InactiveNotificationThread
           
 
Field Summary
protected  long _delay
           
protected  MouseActivityNotifier.InactiveNotificationThread _inactiveNotificationThread
           
protected  Collection _listeners
           
 
Constructor Summary
MouseActivityNotifier(long delay)
          Create a mouse activity notifier that notifies all of its listeners when mouse activity begins and when no activity has been received for the given time period.
 
Method Summary
 void addIsolatedKeyEventListener(MouseActivityListener listener)
          Register a listener that wants to be notified of mouse activity.
 void addSource(Component component)
          Tells this activity notifier to listen to the specified component for mouse events.
 void mouseDragged(MouseEvent e)
           
 void mouseMoved(MouseEvent e)
           
protected  void notifyMouseNowActive(MouseEvent mouseEvent)
          Notify all listeners that the mouse is now active.
protected  void notifyMouseNowInactive()
          Notify all listeners that the mouse is now inactive.
 void removeIsolatedKeyEventListener(MouseActivityListener listener)
          Un-register a listener that does not want to be notified of mouse activity.
 void removeSource(Component component)
          Tells this activity notifier to stop listening to the specified component for mouse events.
protected  void startInactiveNotificationThread()
          Start a new thread that will call the inactive method after the specified delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_listeners

protected Collection _listeners

_delay

protected long _delay

_inactiveNotificationThread

protected MouseActivityNotifier.InactiveNotificationThread _inactiveNotificationThread
Constructor Detail

MouseActivityNotifier

public MouseActivityNotifier(long delay)
Create a mouse activity notifier that notifies all of its listeners when mouse activity begins and when no activity has been received for the given time period.

Parameters:
delay - the number of milli-seconds after which the mouse is considered inactive
Method Detail

mouseDragged

public void mouseDragged(MouseEvent e)
Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Specified by:
mouseMoved in interface MouseMotionListener

addIsolatedKeyEventListener

public void addIsolatedKeyEventListener(MouseActivityListener listener)
Register a listener that wants to be notified of mouse activity.

Parameters:
listener - object that is to receive notifications

removeIsolatedKeyEventListener

public void removeIsolatedKeyEventListener(MouseActivityListener listener)
Un-register a listener that does not want to be notified of mouse activity.

Parameters:
listener - object that is no longer to receive notifications

notifyMouseNowActive

protected void notifyMouseNowActive(MouseEvent mouseEvent)
Notify all listeners that the mouse is now active.

Parameters:
mouseEvent - the mouse event that was received

notifyMouseNowInactive

protected void notifyMouseNowInactive()
Notify all listeners that the mouse is now inactive.


addSource

public void addSource(Component component)
Tells this activity notifier to listen to the specified component for mouse events.

Parameters:
component - the component from which mouse events indicate mouse activity

removeSource

public void removeSource(Component component)
Tells this activity notifier to stop listening to the specified component for mouse events.

Parameters:
component - the component from which mouse events no longer indicate mouse activity

startInactiveNotificationThread

protected void startInactiveNotificationThread()
Start a new thread that will call the inactive method after the specified delay.