com.jme.input
Class ActionTrigger

java.lang.Object
  extended by com.jme.input.ActionTrigger
Direct Known Subclasses:
ActionTrigger.CommandTrigger, JoystickInputHandlerDevice.JoystickAxisTrigger, JoystickInputHandlerDevice.JoystickButtonTrigger, KeyboardInputHandlerDevice.KeyTrigger, MouseInputHandlerDevice.MouseAxisTrigger, MouseInputHandlerDevice.MouseButtonTrigger, SyntheticTrigger

public abstract class ActionTrigger
extends java.lang.Object

Stores data about an action trigger. Subclasses provide the actual trigger functionality. Triggers are used by InputHandler to decouple event occurence and action invocation.
The most important methods of the trigger are activate() and deactivate(): they add and remove this trigger from the list of active trigger in the InputHandler. For all active triggers the performAction(com.jme.input.action.InputActionEvent) method is called in the InputHandler.update(float) method.
A trigger also registers itself with an input handler and can be removed from the list of triggers via the remove() method.


Nested Class Summary
(package private) static class ActionTrigger.CommandTrigger
          Trigger implementation for using KeyBindingManager as trigger.
 
Field Summary
protected  InputActionInterface action
           
protected  boolean allowRepeats
           
protected  InputHandler inputHandler
           
protected  java.lang.String name
           
 
Constructor Summary
protected ActionTrigger(InputHandler inputHandler, java.lang.String triggerName, InputActionInterface action, boolean allowRepeats)
          Create a new action trigger for a fixed input handler.
 
Method Summary
protected  void activate()
          add this trigger to the list of active trigger in the InputHandler.
abstract  void checkActivation(char character, int index, float position, float delta, boolean pressed, java.lang.Object data)
          Invoked to activate or deactivate a trigger on specific event.
protected  void deactivate()
          remove this trigger from the list of active trigger in the InputHandler.
protected  int getActionInvocationCount()
           
protected abstract  java.lang.String getDeviceName()
           
(package private)  ActionTrigger getNext()
          Used to maintain a linked list of active triggers.
(package private)  ActionTrigger getPrevious()
           
 boolean isActive()
           
 void performAction(InputActionEvent event)
          Perform the action and deactivate the trigger if it does not allow repeats.
protected  void putTriggerInfo(InputActionEvent event, int invocationIndex)
          Called by InputHandler to fill info about the trigger into an event.
protected  void remove()
          Remove this trigger.
(package private)  boolean setNext(ActionTrigger value)
          Used to maintain a linked list of active triggers.
(package private)  boolean setPrevious(ActionTrigger value)
          Used to maintain a linked list of active triggers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputHandler

protected final InputHandler inputHandler

name

protected final java.lang.String name

allowRepeats

protected final boolean allowRepeats

action

protected final InputActionInterface action
Constructor Detail

ActionTrigger

protected ActionTrigger(InputHandler inputHandler,
                        java.lang.String triggerName,
                        InputActionInterface action,
                        boolean allowRepeats)
Create a new action trigger for a fixed input handler.

Parameters:
inputHandler - handler this trigger belongs to (cannot be changed)
triggerName - name of this trigger (usually a button or axis name)
action - action that is performed by this trigger
allowRepeats - true to allow multiple action invocations per event
Method Detail

remove

protected void remove()
Remove this trigger.


checkActivation

public abstract void checkActivation(char character,
                                     int index,
                                     float position,
                                     float delta,
                                     boolean pressed,
                                     java.lang.Object data)
Invoked to activate or deactivate a trigger on specific event. The data in the parameters depend on the kind of trigger. Defaults for each parameter (set if value for parameter is unknown or not applicable) are given below. The trigger should activate or deactivate itself if appropriate.

Parameters:
character - some character data associated with the event, default '\0'.
example: keyboard character
index - index of the device part that caused the event, default -1, >= 0 if valid
example: mouse button index, joystick axis index
position - new position of the device part that caused the event, default NaN, common range [-1;1]
example: joystick axis position
delta - position delta of the device part that caused the event, default NaN, common range [-1;1]
example: joystick axis delta
pressed - indicates if a button was pressed or released, default: false
example: true if joystick button is pressed, false if joystick button is released
data - any trigger specific data
example: joystick triggers get the Joystick instance for fast comparison
See Also:
activate(), deactivate()

putTriggerInfo

protected void putTriggerInfo(InputActionEvent event,
                              int invocationIndex)
Called by InputHandler to fill info about the trigger into an event. Commonly overwritten by trigger implementations to provide additional info.

Parameters:
event - where to put the information
invocationIndex - index to distinct multiple action invocations per trigger activation
See Also:
getActionInvocationCount()

getDeviceName

protected abstract java.lang.String getDeviceName()
Returns:
name of the device this trigger belongs to

activate

protected final void activate()
add this trigger to the list of active trigger in the InputHandler.


deactivate

protected final void deactivate()
remove this trigger from the list of active trigger in the InputHandler.


getNext

ActionTrigger getNext()
Used to maintain a linked list of active triggers.

Returns:
current value of the field next

setNext

boolean setNext(ActionTrigger value)
Used to maintain a linked list of active triggers.

Parameters:
value - new value for field next
Returns:
true if next was changed

getPrevious

ActionTrigger getPrevious()
Returns:
current value of the field previous

setPrevious

boolean setPrevious(ActionTrigger value)
Used to maintain a linked list of active triggers.

Parameters:
value - new value for field previous
Returns:
true if previous was changed

getActionInvocationCount

protected int getActionInvocationCount()
Returns:
the number of times the action should be invoked if triggered

performAction

public void performAction(InputActionEvent event)
Perform the action and deactivate the trigger if it does not allow repeats.

Parameters:
event - info about the event that caused the action

isActive

public final boolean isActive()
Returns:
true if the trigger was activated
See Also:
ActionTrigger