* Target.SELF toegevoegd.
* Voormalige Events hernoemd naar States (Press, Release, Hold) --> Nu komt Event vrij als naam voor de parent van Task en toekomstig Feedback --> Exception namen nagelopen, controleren! * Aantal classes verplaatst (Sequence en SequenceListener)
This commit is contained in:
@@ -2,15 +2,14 @@ package pm;
|
||||
|
||||
import pm.exception.device.DeviceExitException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.macro.Event;
|
||||
import pm.macro.event.Hold;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
import pm.macro.event.Sequence;
|
||||
import pm.macro.event.SequenceListener;
|
||||
import pm.macro.Sequence;
|
||||
import pm.macro.SequenceListener;
|
||||
import pm.macro.State;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
import pm.task.Continuous;
|
||||
import pm.task.Stopper;
|
||||
import pm.task.TaskManager;
|
||||
import pm.task.TaskListener;
|
||||
|
||||
public abstract class Device extends TaskListener {
|
||||
@@ -18,7 +17,7 @@ public abstract class Device extends TaskListener {
|
||||
|
||||
public Device() {
|
||||
super();
|
||||
sequenceListener = new SequenceListener();
|
||||
sequenceListener = new SequenceListener(this);
|
||||
}
|
||||
|
||||
/* Register macro's */
|
||||
@@ -26,15 +25,15 @@ public abstract class Device extends TaskListener {
|
||||
sequenceListener.add(sequence, task);
|
||||
}
|
||||
|
||||
protected void add(Event event, Task task) {
|
||||
add(new Sequence(event), task);
|
||||
protected void add(State state, Task task) {
|
||||
add(new Sequence(state), task);
|
||||
}
|
||||
|
||||
protected void add(Press press, Task task, boolean macro) {
|
||||
if (macro) {
|
||||
add(new Macro(press), task);
|
||||
} else {
|
||||
add((Event) press, task);
|
||||
add((State) press, task);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +52,7 @@ public abstract class Device extends TaskListener {
|
||||
add(stopSequence, new Stopper(continuous));
|
||||
}
|
||||
|
||||
protected void add(Event startEvent, Event stopEvent, Continuous continuous) {
|
||||
protected void add(State startEvent, State stopEvent, Continuous continuous) {
|
||||
add(startEvent, continuous);
|
||||
add(stopEvent, new Stopper(continuous));
|
||||
}
|
||||
@@ -69,13 +68,13 @@ public abstract class Device extends TaskListener {
|
||||
}
|
||||
|
||||
/* Recognize events */
|
||||
protected void add(Event event) {
|
||||
sequenceListener.add(event);
|
||||
protected void add(State state) {
|
||||
sequenceListener.add(state);
|
||||
}
|
||||
|
||||
/* Device default methods */
|
||||
public void initialise() throws DeviceInitialiseException {}
|
||||
|
||||
|
||||
public void exit() throws DeviceExitException {
|
||||
stop();
|
||||
}
|
||||
|
||||
@@ -4,36 +4,36 @@ import java.util.ArrayList;
|
||||
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.macro.MacroEventOrderException;
|
||||
import pm.macro.Event;
|
||||
import pm.macro.event.Sequence;
|
||||
import pm.macro.event.Hold;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
import pm.macro.Sequence;
|
||||
import pm.macro.State;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
|
||||
public class Macro extends Sequence {
|
||||
public Macro(Press press) {
|
||||
Button button = press.getButton();
|
||||
this.eventArray = new Event[] {press, new Release(button)};
|
||||
this.eventArray = new State[] {press, new Release(button)};
|
||||
}
|
||||
|
||||
public Macro(Event... eventArray) throws MacroException {
|
||||
public Macro(State... eventArray) throws MacroException {
|
||||
ArrayList<Button> holdList = new ArrayList<Button>();
|
||||
ArrayList<Event> eventList = new ArrayList<Event>();
|
||||
for (Event event : eventArray) {
|
||||
Button button = event.getButton();
|
||||
if (event instanceof Press) {
|
||||
ArrayList<State> eventList = new ArrayList<State>();
|
||||
for (State state : eventArray) {
|
||||
Button button = state.getButton();
|
||||
if (state instanceof Press) {
|
||||
if (holdList.contains(button)) {
|
||||
throw new MacroEventOrderException("Press events cannot follow hold events for the same button.");
|
||||
}
|
||||
eventList.add(event);
|
||||
eventList.add(state);
|
||||
eventList.add(new Release(button));
|
||||
} else if (event instanceof Release) {
|
||||
} else if (state instanceof Release) {
|
||||
if (!holdList.contains(button)) {
|
||||
throw new MacroEventOrderException("Cannot release a button that is not held.");
|
||||
}
|
||||
holdList.remove(button);
|
||||
eventList.add(event);
|
||||
} else if (event instanceof Hold) {
|
||||
eventList.add(state);
|
||||
} else if (state instanceof Hold) {
|
||||
if (holdList.contains(button)) {
|
||||
throw new MacroEventOrderException("Cannot hold a button more than once.");
|
||||
}
|
||||
@@ -44,6 +44,6 @@ public class Macro extends Sequence {
|
||||
if (!holdList.isEmpty()) {
|
||||
throw new MacroEventOrderException("One or more buttons are not released.");
|
||||
}
|
||||
eventArray = (Event[]) eventList.toArray(new Event[0]);
|
||||
eventArray = (State[]) eventList.toArray(new State[0]);
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class Main extends TaskListener {
|
||||
//add(new WMPApplication());
|
||||
//add(new GomPlayerApplication());
|
||||
//add(new WinampApplication());
|
||||
add(new iTunesApplication());
|
||||
//add(new iTunesApplication());
|
||||
for (Application application : applicationCycle) {
|
||||
try {
|
||||
application.initialise();
|
||||
|
||||
@@ -13,7 +13,7 @@ public class Task {
|
||||
}
|
||||
|
||||
public Task(Action action) {
|
||||
this(action, Target.MAIN);
|
||||
this(action, Target.SELF);
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pm.device.javainput;
|
||||
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownDirectionException;
|
||||
import pm.exception.button.UnknownDirectionException;
|
||||
import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
public enum DirectionButton implements Button {
|
||||
|
||||
@@ -8,11 +8,11 @@ import de.hardcode.jxinput.event.JXInputDirectionalEvent;
|
||||
|
||||
import pm.Button;
|
||||
import pm.Device;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.StateException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.exception.device.DeviceNotFoundException;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
|
||||
public abstract class JavaInputDevice extends Device {
|
||||
protected JavaInputListener javaInputListener;
|
||||
@@ -35,7 +35,7 @@ public abstract class JavaInputDevice extends Device {
|
||||
//System.out.println(event);
|
||||
}
|
||||
|
||||
public void processEvent(JXInputButtonEvent event) throws EventException {
|
||||
public void processEvent(JXInputButtonEvent event) throws StateException {
|
||||
Button button = getButton(event);
|
||||
if (event.getButton().getState()) {
|
||||
System.out.println("Press: " + button);
|
||||
@@ -46,7 +46,7 @@ public abstract class JavaInputDevice extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
public void processEvent(JXInputDirectionalEvent event) throws EventException {
|
||||
public void processEvent(JXInputDirectionalEvent event) throws StateException {
|
||||
Button button = getButton(event);
|
||||
if (event.getDirectional().isCentered()) {
|
||||
if (previousDirectionalButton != null) {
|
||||
@@ -60,8 +60,8 @@ public abstract class JavaInputDevice extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Button getButton(JXInputButtonEvent event) throws EventException;
|
||||
protected abstract Button getButton(JXInputDirectionalEvent event) throws EventException;
|
||||
protected abstract Button getButton(JXInputButtonEvent event) throws StateException;
|
||||
protected abstract Button getButton(JXInputDirectionalEvent event) throws StateException;
|
||||
|
||||
public static JXInputDevice getDevice(String name) throws DeviceNotFoundException {
|
||||
int numberOfDevices = JXInputManager.getNumberOfDevices();
|
||||
|
||||
@@ -3,7 +3,7 @@ package pm.device.javainput;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.StateException;
|
||||
|
||||
import de.hardcode.jxinput.Axis;
|
||||
import de.hardcode.jxinput.Button;
|
||||
@@ -86,13 +86,13 @@ public class JavaInputListener implements Runnable, JXInputAxisEventListener, JX
|
||||
if (!buttonEventQueue.isEmpty()) {
|
||||
try {
|
||||
javaInputDevice.processEvent(buttonEventQueue.poll());
|
||||
} catch (EventException e) {}
|
||||
} catch (StateException e) {}
|
||||
sleep = false;
|
||||
}
|
||||
if (!directionalEventQueue.isEmpty()) {
|
||||
try {
|
||||
javaInputDevice.processEvent(directionalEventQueue.poll());
|
||||
} catch (EventException e) {e.printStackTrace();}
|
||||
} catch (StateException e) {e.printStackTrace();}
|
||||
sleep = false;
|
||||
}
|
||||
if (sleep) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package pm.device.javainput.extreme3d;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
|
||||
public enum Extreme3DButton implements Button {
|
||||
ONE ("Button 0"),
|
||||
|
||||
@@ -6,12 +6,12 @@ import pm.Task;
|
||||
import pm.device.javainput.DirectionButton;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
import pm.exception.button.UnknownDirectionException;
|
||||
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 pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
import pm.value.Action;
|
||||
import pm.value.Target;
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
|
||||
@@ -2,7 +2,7 @@ package pm.device.javainput.rumblepad;
|
||||
|
||||
import de.hardcode.jxinput.event.JXInputButtonEvent;
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
|
||||
public enum RumblepadButton implements Button {
|
||||
ONE ("Button 0"),
|
||||
|
||||
@@ -4,11 +4,11 @@ import pm.Button;
|
||||
import pm.Task;
|
||||
import pm.device.javainput.DirectionButton;
|
||||
import pm.device.javainput.JavaInputDevice;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
import pm.exception.button.UnknownDirectionException;
|
||||
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.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.task.Continuous;
|
||||
import pm.task.Dynamic;
|
||||
import pm.value.Action;
|
||||
|
||||
@@ -3,7 +3,7 @@ package pm.device.jintellitype;
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
|
||||
public enum CommandButton implements Button {
|
||||
BROWSER_BACKWARD (JIntellitype.APPCOMMAND_BROWSER_BACKWARD),
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
|
||||
import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.state.Press;
|
||||
import pm.value.Key;
|
||||
|
||||
public class Hotkey extends Press {
|
||||
|
||||
@@ -8,11 +8,11 @@ import com.melloware.jintellitype.JIntellitype;
|
||||
|
||||
import pm.Device;
|
||||
import pm.Task;
|
||||
import pm.exception.EventException;
|
||||
import pm.exception.StateException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.macro.event.Hold;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
import pm.task.Continuous;
|
||||
import pm.value.Action;
|
||||
import pm.value.Command;
|
||||
@@ -63,7 +63,7 @@ public class JIntellitypeDevice extends Device implements HotkeyListener, Intell
|
||||
System.out.println(commandButton);
|
||||
add(new Press(commandButton));
|
||||
add(new Release(commandButton));
|
||||
} catch (EventException e) {
|
||||
} catch (StateException e) {
|
||||
e.printStackTrace(); // Todo: deze exception verder omhoog gooien
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Scanner;
|
||||
|
||||
import pm.Listener;
|
||||
import pm.Task;
|
||||
import pm.exception.task.TaskNotSupportedException;
|
||||
import pm.task.TaskManager;
|
||||
import pm.value.Action;
|
||||
import pm.value.Target;
|
||||
@@ -22,8 +23,10 @@ public class InputListener extends Listener {
|
||||
String string = input.next().toUpperCase();
|
||||
if(string != null) {
|
||||
try {
|
||||
TaskManager.add(
|
||||
new Task(Action.valueOf(string), Target.APPLICATION));
|
||||
try {
|
||||
TaskManager.add(
|
||||
new Task(Action.valueOf(string), Target.APPLICATION));
|
||||
} catch (TaskNotSupportedException e) {}
|
||||
} catch(IllegalArgumentException e) {}
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package pm.device.wiimote;
|
||||
|
||||
import pm.Button;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
|
||||
public enum WiimoteButton implements Button {
|
||||
TWO (0x0001),
|
||||
|
||||
@@ -8,11 +8,11 @@ import pm.Button;
|
||||
import pm.Device;
|
||||
import pm.Task;
|
||||
import pm.device.wiimote.gesture.GestureDevice;
|
||||
import pm.exception.button.UnknownButtonException;
|
||||
import pm.exception.device.DeviceInitialiseException;
|
||||
import pm.exception.event.UnknownButtonException;
|
||||
import pm.macro.event.Hold;
|
||||
import pm.macro.event.Press;
|
||||
import pm.macro.event.Release;
|
||||
import pm.macro.state.Hold;
|
||||
import pm.macro.state.Press;
|
||||
import pm.macro.state.Release;
|
||||
import pm.task.Continuous;
|
||||
import pm.task.Dynamic;
|
||||
import pm.value.Action;
|
||||
@@ -48,20 +48,20 @@ public class WiimoteDevice extends Device implements GestureListener {
|
||||
public void initialise() throws DeviceInitialiseException {
|
||||
wiimote = wiimoteService.getDevice(this);
|
||||
wiimote.activateMotionSensing();
|
||||
/*add(
|
||||
add(
|
||||
new Hold(WiimoteButton.A),
|
||||
new Task(Action.TRAIN, Target.DEVICE),
|
||||
new Task(Action.STOP, Target.DEVICE));
|
||||
new Task(Action.TRAIN),
|
||||
new Task(Action.STOP));
|
||||
add(
|
||||
new Press(WiimoteButton.B),
|
||||
new Task(Action.SAVE, Target.DEVICE));
|
||||
new Task(Action.SAVE));
|
||||
add(
|
||||
new Press(WiimoteButton.DOWN),
|
||||
new Task(Action.LOAD, Target.DEVICE));
|
||||
new Task(Action.LOAD));
|
||||
add(
|
||||
new Hold(WiimoteButton.HOME),
|
||||
new Task(Action.RECOGNIZE, Target.DEVICE),
|
||||
new Task(Action.STOP, Target.DEVICE));*/
|
||||
new Task(Action.RECOGNIZE),
|
||||
new Task(Action.STOP));
|
||||
add(
|
||||
new Press(WiimoteButton.A),
|
||||
new Task(Action.PLAY, Target.APPLICATION));
|
||||
|
||||
5
java/src/pm/exception/ButtonException.java
Normal file
5
java/src/pm/exception/ButtonException.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package pm.exception;
|
||||
|
||||
public class ButtonException extends Exception {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package pm.exception;
|
||||
|
||||
public class EventException extends Exception {
|
||||
public class StateException extends Exception {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
7
java/src/pm/exception/button/UnknownButtonException.java
Normal file
7
java/src/pm/exception/button/UnknownButtonException.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package pm.exception.button;
|
||||
|
||||
import pm.exception.StateException;
|
||||
|
||||
public class UnknownButtonException extends StateException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pm.exception.button;
|
||||
|
||||
import pm.exception.ButtonException;
|
||||
|
||||
public class UnknownDirectionException extends ButtonException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pm.exception.event;
|
||||
|
||||
import pm.exception.EventException;
|
||||
|
||||
public class UnknownButtonException extends EventException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pm.exception.event;
|
||||
|
||||
import pm.exception.EventException;
|
||||
|
||||
public class UnknownDirectionException extends EventException {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package pm.exception.task;
|
||||
|
||||
public class TaskNotSupportedException extends Exception {
|
||||
protected static final long serialVersionUID = 1L;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package pm.macro;
|
||||
|
||||
import pm.macro.event.Sequence;
|
||||
|
||||
public class Active {
|
||||
protected Sequence sequence;
|
||||
@@ -15,9 +14,9 @@ public class Active {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public boolean next(Event event) {
|
||||
Event next = sequence.get(++step);
|
||||
return next == null ? false : event.equals(next);
|
||||
public boolean next(State state) {
|
||||
State next = sequence.get(++step);
|
||||
return next == null ? false : state.equals(next);
|
||||
}
|
||||
|
||||
public boolean last() {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package pm.macro.event;
|
||||
package pm.macro;
|
||||
|
||||
import pm.macro.Event;
|
||||
|
||||
|
||||
public class Sequence {
|
||||
protected Event[] eventArray;
|
||||
protected State[] eventArray;
|
||||
|
||||
public Sequence(Event... eventArray) {
|
||||
public Sequence(State... eventArray) {
|
||||
this.eventArray = eventArray;
|
||||
}
|
||||
|
||||
@@ -14,7 +13,7 @@ public class Sequence {
|
||||
return eventArray.length;
|
||||
}
|
||||
|
||||
public Event get(int i) {
|
||||
public State get(int i) {
|
||||
return eventArray.length > 0 ? eventArray[i] : null;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,42 @@
|
||||
package pm.macro.event;
|
||||
package pm.macro;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import pm.Device;
|
||||
import pm.Task;
|
||||
import pm.macro.Active;
|
||||
import pm.macro.Event;
|
||||
import pm.task.TaskListener;
|
||||
import pm.task.TaskManager;
|
||||
|
||||
public class SequenceListener {
|
||||
public ArrayList<Sequence> sequenceList;
|
||||
public HashMap<Sequence, Task> taskMap;
|
||||
public ArrayList<Active> activeList;
|
||||
protected TaskListener taskListener;
|
||||
protected ArrayList<Sequence> sequenceList;
|
||||
protected HashMap<Sequence, Task> taskMap;
|
||||
protected ArrayList<Active> activeList;
|
||||
|
||||
public SequenceListener() {
|
||||
public SequenceListener(TaskListener taskListener) {
|
||||
this.taskListener = taskListener;
|
||||
sequenceList = new ArrayList<Sequence>();
|
||||
taskMap = new HashMap<Sequence, Task>();
|
||||
activeList = new ArrayList<Active>();
|
||||
}
|
||||
|
||||
public void add(Sequence sequence, Task task) {
|
||||
public int add(Sequence sequence, Task task) {
|
||||
int id = sequenceList.size();
|
||||
sequenceList.add(sequence);
|
||||
taskMap.put(sequence, task);
|
||||
return id;
|
||||
}
|
||||
|
||||
public void add(Event event) {
|
||||
public void add(State state) {
|
||||
for (Sequence sequence : sequenceList) {
|
||||
activeList.add(new Active(sequence));
|
||||
}
|
||||
ArrayList<Active> removeList = new ArrayList<Active>();
|
||||
for (Active active : activeList) {
|
||||
if (active.next(event)) {
|
||||
if (active.next(state)) {
|
||||
if (active.last()) {
|
||||
Task task = taskMap.get(active.getSequence());
|
||||
TaskManager.add(task);
|
||||
TaskManager.add(taskListener, task);
|
||||
removeList.add(active);
|
||||
}
|
||||
} else {
|
||||
@@ -2,10 +2,10 @@ package pm.macro;
|
||||
|
||||
import pm.Button;
|
||||
|
||||
public abstract class Event {
|
||||
public abstract class State {
|
||||
protected Button button;
|
||||
|
||||
public Event(Button button) {
|
||||
public State(Button button) {
|
||||
this.button = button;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public abstract class Event {
|
||||
return button;
|
||||
}
|
||||
|
||||
public boolean equals(Event event) {
|
||||
return event.getClass().equals(getClass()) && event.getButton().equals(button);
|
||||
public boolean equals(State state) {
|
||||
return state.getClass().equals(getClass()) && state.getButton().equals(button);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package pm.macro.event;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Hold extends Event {
|
||||
public Hold(Button button) {
|
||||
super(button);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package pm.macro.event;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Press extends Event {
|
||||
public Press(Button button) {
|
||||
super(button);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package pm.macro.event;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.Event;
|
||||
|
||||
public class Release extends Event {
|
||||
public Release(Button button) {
|
||||
super(button);
|
||||
}
|
||||
}
|
||||
10
java/src/pm/macro/state/Hold.java
Normal file
10
java/src/pm/macro/state/Hold.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package pm.macro.state;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.State;
|
||||
|
||||
public class Hold extends State {
|
||||
public Hold(Button button) {
|
||||
super(button);
|
||||
}
|
||||
}
|
||||
10
java/src/pm/macro/state/Press.java
Normal file
10
java/src/pm/macro/state/Press.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package pm.macro.state;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.State;
|
||||
|
||||
public class Press extends State {
|
||||
public Press(Button button) {
|
||||
super(button);
|
||||
}
|
||||
}
|
||||
10
java/src/pm/macro/state/Release.java
Normal file
10
java/src/pm/macro/state/Release.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package pm.macro.state;
|
||||
|
||||
import pm.Button;
|
||||
import pm.macro.State;
|
||||
|
||||
public class Release extends State {
|
||||
public Release(Button button) {
|
||||
super(button);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import pm.Device;
|
||||
import pm.Main;
|
||||
import pm.Task;
|
||||
import pm.application.ApplicationCycle;
|
||||
import pm.exception.task.TaskNotSupportedException;
|
||||
import pm.value.Target;
|
||||
|
||||
public class TaskManager {
|
||||
@@ -22,40 +23,54 @@ public class TaskManager {
|
||||
taskListenerList.add(taskListener);
|
||||
}
|
||||
|
||||
public static void add(Task task) {
|
||||
public static void add(TaskListener self, Task task) {
|
||||
if (task instanceof Stopper) {
|
||||
Stopper stopper = (Stopper) task;
|
||||
stopper.stop();
|
||||
stopper.stop();
|
||||
} else {
|
||||
Target target = task.getTarget();
|
||||
if (target.equals(Target.APPLICATION)) {
|
||||
applicationCycle.current().add(task);
|
||||
} else {
|
||||
for (TaskListener taskListener : taskListenerList) {
|
||||
switch (target) {
|
||||
case ALL:
|
||||
taskListener.add(task);
|
||||
case MAIN:
|
||||
if (taskListener instanceof Main) {
|
||||
switch (target) {
|
||||
case SELF:
|
||||
self.add(task);
|
||||
break;
|
||||
case APPLICATION:
|
||||
applicationCycle.current().add(task);
|
||||
break;
|
||||
default:
|
||||
for (TaskListener taskListener : taskListenerList) {
|
||||
switch (target) {
|
||||
case ALL:
|
||||
taskListener.add(task);
|
||||
}
|
||||
break;
|
||||
case DEVICES:
|
||||
if (taskListener instanceof Device) {
|
||||
taskListener.add(task);
|
||||
}
|
||||
break;
|
||||
case APPLICATIONS:
|
||||
if (taskListener instanceof Application) {
|
||||
taskListener.add(task);
|
||||
}
|
||||
break;
|
||||
case MAIN:
|
||||
if (taskListener instanceof Main) {
|
||||
taskListener.add(task);
|
||||
}
|
||||
break;
|
||||
case DEVICES:
|
||||
if (taskListener instanceof Device) {
|
||||
taskListener.add(task);
|
||||
}
|
||||
break;
|
||||
case APPLICATIONS:
|
||||
if (taskListener instanceof Application) {
|
||||
taskListener.add(task);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void add(Task task) throws TaskNotSupportedException {
|
||||
Target target = task.getTarget();
|
||||
if (target.equals(Target.SELF)) {
|
||||
throw new TaskNotSupportedException();
|
||||
}
|
||||
add(null, task);
|
||||
}
|
||||
|
||||
public static void remove(TaskListener taskListener) {
|
||||
taskListenerList.remove(taskListener);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package pm.value;
|
||||
|
||||
public enum Target {
|
||||
ALL, MAIN, DEVICES, APPLICATIONS, APPLICATION;
|
||||
ALL, MAIN, DEVICES, APPLICATIONS, APPLICATION, SELF;
|
||||
}
|
||||
Reference in New Issue
Block a user