public class JoystickMonitor
extends java.lang.Object
JoystickMonitor
is an object that attaches to a specific joystick object,
and monitors any changes in the joystick inputs. Any detected changes are forwarded
to the objects that are listening to the specific joystick.
Objects that should listen to the joysticks should register themselves with the
appropriate JoystickMonitor
.
Modifier and Type | Class and Description |
---|---|
private class |
JoystickMonitor.MonitorUpdateRunnable
The
MonitorUpdateRunnable class is run through the task scheduler, and
is used to continuously check the joystick for any changes. |
Modifier and Type | Field and Description |
---|---|
private java.util.Map<JoystickButton,java.util.List<java.lang.reflect.Method>> |
handlers
The
Methods that are called when buttons specified in the
ButtonHandler annotation are updated. |
private java.util.Map<java.lang.reflect.Method,JoystickListener> |
instances
The map of all the appropriate methods to the specific objects that
contain them.
|
private int |
joystick
The joystick to monitor.
|
private java.util.List<JoystickButton> |
lastButtons
The latest 'snapshot' of the buttons on the gamepad.
|
Constructor and Description |
---|
JoystickMonitor(int joystick)
Constructs a new JoystickMonitor that should monitor the given joystick.
|
Modifier and Type | Method and Description |
---|---|
private void |
fillHandlerMap()
Populates the maip of button handlers with an entry for every joystick button.
|
private void |
invokeListenerMethod(java.lang.reflect.Method method,
java.lang.Object instance)
Invokes the given method on the given instance, and catches all exceptions.
|
void |
registerJoystickListener(JoystickListener listener)
Registers the given joystick listener so that joystick updates can be sent
to it.
|
private void |
runHandlers()
Checks for updates in the joystick, and forwards those updates to all the
registered joystick listeners.
|
private int joystick
private java.util.Map<JoystickButton,java.util.List<java.lang.reflect.Method>> handlers
Methods
that are called when buttons specified in the
ButtonHandler
annotation are updated.private java.util.Map<java.lang.reflect.Method,JoystickListener> instances
private java.util.List<JoystickButton> lastButtons
public JoystickMonitor(int joystick)
joystick
- the joystick to monitor.public void registerJoystickListener(JoystickListener listener)
private void runHandlers()
private void invokeListenerMethod(java.lang.reflect.Method method, java.lang.Object instance)
method
- the method to call.instance
- the instance to call the method on.private void fillHandlerMap()