staffui
Class MagicKeyListener

java.lang.Object
  extended by staffui.MagicKeyListener
All Implemented Interfaces:
KeyListener, EventListener

public class MagicKeyListener
extends Object
implements KeyListener

A MagicKeyListener is decorator for a KeyListener.

This class adds three pieces of functionality. First, it delays key events (moving them to the back of the event queue). Second, it maintains state so that when a press-and-release event pair is sitting in the queue, neither event is propogated to the adaptee (decoratee). Finally, it can (optionally) add to the semantics so that any release event implies that any still-pressed keys have also been released.

Together, these additions may provide more meaningful semantics of key listening in an environment where a key being held down generates repeated key events, or where multiple keys pressed generate a release event for only one of them.


Constructor Summary
MagicKeyListener(KeyListener adaptee)
           
MagicKeyListener(KeyListener adaptee, boolean assumeAllReleased)
           
 
Method Summary
 void keyPressed(KeyEvent e)
           
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MagicKeyListener

public MagicKeyListener(KeyListener adaptee)
Requires:
adaptee != null
Effects:
creates a new MagicKeyListener without the generation of additional key release events (the third option given in the class overview is disabled).

MagicKeyListener

public MagicKeyListener(KeyListener adaptee,
                        boolean assumeAllReleased)
Parameters:
assumeAllReleased - enables the third option listed in the class overview, namely that any key release event implies that all keys have been released.
Requires:
adaptee != null
Effects:
creates a new MagicKeyListener.
Method Detail

keyPressed

public void keyPressed(KeyEvent e)
Specified by:
keyPressed in interface KeyListener
Effects:
Acts on the given event as specified in the class overview.

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener
Effects:
Acts on the given event as specified in the class overview.

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener
Effects:
Acts on the given event as specified in the class overview