GF4J 0.9.4 Beta

gameframe.engines.jdk12x
Class CEventQueue

java.lang.Object
  |
  +--java.awt.EventQueue
        |
        +--gameframe.engines.jdk12x.CEventQueue
All Implemented Interfaces:
KeyboardDevice, PointerDevice

class CEventQueue
extends java.awt.EventQueue
implements KeyboardDevice, PointerDevice

Implementation of the keyboard and pointer device for Java 2 platforms. The implementation is actually a replacement for system event queue that monitors the event queue and picks up all mouse and keyboard related events directly (slightly faster than the normal listener architecture). Other types of events are handled normally by the java.awt.EventQueue superclass.

Since:
GameFrame for Java 0.9.3
Version:
GameFrame for Java 0.9.3

Field Summary
private static int BUTTONSTATE_DOWN
          Enumerated value for state button is down.
private static int BUTTONSTATE_UP
          Enumerated value for state button is up.
private static int BUTTONSTATE_WAS_DOWN_NOT_READ
          Enumerated value for state where button was down but was not read during that time.
private static int BUTTONSTATE_WAS_DOWN_READ
          Enumerated value for state where button was down and was read during that time.
private static int KEY_DOWN
          Enumerated value for state key is down.
private static int KEY_UP
          Enumerated value for state key is up.
private static int KEY_WAS_DOWN_NOT_READ
          Enumerated value for state where key was down but was not read during that time.
private static int KEY_WAS_DOWN_READ
          Enumerated value for state where key was down and was read during that time.
private  int[] m_aButtonStates
          States of the buttons.
private  int[] m_aKeyStates
          States of the keys.
private  int[] m_aNumButtonPresses
          Number of times the button was stroken.
private  int[] m_aNumKeystrokes
          Number of times the key was stroken.
private  java.awt.Component m_focusComponent
          The focus component that is listened for events.
private  int m_lastAlphanumericKey
          The last alphanumeric key value typed.
private  int m_x
          The current X-coordinate of the mouse.
private  int m_y
          The current Y-coordinate of the mouse.
private static CEventQueue mStatic_queueInstance
          The singleton instance of this event queue.
 
Fields inherited from class java.awt.EventQueue
dbg, debug, dispatchThread, HIGH_PRIORITY, LOW_PRIORITY, nextQueue, NORM_PRIORITY, NUM_PRIORITIES, previousQueue, queues, threadInitNumber
 
Constructor Summary
private CEventQueue(java.awt.Component focusComponent)
          Constructs a keyboard engine that has the given window set as the focus window.
 
Method Summary
protected  void dispatchEvent(java.awt.AWTEvent event)
          Overrides the default event queues AWT event dispatch method to capture mouse and keyboard events from the queue.
 void finalize()
          Releases all resources held by the keyboard device implementation.
 int getButtonDownCount(int buttonId)
          Returns the number of times the button has been stroken since last reading (after last call made to wasButtonDown or getButtonDownCount methods with the same button id number).
static CEventQueue getInstance(java.awt.Component focusComponent)
          Returns the singleton instance.
 int getKeyDownCount(int keyCode)
          Returns the number of times the key has been stroken since last reading (after last call made to isKeyDown or getKeyDownCount methods with the same key code).
private  int getMouseButtonId(java.awt.event.MouseEvent event)
          Returns the mouse button ID (number) from the given event.
 int getTypedAlphanumericKey()
          Returns any typed alphanumeric keys (including space and dot) as int values that correspond to that keys char value or -1 if no such keys were pressed after last invokation of this method.
 int getX()
          Returns the X-coordinate of the pointer devices current location.
 int getY()
          Returns the Y-coordinate of the pointer devices current location.
 boolean isButtonDown(int buttonId)
          Returns true if the button is down.
 boolean isKeyDown(int keyCode)
          Returns true if the key is currently down
private  void keyPressed(java.awt.event.KeyEvent event)
          Called when a key has been pressed.
private  void keyReleased(java.awt.event.KeyEvent event)
          Called when a key has been released.
private  void keyTyped(java.awt.event.KeyEvent event)
          Called when a key has been pressed and then released.
private  void mouseClicked(java.awt.event.MouseEvent event)
          Called when mouse button is clicked in the focus window.
private  void mouseDragged(java.awt.event.MouseEvent event)
          Called when mouse is dragged inside the focus window.
private  void mouseEntered(java.awt.event.MouseEvent event)
          Called when mouse enters the focus window.
private  void mouseExited(java.awt.event.MouseEvent event)
          Called when mouse leaves the focus window.
