com.jme.input
Class AbstractInputHandler

java.lang.Object
  extended bycom.jme.input.AbstractInputHandler
Direct Known Subclasses:
WidgetMouseTestControllerBasic, WidgetMouseTestControllerFirstPerson

public abstract class AbstractInputHandler
extends java.lang.Object

AbstractInputHandler defines a super abstract class for input controlling. It maintains a list of actions and mouse actions. These actions are then processed during every update cycle. Subclasses are required to defined to setMouse and setActions methods for custom InputControllers.

Version:
$Id: AbstractInputHandler.java,v 1.8 2004/10/22 23:17:34 renanse Exp $
Author:
Mark Powell, Gregg Patton, Jack Lindamood - (Javadoc only)

Field Summary
protected  AbstractGame app
          Optional.
protected  Camera camera
          Optional.
protected  java.util.ArrayList keyActions
          List of keyboard actions.
protected  KeyBindingManager keyboard
          The keyboard where valid key actions are taken from in update.
protected  Mouse mouse
          The mouse where valid mouse actions are taken from in update.
protected  java.util.ArrayList mouseActions
          List of mouse actions.
protected  boolean updateKeyboardActionsEnabled
          If false, keyboard actions are not done.
protected  boolean updateMouseActionsEnabled
          If false, mouse actions are not done.
 
Constructor Summary
AbstractInputHandler()
          Constructor creates a default AbstractInputHandler.
AbstractInputHandler(AbstractGame app)
          Constructor instantiates a new AbstractInputHandler defining the app that defines the application actions.
AbstractInputHandler(AbstractGame app, Camera camera)
          Constructor instantiates a new AbstractInputHandler defining the app that defines the application actions and the camera that will define viewing.
AbstractInputHandler(Camera camera)
          Constructor instantiates a new AbstractInputHandler defining the camera that defines the viewing.
 
Method Summary
 void addAction(KeyInputAction inputAction)
          Adds a keyboard input action to be polled by this handler during update.
 void addAction(MouseInputAction mouseAction)
          Adds a mouse input action to be polled by this handler during update.
 AbstractGame getApp()
          getApp returns the AbstractGame controlling this handler.
 Camera getCamera()
          getCamera returns the camera that defines the viewing for this handler.
 KeyBindingManager getKeyBindingManager()
          Returns the currently assigned keybard to receive key inputs.
 Mouse getMouse()
          Returns the mouse currently receiving inputs by this handler.
 boolean isUpdateKeyboardActionsEnabled()
          Returns if keyboard actions are performed during update.
 boolean isUpdateMouseActionsEnabled()
          Returns if mouse actions are performed during update.
 void removeAction(KeyInputAction inputAction)
          Removes a keyboard input action from the list of keyActions that are polled during update.
 void removeAction(MouseInputAction mouseAction)
          Removes a mouse input action from the list of mouseActions that are polled during update.
protected abstract  void setActions()
          Defined by subclasses, this function should set the appropriate, default keyboard actions for this handler.
 void setApp(AbstractGame game)
          setApp sets the AbstractGame controlling this handler.
 void setCamera(Camera camera)
          setCamera sets this handler's camera that will define viewing.
 void setKeyBindingManager(KeyBindingManager keyboard)
          Sets the keyboard that will receive key inputs by this handler.
protected  void setKeyBindings(RendererType rendererType)
          Sets up a keyboard to receive inputs acording to the RenderType.
 void setKeySpeed(float speed)
          Sets the speed of all key actions currently defined by this handler to the given value.
protected abstract  void setMouse()
          Defined by subclasses, this function should set the appropriate, default mouse for this handler.
 void setMouse(Mouse mouse)
          Sets the mouse to receive mouse inputs from.
 void setMouseSpeed(float speed)
          Sets the speed of all mouse actions currently defined by this handler to the given value.
 void setUpdateKeyboardActionsEnabled(boolean b)
          Keyboard actions are performed during update only if this value is true.
 void setUpdateMouseActionsEnabled(boolean b)
          Mouse actions are performed during update only if this value is true.
 void update(boolean updateMouseState, boolean updateKeyboard, float time)
          Updates and calls actions on mice and keyboard inputs.
 void update(float time)
          Equivalent to update(true,true,time)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

app

protected AbstractGame app
Optional. The game controlling this InputHandler.


camera

protected Camera camera
Optional. The camera controlled by this InputHandler.


keyActions

protected java.util.ArrayList keyActions
List of keyboard actions. They are performed in update if valid.


mouseActions

protected java.util.ArrayList mouseActions
List of mouse actions. They are performed in update.


keyboard

protected KeyBindingManager keyboard
The keyboard where valid key actions are taken from in update.


mouse

protected Mouse mouse
The mouse where valid mouse actions are taken from in update.


updateKeyboardActionsEnabled

protected boolean updateKeyboardActionsEnabled
If false, keyboard actions are not done.


updateMouseActionsEnabled

protected boolean updateMouseActionsEnabled
If false, mouse actions are not done.

Constructor Detail

AbstractInputHandler

public AbstractInputHandler()
Constructor creates a default AbstractInputHandler. It has no set AbstractGame or Camera.


AbstractInputHandler

public AbstractInputHandler(Camera camera)
Constructor instantiates a new AbstractInputHandler defining the camera that defines the viewing. The AbstractGame app is by default null.

