JXInput verder geimplementeerd compleet met listeners. Het werkt nog niet helemaal.
This commit is contained in:
@@ -8,13 +8,11 @@ import pm.action.Action;
|
|||||||
import pm.application.Application;
|
import pm.application.Application;
|
||||||
import pm.application.voorbeeld.VoorbeeldApplication;
|
import pm.application.voorbeeld.VoorbeeldApplication;
|
||||||
import pm.device.Device;
|
import pm.device.Device;
|
||||||
import pm.device.JavaInputDevice;
|
|
||||||
import pm.device.example.ExampleDevice;
|
import pm.device.example.ExampleDevice;
|
||||||
import pm.device.rumblepad.RumblepadDevice;
|
import pm.device.rumblepad.RumblepadDevice;
|
||||||
import pm.exception.ActionException;
|
import pm.exception.ActionException;
|
||||||
import pm.exception.ActionNotImplementedException;
|
import pm.exception.ActionNotImplementedException;
|
||||||
import pm.exception.EventException;
|
import pm.exception.EventException;
|
||||||
import pm.service.javainput.JavaInputService;
|
|
||||||
|
|
||||||
public class Main extends Target {
|
public class Main extends Target {
|
||||||
protected static final int SLEEP = 100;
|
protected static final int SLEEP = 100;
|
||||||
@@ -31,8 +29,8 @@ public class Main extends Target {
|
|||||||
//applicationList.iterator();
|
//applicationList.iterator();
|
||||||
deviceList = new ArrayList<Device>();
|
deviceList = new ArrayList<Device>();
|
||||||
actionQueue = new ConcurrentLinkedQueue<Action>();
|
actionQueue = new ConcurrentLinkedQueue<Action>();
|
||||||
JavaInputService.initialize();
|
//JavaInputService.initialize();
|
||||||
//JXInputDevice.jxinputService = new JXInputService();
|
Device.initialise(actionQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addApplication(Application application) {
|
public void addApplication(Application application) {
|
||||||
@@ -52,16 +50,17 @@ public class Main extends Target {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
Device device = new ExampleDevice(actionQueue);
|
addDevice(new ExampleDevice());
|
||||||
//addDevice(device);
|
addDevice(new RumblepadDevice());
|
||||||
|
|
||||||
device = new RumblepadDevice(actionQueue);
|
|
||||||
|
|
||||||
addDevice(device);
|
|
||||||
device.initialise();
|
|
||||||
Application application = new VoorbeeldApplication();
|
Application application = new VoorbeeldApplication();
|
||||||
addApplication(application);
|
addApplication(application);
|
||||||
currentApplication = application;
|
currentApplication = application;
|
||||||
|
|
||||||
|
for (Device device : deviceList) {
|
||||||
|
device.start();
|
||||||
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +96,10 @@ public class Main extends Target {
|
|||||||
|
|
||||||
public void exit() {
|
public void exit() {
|
||||||
run = false;
|
run = false;
|
||||||
|
for (Device device : deviceList) {
|
||||||
|
device.exit();
|
||||||
|
}
|
||||||
|
System.out.println("Als ie nu niet uit gaat, dan hebben we een verstekeling! Dat is vervelend ende naar!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -7,16 +7,17 @@ import pm.event.Target;
|
|||||||
|
|
||||||
|
|
||||||
public abstract class Device {
|
public abstract class Device {
|
||||||
protected Queue<Action> actionQueue;
|
protected static Queue<Action> actionQueue;
|
||||||
|
|
||||||
public Device(Queue<Action> actionQueue) {
|
|
||||||
this.actionQueue = actionQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAction(Action action, Target target) {
|
public void addAction(Action action, Target target) {
|
||||||
action.setTarget(target);
|
action.setTarget(target);
|
||||||
actionQueue.add(action);
|
actionQueue.add(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void initialise();
|
public static void initialise(Queue<Action> actionQueue) {
|
||||||
|
Device.actionQueue = actionQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void start();
|
||||||
|
public abstract void exit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,117 @@
|
|||||||
package pm.device;
|
package pm.device;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import de.hardcode.jxinput.Axis;
|
||||||
|
import de.hardcode.jxinput.Button;
|
||||||
|
import de.hardcode.jxinput.Directional;
|
||||||
import de.hardcode.jxinput.JXInputDevice;
|
import de.hardcode.jxinput.JXInputDevice;
|
||||||
|
import de.hardcode.jxinput.JXInputManager;
|
||||||
|
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||||
|
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||||
|
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||||
|
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||||
|
|
||||||
import pm.action.Action;
|
import pm.exception.ServiceJavaInputDeviceNotFoundException;
|
||||||
import pm.exception.ServiceJavaInputException;
|
import pm.exception.ServiceJavaInputException;
|
||||||
import pm.service.javainput.JavaInputService;
|
|
||||||
|
|
||||||
public abstract class JavaInputDevice extends Device {
|
public abstract class JavaInputDevice extends Device {
|
||||||
|
protected static int SLEEP = 100;
|
||||||
|
|
||||||
public static JavaInputService jxinputService;
|
public boolean run = true;
|
||||||
|
|
||||||
protected JavaInputDevice(Queue<Action> actionQueue, String name) throws ServiceJavaInputException {
|
public JavaInputListener javaInputListener;
|
||||||
super(actionQueue);
|
public Queue<JXInputAxisEvent> axisEventQueue;
|
||||||
if (jxinputService == null) {
|
public Queue<JXInputButtonEvent> buttonEventQueue;
|
||||||
|
public Queue<JXInputDirectionalEvent> directionalEventQueue;
|
||||||
|
//public static JavaInputService jxinputService;
|
||||||
|
|
||||||
|
protected JXInputDevice jxinputDevice;
|
||||||
|
|
||||||
|
protected JavaInputDevice(String name) throws ServiceJavaInputException {
|
||||||
|
axisEventQueue = new LinkedList<JXInputAxisEvent>();
|
||||||
|
buttonEventQueue = new LinkedList<JXInputButtonEvent>();
|
||||||
|
directionalEventQueue = new LinkedList<JXInputDirectionalEvent>();
|
||||||
|
javaInputListener = new JavaInputListener(axisEventQueue, buttonEventQueue, directionalEventQueue);
|
||||||
|
|
||||||
|
/*if (jxinputService == null) {
|
||||||
throw new ServiceJavaInputException();
|
throw new ServiceJavaInputException();
|
||||||
}
|
}*/
|
||||||
JXInputDevice x = jxinputService.getDevice(name);
|
//JXInputDevice x = jxinputService.getDevice(name);
|
||||||
System.out.printf("Initialized: %s\n", x.getName());
|
jxinputDevice = getDevice(name);
|
||||||
|
System.out.printf("Initialized: %s\n", jxinputDevice.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialise() {
|
public static JXInputDevice getDevice(String name) throws ServiceJavaInputException {
|
||||||
|
int numberOfDevices = JXInputManager.getNumberOfDevices();
|
||||||
|
for (int i = 0; i < numberOfDevices; ++i) {
|
||||||
|
JXInputDevice device = JXInputManager.getJXInputDevice(i);
|
||||||
|
if (device.getName().startsWith(name)) {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new ServiceJavaInputDeviceNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
startListeners();
|
||||||
|
while (run) {
|
||||||
|
boolean sleep = true;
|
||||||
|
if (!axisEventQueue.isEmpty()) {
|
||||||
|
processEvent(axisEventQueue.poll());
|
||||||
|
sleep = false;
|
||||||
|
}
|
||||||
|
if (!buttonEventQueue.isEmpty()) {
|
||||||
|
processEvent(buttonEventQueue.poll());
|
||||||
|
sleep = false;
|
||||||
|
}
|
||||||
|
if (!directionalEventQueue.isEmpty()) {
|
||||||
|
processEvent(directionalEventQueue.poll());
|
||||||
|
sleep = false;
|
||||||
|
}
|
||||||
|
if (sleep) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(SLEEP);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void processEvent(JXInputAxisEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void processEvent(JXInputButtonEvent event) {
|
||||||
|
System.out.println(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void processEvent(JXInputDirectionalEvent event) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startListeners() {
|
||||||
|
for (int i = 0; i < jxinputDevice.getMaxNumberOfAxes(); ++i) {
|
||||||
|
Axis axis = jxinputDevice.getAxis(i);
|
||||||
|
if (axis != null) {
|
||||||
|
JXInputEventManager.addListener(javaInputListener, axis);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < jxinputDevice.getMaxNumberOfButtons(); ++i) {
|
||||||
|
Button button = jxinputDevice.getButton(i);
|
||||||
|
if (button != null) {
|
||||||
|
JXInputEventManager.addListener(javaInputListener, button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < jxinputDevice.getMaxNumberOfDirectionals(); ++i) {
|
||||||
|
Directional directional = jxinputDevice.getDirectional(i);
|
||||||
|
if (directional != null) {
|
||||||
|
JXInputEventManager.addListener(javaInputListener, directional);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exit() {
|
||||||
|
run = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
java/src/pm/device/JavaInputListener.java
Normal file
35
java/src/pm/device/JavaInputListener.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package pm.device;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||||
|
import de.hardcode.jxinput.event.JXInputAxisEventListener;
|
||||||
|
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||||
|
import de.hardcode.jxinput.event.JXInputButtonEventListener;
|
||||||
|
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||||
|
import de.hardcode.jxinput.event.JXInputDirectionalEventListener;
|
||||||
|
|
||||||
|
public class JavaInputListener implements JXInputAxisEventListener, JXInputButtonEventListener, JXInputDirectionalEventListener {
|
||||||
|
|
||||||
|
protected Queue<JXInputAxisEvent> axisEventQueue;
|
||||||
|
protected Queue<JXInputButtonEvent> buttonEventQueue;
|
||||||
|
protected Queue<JXInputDirectionalEvent> directonalEventQueue;
|
||||||
|
|
||||||
|
public JavaInputListener(Queue<JXInputAxisEvent> axisEventQueue, Queue<JXInputButtonEvent> buttonEventQueue, Queue<JXInputDirectionalEvent> directonalEventQueue) {
|
||||||
|
this.axisEventQueue = axisEventQueue;
|
||||||
|
this.buttonEventQueue = buttonEventQueue;
|
||||||
|
this.directonalEventQueue = directonalEventQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changed(JXInputAxisEvent event) {
|
||||||
|
axisEventQueue.add(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changed(JXInputButtonEvent event) {
|
||||||
|
buttonEventQueue.add(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changed(JXInputDirectionalEvent event) {
|
||||||
|
directonalEventQueue.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +1,18 @@
|
|||||||
package pm.device.example;
|
package pm.device.example;
|
||||||
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
import pm.action.Action;
|
import pm.action.Action;
|
||||||
import pm.device.Device;
|
import pm.device.Device;
|
||||||
import pm.event.Target;
|
import pm.event.Target;
|
||||||
|
|
||||||
public class ExampleDevice extends Device {
|
public class ExampleDevice extends Device {
|
||||||
public ExampleDevice(Queue<Action> actionQueue) {
|
public void start() {
|
||||||
super(actionQueue);
|
System.out.println("Ik hoef niets te starten");
|
||||||
}
|
|
||||||
|
|
||||||
public void initialise() {
|
|
||||||
addAction(Action.START, Target.APPLICATION);
|
addAction(Action.START, Target.APPLICATION);
|
||||||
addAction(Action.TEST, Target.APPLICATION);
|
addAction(Action.TEST, Target.APPLICATION);
|
||||||
addAction(Action.EXIT, Target.MAIN);
|
addAction(Action.EXIT, Target.MAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void processEvent() {
|
public void exit() {
|
||||||
/*ExampleEvent de;
|
|
||||||
if (specifiekEvent == start) {
|
|
||||||
addAction()
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package pm.device.rumblepad;
|
package pm.device.rumblepad;
|
||||||
|
|
||||||
import java.util.Queue;
|
|
||||||
|
|
||||||
import pm.action.Action;
|
|
||||||
import pm.device.JavaInputDevice;
|
import pm.device.JavaInputDevice;
|
||||||
import pm.exception.ServiceJavaInputException;
|
import pm.exception.ServiceJavaInputException;
|
||||||
|
|
||||||
@@ -10,8 +7,8 @@ public class RumblepadDevice extends JavaInputDevice {
|
|||||||
|
|
||||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||||
|
|
||||||
public RumblepadDevice(Queue<Action> actionQueue) throws ServiceJavaInputException {
|
public RumblepadDevice() throws ServiceJavaInputException {
|
||||||
super(actionQueue, NAME);
|
super(NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package pm.service.javainput;
|
|||||||
import de.hardcode.jxinput.JXInputDevice;
|
import de.hardcode.jxinput.JXInputDevice;
|
||||||
import de.hardcode.jxinput.JXInputManager;
|
import de.hardcode.jxinput.JXInputManager;
|
||||||
|
|
||||||
import pm.device.JavaInputDevice;
|
|
||||||
import pm.exception.ServiceJavaInputDeviceNotFoundException;
|
import pm.exception.ServiceJavaInputDeviceNotFoundException;
|
||||||
import pm.exception.ServiceJavaInputException;
|
import pm.exception.ServiceJavaInputException;
|
||||||
import pm.service.Service;
|
import pm.service.Service;
|
||||||
@@ -22,7 +21,7 @@ public class JavaInputService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
JavaInputDevice.jxinputService = new JavaInputService();
|
//JavaInputDevice.jxinputService = new JavaInputService();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user