bugfixes, added new Condition AutopilotActive, extended StopAutopilot action to StartStopAutopilot, implemented ActionList export
This commit is contained in:
@@ -81,7 +81,7 @@ public abstract class Action extends BaseClass {
|
||||
SetTurnout.class,
|
||||
ShowText.class,
|
||||
StopAllTrains.class,
|
||||
StopAuto.class,
|
||||
StartStopAuto.class,
|
||||
TriggerContact.class,
|
||||
TurnTrain.class
|
||||
);
|
||||
@@ -97,7 +97,7 @@ public abstract class Action extends BaseClass {
|
||||
ActionList actionList = (ActionList) parent;
|
||||
return actionList.moveUp(this);
|
||||
}
|
||||
LOG.error("Action.drop() called on Action ({}) whose parent ({}) is not an ActionList!",this,parent);
|
||||
LOG.error("Action.moveUp() called on Action ({}) whose parent ({}) is not an ActionList!",this,parent);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,16 +116,13 @@ public class ActionList extends Action implements Iterable<Action>{
|
||||
public Tag list() {
|
||||
Tag span = new Tag("span");
|
||||
button(t("add action"), Map.of(ACTION, ACTION_ADD)).addTo(span);
|
||||
|
||||
button(t("export"), Map.of(ACTION, ACTION_SAVE)).addTo(span);
|
||||
if (!isEmpty()) {
|
||||
Tag list = new Tag("ol");
|
||||
boolean first = true;
|
||||
for (Action action : actions) {
|
||||
Tag item = action.link("span",action).addTo(new Tag("li")).content(NBSP);
|
||||
action.button("-", Map.of(ACTION,ACTION_DROP)).addTo(item);
|
||||
if (first) {
|
||||
first = false;
|
||||
} else action.button("↑", Map.of(ACTION,ACTION_MOVE)).addTo(item);
|
||||
action.button("↑", Map.of(ACTION,ACTION_MOVE)).addTo(item);
|
||||
if (action instanceof ActionList) ((ActionList) action).list().addTo(item);
|
||||
item.addTo(list);
|
||||
}
|
||||
@@ -151,10 +148,25 @@ public class ActionList extends Action implements Iterable<Action>{
|
||||
}
|
||||
|
||||
public boolean moveUp(Action action) {
|
||||
if (isNull(action)) return false;
|
||||
if (actions.firstElement() == action && parent() instanceof ActionList) {
|
||||
ActionList parentList = (ActionList) parent();
|
||||
for (int i=0; i<parentList.actions.size(); i++) {
|
||||
if (parentList.actions.get(i) == this) {
|
||||
actions.remove(0);
|
||||
parentList.actions.insertElementAt(action, i);
|
||||
action.parent(parentList);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=1; i<actions.size(); i++) {
|
||||
if (actions.elementAt(i) == action) {
|
||||
actions.remove(i);
|
||||
actions.insertElementAt(action, i-1);
|
||||
Action aboveAction = actions.get(i-1);
|
||||
if (aboveAction instanceof ActionList) {
|
||||
((ActionList)aboveAction).add(action);
|
||||
} else actions.insertElementAt(action, i-1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -180,9 +192,16 @@ public class ActionList extends Action implements Iterable<Action>{
|
||||
action.remove();
|
||||
return context.properties();
|
||||
case ACTION_MOVE:
|
||||
return action.moveUp() ? action.context().properties() : t("No action with id {} found!",actionId);
|
||||
if (isNull(action)) return t("No action with id {} found!",actionId);
|
||||
if (action.moveUp()) return action.context().properties();
|
||||
Window result = action.context().properties();
|
||||
return new Tag("fieldset").content(t("Was not able to move \"{}\" up!",action)).addTo(result);
|
||||
case ACTION_PROPS:
|
||||
return action.properties();
|
||||
case ACTION_SAVE:
|
||||
Window win = new Window("action-export", t("Export of {}",action));
|
||||
new Tag("textarea").content(action.json().toString()).addTo(win);
|
||||
return win;
|
||||
case ACTION_UPDATE:
|
||||
return action.update(params);
|
||||
}
|
||||
|
||||
@@ -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 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user