staffui
Class MagicKeyListener

java.lang.Object
  |
  +--staffui.MagicKeyListener
All Implemented Interfaces:
EventListener, KeyListener

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)
          creates a new MagicKeyListener without the generation of additional key release events (the third option given in the class overview is disabled).
MagicKeyListener(KeyListener adaptee, boolean assumeAllReleased)
          creates a new MagicKeyListener.
 
Method Summary
 void keyPressed(KeyEvent e)
          Acts on the given event as specified in the class overview.
 void keyReleased(KeyEvent e)
          Acts on the given event as specified in the class overview.
 void keyTyped(KeyEvent e)
          Acts on the given event as specified in the class overview
 
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)
Requires:
adaptee != null
Effects:
creates a new MagicKeyListener.
Parameters:
assumeAllReleased - enables the third option listed in the class overview, namely that any key release event implies that all keys have been released.
Method Detail

keyPressed

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

keyReleased

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

keyTyped

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