This commit is contained in:
2011-02-07 21:21:39 +00:00
parent 0e8c212999
commit eb36318a76
17 changed files with 233 additions and 78 deletions

View File

@@ -0,0 +1,26 @@
package pm.macro;
import pm.Macro;
public class Active {
protected Macro macro;
protected int step;
public Active(Macro macro) {
this.macro = macro;
step = -1;
}
public Macro getMacro() {
return macro;
}
public boolean next(Event event) {
Event next = macro.get(++step);
return next == null ? false : event.equals(next);
}
public boolean last() {
return step == macro.count() - 1;
}
}

View File

@@ -2,6 +2,18 @@ package pm.macro;
import pm.Button;
public interface Event {
public Button button = null;
public abstract class Event {
protected Button button;
public Event(Button button) {
this.button = button;
}
public Button getButton() {
return button;
}
public boolean equals(Event event) {
return event.getClass().equals(getClass()) && event.getButton().equals(button); // Todo: controleren of equals goed werkt bij buttons van verschillende typen
}
}

View File

@@ -0,0 +1,54 @@
package pm.macro;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Queue;
import pm.Macro;
import pm.action.Actions;
import pm.action.Targets;
public class MacroListener extends Thread {
protected static Queue<Actions> actionQueue;
public ArrayList<Macro> macroList;
public HashMap<Macro, Actions> actionMap;
public ArrayList<Active> activeList;
public MacroListener() {
macroList = new ArrayList<Macro>();
actionMap = new HashMap<Macro, Actions>();
activeList = new ArrayList<Active>();
}
public void add(Macro macro, Actions action, Targets target) {
action.setTarget(target); // Todo: target en action duidelijker integreren / hernoemen.
macroList.add(macro);
actionMap.put(macro, action);
}
public void add(Event event) {
for (Macro macro : macroList) {
activeList.add(new Active(macro));
}
ArrayList<Active> removeList = new ArrayList<Active>();
for (Active active : activeList) {
if (active.next(event)) {
if (active.last()) {
actionQueue.add(actionMap.get(active.getMacro())); // Todo: dit indirect doen?
removeList.add(active);
}
} else {
removeList.add(active);
}
}
for (Active active : removeList) {
activeList.remove(active);
}
}
public static void initialise(Queue<Actions> actionQueue) {
MacroListener.actionQueue = actionQueue;
}
}

View File

@@ -3,10 +3,8 @@ package pm.macro.event;
import pm.Button;
import pm.macro.Event;
public class Hold implements Event {
public Button button;
public class Hold extends Event {
public Hold(Button button) {
this.button = button;
super(button);
}
}

View File

@@ -3,10 +3,8 @@ package pm.macro.event;
import pm.Button;
import pm.macro.Event;
public class Press implements Event {
public Button button;
public class Press extends Event {
public Press(Button button) {
this.button = button;
super(button);
}
}

View File

@@ -3,10 +3,8 @@ package pm.macro.event;
import pm.Button;
import pm.macro.Event;
public class Release implements Event {
public Button button;
public class Release extends Event {
public Release(Button button) {
this.button = button;
super(button);
}
}