com.jme.input.joystick
Class JoystickInput

java.lang.Object
  extended by com.jme.input.Input
      extended by com.jme.input.joystick.JoystickInput
Direct Known Subclasses:
DummyJoystickInput, LWJGLJoystickInput

public abstract class JoystickInput
extends Input

Manager for attached Joysticks. Singleton - use the get() method. Joysticks can be polled by calling Input.update().

Author:
Matthew D. Hicks, Irrisor

Field Summary
static java.lang.String INPUT_DUMMY
           
static java.lang.String INPUT_LWJGL
           
protected  java.util.ArrayList<JoystickInputListener> listeners
          list of event listeners.
 
Constructor Summary
protected JoystickInput()
          Protect contructor to avoid direct invocation.
 
Method Summary
 void addListener(JoystickInputListener listener)
          Subscribe a listener to receive joystick events.
protected abstract  void destroy()
           
static void destroyIfInitalized()
          Destroy the input if it was initialized.
abstract  java.util.ArrayList<Joystick> findJoysticksByAxis(java.lang.String... axis)
          Locate and return a joystick with the given axis names.
static JoystickInput get()
          Initialize (if needed) and return the JoystickInput.
abstract  Joystick getDefaultJoystick()
          This is a method to obtain a single joystick.
abstract  Joystick getJoystick(int index)
          Game controller at specified index.
abstract  int getJoystickCount()
           
static java.lang.Class<?> getProvider()
          Query current provider for input.
 void removeListener(JoystickInputListener listener)
          Unsubscribe a listener.
 void removeListeners()
          Remove all listeners and disable event generation.
static void setProvider(java.lang.Class value)
          Change the provider used for joystick input.
static void setProvider(java.lang.String value)
          Change the provider used for joystick input.
 
Methods inherited from class com.jme.input.Input
update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INPUT_LWJGL

public static final java.lang.String INPUT_LWJGL

INPUT_DUMMY

public static final java.lang.String INPUT_DUMMY

listeners

protected java.util.ArrayList<JoystickInputListener> listeners
list of event listeners.

Constructor Detail

JoystickInput

protected JoystickInput()
Protect contructor to avoid direct invocation.

Method Detail

get

public static JoystickInput get()
Initialize (if needed) and return the JoystickInput. Implementation is determined by querying getProvider().
Joystick support is disabled by default - call setProvider(String) before creating the display system to enable it (and choose implementation).

Returns:
the only instance of the joystick manager

getProvider

public static java.lang.Class<?> getProvider()
Query current provider for input.

Returns:
currently selected provider

setProvider

public static void setProvider(java.lang.String value)
Change the provider used for joystick input. Default is INPUT_LWJGL.

Parameters:
value - new provider class name
Throws:
java.lang.IllegalStateException - if called after first call of get(). Note that get is called when creating the DisplaySystem.
java.lang.IllegalArgumentException - if the specified class cannot be found using Class.forName(String)

setProvider

public static void setProvider(java.lang.Class value)
Change the provider used for joystick input. Default is InputSystem.INPUT_SYSTEM_LWJGL.

Parameters:
value - new provider
Throws:
java.lang.IllegalStateException - if called after first call of get(). Note that get is called when creating the DisplaySystem.

addListener

public void addListener(JoystickInputListener listener)
Subscribe a listener to receive joystick events. Enable event generation.

Parameters:
listener - to be subscribed

removeListener

public void removeListener(JoystickInputListener listener)
Unsubscribe a listener. Disable event generation if no more listeners.

Parameters:
listener - to be unsuscribed
See Also:
addListener(JoystickInputListener)

removeListeners

public void removeListeners()
Remove all listeners and disable event generation.


getJoystickCount

public abstract int getJoystickCount()
Returns:
number of attached game controllers

getJoystick

public abstract Joystick getJoystick(int index)
Game controller at specified index.

Parameters:
index - index of the controller (0 <= index <= getJoystickCount())
Returns:
game controller

getDefaultJoystick

public abstract Joystick getDefaultJoystick()
This is a method to obtain a single joystick. It's simple to used but not recommended (user may have multiple joysticks!).

Returns:
what the implementation thinks is the main joystick, not null!

destroyIfInitalized

public static void destroyIfInitalized()
Destroy the input if it was initialized.


destroy

protected abstract void destroy()

findJoysticksByAxis

public abstract java.util.ArrayList<Joystick> findJoysticksByAxis(java.lang.String... axis)
Locate and return a joystick with the given axis names.

Parameters:
axis - 1 or more names to look by
Returns:
array of joysticks, each having axis to match every name (case insensitive)