org.deken.game.input
Class InputAction

java.lang.Object
  extended by org.deken.game.input.Action
      extended by org.deken.game.input.InputAction

public class InputAction
extends Action

Title: InputAction

Description: InputAction stores the value of an input from the key board and the list of InputListeners that want to be notified when the input action occurs. Actions are identified by the key ID.

A static NO_KEY_IDS is added for convenience. Copyright: Copyright (c) 2005

Version:
1.0
Author:
Gary Deken

Nested Class Summary
 
Nested classes/interfaces inherited from class org.deken.game.input.Action
Action.Behavior, Action.State
 
Field Summary
static int[] NO_KEY_IDS
           
 
Fields inherited from class org.deken.game.input.Action
amount, behavior, consumed, id, state
 
Constructor Summary
InputAction(int keyEventId, Action.Behavior behavior)
          Creates an InputAction with the specified behavior.
 
Method Summary
 void activate()
          This signals that the key was pressed, or that the mouse event occurred.
 void activate(int amount)
          This signals that the key was pressed a specified number of times, or that the mouse moved a specified distance.
 boolean add(InputListener listener)
          Adds an InputListener to this InputAction, that wants to be notified if this input occurs.
 boolean contains(InputListener listener)
          Return true if this InputAction contains the InputListener, otherwise it returns false.
 void deactivate()
          This signals that the input has ceased to be pressed or mouse stopped moving.
 boolean equals(java.lang.Object object)
          Use to determine if two InputActions are equal.
 int getAmount()
          This returns the number of times a key was pressed or mouse moved since last check.
 char getCharValue()
          Used for the AnyKeyAction
 java.util.Collection<InputListener> getInputListeners()
           
 java.lang.String getStringValue()
          Used for the AnyKeyAction
 int hashCode()
           
 boolean isActive()
          Returns whether this Input Action is activated or not.
 boolean isEmpty()
          Returns true if there are no InputListeners wanting to be notified by this input, otherwise it returns false if there are InputListeners wanting to be notified.
protected  void notifyListeners()
          Notifies Listeners the an event has occurred on this action.
 boolean remove(InputListener listener)
          Removes the InputListener passed in from this InputAction.
 void reset()
          Resets this InputAction to an un-active state.
 void setCharValue(char charValue)
          Used by the AnyKeyAction()
 
Methods inherited from class org.deken.game.input.Action
consumed, getId, isConsumed, setId, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_KEY_IDS

public static final int[] NO_KEY_IDS
Constructor Detail

InputAction

public InputAction(int keyEventId,
                   Action.Behavior behavior)
Creates an InputAction with the specified behavior.

Parameters:
keyEventId - int
behavior - Behavior
Method Detail

activate

public void activate()
This signals that the key was pressed, or that the mouse event occurred.

Specified by:
activate in class Action

activate

public void activate(int amount)
This signals that the key was pressed a specified number of times, or that the mouse moved a specified distance.

Parameters:
amount - int

add

public boolean add(InputListener listener)
Adds an InputListener to this InputAction, that wants to be notified if this input occurs.

Parameters:
listener - InputListener
Returns:
boolean

contains

public boolean contains(InputListener listener)
Return true if this InputAction contains the InputListener, otherwise it returns false.

Parameters:
listener - InputListener
Returns:
boolean

deactivate

public void deactivate()
This signals that the input has ceased to be pressed or mouse stopped moving.

Specified by:
deactivate in class Action

equals

public boolean equals(java.lang.Object object)
Use to determine if two InputActions are equal. This is based on the name.

Overrides:
equals in class java.lang.Object
Parameters:
object - Object
Returns:
boolean

getAmount

public int getAmount()
This returns the number of times a key was pressed or mouse moved since last check.

Returns:
int

getCharValue

public char getCharValue()
Used for the AnyKeyAction

Returns:

getInputListeners

public java.util.Collection<InputListener> getInputListeners()

getStringValue

public java.lang.String getStringValue()
Used for the AnyKeyAction

Returns:

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isActive

public boolean isActive()
Returns whether this Input Action is activated or not.

Overrides:
isActive in class Action
Returns:
boolean

isEmpty

public boolean isEmpty()
Returns true if there are no InputListeners wanting to be notified by this input, otherwise it returns false if there are InputListeners wanting to be notified.

Returns:
boolean

reset

public void reset()
Resets this InputAction to an un-active state.


remove

public boolean remove(InputListener listener)
Removes the InputListener passed in from this InputAction. It returns true if it was successfully removed.

Parameters:
listener - InputListener
Returns:
boolean

setCharValue

public void setCharValue(char charValue)
Used by the AnyKeyAction()

Parameters:
charValue -

notifyListeners

protected void notifyListeners()
Notifies Listeners the an event has occurred on this action.

Specified by:
notifyListeners in class Action