Parameters:
camera - the camera that defines the viewport frame.

AbstractInputHandler

public AbstractInputHandler(AbstractGame app)
Constructor instantiates a new AbstractInputHandler defining the app that defines the application actions. The Camera cam is by default null.

Parameters:
app - The AbstractGame that will take application actions.

AbstractInputHandler

public AbstractInputHandler(AbstractGame app,
                            Camera camera)
Constructor instantiates a new AbstractInputHandler defining the app that defines the application actions and the camera that will define viewing.

Parameters:
app - The AbstractGame that will take application actions.
camera - The camera that defines the viewport frame.
Method Detail

getApp

public AbstractGame getApp()
getApp returns the AbstractGame controlling this handler.

Returns:
This handler's AbstractGame.

setApp

public void setApp(AbstractGame game)
setApp sets the AbstractGame controlling this handler.

Parameters:
game - The game to set.

getCamera

public Camera getCamera()
getCamera returns the camera that defines the viewing for this handler.

Returns:
This handler's camera.

setCamera

public void setCamera(Camera camera)
setCamera sets this handler's camera that will define viewing.

Parameters:
camera - The new camera.

setKeyBindingManager

public void setKeyBindingManager(KeyBindingManager keyboard)
Sets the keyboard that will receive key inputs by this handler.

Parameters:
keyboard - The keyboard to receive key inputs.

getKeyBindingManager

public KeyBindingManager getKeyBindingManager()
Returns the currently assigned keybard to receive key inputs.

Returns:
This handler's keyboard.

setMouse

public void setMouse(Mouse mouse)
Sets the mouse to receive mouse inputs from.

Parameters:
mouse - This handler's new mouse.

getMouse

public Mouse getMouse()
Returns the mouse currently receiving inputs by this handler.

Returns:
This handler's mouse.

setKeySpeed

public void setKeySpeed(float speed)
Sets the speed of all key actions currently defined by this handler to the given value.

Parameters:
speed - The new speed for all currently defined key actions.
See Also:
KeyInputAction.setSpeed(float)

setMouseSpeed

public void setMouseSpeed(float speed)
Sets the speed of all mouse actions currently defined by this handler to the given value.

Parameters:
speed - The new speed for all currently defined mouse actions.
See Also:
InputAction.setSpeed(float)

addAction

public void addAction(KeyInputAction inputAction)
Adds a keyboard input action to be polled by this handler during update.

Parameters:
inputAction - The input action to be added

addAction

public void addAction(MouseInputAction mouseAction)
Adds a mouse input action to be polled by this handler during update.

Parameters:
mouseAction - The input action to be added

removeAction

public void removeAction(KeyInputAction inputAction)
Removes a keyboard input action from the list of keyActions that are polled during update.

Parameters:
inputAction - The action to remove.

removeAction

public void removeAction(MouseInputAction mouseAction)
Removes a mouse input action from the list of mouseActions that are polled during update.

Parameters:
mouseAction - The action to remove.

update

public void update(float time)
Equivalent to update(true,true,time)

Parameters:
time - The time to pass to update.
See Also:
update(boolean, boolean, float)

update

public void update(boolean updateMouseState,
                   boolean updateKeyboard,
                   float time)
Updates and calls actions on mice and keyboard inputs. If updateKeyboard is true, the keyboard is updated for inputs. If updating of keyboard actions is enabled, all key actions that are active are performed. The same is true for mouse inputs.

Parameters:
updateMouseState - If true, the mouse state is updated.
updateKeyboard - If true, the keyboard state is updated.
time - The time value to pass to all performed actions.
See Also:
com.jme.input.action.KeyInputAction#performAction(float), com.jme.input.action.MouseInputAction#performAction(float)

setKeyBindings

protected void setKeyBindings(RendererType rendererType)
Sets up a keyboard to receive inputs acording to the RenderType.

Parameters:
rendererType - The render type to create a keyboard input from.
See Also:
setKeyBindingManager(com.jme.input.KeyBindingManager)

isUpdateKeyboardActionsEnabled

public boolean isUpdateKeyboardActionsEnabled()
Returns if keyboard actions are performed during update.

Returns:
True if update will perform keyboard actions.
See Also:
update(boolean, boolean, float)

setUpdateKeyboardActionsEnabled

public void setUpdateKeyboardActionsEnabled(boolean b)
Keyboard actions are performed during update only if this value is true.

Parameters:
b - If true, keyboard actions are performed during update.
See Also:
update(boolean, boolean, float)

isUpdateMouseActionsEnabled

public boolean isUpdateMouseActionsEnabled()
Returns if mouse actions are performed during update.

Returns:
True if update will perform mouse actions.
See Also:
update(boolean, boolean, float)

setUpdateMouseActionsEnabled

public void setUpdateMouseActionsEnabled(boolean b)
Mouse actions are performed during update only if this value is true.

Parameters:
b - If true, mouse actions are performed during update.
See Also:
update(boolean, boolean, float)

setMouse

protected abstract void setMouse()
Defined by subclasses, this function should set the appropriate, default mouse for this handler. setMouse is called after the constructor.


setActions

protected abstract void setActions()
Defined by subclasses, this function should set the appropriate, default keyboard actions for this handler. setActions is called after the constructor.