refurbishing route.save
This commit is contained in:
@@ -48,9 +48,7 @@ public abstract class Action implements Constants {
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put(TYPE, getClass().getSimpleName());
|
||||
return json;
|
||||
return new JSONObject().put(TYPE, getClass().getSimpleName());
|
||||
}
|
||||
|
||||
protected Tag link(int actionId, String context) {
|
||||
@@ -69,7 +67,7 @@ public abstract class Action implements Constants {
|
||||
case "SetSignalsToStop":
|
||||
return new SetSignalsToStop();
|
||||
case "SpeedReduction":
|
||||
return new SpeedReduction(json.getInt(SpeedReduction.MAX_SPEED));
|
||||
return new SetSpeed(json.getInt(SetSpeed.MAX_SPEED));
|
||||
case "TurnTrain":
|
||||
return new TurnTrain();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
Select select = new Select(TYPE);
|
||||
List<Class<? extends Action>> classes = List.of(
|
||||
ConditionalAction.class,
|
||||
SpeedReduction.class,
|
||||
SetSpeed.class,
|
||||
SetSignalsToStop.class,
|
||||
FinishRoute.class,
|
||||
TurnTrain.class,
|
||||
@@ -85,8 +86,8 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
case "SetSignalsToStop":
|
||||
add(new SetSignalsToStop());
|
||||
break;
|
||||
case "SpeedReduction":
|
||||
add(new SpeedReduction(0));
|
||||
case "SetSpeed":
|
||||
add(new SetSpeed(0));
|
||||
break;
|
||||
case "TurnTrain":
|
||||
add(new TurnTrain());
|
||||
@@ -170,6 +171,12 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
return id;
|
||||
}
|
||||
|
||||
public JSONArray json() {
|
||||
JSONArray result = new JSONArray();
|
||||
for (Action action : this) result.put(action.json());
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean moveUp(int actionId) {
|
||||
for (int i=1; i<size(); i++) {
|
||||
if (actionId == elementAt(i).id()) {
|
||||
|
||||
@@ -5,6 +5,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.conditions.Condition;
|
||||
@@ -17,6 +20,8 @@ import de.srsoftware.web4rail.tags.Select;
|
||||
|
||||
public class ConditionalAction extends Action {
|
||||
|
||||
private static final String CONDITIONS = "conditions";
|
||||
private static final String ACTIONS = "actions";
|
||||
private Vector<Condition> conditions = new Vector<Condition>();
|
||||
private ActionList actions = new ActionList();
|
||||
|
||||
@@ -26,6 +31,10 @@ public class ConditionalAction extends Action {
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
|
||||
private Tag conditionForm(HashMap<String, String> params) {
|
||||
Fieldset fieldset = new Fieldset(t("Conditions"));
|
||||
|
||||
@@ -64,6 +73,16 @@ public class ConditionalAction extends Action {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
JSONObject json = super.json();
|
||||
JSONArray conditions = new JSONArray();
|
||||
for (Condition condition : this.conditions) conditions.put(condition.json());
|
||||
json.put(CONDITIONS, conditions);
|
||||
json.put(ACTIONS, actions.json());
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
@@ -99,8 +118,4 @@ public class ConditionalAction extends Action {
|
||||
}
|
||||
return super.update(params);
|
||||
}
|
||||
|
||||
public ActionList children() {
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public class SpeedReduction extends Action{
|
||||
public class SetSpeed extends Action{
|
||||
|
||||
public static final String MAX_SPEED = "max_speed";
|
||||
private int maxSpeed = -1;
|
||||
|
||||
public SpeedReduction(int kmh) {
|
||||
public SetSpeed(int kmh) {
|
||||
super();
|
||||
maxSpeed = kmh;
|
||||
}
|
||||
Reference in New Issue
Block a user