org.jagatoo.input.devices
Class Keyboard

java.lang.Object
  extended by org.jagatoo.input.devices.InputDevice
      extended by org.jagatoo.input.devices.Keyboard
All Implemented Interfaces:
Enableable
Direct Known Subclasses:
AWTKeyboard, JInputKeyboard, LWJGLKeyboard, SWTKeyboard

public abstract class Keyboard
extends InputDevice

This is the base-class for all Keyboard implementations.
Applications should always use instances as Keyboard, but never cast them to the concrete implementation.
Instances can only be created/retrieved through an InputDeviceFactory.


Constructor Summary
protected Keyboard(KeyboardFactory sourceFactory, InputSourceWindow sourceWindow, EventQueue eventQueue, java.lang.String name)
           
 
Method Summary
 void addKeyboardListener(KeyboardListener l)
          Adds a KeyboardListener to the list of notified instances.
protected  int applyModifier(Key key, boolean isKeyDown)
          Combines the given key's maks-value to the modifier-mask, if the Key is a modifier.
 void destroy()
          Destroys the InputDevice.
protected abstract  void destroyImpl()
          Destroys the Keyboard.
 void fireKeyboardEvent(KeyboardEvent e, boolean consumeEvent)
          this method simply forwards to the concrete fire* methods.
 void fireOnKeyPressed(KeyPressedEvent e, boolean consumeEvent)
          Fires a KeyPressedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnKeyReleased(KeyReleasedEvent e, boolean consumeEvent)
          Fires a KeyReleasedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnKeyTyped(KeyTypedEvent e, boolean consumeEvent)
          Fires a KeyTypedEvent and pushes it back to the pool, if consumeEvent is true.
 InputState getKeyState(Key key)
           
 int getModifierMask()
           
 KeyboardFactory getSourceFactory()
           
 int getState(DeviceComponent component)
          This method returns an abstract input-state for the given DeviceComponent.
 boolean hasKeyboardListener()
           
protected abstract  boolean hasKeyStateChanged(Key key, boolean keyState)
          This method is asked by the fireOnKeyPressed(KeyPressedEvent, boolean) and fireOnKeyReleased(KeyReleasedEvent, boolean) methods and listeners are not notified, if this method returns false.
 boolean hasListener()
           
 boolean isKeyPressed(Key key)
           
protected  KeyPressedEvent prepareKeyPressedEvent(Key key, int modifierMask, long when, long lastWhen)
          Prepares a KeyPressedEvent for being fired.
protected  KeyReleasedEvent prepareKeyReleasedEvent(Key key, int modifierMask, long when, long lastWhen)
          Prepares a KeyReleasedEvent for being fired.
protected  KeyTypedEvent prepareKeyTypedEvent(char keyChar, int modifierMask, long when, long lastWhen)
          Prepares a KeyTypedEvent for being fired.
 void removeKeyboardListener(KeyboardListener l)
          Removes a KeyboardListener from the list of notified instances.
 java.lang.String toString()
          
 
Methods inherited from class org.jagatoo.input.devices.InputDevice
addInputStateListener, collectEvents, consumePendingEvents, equals, fireStateEventsAndDoActions, getEventQueue, getName, getSourceWindow, hasInputStateListener, isEnabled, onDeviceRegistered, onDeviceUnregistered, removeInputStateListener, setEnabled, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Keyboard

protected Keyboard(KeyboardFactory sourceFactory,
                   InputSourceWindow sourceWindow,
                   EventQueue eventQueue,
                   java.lang.String name)
            throws InputSystemException
Throws:
InputSystemException
Method Detail

getSourceFactory

public final KeyboardFactory getSourceFactory()
Returns:
the KeyboardFactory, that created this instance.

hasKeyboardListener

public final boolean hasKeyboardListener()
Returns:
true, of at least one KeyboardListener is currently registered.

hasListener

public final boolean hasListener()
Returns:
true, if one of InputDevice.hasInputStateListener() or hasKeyboardListener() return true.

addKeyboardListener

public void addKeyboardListener(KeyboardListener l)
Adds a KeyboardListener to the list of notified instances.

Parameters:
l -

removeKeyboardListener

public void removeKeyboardListener(KeyboardListener l)
Removes a KeyboardListener from the list of notified instances.

Parameters:
l -

applyModifier

protected int applyModifier(Key key,
                            boolean isKeyDown)
Combines the given key's maks-value to the modifier-mask, if the Key is a modifier.

Parameters:
key -
isKeyDown -
Returns:
the new modifier-mask.

getModifierMask

public final int getModifierMask()
Returns:
the current modifier-mask.

prepareKeyPressedEvent

protected final KeyPressedEvent prepareKeyPressedEvent(Key key,
                                                       int modifierMask,
                                                       long when,
                                                       long lastWhen)
Prepares a KeyPressedEvent for being fired.
The event is not fired from this method.
This method cares about the current key-state.

Parameters:
key -
modifierMask -
when -
lastWhen -
Returns:
the new event from the pool or null, if no events are currently accepted.

hasKeyStateChanged

protected abstract boolean hasKeyStateChanged(Key key,
                                              boolean keyState)
This method is asked by the fireOnKeyPressed(KeyPressedEvent, boolean) and fireOnKeyReleased(KeyReleasedEvent, boolean) methods and listeners are not notified, if this method returns false.

Parameters:
key -
keyState -

fireOnKeyPressed

public final void fireOnKeyPressed(KeyPressedEvent e,
                                   boolean consumeEvent)
Fires a KeyPressedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

prepareKeyReleasedEvent

protected final KeyReleasedEvent prepareKeyReleasedEvent(Key key,
                                                         int modifierMask,
                                                         long when,
                                                         long lastWhen)
Prepares a KeyReleasedEvent for being fired.
The event is not fired from this method.
This method cares about the current key-state.

Parameters:
key -
modifierMask -
when -
lastWhen -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnKeyReleased

public final void fireOnKeyReleased(KeyReleasedEvent e,
                                    boolean consumeEvent)
Fires a KeyReleasedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

prepareKeyTypedEvent

protected final KeyTypedEvent prepareKeyTypedEvent(char keyChar,
                                                   int modifierMask,
                                                   long when,
                                                   long lastWhen)
Prepares a KeyTypedEvent for being fired.
The event is not fired from this method.

Parameters:
keyChar -
modifierMask -
when -
lastWhen -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnKeyTyped

public final void fireOnKeyTyped(KeyTypedEvent e,
                                 boolean consumeEvent)
Fires a KeyTypedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

fireKeyboardEvent

public final void fireKeyboardEvent(KeyboardEvent e,
                                    boolean consumeEvent)
this method simply forwards to the concrete fire* methods.

Parameters:
e -
consumeEvent -

isKeyPressed

public final boolean isKeyPressed(Key key)
Parameters:
key -
Returns:
true, if the given Key is currently pressed on this Keyboard.

getKeyState

public final InputState getKeyState(Key key)
Parameters:
key -
Returns:
The given Key's state on this Keyboard.

getState

public int getState(DeviceComponent component)
             throws InputSystemRuntimeException
This method returns an abstract input-state for the given DeviceComponent. Note, that only supported components are accepted.

Specified by:
getState in class InputDevice
Returns:
the current state of the given component on this device.
Throws:
InputSystemRuntimeException

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

destroyImpl

protected abstract void destroyImpl()
                             throws InputSystemException
Destroys the Keyboard.

Throws:
InputSystemException

destroy

public final void destroy()
                   throws InputSystemException
Destroys the InputDevice. This must be called when the InputDevice is unregistered.

Specified by:
destroy in class InputDevice
Throws:
InputSystemException