GF4J 0.9.4 Beta

gameframe.engines.jdk11x
Class CPointer

java.lang.Object
  |
  +--gameframe.engines.jdk11x.CPointer
All Implemented Interfaces:
java.util.EventListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, PointerDevice

class CPointer
extends java.lang.Object
implements PointerDevice, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Implementation of the pointer device for the Java 1.1 platform.

Since:
GameFrame for Java 0.9
Version:
GameFrame for Java 0.9.4

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  int[] m_aButtonStates
          States of the buttons.
private  int[] m_aNumButtonPresses
          Number of times the button was stroken.
private  java.awt.Component m_focusComponent
          Reference to the focus component that is the source of keyboard events.
private  int m_x
          The current X-coordinate of the mouse.
private  int m_y
          The current Y-coordinate of the mouse.
 
Constructor Summary
(package private) CPointer(java.awt.Component focusComponent)
          Constructs a pointer device whose focus component is the given window.
 
Method Summary
 void finalize()
          Releases all resources held by the pointer 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).
private  int getMouseButtonId(java.awt.event.MouseEvent event)
          Returns the mouse button ID (number) from the given event.
 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.
 void mouseClicked(java.awt.event.MouseEvent event)
          Called when mouse button is clicked in the focus window.
 void mouseDragged(java.awt.event.MouseEvent event)
          Called when mouse is dragged inside the focus window.
 void mouseEntered(java.awt.event.MouseEvent event)
          Called when mouse enters the focus window.
 void mouseExited(java.awt.event.MouseEvent event)
          Called when mouse leaves the focus window.
 void mouseMoved(java.awt.event.MouseEvent event)
          Called when mouse is moved inside the focus window.
 void mousePressed(java.awt.event.MouseEvent event)
          Called when mouse is pressed inside the focus window.
 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).
 
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
Reference to the focus component that is the source of keyboard events.

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

CPointer

CPointer(java.awt.Component focusComponent)
Constructs a pointer device whose focus component is the given window.
Parameters:
focusComponent - The component that receives the mouse events.
Method Detail

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

public void mouseEntered(java.awt.event.MouseEvent event)
Called when mouse enters the focus window.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
event - The event object that describes the event in more detail.

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Called when mouse leaves the focus window.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
event - The event object that describes the event in more detail.

mouseClicked

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

mouseMoved

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

mousePressed

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

mouseReleased

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

mouseDragged

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

getMouseButtonId

private 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).

finalize

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

GF4J 0.9.4 Beta