org.jagatoo.input.impl.swt
Class SWTKeyboard

java.lang.Object
  extended by org.jagatoo.input.devices.InputDevice
      extended by org.jagatoo.input.devices.Keyboard
          extended by org.jagatoo.input.impl.swt.SWTKeyboard
All Implemented Interfaces:
Enableable

public class SWTKeyboard
extends Keyboard

SWT implementation of the Keyboard class.


Field Summary
protected static java.util.HashMap<java.lang.Character,Key> CHAR_CONVERSION
           
protected static java.util.HashMap<java.lang.Integer,Key> KEYCODE_CONVERSION
           An hash map of net.jtank.input.KeyCode keys with their SWT equivalents as the keys.
 
Constructor Summary
protected SWTKeyboard(KeyboardFactory factory, InputSourceWindow sourceWindow, EventQueue eventQueue)
           
 
Method Summary
 void collectEvents(InputSystem is, EventQueue eventQueue, long nanoTime)
          Processes pending events from the system and places them into the EventQueue.
 void consumePendingEvents(InputSystem is, EventQueue eventQueue, long nanoTime)
          Processes pending events from the system and simply wastes them.
static Key convertKey(org.eclipse.swt.events.KeyEvent ev)
          Returns the HIAL key code for the given SWT key code.
 void destroyImpl()
          Destroys the Keyboard.
protected  boolean hasKeyStateChanged(Key key, boolean keyState)
          This method is asked by the Keyboard.fireOnKeyPressed(KeyPressedEvent, boolean) and Keyboard.fireOnKeyReleased(KeyReleasedEvent, boolean) methods and listeners are not notified, if this method returns false.
 void update(InputSystem is, EventQueue eventQueue, long nanoTime)
          Processes pending events from the system and directly fires them (notifes the listeners).
 
Methods inherited from class org.jagatoo.input.devices.Keyboard
addKeyboardListener, applyModifier, destroy, fireKeyboardEvent, fireOnKeyPressed, fireOnKeyReleased, fireOnKeyTyped, getKeyState, getModifierMask, getSourceFactory, getState, hasKeyboardListener, hasListener, isKeyPressed, prepareKeyPressedEvent, prepareKeyReleasedEvent, prepareKeyTypedEvent, removeKeyboardListener, toString
 
Methods inherited from class org.jagatoo.input.devices.InputDevice
addInputStateListener, equals, fireStateEventsAndDoActions, getEventQueue, getName, getSourceWindow, hasInputStateListener, isEnabled, onDeviceRegistered, onDeviceUnregistered, removeInputStateListener, setEnabled
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

KEYCODE_CONVERSION

protected static final java.util.HashMap<java.lang.Integer,Key> KEYCODE_CONVERSION

An hash map of net.jtank.input.KeyCode keys with their SWT equivalents as the keys.

Example: assert(KEY_CONVERSION.get(SWT.CTRL) == KeyCode.VK_CTRL) should not fail.


CHAR_CONVERSION

protected static final java.util.HashMap<java.lang.Character,Key> CHAR_CONVERSION
Constructor Detail

SWTKeyboard

protected SWTKeyboard(KeyboardFactory factory,
                      InputSourceWindow sourceWindow,
                      EventQueue eventQueue)
               throws InputSystemException
Throws:
InputSystemException
Method Detail

convertKey

public static Key convertKey(org.eclipse.swt.events.KeyEvent ev)
Returns the HIAL key code for the given SWT key code. This is an O(1) complexity operation.

Parameters:
ev - the SWT key code to convert
Returns:
the HIAL key code for the given SWT key code

hasKeyStateChanged

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

Specified by:
hasKeyStateChanged in class Keyboard

consumePendingEvents

public void consumePendingEvents(InputSystem is,
                                 EventQueue eventQueue,
                                 long nanoTime)
                          throws InputSystemException
Processes pending events from the system and simply wastes them.
This method is invoked by the InputSystem when a new InputDevice is registered and instead of the InputDevice.update(InputSystem, EventQueue, long) method, if the device is disabled or its InputSourceWindow doesn't currently receive input events.

Specified by:
consumePendingEvents in class InputDevice
Throws:
InputSystemException

collectEvents

public void collectEvents(InputSystem is,
                          EventQueue eventQueue,
                          long nanoTime)
                   throws InputSystemException
Processes pending events from the system and places them into the EventQueue.
The events are not fired (listeners are not notified). They are fired when the InputDevice.update(InputSystem, EventQueue, long) method is invoked.

Specified by:
collectEvents in class InputDevice
Throws:
InputSystemException

update

public void update(InputSystem is,
                   EventQueue eventQueue,
                   long nanoTime)
            throws InputSystemException
Processes pending events from the system and directly fires them (notifes the listeners).
This method also flushes the EventQueue, if the previously called InputDevice.collectEvents(InputSystem, EventQueue, long) method placed events into it.

Specified by:
update in class InputDevice
Throws:
InputSystemException

destroyImpl

public void destroyImpl()
                 throws InputSystemException
Destroys the Keyboard.

Specified by:
destroyImpl in class Keyboard
Throws:
InputSystemException