Basis gelegd voor Events: Feedback en Task, daartoe aantal dingen hernoemd.
This commit is contained in:
@@ -3,7 +3,7 @@ package pm;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import pm.exception.MacroException;
|
||||
import pm.exception.macro.MacroEventOrderException;
|
||||
import pm.exception.state.StateOrderException;
|
||||
import pm.macro.Sequence;
|
||||
import pm.macro.State;
|
||||
import pm.macro.state.Hold;
|
||||
@@ -16,33 +16,33 @@ public class Macro extends Sequence {
|
||||
this.eventArray = new State[] {press, new Release(button)};
|
||||
}
|
||||
|
||||
public Macro(State... eventArray) throws MacroException {
|
||||
public Macro(State... eventArray) throws StateOrderException {
|
||||
ArrayList<Button> holdList = new ArrayList<Button>();
|
||||
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.");
|
||||
throw new StateOrderException("Press events cannot follow hold events for the same button.");
|
||||
}
|
||||
eventList.add(state);
|
||||
eventList.add(new Release(button));
|
||||
} else if (state instanceof Release) {
|
||||
if (!holdList.contains(button)) {
|
||||
throw new MacroEventOrderException("Cannot release a button that is not held.");
|
||||
throw new StateOrderException("Cannot release a button that is not held.");
|
||||
}
|
||||
holdList.remove(button);
|
||||
eventList.add(state);
|
||||
} else if (state instanceof Hold) {
|
||||
if (holdList.contains(button)) {
|
||||
throw new MacroEventOrderException("Cannot hold a button more than once.");
|
||||
throw new StateOrderException("Cannot hold a button more than once.");
|
||||
}
|
||||
holdList.add(button);
|
||||
eventList.add(new Press(button));
|
||||
}
|
||||
}
|
||||
if (!holdList.isEmpty()) {
|
||||
throw new MacroEventOrderException("One or more buttons are not released.");
|
||||
throw new StateOrderException("One or more buttons are not released.");
|
||||
}
|
||||
eventArray = (State[]) eventList.toArray(new State[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user