org.jagatoo.input
Class InputSystem

java.lang.Object
  extended by org.jagatoo.input.InputSystem

public class InputSystem
extends java.lang.Object

The InputSystem is the root starting point for all input related tasks. You can use it as a singleton by using the getInstance() method to retrieve an instance.
The InputSystem allows for registering InputDevices and appropriate listeners/managers.


Field Summary
static LogChannel LOG_CHANNEL
           
 
Constructor Summary
InputSystem()
          Creates a new InputSystem instance.
 
Method Summary
 void addInputHandler(InputHandler<?> inputHandler)
          Adds an InputHandler to be updated automatically.
 void addInputListener(InputListener l)
          Adds an InputListener.
 void addInputStateListener(InputStateListener l)
          Adds an InputStateListener.
protected  void collectControllerEvents(EventQueue eventQueue, long nanoTime)
           
 void collectEvents(long nanoTime)
          Processes pending events from the system and places them into the EventQueue.
protected  void collectKeyboardEvents(long nanoTime)
           
protected  void collectMouseEvents(long nanoTime)
           
 void deregisterController(Controller controller)
          Deregisters the given Controller from this InputSystem.
 void deregisterInputStatesManager(InputStatesManager mgr)
          Deregisters an InputStatesManager.
 void deregisterKeyboard(Keyboard keyboard)
          Deregisters the given Keyboard from this InputSystem and calls the destroy() method.
 void deregisterMouse(Mouse mouse)
          Deregisters the given Mouse from this InputSystem.
 void destroy()
          Destroys the InputSystem.
 void destroy(ControllerFactory deviceFactory)
          Destroys all Controllers from the given factory.
 void destroy(InputDeviceFactory deviceFactory)
          Destroys all InputDevices from the given factory.
 void destroy(InputSourceWindow sourceWindow)
          Destroys all InputDevices from the InputDeviceFactory, that is retrieved from the given InputSourceWindow.
 void destroy(KeyboardFactory deviceFactory)
          Destroys all Keyboards from the given factory.
 void destroy(MouseFactory deviceFactory)
          Destroys all Mouses from the given factory.
 Controller getController()
           
 Controller getController(int index)
           
 Controller[] getControllers()
           
 int getControllersCount()
           
 EventQueue getEventQueue()
           
static InputSystem getInstance()
           
 Keyboard getKeyboard()
           
 Keyboard getKeyboard(int index)
           
 Keyboard[] getKeyboards()
           
 int getKeyboardsCount()
           
 Mouse getMouse()
           
 Mouse getMouse(int index)
           
 long getMouseButtonClickThreshold()
           
 Mouse[] getMouses()
           
 int getMousesCount()
           
 boolean hasController()
           
static boolean hasInstance()
           
 boolean hasKeyboard()
           
 boolean hasMouse()
           
 boolean isControllerRegistered(Controller controller)
          Checks, wether the given Controller is already registered at this InputSystem.
 boolean isKeyboardRegistered(Keyboard keyboard)
          Checks, wether the given Keyboard is already registered at this InputSystem.
 boolean isMouseRegistered(Mouse mouse)
          Checks, wether the given Mouse is already registered at this InputSystem.
 void notifyInputStatesManagers(InputDevice device, DeviceComponent comp, int state, int delta, long nanoTime)
          Notifies all registered InputStateManagers about a state-change.
 void registerController(Controller controller)
          Registers the given Controller at this InputSystem.
 void registerInputStatesManager(InputStatesManager mgr)
          Registers an InputStatesManager to be updated automatically.
 void registerKeyboard(Keyboard keyboard)
          Registers the given Keyboard at this InputSystem.
 void registerMouse(Mouse mouse)
          Registers the given Mouse at this InputSystem.
 Controller registerNewController(ControllerFactory factory)
          Registers a new Controller.
 Controller registerNewController(InputSourceWindow sourceWindow)
          Registers a new Controller.
 Keyboard registerNewKeyboard(InputSourceWindow sourceWindow)
          Registers a new Keyboard.
 Keyboard registerNewKeyboard(KeyboardFactory factory)
          Registers a new Keyboard.
 void registerNewKeyboardAndMouse(InputDeviceFactory factory)
          Registers a new Keyboard and Mouse.
 void registerNewKeyboardAndMouse(InputSourceWindow sourceWindow)
          Registers a new Keyboard and Mouse.
 Mouse registerNewMouse(InputSourceWindow sourceWindow)
          Registers a new Mouse.
 Mouse registerNewMouse(MouseFactory factory)
          Registers a new Mouse.
 void removeInputHandler(InputHandler<?> inputHandler)
          Removes an InputHandler.
 void removeInputListener(InputListener l)
          Removes an InputListener from this InputSystem and all registered InputDevices.
 void removeInputStateListener(InputStateListener l)
          Removes an InputStateListener from this InputSystem and all registered InputDevices.
