org.jagatoo.input.devices
Class Controller

java.lang.Object
  extended by org.jagatoo.input.devices.InputDevice
      extended by org.jagatoo.input.devices.Controller
All Implemented Interfaces:
Enableable
Direct Known Subclasses:
JInputController, LWJGLController

public abstract class Controller
extends InputDevice

This is the base-class for all Controller implementations.
Applications should always use instances as Controller, but never cast them to the concrete implementation.
Instances can only be created/retrieved through an InputDeviceFactory.


Constructor Summary
protected Controller(ControllerFactory sourceFactory, InputSourceWindow sourceWindow, EventQueue eventQueue, java.lang.String name, java.lang.Object implObj)
           
 
Method Summary
 void addControllerListener(ControllerListener l)
          Adds a new ControllerListener to the list of notified instances.
protected abstract  ControllerAxis[] createAxesArray(java.lang.Object implObj)
           
protected abstract  ControllerButton[] createButtonsArray(java.lang.Object implObj)
           
 void destroy()
          Destroys the InputDevice.
protected abstract  void destroyImpl()
          Destroys the Controller.
 void fireControllerEvent(ControllerEvent e, boolean consumeEvent)
          This method just forwards to the concrete fire* methods.
 void fireOnControllerAxisChanged(ControllerAxisChangedEvent e, boolean consumeEvent)
          Fires a ControllerAxisChangedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnControllerButtonPressed(ControllerButtonPressedEvent e, boolean consumeEvent)
          Fires a ControllerButtonPressedEvent and pushes it back to the pool, if consumeEvent is true.
 void fireOnControllerButtonReleased(ControllerButtonReleasedEvent e, boolean consumeEvent)
          Fires a ControllerButtonReleasedEvent and pushes it back to the pool, if consumeEvent is true.
 int getAxesCount()
           
 ControllerAxis getAxis(int index)
           
 ControllerButton getButton(int index)
           
 int getButtonsCount()
           
 int getButtonState(ControllerButton button)
           
 ControllerFactory getSourceFactory()
           
 int getState(DeviceComponent component)
          This method returns an abstract input-state for the given DeviceComponent.
 boolean hasControllerListener()
           
 boolean hasListener()
           
 boolean isButtonPressed(ControllerButton button)
           
 ControllerAxisChangedEvent prepareControllerAxisChanged(ControllerAxis axis, float delta, long when)
          Prepares a ControllerAxisChangedEvent for being fired.
protected  ControllerButtonPressedEvent prepareControllerButtonPressed(ControllerButton button, long when)
          Prepares a ControllerButtonPressedEvent for being fired.
 ControllerButtonReleasedEvent prepareControllerButtonReleased(ControllerButton button, long when)
          Prepares a ControllerButtonReleasedEvent for being fired.
 void removeControllerListener(ControllerListener l)
          Removes a ControllerListener from the list of notified instances.
 java.lang.String toString()
          
 
Methods inherited from class org.jagatoo.input.devices.InputDevice
addInputStateListener, collectEvents, consumePendingEvents, equals, fireStateEventsAndDoActions, getEventQueue, getName, getSourceWindow, hasInputStateListener, isEnabled, onDeviceRegistered, onDeviceUnregistered, removeInputStateListener, setEnabled, update
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Controller

protected Controller(ControllerFactory sourceFactory,
                     InputSourceWindow sourceWindow,
                     EventQueue eventQueue,
                     java.lang.String name,
                     java.lang.Object implObj)
              throws InputSystemException
Throws:
InputSystemException
Method Detail

getSourceFactory

public final ControllerFactory getSourceFactory()
Returns:
the ControllerFactory, that created this instance.

getAxesCount

public final int getAxesCount()
Returns:
the number of ControllerAxis mounted to this Controller.

getAxis

public final ControllerAxis getAxis(int index)
Parameters:
index -
Returns:
the index'th ControllerAxis.

getButtonsCount

public final int getButtonsCount()
Returns:
the number of ControllerButtons mounted to this Controller.

getButton

public final ControllerButton getButton(int index)
Parameters:
index -
Returns:
the index'th ControllerButton.

getState

public int getState(DeviceComponent component)
             throws InputSystemRuntimeException
This method returns an abstract input-state for the given DeviceComponent. Note, that only supported components are accepted.

Specified by:
getState in class InputDevice
Returns:
the current state of the given component on this device.
Throws:
InputSystemRuntimeException

hasControllerListener

public final boolean hasControllerListener()
Returns:
true, of at least one ControllerListener is currently registered.

hasListener

public final boolean hasListener()
Returns:
true, if one of InputDevice.hasInputStateListener() or hasControllerListener() return true.

addControllerListener

public void addControllerListener(ControllerListener l)
Adds a new ControllerListener to the list of notified instances.

Parameters:
l -

removeControllerListener

public void removeControllerListener(ControllerListener l)
Removes a ControllerListener from the list of notified instances.

Parameters:
l -

isButtonPressed

public final boolean isButtonPressed(ControllerButton button)
Parameters:
button -
Returns:
true, if the queried ControllerButton is pressed on this Controller.

getButtonState

public final int getButtonState(ControllerButton button)
Parameters:
button -
Returns:
the current state-mask for this Controller's buttons.

prepareControllerButtonPressed

protected final ControllerButtonPressedEvent prepareControllerButtonPressed(ControllerButton button,
                                                                            long when)
Prepares a ControllerButtonPressedEvent for being fired.
The event is not fired from this method.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnControllerButtonPressed

public final void fireOnControllerButtonPressed(ControllerButtonPressedEvent e,
                                                boolean consumeEvent)
Fires a ControllerButtonPressedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

prepareControllerButtonReleased

public final ControllerButtonReleasedEvent prepareControllerButtonReleased(ControllerButton button,
                                                                           long when)
Prepares a ControllerButtonReleasedEvent for being fired.
The event is not fired from this method.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnControllerButtonReleased

public final void fireOnControllerButtonReleased(ControllerButtonReleasedEvent e,
                                                 boolean consumeEvent)
Fires a ControllerButtonReleasedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

prepareControllerAxisChanged

public final ControllerAxisChangedEvent prepareControllerAxisChanged(ControllerAxis axis,
                                                                     float delta,
                                                                     long when)
Prepares a ControllerAxisChangedEvent for being fired.
The event is not fired from this method.

Parameters:
button -
when -
Returns:
the new event from the pool or null, if no events are currently accepted.

fireOnControllerAxisChanged

public final void fireOnControllerAxisChanged(ControllerAxisChangedEvent e,
                                              boolean consumeEvent)
Fires a ControllerAxisChangedEvent and pushes it back to the pool, if consumeEvent is true.

Parameters:
e -
consumeEvent -

fireControllerEvent

public final void fireControllerEvent(ControllerEvent e,
                                      boolean consumeEvent)
This method just forwards to the concrete fire* methods.

Parameters:
e -
consumeEvent -

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

destroyImpl

protected abstract void destroyImpl()
                             throws InputSystemException
Destroys the Controller.

Throws:
InputSystemException

destroy

public final void destroy()
                   throws InputSystemException
Destroys the InputDevice. This must be called when the InputDevice is unregistered.

Specified by:
destroy in class InputDevice
Throws:
InputSystemException

createAxesArray

protected abstract ControllerAxis[] createAxesArray(java.lang.Object implObj)

createButtonsArray

protected abstract ControllerButton[] createButtonsArray(java.lang.Object implObj)