private  void mouseMoved(java.awt.event.MouseEvent event)
          Called when mouse is moved inside the focus window.
private  void mousePressed(java.awt.event.MouseEvent event)
          Called when mouse is pressed inside the focus window.
private  void mouseReleased(java.awt.event.MouseEvent event)
          Called when mouse is released inside the focus window.
 boolean wasButtonDown(int buttonId)
          Returns true if the button was briefly kept down after last reading of the buttons state and that event hasn't been read by any other method (after last call made to isButtonDown, wasButtonDown or getButtonDownCount methods with the same button id number).
 boolean wasKeyDown(int keyCode)
          Returns true if the key was briefly kept down after last reading of the keys state (after last call made to isKeyDown or getKeyDownCount methods with the same key code).
 
Methods inherited from class java.awt.EventQueue
, changeKeyEventFocus, getDispatchThread, getNextEvent, invokeAndWait, invokeLater, isDispatchThread, nextThreadNum, noEvents, peekEvent, peekEvent, pop, postEvent, postEvent, postEventPrivate, push, removeSourceEvents
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_focusComponent

private java.awt.Component m_focusComponent
The focus component that is listened for events.

mStatic_queueInstance

private static CEventQueue mStatic_queueInstance
The singleton instance of this event queue.

m_aKeyStates

private int[] m_aKeyStates
States of the keys. Can have one of the enumerated KEY_ values.

m_aNumKeystrokes

private int[] m_aNumKeystrokes
Number of times the key was stroken.

KEY_UP

private static final int KEY_UP
Enumerated value for state key is up.

KEY_DOWN

private static final int KEY_DOWN
Enumerated value for state key is down.

KEY_WAS_DOWN_NOT_READ

private static final int KEY_WAS_DOWN_NOT_READ
Enumerated value for state where key was down but was not read during that time.

KEY_WAS_DOWN_READ

private static final int KEY_WAS_DOWN_READ
Enumerated value for state where key was down and was read during that time.

m_lastAlphanumericKey

private int m_lastAlphanumericKey
The last alphanumeric key value typed.

m_x

private int m_x
The current X-coordinate of the mouse.

m_y

private int m_y
The current Y-coordinate of the mouse.

m_aButtonStates

private int[] m_aButtonStates
States of the buttons. Can have one of the enumerated BUTTONSTATE_ values.

m_aNumButtonPresses

private int[] m_aNumButtonPresses
Number of times the button was stroken.

BUTTONSTATE_UP

private static final int BUTTONSTATE_UP
Enumerated value for state button is up.

BUTTONSTATE_DOWN

private static final int BUTTONSTATE_DOWN
Enumerated value for state button is down.

BUTTONSTATE_WAS_DOWN_NOT_READ

private static final int BUTTONSTATE_WAS_DOWN_NOT_READ
Enumerated value for state where button was down but was not read during that time.

BUTTONSTATE_WAS_DOWN_READ

private static final int BUTTONSTATE_WAS_DOWN_READ
Enumerated value for state where button was down and was read during that time.
Constructor Detail

CEventQueue

private CEventQueue(java.awt.Component focusComponent)
Constructs a keyboard engine that has the given window set as the focus window.
Parameters:
focusComponent - The component that where listeners are registered.
Method Detail

getInstance

public static CEventQueue getInstance(java.awt.Component focusComponent)
Returns the singleton instance.
Returns:
The single instance of the keyboard.

isKeyDown

public boolean isKeyDown(int keyCode)
Returns true if the key is currently down
Specified by:
isKeyDown in interface KeyboardDevice
Parameters:
keyCode - The keycode of the key we want to query.
Returns:
True if the key is or was down.

wasKeyDown

public boolean wasKeyDown(int keyCode)
Returns true if the key was briefly kept down after last reading of the keys state (after last call made to isKeyDown or getKeyDownCount methods with the same key code).
Specified by:
wasKeyDown in interface KeyboardDevice
Following copied from interface: gameframe.input.KeyboardDevice
Parameters:
keyCode - The keycode of the key we want to query.
Returns:
True if the key was down.

getKeyDownCount

public int getKeyDownCount(int keyCode)
Returns the number of times the key has been stroken since last reading (after last call made to isKeyDown or getKeyDownCount methods with the same key code).
Specified by:
getKeyDownCount in interface KeyboardDevice
Parameters:
keyCode - The keycode of the key we want to query.
Returns:
The number of times the key was stroken (pressed and released)

dispatchEvent

protected void dispatchEvent(java.awt.AWTEvent event)
Overrides the default event queues AWT event dispatch method to capture mouse and keyboard events from the queue.
Overrides:
dispatchEvent in class java.awt.EventQueue
Parameters:
event - The dispatched AWT event.