static void setInstance(InputSystem inputSystem)
          Sets the instance to be used as the singleton instance.
 void setMouseButtonClickThreshold(long threshold)
          Sets the threshold delay for collecting mouse-clicked-events.
 void update(long nanoTime)
          Processes pending events from the system and directly fires them (notifes the listeners).
protected  void updateControllers(EventQueue eventQueue, long nanoTime)
           
protected  void updateInputHandlers(long nanoTime)
           
protected  void updateKeyboards(long nanoTime)
           
protected  void updateMouses(long nanoTime)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_CHANNEL

public static final LogChannel LOG_CHANNEL
Constructor Detail

InputSystem

public InputSystem()
Creates a new InputSystem instance.

Method Detail

setInstance

public static final void setInstance(InputSystem inputSystem)
Sets the instance to be used as the singleton instance.

Parameters:
inputSystem -

hasInstance

public static final boolean hasInstance()
Returns:
true, if there currently is a singleton-instance.

getInstance

public static final InputSystem getInstance()
Returns:
the singleton instance. If none is currently registered, a new one is created (and returned).

getEventQueue

public final EventQueue getEventQueue()

registerInputStatesManager

public void registerInputStatesManager(InputStatesManager mgr)
Registers an InputStatesManager to be updated automatically.

Parameters:
mgr -

deregisterInputStatesManager

public void deregisterInputStatesManager(InputStatesManager mgr)
Deregisters an InputStatesManager.

Parameters:
mgr -

notifyInputStatesManagers

public final void notifyInputStatesManagers(InputDevice device,
                                            DeviceComponent comp,
                                            int state,
                                            int delta,
                                            long nanoTime)
Notifies all registered InputStateManagers about a state-change.

Parameters:
device -
comp -
state -
delta -
nanoTime -

addInputHandler

public void addInputHandler(InputHandler<?> inputHandler)
Adds an InputHandler to be updated automatically.
This method calls InputHandler.setInputSystem(InputSystem) with this InputSystem as the parameter.

Parameters:
inputHandler -

removeInputHandler

public void removeInputHandler(InputHandler<?> inputHandler)
Removes an InputHandler.
This method calls InputHandler.setInputSystem(InputSystem) with null as the parameter.

Parameters:
inputHandler -

addInputListener

public void addInputListener(InputListener l)
Adds an InputListener.
This automatically adds the listener to all registered InputDevices and also adds them to all devices, that are registered later.

Parameters:
l -

removeInputListener

public void removeInputListener(InputListener l)
Removes an InputListener from this InputSystem and all registered InputDevices.

Parameters:
l -

addInputStateListener

public void addInputStateListener(InputStateListener l)
Adds an InputStateListener.
This automatically adds the listener to all registered InputDevices and also adds them to all devices, that are registered later.

Parameters:
l -

removeInputStateListener

public void removeInputStateListener(InputStateListener l)
Removes an InputStateListener from this InputSystem and all registered InputDevices.

Parameters:
l -

registerKeyboard

public void registerKeyboard(Keyboard keyboard)
                      throws InputSystemException
Registers the given Keyboard at this InputSystem.

Parameters:
keyboard -
Throws:
InputSystemException

registerNewKeyboard

public final Keyboard registerNewKeyboard(KeyboardFactory factory)
                                   throws InputSystemException
