11 changed files with 108 additions and 33 deletions
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
package de.srsoftware.web4rail.actions; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
import de.srsoftware.web4rail.BaseClass; |
||||
import de.srsoftware.web4rail.Window; |
||||
import de.srsoftware.web4rail.tags.Checkbox; |
||||
import de.srsoftware.web4rail.tags.Fieldset; |
||||
|
||||
public class StartStopAuto extends Action { |
||||
|
||||
private static final String INVERTED = "inverted"; |
||||
public boolean inverted = false; |
||||
|
||||
public StartStopAuto(BaseClass parent) { |
||||
super(parent); |
||||
} |
||||
|
||||
@Override |
||||
public boolean fire(Context context) { |
||||
if (isNull(context.train())) return false; |
||||
context.train().quitAutopilot(); |
||||
return true; |
||||
} |
||||
|
||||
public JSONObject json() { |
||||
JSONObject json = new JSONObject().put(TYPE, getClass().getSimpleName()); |
||||
if (inverted) json.put(INVERTED, true); |
||||
return json; |
||||
} |
||||
|
||||
public StartStopAuto load(JSONObject json) { |
||||
inverted = json.has(INVERTED) && json.getBoolean(INVERTED); |
||||
return this; |
||||
} |
||||
|
||||
@Override |
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) { |
||||
formInputs.add(t("inverted"),new Checkbox(INVERTED, t("inverted"), inverted)); |
||||
return super.properties(preForm, formInputs, postForm); |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return inverted ? t("Start autopilot") : t("Stop autopilot"); |
||||
} |
||||
|
||||
protected Object update(HashMap<String, String> params) { |
||||
inverted = "on".equals(params.get(INVERTED)); |
||||
return super.update(params); |
||||
} |
||||
} |
@ -1,17 +0,0 @@
@@ -1,17 +0,0 @@
|
||||
package de.srsoftware.web4rail.actions; |
||||
|
||||
import de.srsoftware.web4rail.BaseClass; |
||||
|
||||
public class StopAuto extends Action { |
||||
|
||||
public StopAuto(BaseClass parent) { |
||||
super(parent); |
||||
} |
||||
|
||||
@Override |
||||
public boolean fire(Context context) { |
||||
if (isNull(context.train())) return false; |
||||
context.train().quitAutopilot(); |
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
package de.srsoftware.web4rail.conditions; |
||||
|
||||
public class AutopilotActive extends Condition { |
||||
|
||||
@Override |
||||
public boolean fulfilledBy(Context context) { |
||||
if (isNull(context.train())) return false; |
||||
return context.train().usesAutopilot() != inverted; |
||||
} |
||||
|
||||
@Override |
||||
public String toString() { |
||||
return t(inverted ? "autopilot inactive for train":"autopilot active for train") ; |
||||
} |
||||
} |
Loading…
Reference in new issue