Structuur consequenter gemaakt met initialise en exit methoden. De start methode wordt gereserveerd voor wanneer er een Thread moet worden gestart. Exceptions georganiseerd, hierbij opletten op het doorgeven van exceptions vanuit Threads! Poging tot het dynamisch toevoegen van devices is niet helemaal gelukt.
This commit is contained in:
@@ -3,11 +3,13 @@ package pm.device;
|
||||
import pm.Action;
|
||||
import pm.Macro;
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.device.DeviceExitException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.listener.ActionProvider;
|
||||
import pm.listener.MacroListener;
|
||||
import pm.macro.Event;
|
||||
|
||||
public abstract class Device extends ActionProvider {
|
||||
public abstract class Device {
|
||||
protected MacroListener macroListener;
|
||||
|
||||
public Device() {
|
||||
@@ -26,6 +28,10 @@ public abstract class Device extends ActionProvider {
|
||||
macroListener.add(event);
|
||||
}
|
||||
|
||||
public void start() {}
|
||||
public void exit() {}
|
||||
public void add(Action action) {
|
||||
ActionProvider.add(action);
|
||||
}
|
||||
|
||||
public void initialise() throws DeviceInitialiseException {}
|
||||
public void exit() throws DeviceExitException {}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import pm.Target;
|
||||
import pm.device.Device;
|
||||
|
||||
public class ExampleDevice extends Device {
|
||||
public void start() {
|
||||
public void initialise() {
|
||||
//System.out.println("Ik hoef niets te starten");
|
||||
//addAction(Action.START, Target.APPLICATION);
|
||||
//addAction(Action.TEST, Target.APPLICATION);
|
||||
|
||||
@@ -4,7 +4,7 @@ import pm.Button;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public enum DirectionalSwitch implements Button {
|
||||
public enum DirectionButton implements Button {
|
||||
NORTH (0),
|
||||
NORTHEAST (45),
|
||||
EAST (90),
|
||||
@@ -16,7 +16,7 @@ public enum DirectionalSwitch implements Button {
|
||||
|
||||
protected int code;
|
||||
|
||||
private DirectionalSwitch(int code) {
|
||||
private DirectionButton(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public enum DirectionalSwitch implements Button {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static DirectionalSwitch create(int angle) throws UnknownDirectionException {
|
||||
for (DirectionalSwitch button : DirectionalSwitch.values()) {
|
||||
public static DirectionButton create(int angle) throws UnknownDirectionException {
|
||||
for (DirectionButton button : DirectionButton.values()) {
|
||||
if (button.getCode() == angle) {
|
||||
return button;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public enum DirectionalSwitch implements Button {
|
||||
throw new UnknownDirectionException();
|
||||
}
|
||||
|
||||
public static DirectionalSwitch create(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
public static DirectionButton create(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return create(event.getDirectional().getDirection() / 100);
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@ import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
import pm.Button;
|
||||
import pm.device.Device;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.device.JavaInputDeviceNotFoundException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.exception.device.DeviceNotFoundException;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
|
||||
@@ -18,30 +18,19 @@ public abstract class JavaInputDevice extends Device {
|
||||
protected JavaInputListener javaInputListener;
|
||||
protected Button previousDirectionalButton;
|
||||
|
||||
protected JavaInputDevice(String name) throws DeviceException {
|
||||
super();
|
||||
javaInputListener = new JavaInputListener(this, getDevice(name));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
javaInputListener.start();
|
||||
public void initialise(String name) throws DeviceInitialiseException {
|
||||
try {
|
||||
javaInputListener = new JavaInputListener(this, getDevice(name));
|
||||
javaInputListener.start();
|
||||
} catch (DeviceNotFoundException e) {
|
||||
throw new DeviceInitialiseException();
|
||||
}
|
||||
}
|
||||
|
||||
public void exit() {
|
||||
javaInputListener.exit();
|
||||
}
|
||||
|
||||
public static JXInputDevice getDevice(String name) throws DeviceException {
|
||||
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 JavaInputDeviceNotFoundException();
|
||||
}
|
||||
|
||||
public void processEvent(JXInputAxisEvent event) {
|
||||
//System.out.println(event);
|
||||
}
|
||||
@@ -73,4 +62,15 @@ public abstract class JavaInputDevice extends Device {
|
||||
|
||||
protected abstract Button getButton(JXInputButtonEvent event) throws EventException;
|
||||
protected abstract Button getButton(JXInputDirectionalEvent event) throws EventException;
|
||||
|
||||
public static JXInputDevice getDevice(String name) throws DeviceNotFoundException {
|
||||
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 DeviceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEventListener;
|
||||
import de.hardcode.jxinput.event.JXInputEventManager;
|
||||
|
||||
public class JavaInputListener extends Thread implements JXInputAxisEventListener, JXInputButtonEventListener, JXInputDirectionalEventListener {
|
||||
public class JavaInputListener implements Runnable, JXInputAxisEventListener, JXInputButtonEventListener, JXInputDirectionalEventListener {
|
||||
protected static final int SLEEP = 100;
|
||||
|
||||
protected boolean run;
|
||||
@@ -70,6 +70,10 @@ public class JavaInputListener extends Thread implements JXInputAxisEventListene
|
||||
directionalEventQueue.add(event);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
run = true;
|
||||
while (run) {
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
package pm.device.javainput.extreme3d;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
import pm.Action;
|
||||
import pm.Button;
|
||||
import pm.Macro;
|
||||
import pm.Target;
|
||||
import pm.device.javainput.DirectionalSwitch;
|
||||
import pm.device.javainput.DirectionButton;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
import pm.macro.event.Hold;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public class Extreme3DDevice extends JavaInputDevice {
|
||||
protected static final String NAME = "Logitech Extreme 3D";
|
||||
|
||||
public Extreme3DDevice() throws DeviceException {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
super.initialise(NAME);
|
||||
try {
|
||||
add(
|
||||
new Press(Extreme3DButton.TWELVE),
|
||||
@@ -46,6 +42,6 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return DirectionalSwitch.create(event);
|
||||
return DirectionButton.create(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ package pm.device.javainput.rumblepad;
|
||||
|
||||
import pm.Action;
|
||||
import pm.Button;
|
||||
import pm.Macro;
|
||||
import pm.Target;
|
||||
import pm.device.javainput.DirectionalSwitch;
|
||||
import pm.device.javainput.DirectionButton;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
import pm.macro.event.Press;
|
||||
@@ -15,15 +14,10 @@ import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public class RumblepadDevice extends JavaInputDevice {
|
||||
|
||||
protected static final String NAME = "Logitech RumblePad 2 USB";
|
||||
|
||||
public RumblepadDevice() throws DeviceException {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
super.initialise(NAME);
|
||||
try {
|
||||
add(
|
||||
new Press(RumblepadButton.ONE),
|
||||
@@ -62,6 +56,6 @@ public class RumblepadDevice extends JavaInputDevice {
|
||||
}
|
||||
|
||||
protected Button getButton(JXInputDirectionalEvent event) throws UnknownDirectionException {
|
||||
return DirectionalSwitch.create(event);
|
||||
return DirectionButton.create(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import pm.Target;
|
||||
import pm.device.Device;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
|
||||
@@ -24,13 +25,12 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
Hotkey.initialise(hotkeyList, jit);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
jit.addHotKeyListener(this);
|
||||
jit.addIntellitypeListener(this);
|
||||
try {
|
||||
add(
|
||||
new Hotkey(HotkeyButton.CTRL, 'x'),
|
||||
new Hotkey(HotkeyButton.CTRL | HotkeyButton.WIN, 'x'),
|
||||
Action.EXIT.setTarget(Target.MAIN));
|
||||
add(
|
||||
new Press(CommandButton.VOLUME_UP),
|
||||
|
||||
@@ -15,7 +15,7 @@ public class TextinputDevice extends Device {
|
||||
run = true;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
public void initialise() {
|
||||
while(run) {
|
||||
String textinput = textinputScanner.next();
|
||||
if(textinput != null) {
|
||||
|
||||
@@ -24,8 +24,8 @@ public class WiimoteDevice extends Device {
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
public void initialise() {
|
||||
super.initialise();
|
||||
try {
|
||||
add(
|
||||
new Press(WiimoteButton.A),
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.device.JavaInputDeviceNotFoundException;
|
||||
import pm.exception.device.javainput.JavaInputDeviceSpecificException;
|
||||
import wiiusej.WiiUseApiManager;
|
||||
import wiiusej.Wiimote;
|
||||
import wiiusej.wiiusejevents.GenericEvent;
|
||||
@@ -54,7 +54,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
||||
return wiimote;
|
||||
}
|
||||
}
|
||||
throw new JavaInputDeviceNotFoundException();
|
||||
throw new JavaInputDeviceSpecificException();
|
||||
}
|
||||
|
||||
public Wiimote getWiimote(GenericEvent event) {
|
||||
|
||||
Reference in New Issue
Block a user