keyPressed

private final void keyPressed(java.awt.event.KeyEvent event)
Called when a key has been pressed.
Parameters:
event - The event object that describes the event in more detail.

keyReleased

private final void keyReleased(java.awt.event.KeyEvent event)
Called when a key has been released.
Parameters:
event - The event object that describes the event in more detail.

keyTyped

private final void keyTyped(java.awt.event.KeyEvent event)
Called when a key has been pressed and then released.
Parameters:
event - The event object that describes the event in more detail.

getTypedAlphanumericKey

public int getTypedAlphanumericKey()
Returns any typed alphanumeric keys (including space and dot) as int values that correspond to that keys char value or -1 if no such keys were pressed after last invokation of this method.
Specified by:
getTypedAlphanumericKey in interface KeyboardDevice
Returns:
Any typed alphanumeric keys

finalize

public void finalize()
Releases all resources held by the keyboard device implementation.
Specified by:
finalize in interface KeyboardDevice
Overrides:
finalize in class java.lang.Object

getX

public int getX()
Returns the X-coordinate of the pointer devices current location. If the mouse is outside of the screen returns -1.
Specified by:
getX in interface PointerDevice
Returns:
Pointers current X-location or -1 if not on screen.

getY

public int getY()
Returns the Y-coordinate of the pointer devices current location. If the mouse is outside of the screen returns -1.
Specified by:
getY in interface PointerDevice
Returns:
Pointers current Y-location or -1 if not on screen.

isButtonDown

public boolean isButtonDown(int buttonId)
Returns true if the button is down. Id numbers should be 0 = primary button, 1 = secondary or "popup menu" button, 2 etc. for rest of the buttons. Max. 3 buttons are supported (button id's from 0 to 2).
Specified by:
isButtonDown in interface PointerDevice
Parameters:
buttonId - The number of the button we want to query.
Returns:
True if the button is or was down.

wasButtonDown

public boolean wasButtonDown(int buttonId)
Returns true if the button was briefly kept down after last reading of the buttons state and that event hasn't been read by any other method (after last call made to isButtonDown, wasButtonDown or getButtonDownCount methods with the same button id number). Id numbers should be 0 = primary button, 1 = secondary or "popup menu" button, 2 etc. for rest of the buttons. Max. 3 buttons are supported (button id's from 0 to 2).
Specified by:
wasButtonDown in interface PointerDevice
Parameters:
buttonId - The number of the button we want to query.
Returns:
True if the button is or was down.

getButtonDownCount

public int getButtonDownCount(int buttonId)
Returns the number of times the button has been stroken since last reading (after last call made to wasButtonDown or getButtonDownCount methods with the same button id number). Id numbers should be 0 = primary button, 1 = secondary or "popup menu" button, 2 = third button. Max. 3 buttons are supported (button id's from 0 to 2).
Specified by:
getButtonDownCount in interface PointerDevice
Parameters:
buttonId - The number of the button we want to query.
Returns:
The number of times the button was stroken (pressed and released)

mouseEntered

private final void mouseEntered(java.awt.event.MouseEvent event)
Called when mouse enters the focus window.
Parameters:
event - The event object that describes the event in more detail.

mouseExited

private final void mouseExited(java.awt.event.MouseEvent event)
Called when mouse leaves the focus window.
Parameters:
event - The event object that describes the event in more detail.

mouseClicked

private final void mouseClicked(java.awt.event.MouseEvent event)
Called when mouse button is clicked in the focus window.
Parameters:
event - The event object that describes the event in more detail.

mouseMoved

private final void mouseMoved(java.awt.event.MouseEvent event)
Called when mouse is moved inside the focus window.
Parameters:
event - The event object that describes the event in more detail.

mousePressed

private final void mousePressed(java.awt.event.MouseEvent event)
Called when mouse is pressed inside the focus window.
Parameters:
event - The event object that describes the event in more detail.

mouseReleased

private final void mouseReleased(java.awt.event.MouseEvent event)
Called when mouse is released inside the focus window.
Parameters:
event - The event object that describes the event in more detail.

mouseDragged

private final void mouseDragged(java.awt.event.MouseEvent event)
Called when mouse is dragged inside the focus window.
Parameters:
event - The event object that describes the event in more detail.

getMouseButtonId

private final int getMouseButtonId(java.awt.event.MouseEvent event)
Returns the mouse button ID (number) from the given event.
Parameters:
event - The event object that describes the event in more detail.
Returns:
The number of the mouse button that was pressed (0-2).

GF4J 0.9.4 Beta