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.voorbeeld.VoorbeeldApplication;
|
||||
import pm.device.Device;
|
||||
import pm.device.JavaInputDevice;
|
||||
import pm.device.example.ExampleDevice;
|
||||
import pm.device.rumblepad.RumblepadDevice;
|
||||
import pm.exception.ActionException;
|
||||
import pm.exception.ActionNotImplementedException;
|
||||
import pm.exception.EventException;
|
||||
import pm.service.javainput.JavaInputService;
|
||||
|
||||
public class Main extends Target {
|
||||
protected static final int SLEEP = 100;
|
||||
@@ -31,8 +29,8 @@ public class Main extends Target {
|
||||
//applicationList.iterator();
|
||||
deviceList = new ArrayList<Device>();
|
||||
actionQueue = new ConcurrentLinkedQueue<Action>();
|
||||
JavaInputService.initialize();
|
||||
//JXInputDevice.jxinputService = new JXInputService();
|
||||
//JavaInputService.initialize();
|
||||
Device.initialise(actionQueue);
|
||||
}
|
||||
|
||||
public void addApplication(Application application) {
|
||||
@@ -52,16 +50,17 @@ public class Main extends Target {
|
||||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
Device device = new ExampleDevice(actionQueue);
|
||||
//addDevice(device);
|
||||
|
||||
device = new RumblepadDevice(actionQueue);
|
||||
|
||||
addDevice(device);
|
||||
device.initialise();
|
||||
addDevice(new ExampleDevice());
|
||||
addDevice(new RumblepadDevice());
|
||||
|
||||
Application application = new VoorbeeldApplication();
|
||||
addApplication(application);
|
||||
currentApplication = application;
|
||||
|
||||
for (Device device : deviceList) {
|
||||
device.start();
|
||||
}
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
@@ -97,6 +96,10 @@ public class Main extends Target {
|
||||
|
||||
public void exit() {
|
||||
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) {
|
||||
|
||||
@@ -7,16 +7,17 @@ import pm.event.Target;
|
||||
|
||||
|
||||
public abstract class Device {
|
||||
protected Queue<Action> actionQueue;
|
||||
|
||||
public Device(Queue<Action> actionQueue) {
|
||||
this.actionQueue = actionQueue;
|
||||
}
|
||||
protected static Queue<Action> actionQueue;
|
||||
|
||||
public void addAction(Action action, Target target) {
|
||||
action.setTarget(target);
|
||||
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;
|
||||
|
||||
import java.util.LinkedList;
|
||||
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.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.service.javainput.JavaInputService;
|
||||
|
||||
public abstract class JavaInputDevice extends Device {
|
||||
|
||||
public static JavaInputService jxinputService;
|
||||
|
||||
protected JavaInputDevice(Queue<Action> actionQueue, String name) throws ServiceJavaInputException {
|
||||
super(actionQueue);
|
||||
if (jxinputService == null) {
|
||||
protected static int SLEEP = 100;
|
||||
|
||||
public boolean run = true;
|
||||
|
||||
public JavaInputListener javaInputListener;
|
||||
public Queue<JXInputAxisEvent> axisEventQueue;
|
||||
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();
|
||||
}*/
|
||||
//JXInputDevice x = jxinputService.getDevice(name);
|
||||
jxinputDevice = getDevice(name);
|
||||
System.out.printf("Initialized: %s\n", jxinputDevice.getName());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
JXInputDevice x = jxinputService.getDevice(name);
|
||||
System.out.printf("Initialized: %s\n", x.getName());
|
||||
throw new ServiceJavaInputDeviceNotFoundException();
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
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;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.device.Device;
|
||||
import pm.event.Target;
|
||||
|
||||
public class ExampleDevice extends Device {
|
||||
public ExampleDevice(Queue<Action> actionQueue) {
|
||||
super(actionQueue);
|
||||
public void start() {
|
||||
System.out.println("Ik hoef niets te starten");
|
||||
addAction(Action.START, Target.APPLICATION);
|
||||
addAction(Action.TEST, Target.APPLICATION);
|
||||
addAction(Action.EXIT, Target.MAIN);
|
||||
}
|
||||
|
||||
public void initialise() {
|
||||
addAction(Action.START, Target.APPLICATION);
|
||||
addAction(Action.TEST, Target.APPLICATION);
|
||||
addAction(Action.EXIT, Target.MAIN);
|
||||
}
|
||||
|
||||
public void processEvent() {
|
||||
/*ExampleEvent de;
|
||||
if (specifiekEvent == start) {
|
||||
addAction()
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package pm.device.rumblepad;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.device.JavaInputDevice;
|
||||
import pm.exception.ServiceJavaInputException;
|
||||
|
||||
public class RumblepadDevice extends JavaInputDevice {
|
||||
|
||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||
|
||||
public RumblepadDevice(Queue<Action> actionQueue) throws ServiceJavaInputException {
|
||||
super(actionQueue, NAME);
|
||||
|
||||
public RumblepadDevice() throws ServiceJavaInputException {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package pm.service.javainput;
|
||||
import de.hardcode.jxinput.JXInputDevice;
|
||||
import de.hardcode.jxinput.JXInputManager;
|
||||
|
||||
import pm.device.JavaInputDevice;
|
||||
import pm.exception.ServiceJavaInputDeviceNotFoundException;
|
||||
import pm.exception.ServiceJavaInputException;
|
||||
import pm.service.Service;
|
||||
@@ -22,7 +21,7 @@ public class JavaInputService extends Service {
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
JavaInputDevice.jxinputService = new JavaInputService();
|
||||
//JavaInputDevice.jxinputService = new JavaInputService();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user