Registers a new Keyboard.

Parameters:
factory -
Returns:
the registered Keyboard.
Throws:
InputSystemException

registerNewKeyboard

public final Keyboard registerNewKeyboard(InputSourceWindow sourceWindow)
                                   throws InputSystemException
Registers a new Keyboard.

Parameters:
sourceWindow -
Returns:
the registered Keyboard.
Throws:
InputSystemException

deregisterKeyboard

public void deregisterKeyboard(Keyboard keyboard)
                        throws InputSystemException
Deregisters the given Keyboard from this InputSystem and calls the destroy() method.

Parameters:
keyboard -
Throws:
InputSystemException

hasKeyboard

public final boolean hasKeyboard()
Returns:
true, if at least one Keyboard is currently registered.

getKeyboardsCount

public final int getKeyboardsCount()
Returns:
the number of currently registered Keyboards.

getKeyboard

public final Keyboard getKeyboard()
Returns:
the first registered Keyboard.

getKeyboard

public final Keyboard getKeyboard(int index)
Parameters:
index -
Returns:
the i-th registered Keyboard.

getKeyboards

public final Keyboard[] getKeyboards()
Returns:
an array of all registered Keyboards in this InputSystem.

isKeyboardRegistered

public final boolean isKeyboardRegistered(Keyboard keyboard)
Checks, wether the given Keyboard is already registered at this InputSystem.

Parameters:
keyboard -
Returns:
true, if the Keyboard is registered.

setMouseButtonClickThreshold

public void setMouseButtonClickThreshold(long threshold)
Sets the threshold delay for collecting mouse-clicked-events.

Parameters:
threshold - in nano-seconds

getMouseButtonClickThreshold

public final long getMouseButtonClickThreshold()
Returns:
the threshold delay for collecting mouse-clicked-events in nano-seconds.

registerMouse

public void registerMouse(Mouse mouse)
                   throws InputSystemException
Registers the given Mouse at this InputSystem.

Parameters:
mouse -
Throws:
InputSystemException

registerNewMouse

public final Mouse registerNewMouse(MouseFactory factory)
                             throws InputSystemException
Registers a new Mouse.

Parameters:
factory -
Returns:
the registered Mouse.
Throws:
InputSystemException

registerNewMouse

public final Mouse registerNewMouse(InputSourceWindow sourceWindow)
                             throws InputSystemException
Registers a new Mouse.

Parameters:
sourceWindow -
Returns:
the registered Mouse.
Throws:
InputSystemException

deregisterMouse

public void deregisterMouse(Mouse mouse)
                     throws InputSystemException
Deregisters the given Mouse from this InputSystem.

Parameters:
mouse -
Throws:
InputSystemException

hasMouse

public final boolean hasMouse()
Returns:
true, if at least one Mouse is currently registered at this InputSystem.

getMousesCount

public final int getMousesCount()
Returns:
the number of currently registered Mouses.

getMouse

public final Mouse getMouse()
Returns:
the first registered Mouse.

getMouse

public final Mouse getMouse(int index)
Parameters:
index -
Returns:
the i-th registered Mouse.

getMouses

public final Mouse[] getMouses()
Returns:
an array of all currently registered Mouses.

isMouseRegistered

public final boolean isMouseRegistered(Mouse mouse)
Checks, wether the given Mouse is already registered at this InputSystem.

Parameters:
mouse -
Returns:
true, if the Mouse is registered.

registerNewKeyboardAndMouse

public final void registerNewKeyboardAndMouse(InputDeviceFactory factory)
                                       throws InputSystemException
Registers a new Keyboard and Mouse.

Parameters:
factory -
Throws:
InputSystemException

registerNewKeyboardAndMouse

public final void registerNewKeyboardAndMouse(InputSourceWindow sourceWindow)
                                       throws InputSystemException
Registers a new Keyboard and Mouse.

Parameters:
sourceWindow -
Throws:
InputSystemException

registerController

public void registerController(Controller controller)
                        throws InputSystemException
Registers the given Controller at this InputSystem.

Parameters:
controller -
Throws:
InputSystemException

