Skip to content

Commit

Permalink
Change interface of AsterCommand
Browse files Browse the repository at this point in the history
An outer class still calls fillSettings to AsterCommand.
However, subclass of AsterCommand should overwrite onFillSettings
so that we could put some 'Must done' action in
AsterCommand.fillSettings
  • Loading branch information
walkingice committed Aug 20, 2011
1 parent 6924fd2 commit 143ef81
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/org/zeroxlab/aster/cmds/AsterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class AsterCommand {
protected BufferedImage mImage = null;
protected AsterOperation[] mOps;
protected boolean mExecuting = false;
protected boolean mFilled = false;

public static class ExecutionResult {
public boolean mSuccess;
Expand All @@ -54,6 +55,14 @@ public ExecutionResult(boolean success, String message) {
}
}

public boolean isFilled() {
return mFilled;
}

protected void setFilled(boolean status) {
mFilled = status;
}

static public void setScriptRunner(ScriptRunner runner) {
mRunner = runner;
}
Expand Down Expand Up @@ -98,14 +107,19 @@ public AsterOperation[] getOperations() {
return mOps;
}

public final void fillSettings(SimpleBindings settings) throws IOException {
setFilled(true);
onFillSettings(settings);
}

/* Get name of command */
public abstract String getName();

/* Get settings of a command */
public abstract SimpleBindings getSettings();

/* Set settings of a command */
public abstract void fillSettings(SimpleBindings settings) throws IOException;
protected abstract void onFillSettings(SimpleBindings settings) throws IOException;

/* Dump command to script text */
protected abstract String toScript();
Expand Down
3 changes: 2 additions & 1 deletion src/org/zeroxlab/aster/cmds/Drag.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Drag() {

public Drag(String prefix, String argline) throws IllegalArgumentException {
String[] args = splitArgs(argline);
super.setFilled(true);

if (args.length == 8) {
// drag(start_image, (dx, dy), duration, steps, timeout, similarity,
Expand Down Expand Up @@ -146,7 +147,7 @@ public SimpleBindings getSettings() {
}

@Override
public void fillSettings(SimpleBindings settings) throws IOException {
protected void onFillSettings(SimpleBindings settings) throws IOException {
if (settings.containsKey("CoordType")) {
mCoordType = (CoordType)settings.get("CoordType");
}
Expand Down
5 changes: 3 additions & 2 deletions src/org/zeroxlab/aster/cmds/Press.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ public Press(AsterOperation op) {
super.mOps = new AsterOperation[1];
super.mOps[0] = op;
try {
fillSettings(op.getSettings());
this.onFillSettings(op.getSettings());
} catch (Exception e) {
e.printStackTrace();
}
}

public Press(String argline) throws IllegalArgumentException {
super.setFilled(true);
String[] args = splitArgs(argline);
if (args.length == 2) {
// press(keycode, type)
Expand Down Expand Up @@ -102,7 +103,7 @@ public SimpleBindings getSettings() {
}

@Override
public void fillSettings(SimpleBindings settings) throws IOException {
protected void onFillSettings(SimpleBindings settings) throws IOException {
if (settings.containsKey("KeyCode")) {
mKeyCode = (String)settings.get("KeyCode");
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/zeroxlab/aster/cmds/Recall.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public Recall() {
}

public Recall(String argline) throws IllegalArgumentException {
super.setFilled(true);
String[] args = splitArgs(argline);

if (args.length == 1) {
Expand All @@ -61,7 +62,7 @@ public SimpleBindings getSettings() {
}

@Override
public void fillSettings(SimpleBindings settings) throws IOException {
protected void onFillSettings(SimpleBindings settings) throws IOException {
if (settings.containsKey("Script")) {
mScript = (String)settings.get("Script");
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/zeroxlab/aster/cmds/Touch.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public Touch() {

public Touch(String prefix, String argline)
throws IllegalArgumentException {
super.setFilled(true);
String[] args = splitArgs(argline);

if (args.length == 5) {
Expand Down Expand Up @@ -150,7 +151,7 @@ public SimpleBindings getSettings() {
}

@Override
public void fillSettings(SimpleBindings settings) throws IOException {
protected void onFillSettings(SimpleBindings settings) throws IOException {
if (settings.containsKey("CoordType")) {
mCoordType = (CoordType)settings.get("CoordType");
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/zeroxlab/aster/cmds/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public Type() {
}

public Type(String argline) throws IllegalArgumentException {
super.setFilled(true);
String[] args = splitArgs(argline);

if (args.length == 1) {
Expand Down Expand Up @@ -66,7 +67,7 @@ public SimpleBindings getSettings() {
}

@Override
public void fillSettings(SimpleBindings settings) throws IOException {
protected void onFillSettings(SimpleBindings settings) throws IOException {
if (settings == null) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/org/zeroxlab/aster/cmds/Wait.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Wait() {

public Wait(String prefix, String argline)
throws IllegalArgumentException {
super.setFilled(true);
String[] args = splitArgs(argline);
if (args.length == 4) {
// wait(image, timeout, similarity, landscape)
Expand Down Expand Up @@ -98,7 +99,7 @@ public SimpleBindings getSettings() {
}

@Override
public void fillSettings(SimpleBindings settings) throws IOException {
protected void onFillSettings(SimpleBindings settings) throws IOException {
if (settings.containsKey("WaitType")) {
mWaitType = (WaitType)settings.get("WaitType");
}
Expand Down

0 comments on commit 143ef81

Please sign in to comment.