Aantal reorganisaties om implementatie van macro's ondubbelzinnig duidelijk te maken.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package pm.device.macro;
|
||||
package pm;
|
||||
|
||||
public interface Button {
|
||||
|
||||
15
java/src/pm/Macro.java
Normal file
15
java/src/pm/Macro.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package pm;
|
||||
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Macro {
|
||||
protected Event[] eventArray;
|
||||
|
||||
public Macro(Event... eventArray) {
|
||||
this.eventArray = eventArray;
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return eventArray.length;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.action.Actions;
|
||||
import pm.application.Application;
|
||||
import pm.application.voorbeeld.VoorbeeldApplication;
|
||||
import pm.device.Device;
|
||||
@@ -19,16 +19,16 @@ public class Main extends Target {
|
||||
|
||||
ArrayList<Application> applicationList;
|
||||
ArrayList<Device> deviceList;
|
||||
Queue<Action> actionQueue;
|
||||
Queue<Actions> actionQueue;
|
||||
|
||||
boolean run;
|
||||
Application currentApplication;
|
||||
|
||||
|
||||
public Main() {
|
||||
applicationList = new ArrayList<Application>();
|
||||
//applicationList.iterator();
|
||||
deviceList = new ArrayList<Device>();
|
||||
actionQueue = new ConcurrentLinkedQueue<Action>();
|
||||
actionQueue = new ConcurrentLinkedQueue<Actions>();
|
||||
//JavaInputService.initialize();
|
||||
Device.initialise(actionQueue);
|
||||
}
|
||||
@@ -74,12 +74,11 @@ public class Main extends Target {
|
||||
Thread.sleep(SLEEP);
|
||||
} catch (InterruptedException e) {}
|
||||
} else {
|
||||
Action action = actionQueue.poll();
|
||||
Actions action = actionQueue.poll();
|
||||
Target target;
|
||||
switch (action.getTarget()) {
|
||||
case MAIN:
|
||||
target = this;
|
||||
invoke(action);
|
||||
break;
|
||||
case APPLICATION:
|
||||
target = currentApplication;
|
||||
|
||||
@@ -2,12 +2,12 @@ package pm;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.action.Actions;
|
||||
import pm.exception.ActionException;
|
||||
import pm.exception.action.InvokeActionException;
|
||||
|
||||
public abstract class Target {
|
||||
public void invoke(Action action) throws ActionException {
|
||||
public void invoke(Actions action) throws ActionException {
|
||||
try {
|
||||
action.getMethod(this).invoke(this);
|
||||
return;
|
||||
|
||||
@@ -2,26 +2,25 @@ package pm.action;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import pm.event.Target;
|
||||
import pm.exception.action.NotImplementedActionException;
|
||||
|
||||
public enum Action {
|
||||
public enum Actions {
|
||||
START ("start"),
|
||||
TEST ("test"),
|
||||
EXIT ("exit");
|
||||
|
||||
protected String action;
|
||||
protected Target target;
|
||||
protected Targets target;
|
||||
|
||||
Action(String action) {
|
||||
Actions(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public void setTarget(Target target) {
|
||||
public void setTarget(Targets target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public Target getTarget() {
|
||||
public Targets getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
5
java/src/pm/action/Targets.java
Normal file
5
java/src/pm/action/Targets.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.action;
|
||||
|
||||
public enum Targets {
|
||||
MAIN, DEVICE, APPLICATION;
|
||||
}
|
||||
@@ -2,11 +2,11 @@ package pm.device;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.event.Target;
|
||||
import pm.action.Actions;
|
||||
import pm.action.Targets;
|
||||
|
||||
public abstract class Device {
|
||||
protected static Queue<Action> actionQueue;
|
||||
protected static Queue<Actions> actionQueue;
|
||||
protected MacroListener macroListener;
|
||||
|
||||
public Device() {
|
||||
@@ -14,12 +14,12 @@ public abstract class Device {
|
||||
macroListener.start();
|
||||
}
|
||||
|
||||
public void addAction(Action action, Target target) {
|
||||
public void addAction(Actions action, Targets target) {
|
||||
action.setTarget(target);
|
||||
actionQueue.add(action);
|
||||
}
|
||||
|
||||
public static void initialise(Queue<Action> actionQueue) {
|
||||
public static void initialise(Queue<Actions> actionQueue) {
|
||||
Device.actionQueue = actionQueue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package pm.device;
|
||||
|
||||
import pm.device.macro.Macro;
|
||||
import pm.Macro;
|
||||
|
||||
import pm.action.Actions;
|
||||
import pm.action.Targets;
|
||||
|
||||
|
||||
public class MacroListener extends Thread {
|
||||
/*public void add(Macro macro, Action action, Target target) {
|
||||
public void add(Macro macro, Actions action, Targets target) {
|
||||
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package pm.device.example;
|
||||
|
||||
import pm.action.Action;
|
||||
import pm.action.Actions;
|
||||
import pm.action.Targets;
|
||||
import pm.device.Device;
|
||||
import pm.event.Target;
|
||||
|
||||
public class ExampleDevice extends Device {
|
||||
public void start() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pm.device.javainput.extreme3d;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import pm.device.macro.Button;
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
|
||||
public enum Extreme3DButton implements Button {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package pm.device.javainput.extreme3d;
|
||||
|
||||
import de.hardcode.jxinput.Button;
|
||||
import de.hardcode.jxinput.Directional;
|
||||
import de.hardcode.jxinput.event.JXInputAxisEvent;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
import pm.Macro;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.DeviceException;
|
||||
import pm.exception.EventException;
|
||||
@@ -21,13 +20,13 @@ public class Extreme3DDevice extends JavaInputDevice {
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
/*macroListener.addMacro(
|
||||
macroListener.addMacro(
|
||||
new Macro(
|
||||
new Hold(Button.A),
|
||||
new Press(Button.B),
|
||||
new Press(Button.TWO),
|
||||
new Release(Button.A)),
|
||||
Action.EXIT, Target.APPLICATION));*/
|
||||
Action.EXIT, Target.APPLICATION));
|
||||
}
|
||||
|
||||
public void processEvent(JXInputAxisEvent event) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pm.device.javainput.extreme3d;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
import pm.device.macro.Button;
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
|
||||
public enum Extreme3DDirection implements Button {
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package pm.device.macro;
|
||||
|
||||
public interface Action {
|
||||
public Button button = null;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package pm.device.macro;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import wiitunes.interaction.macro.Action;
|
||||
import wiitunes.interaction.macro.Button;
|
||||
import wiitunes.interaction.macro.Buttons;
|
||||
import wiitunes.interaction.macro.Combination;
|
||||
import wiitunes.interaction.macro.action.Hold;
|
||||
import wiitunes.interaction.macro.action.Press;
|
||||
import wiitunes.interaction.macro.action.Release;
|
||||
|
||||
public class Actions {
|
||||
protected Combination[] combinationArray;
|
||||
|
||||
public Actions(Action... actionArray) {
|
||||
ArrayList<Combination> combinationList = new ArrayList<Combination>();
|
||||
Buttons heldButtons = new Buttons();
|
||||
for (Action action : actionArray) {
|
||||
if (action instanceof Press) {
|
||||
Button button = ((Press) action).button;
|
||||
Buttons buttons = new Buttons(button);
|
||||
combinationList.add(new Combination(buttons, null, heldButtons));
|
||||
combinationList.add(new Combination(null, buttons, heldButtons));
|
||||
} else if (action instanceof Release) {
|
||||
Button button = ((Release) action).button;
|
||||
Buttons buttons = new Buttons(button);
|
||||
heldButtons = heldButtons.clone();
|
||||
heldButtons.remove(button);
|
||||
combinationList.add(new Combination(null, buttons, heldButtons));
|
||||
} else if (action instanceof Hold) {
|
||||
Button button = ((Hold) action).button;
|
||||
Buttons buttons = new Buttons(button);
|
||||
combinationList.add(new Combination(buttons, null, heldButtons));
|
||||
heldButtons = heldButtons.clone();
|
||||
heldButtons.add(button);
|
||||
}
|
||||
}
|
||||
combinationArray = (Combination[]) combinationList.toArray(new Combination[0]);
|
||||
}
|
||||
|
||||
public Combination get(int step) {
|
||||
return combinationArray[step];
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return combinationArray.length;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String string = String.format("Gesture contains %d actions:\n", combinationArray.length);;
|
||||
for (Combination combination : combinationArray) {
|
||||
string += String.format("> %s\n", combination);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package pm.device.macro;
|
||||
|
||||
public class Macro {
|
||||
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pm.device.macro.action;
|
||||
|
||||
import pm.device.macro.Action;
|
||||
import pm.device.macro.Button;
|
||||
|
||||
public class Hold implements Action {
|
||||
public Button button;
|
||||
|
||||
public Hold(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pm.device.macro.action;
|
||||
|
||||
import pm.device.macro.Action;
|
||||
import pm.device.macro.Button;
|
||||
|
||||
public class Press implements Action {
|
||||
public Button button;
|
||||
|
||||
public Press(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pm.device.macro.action;
|
||||
|
||||
import pm.device.macro.Action;
|
||||
import pm.device.macro.Button;
|
||||
|
||||
public class Release implements Action {
|
||||
public Button button;
|
||||
|
||||
public Release(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package pm.event;
|
||||
|
||||
import pm.action.Action;
|
||||
|
||||
public class Event {
|
||||
protected Target type;
|
||||
protected Action action;
|
||||
|
||||
public Event(Target type, Action action) {
|
||||
this.type = type;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Target getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package pm.event;
|
||||
|
||||
public enum Target {
|
||||
MAIN, DEVICE, APPLICATION;
|
||||
}
|
||||
7
java/src/pm/macro/Event.java
Normal file
7
java/src/pm/macro/Event.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.macro;
|
||||
|
||||
import pm.Button;
|
||||
|
||||
public interface Event {
|
||||
public Button button = null;
|
||||
}
|
||||
12
java/src/pm/macro/event/Hold.java
Normal file
12
java/src/pm/macro/event/Hold.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package pm.macro.event;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Hold implements Event {
|
||||
public Button button;
|
||||
|
||||
public Hold(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
12
java/src/pm/macro/event/Press.java
Normal file
12
java/src/pm/macro/event/Press.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package pm.macro.event;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Press implements Event {
|
||||
public Button button;
|
||||
|
||||
public Press(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
12
java/src/pm/macro/event/Release.java
Normal file
12
java/src/pm/macro/event/Release.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package pm.macro.event;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Release implements Event {
|
||||
public Button button;
|
||||
|
||||
public Release(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user