net.lucidviews.util.gui.event
Class IsolatedKeyEventProcessor

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

public class IsolatedKeyEventProcessor
extends Object
implements KeyListener

Listens for key events and isolates a single key press.
For each key event a thread is started which causes a delay before sending the actual notification for that key press. If another key event is received within the tolerance (delay) time slot then both events are cancelled.

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

Nested Class Summary
static class IsolatedKeyEventProcessor.IsolationThread
           
 
Field Summary
protected  IsolatedKeyEventProcessor.IsolationThread _isolationThread
           
protected  Collection _listeners
           
protected  long _tolerance
           
 
Constructor Summary
IsolatedKeyEventProcessor(long tolerance)
          Create a processor for key events which only accepts isolated key events (those which occur apart by least the tolerance).
 
Method Summary
 void addIsolatedKeyEventListener(IsolatedKeyEventListener listener)
          Register a listener that wants to be notified of isolated key press events.
 void keyPressed(KeyEvent e)
           
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
protected  void notifyIsolatedKeyPress(KeyEvent keyEvent)
          Notify all listeners that an isolated key press has occurred.
 void removeIsolatedKeyEventListener(IsolatedKeyEventListener listener)
          Un-register a listener that does not want to be notified of isolated key press events.
protected  void startIsolationThread(KeyEvent keyEvent)
          Start a new isolation thread to verify a given key event is isolated.
protected  void stopIsolationThread(IsolatedKeyEventProcessor.IsolationThread isolationThread)
          Stop an isolation thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_listeners

protected Collection _listeners

_tolerance

protected long _tolerance

_isolationThread

protected IsolatedKeyEventProcessor.IsolationThread _isolationThread
Constructor Detail

IsolatedKeyEventProcessor

public IsolatedKeyEventProcessor(long tolerance)
Create a processor for key events which only accepts isolated key events (those which occur apart by least the tolerance).

Parameters:
tolerance - the isolation tolerance, in milli-seconds
Method Detail

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener

keyPressed

public void keyPressed(KeyEvent e)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener

addIsolatedKeyEventListener

public void addIsolatedKeyEventListener(IsolatedKeyEventListener listener)
Register a listener that wants to be notified of isolated key press events.

Parameters:
listener - object that is to receive notifications

removeIsolatedKeyEventListener

public void removeIsolatedKeyEventListener(IsolatedKeyEventListener listener)
Un-register a listener that does not want to be notified of isolated key press events.

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

notifyIsolatedKeyPress

protected void notifyIsolatedKeyPress(KeyEvent keyEvent)
Notify all listeners that an isolated key press has occurred.

Parameters:
keyEvent - the key event associated with the isolated key press

startIsolationThread

protected void startIsolationThread(KeyEvent keyEvent)
Start a new isolation thread to verify a given key event is isolated.
This method is called from the keyPressed method. It will pass control of processing the key event to the IsolationThread::run method.

Parameters:
keyEvent - the incoming key event

stopIsolationThread

protected void stopIsolationThread(IsolatedKeyEventProcessor.IsolationThread isolationThread)
Stop an isolation thread.
This method is called from the IsolationThread::run method. It will check the event has been successfully isolated before calling the notifyIsolatedKeyPress which will pass control of processing the key event to any listeners.

Parameters:
isolationThread - the thread which may have isolated a key event