registerNewController

public final Controller registerNewController(ControllerFactory factory)
                                       throws InputSystemException
Registers a new Controller.

Parameters:
factory -
Returns:
the registered Controller.
Throws:
InputSystemException

registerNewController

public final Controller registerNewController(InputSourceWindow sourceWindow)
                                       throws InputSystemException
Registers a new Controller.

Parameters:
sourceWindow -
Returns:
the registered Controller.
Throws:
InputSystemException

deregisterController

public void deregisterController(Controller controller)
                          throws InputSystemException
Deregisters the given Controller from this InputSystem.

Parameters:
controller -
Throws:
InputSystemException

hasController

public final boolean hasController()
Returns:
true, if at least one Controller is currently registered.

getControllersCount

public final int getControllersCount()
Returns:
the number of currently registered Controllers.

getController

public final Controller getController()
Returns:
the first registered Controller.

getController

public final Controller getController(int index)
Parameters:
index -
Returns:
the i-th registered Controller.

getControllers

public final Controller[] getControllers()
Returns:
an array of all currently registered Controllers.

isControllerRegistered

public final boolean isControllerRegistered(Controller controller)
Checks, wether the given Controller is already registered at this InputSystem.

Parameters:
controller -
Returns:
true, if the Controller is registered.

collectKeyboardEvents

protected void collectKeyboardEvents(long nanoTime)
                              throws InputSystemException
Throws:
InputSystemException

collectMouseEvents

protected void collectMouseEvents(long nanoTime)
                           throws InputSystemException
Throws:
InputSystemException

collectControllerEvents

protected void collectControllerEvents(EventQueue eventQueue,
                                       long nanoTime)
                                throws InputSystemException
Throws:
InputSystemException

collectEvents

public void collectEvents(long nanoTime)
                   throws InputSystemException
Processes pending events from the system and places them into the EventQueue.
The events are not fired (listeners are not notified). They are fired when the #update(InputSystem, EventQueue, long) method is invoked.

Parameters:
nanoTime -
Throws:
InputSystemException

updateKeyboards

protected void updateKeyboards(long nanoTime)
                        throws InputSystemException
Throws:
InputSystemException

updateMouses

protected void updateMouses(long nanoTime)
                     throws InputSystemException
Throws:
InputSystemException

updateControllers

protected void updateControllers(EventQueue eventQueue,
                                 long nanoTime)
                          throws InputSystemException
Throws:
InputSystemException

updateInputHandlers

protected void updateInputHandlers(long nanoTime)
                            throws InputSystemException
Throws:
InputSystemException

update

public void update(long nanoTime)
            throws InputSystemException
Processes pending events from the system and directly fires them (notifes the listeners).
This method also flushes the EventQueue, if the previously called #collectEvents(InputSystem, EventQueue, long) method placed events into it.

Parameters:
nanoTime -
Throws:
InputSystemException

destroy

public void destroy()
             throws InputSystemException
Destroys the InputSystem.
This first deregisters all currently registered InputDevices.

Throws:
InputSystemException

destroy

public void destroy(KeyboardFactory deviceFactory)
             throws InputSystemException
Destroys all Keyboards from the given factory.

Parameters:
deviceFactory -
Throws:
InputSystemException

destroy

public void destroy(MouseFactory deviceFactory)
             throws InputSystemException
Destroys all Mouses from the given factory.

Parameters:
deviceFactory -
Throws:
InputSystemException

destroy

public void destroy(ControllerFactory deviceFactory)
             throws InputSystemException
Destroys all Controllers from the given factory.

Parameters:
deviceFactory -
Throws:
InputSystemException

destroy

public void destroy(InputDeviceFactory deviceFactory)
             throws InputSystemException
Destroys all InputDevices from the given factory.

Parameters:
deviceFactory -
Throws:
InputSystemException

destroy

public final void destroy(InputSourceWindow sourceWindow)
                   throws InputSystemException
Destroys all InputDevices from the InputDeviceFactory, that is retrieved from the given InputSourceWindow.

Parameters:
sourceWindow -
Throws:
InputSystemException