more refactoring
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.2.8</version>
|
<version>1.2.9</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Add tile : Kachel hinzufügen
|
|||||||
Address : Adresse
|
Address : Adresse
|
||||||
Address\: : Adresse:
|
Address\: : Adresse:
|
||||||
Analyze : analysieren
|
Analyze : analysieren
|
||||||
|
and : und
|
||||||
Apply : Übernehmen
|
Apply : Übernehmen
|
||||||
Auto pilot : Autopilot
|
Auto pilot : Autopilot
|
||||||
Availability : Verfügbarkeit
|
Availability : Verfügbarkeit
|
||||||
@@ -37,9 +38,10 @@ Car manager : Waggon-Verwaltung
|
|||||||
Cars\: : Waggons:
|
Cars\: : Waggons:
|
||||||
Click here to select train! : HIer klicken, um Zug auszuwählen!
|
Click here to select train! : HIer klicken, um Zug auszuwählen!
|
||||||
[Click here to select block!] : [Hier klicken, um Block auszuwählen!]
|
[Click here to select block!] : [Hier klicken, um Block auszuwählen!]
|
||||||
[Click here to add condition] : [Hier klicken, um Bedingung hinzuzufügen]
|
Click to setup tag : Hier klicken, um Markierung anzugeben
|
||||||
|
Click here to add conditions : Hier klicken, um Bedingungen hinzuzufügen
|
||||||
[Click here to select display!] : [Hier klicken, um Anzeige auszuwählen!]
|
[Click here to select display!] : [Hier klicken, um Anzeige auszuwählen!]
|
||||||
[Click here to select train!] : [Hier klicken, um Zug auszuwählen!]
|
Click here to select train! : Hier klicken, um Zug auszuwählen!
|
||||||
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
||||||
click here to setup relay : Hier klicken, um Relais einzurichten
|
click here to setup relay : Hier klicken, um Relais einzurichten
|
||||||
Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu bearbeiten.
|
Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu bearbeiten.
|
||||||
@@ -69,7 +71,7 @@ Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
|||||||
Direction : Richtung
|
Direction : Richtung
|
||||||
Direction\: heading {} : Richtung: nach {}
|
Direction\: heading {} : Richtung: nach {}
|
||||||
disabled : deaktiviert
|
disabled : deaktiviert
|
||||||
Display "{}" on clients. : „{}“ auf den Clients anzeigen.
|
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
||||||
Drop : Verwerfen
|
Drop : Verwerfen
|
||||||
Dropped destination of {}. : Ziel von {} verworfen.
|
Dropped destination of {}. : Ziel von {} verworfen.
|
||||||
1) Duration between 5 {} steps during brake process. : 1) Zeit zwischen 5 {}-Schritten beim Bremsvorgang.
|
1) Duration between 5 {} steps during brake process. : 1) Zeit zwischen 5 {}-Schritten beim Bremsvorgang.
|
||||||
@@ -124,8 +126,10 @@ Notes : Notizen
|
|||||||
Occupied area\: : Belegte Abschnitte:
|
Occupied area\: : Belegte Abschnitte:
|
||||||
Off : Aus
|
Off : Aus
|
||||||
On : An
|
On : An
|
||||||
|
One of : eine von
|
||||||
One way : Richtung
|
One way : Richtung
|
||||||
Online Documentation : Online-Dokumentation
|
Online Documentation : Online-Dokumentation
|
||||||
|
or : oder
|
||||||
OrCondition : Oder-Bedingung
|
OrCondition : Oder-Bedingung
|
||||||
other train properties : andere Zug-Eigenschaften
|
other train properties : andere Zug-Eigenschaften
|
||||||
Origin and destination : Start und Ziel
|
Origin and destination : Start und Ziel
|
||||||
@@ -148,10 +152,10 @@ Route will only be available, if all conditions are fulfilled. : Route ist nur v
|
|||||||
Save : speichern
|
Save : speichern
|
||||||
Select block : Block auswählen
|
Select block : Block auswählen
|
||||||
Select contact\: : Kotakt auswählen:
|
Select contact\: : Kotakt auswählen:
|
||||||
Select display\: : Anzeige auswählen:
|
Select display : Anzeige auswählen
|
||||||
Select from plan : Auf Plan auswählen
|
Select from plan : Auf Plan auswählen
|
||||||
Select relay\: : Relais auswählen:
|
Select relay\: : Relais auswählen:
|
||||||
Select train\: : Zug auswählen:
|
Select train: : Zug auswählen
|
||||||
SendCommand : Kommando senden
|
SendCommand : Kommando senden
|
||||||
Send command "{}" to control unit : Kommando „{}“ an Zentrale senden
|
Send command "{}" to control unit : Kommando „{}“ an Zentrale senden
|
||||||
Set {} as context : {} als Kontext setzen
|
Set {} as context : {} als Kontext setzen
|
||||||
|
|||||||
@@ -238,11 +238,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
if (this instanceof Train) return REALM_TRAIN;
|
if (this instanceof Train) return REALM_TRAIN;
|
||||||
return REALM_PLAN;
|
return REALM_PLAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,String> contextAction(String action){
|
|
||||||
return Map.of(ACTION,action,CONTEXT,realm()+":"+id());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Form form(String id,List<Map.Entry<String, Tag>> elements) {
|
public Form form(String id,List<Map.Entry<String, Tag>> elements) {
|
||||||
Form form = new Form(id);
|
Form form = new Form(id);
|
||||||
|
|
||||||
@@ -356,7 +352,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
|
|
||||||
|
|
||||||
protected Window properties(List<Fieldset> preForm,FormInput formInputs,List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm,FormInput formInputs,List<Fieldset> postForm) {
|
||||||
Window win = new Window(getClass().getSimpleName()+"-properties", t("Properties of {}",this));
|
Window win = new Window(getClass().getSimpleName()+"-properties", t("Properties of {} ({})",this.title(),id));
|
||||||
|
|
||||||
preForm.forEach(fieldset -> fieldset.addTo(win));
|
preForm.forEach(fieldset -> fieldset.addTo(win));
|
||||||
|
|
||||||
@@ -375,6 +371,10 @@ public abstract class BaseClass implements Constants{
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String title() {
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
private Map<String,String> props(Map<String,String> additionalProps){
|
private Map<String,String> props(Map<String,String> additionalProps){
|
||||||
HashMap<String,String> props = new HashMap<String, String>(Map.of(REALM, realm(), ACTION, ACTION_PROPS, ID, id().toString()));
|
HashMap<String,String> props = new HashMap<String, String>(Map.of(REALM, realm(), ACTION, ACTION_PROPS, ID, id().toString()));
|
||||||
if (isSet(additionalProps)) props.putAll(additionalProps);
|
if (isSet(additionalProps)) props.putAll(additionalProps);
|
||||||
|
|||||||
@@ -716,10 +716,10 @@ public class Plan extends BaseClass{
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void set(int x,int y,Tile tile) throws IOException {
|
public void set(int x,int y,Tile tile) throws IOException {
|
||||||
if (tile == null) return;
|
if (isNull(tile)) return;
|
||||||
for (int i=1; i<tile.width(); i++) set(x+i,y,new Shadow(tile));
|
|
||||||
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
|
|
||||||
setIntern(x,y,tile);
|
setIntern(x,y,tile);
|
||||||
|
for (int i=1; i<tile.width(); i++) set(x+i,y,new Shadow(tile,x+i,y));
|
||||||
|
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile,x,y+1));
|
||||||
place(tile);
|
place(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,8 +167,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
switch (params.get(ACTION)) {
|
switch (params.get(ACTION)) {
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
route.remove();
|
route.remove();
|
||||||
return t("Removed {}.",route);
|
return t("Removed {}.",route);
|
||||||
|
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return route.properties();
|
return route.properties();
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
@@ -552,9 +551,9 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
for (Object signalId : json.getJSONArray(SIGNALS)) addSignal((Signal) plan.get(new Id((String) signalId), false));
|
for (Object signalId : json.getJSONArray(SIGNALS)) addSignal((Signal) plan.get(new Id((String) signalId), false));
|
||||||
}
|
}
|
||||||
if (json.has(ACTION_LISTS)) loadActions(json.getJSONArray(ACTION_LISTS));
|
if (json.has(ACTION_LISTS)) loadActions(json.getJSONArray(ACTION_LISTS));
|
||||||
if (json.has(CONDITIONS)) conditions.load(json.getJSONArray(CONDITIONS));
|
if (json.has(CONDITIONS)) conditions.load(json.getJSONArray(CONDITIONS)).parent(this);
|
||||||
if (json.has(SETUP_ACTIONS)) setupActions.load(json.getJSONArray(SETUP_ACTIONS));
|
if (json.has(SETUP_ACTIONS)) setupActions.load(json.getJSONArray(SETUP_ACTIONS)).parent(this);
|
||||||
if (json.has(START_ACTIONS)) startActions.load(json.getJSONArray(START_ACTIONS));
|
if (json.has(START_ACTIONS)) startActions.load(json.getJSONArray(START_ACTIONS)).parent(this);
|
||||||
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
|
if (json.has(DISABLED)) disabled = json.getBoolean(DISABLED);
|
||||||
if (json.has(BRAKE_TIMES)) {
|
if (json.has(BRAKE_TIMES)) {
|
||||||
JSONObject dummy = json.getJSONObject(BRAKE_TIMES);
|
JSONObject dummy = json.getJSONObject(BRAKE_TIMES);
|
||||||
@@ -568,6 +567,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
JSONObject json = arr.getJSONObject(i);
|
JSONObject json = arr.getJSONObject(i);
|
||||||
String trigger = json.getString(TRIGGER);
|
String trigger = json.getString(TRIGGER);
|
||||||
ActionList actionList = new ActionList(this).load(json.getJSONArray(ACTIONS));
|
ActionList actionList = new ActionList(this).load(json.getJSONArray(ACTIONS));
|
||||||
|
actionList.parent(this);
|
||||||
triggers.put(trigger, actionList);
|
triggers.put(trigger, actionList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import de.keawe.tools.translations.Translation;
|
|||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Application;
|
import de.srsoftware.web4rail.Application;
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Window;
|
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tags.Select;
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
|
||||||
@@ -32,6 +31,12 @@ public abstract class Action extends BaseClass {
|
|||||||
parent(parent);
|
parent(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseClass context() {
|
||||||
|
BaseClass context = this;
|
||||||
|
while (context instanceof Action && isSet(context.parent())) context = context.parent();
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
public static Action create(String type,BaseClass parent) {
|
public static Action create(String type,BaseClass parent) {
|
||||||
try {
|
try {
|
||||||
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor(BaseClass.class).newInstance(parent);
|
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor(BaseClass.class).newInstance(parent);
|
||||||
@@ -41,16 +46,6 @@ public abstract class Action extends BaseClass {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean drop() {
|
|
||||||
BaseClass parent = parent();
|
|
||||||
if (parent instanceof ActionList) {
|
|
||||||
ActionList actionList = (ActionList) parent;
|
|
||||||
return actionList.drop(this);
|
|
||||||
}
|
|
||||||
LOG.error("Action.drop() called on Action ({}) whose parent ({}) is not an ActionList!",this,parent);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean equals(Action other) {
|
public boolean equals(Action other) {
|
||||||
return this.toString().equals(other.toString());
|
return this.toString().equals(other.toString());
|
||||||
}
|
}
|
||||||
@@ -104,10 +99,10 @@ public abstract class Action extends BaseClass {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* @Override
|
||||||
public Window properties() { // goes up to first ancestor, which is not an Action
|
public Window properties() { // goes up to first ancestor, which is not an Action
|
||||||
return parent().properties();
|
return parent().properties();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public static Tag selector() {
|
public static Tag selector() {
|
||||||
Select select = new Select(TYPE);
|
Select select = new Select(TYPE);
|
||||||
@@ -134,6 +129,6 @@ public abstract class Action extends BaseClass {
|
|||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
super.update(params);
|
||||||
return properties();
|
return context().properties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.srsoftware.web4rail.actions;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@@ -29,12 +30,12 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
actions = new Vector<Action>();
|
actions = new Vector<Action>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object actionTypeForm(Window win, String context) {
|
private Tag actionTypeForm() {
|
||||||
|
Window win = new Window("add-action-form", t("Add action to action list"));
|
||||||
Form typeForm = new Form("add-action-to-"+id);
|
Form typeForm = new Form("add-action-to-"+id);
|
||||||
new Input(REALM, REALM_ACTIONS).hideIn(typeForm);
|
new Input(REALM, REALM_ACTIONS).hideIn(typeForm);
|
||||||
new Input(ID,id).hideIn(typeForm);
|
new Input(ID,id).hideIn(typeForm);
|
||||||
new Input(ACTION,ACTION_ADD).hideIn(typeForm);
|
new Input(ACTION,ACTION_ADD).hideIn(typeForm);
|
||||||
new Input(CONTEXT,context).hideIn(typeForm);
|
|
||||||
Action.selector().addTo(typeForm);
|
Action.selector().addTo(typeForm);
|
||||||
return new Button(t("Create action"),typeForm).addTo(typeForm).addTo(win);
|
return new Button(t("Create action"),typeForm).addTo(typeForm).addTo(win);
|
||||||
}
|
}
|
||||||
@@ -45,18 +46,14 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object addActionForm(HashMap<String, String> params, Plan plan) {
|
private Object addActionForm(HashMap<String, String> params, Plan plan) {
|
||||||
Window win = new Window("add-action-form", t("Add action to action list"));
|
|
||||||
String type = params.get(TYPE);
|
String type = params.get(TYPE);
|
||||||
String context = params.get(CONTEXT);
|
if (isNull(type)) return actionTypeForm();
|
||||||
if (type == null) return actionTypeForm(win,context);
|
|
||||||
Action action = Action.create(type,this);
|
Action action = Action.create(type,this);
|
||||||
if (action instanceof Action) {
|
if (action instanceof Action) {
|
||||||
add(action);
|
add(action);
|
||||||
return parent().properties();
|
return context().properties();
|
||||||
}
|
}
|
||||||
actionTypeForm(win,context);
|
return new Tag("span").content(t("Unknown action type: {}",type)).addTo(actionTypeForm());
|
||||||
new Tag("span").content(t("Unknown action type: {}",type)).addTo(win);
|
|
||||||
return win;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addActionsFrom(ActionList other) {
|
public void addActionsFrom(ActionList other) {
|
||||||
@@ -117,18 +114,18 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tag list() {
|
public Tag list() {
|
||||||
Button button = button(t("add action"), contextAction(ACTION_ADD_ACTION));
|
|
||||||
Tag span = new Tag("span");
|
Tag span = new Tag("span");
|
||||||
button.addTo(span);
|
button(t("add action"), Map.of(ACTION, ACTION_ADD)).addTo(span);
|
||||||
|
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
Tag list = new Tag("ol");
|
Tag list = new Tag("ol");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Action action : actions) {
|
for (Action action : actions) {
|
||||||
Tag item = action.link("span",action).addTo(new Tag("li"));
|
Tag item = action.link("span",action).addTo(new Tag("li")).content(NBSP);
|
||||||
|
action.button("-", Map.of(ACTION,ACTION_DROP)).addTo(item);
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else action.button("↑", contextAction(ACTION_MOVE)).addTo(item.content(NBSP));
|
} else action.button("↑", Map.of(ACTION,ACTION_MOVE)).addTo(item);
|
||||||
if (action instanceof ActionList) ((ActionList) action).list().addTo(item);
|
if (action instanceof ActionList) ((ActionList) action).list().addTo(item);
|
||||||
item.addTo(list);
|
item.addTo(list);
|
||||||
}
|
}
|
||||||
@@ -174,7 +171,10 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
if (isNull(actionList)) return t("Id ({}) does not belong to ActionList!",actionId);
|
if (isNull(actionList)) return t("Id ({}) does not belong to ActionList!",actionId);
|
||||||
return actionList.addActionForm(params,plan);
|
return actionList.addActionForm(params,plan);
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
return action.drop() ? action.properties() : t("No action with id {} found!",actionId);
|
if (isNull(action)) return t("No action with id {} found!",actionId);
|
||||||
|
BaseClass context = action.context();
|
||||||
|
action.remove();
|
||||||
|
return context.properties();
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
return action.moveUp() ? action.properties() : t("No action with id {} found!",actionId);
|
return action.moveUp() ? action.properties() : t("No action with id {} found!",actionId);
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
@@ -189,7 +189,7 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
Fieldset fieldset = new Fieldset(t("Actions"));
|
||||||
list().addTo(fieldset);
|
list().addTo(fieldset);
|
||||||
preForm.add(fieldset);
|
postForm.add(fieldset);
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,68 +2,29 @@ package de.srsoftware.web4rail.actions;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.conditions.Condition;
|
import de.srsoftware.web4rail.conditions.Condition;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.conditions.ConditionList;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
|
||||||
|
|
||||||
public class ConditionalAction extends ActionList {
|
public class ConditionalAction extends ActionList {
|
||||||
|
|
||||||
private static final String CONDITIONS = "conditions";
|
private static final String CONDITIONS = "conditions";
|
||||||
private static final String ACTIONS = "actions";
|
private static final String ACTIONS = "actions";
|
||||||
private Vector<Condition> conditions = new Vector<Condition>();
|
private ConditionList conditions = new ConditionList();
|
||||||
|
|
||||||
public ConditionalAction(BaseClass parent) {
|
public ConditionalAction(BaseClass parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
conditions.parent(this);
|
||||||
|
|
||||||
private StringBuffer conditions() {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for (int i = 0; i<conditions.size(); i++) {
|
|
||||||
if (i>0) sb.append(t(" and "));
|
|
||||||
sb.append(conditions.get(i).toString());
|
|
||||||
}
|
|
||||||
return sb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Fieldset conditionForm() {
|
|
||||||
Fieldset fieldset = new Fieldset(t("Conditions"));
|
|
||||||
|
|
||||||
new Tag("p").content(t("Actions will only fire, if all conditions are fullfilled.")).addTo(fieldset);
|
|
||||||
if (!conditions.isEmpty()) {
|
|
||||||
Tag list = new Tag("ul");
|
|
||||||
for (Condition condition : conditions) {
|
|
||||||
Tag li = link("span", condition+NBSP,Map.of()).addTo(new Tag("li"));
|
|
||||||
HashMap<String,Object> props = new HashMap<String, Object>(Map.of(REALM,REALM_CONDITION,ID,condition.id(),ACTION,ACTION_DROP,CONTEXT, REALM_ACTIONS+":"+id()));
|
|
||||||
new Button(t("delete"), props).addTo(li).addTo(list);
|
|
||||||
}
|
|
||||||
list.addTo(fieldset);
|
|
||||||
}
|
|
||||||
|
|
||||||
Form form = new Form("action-prop-form-"+id);
|
|
||||||
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
|
||||||
new Input(ID,id()).hideIn(form);
|
|
||||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
|
||||||
|
|
||||||
Condition.selector().addTo(form);
|
|
||||||
|
|
||||||
new Button(t("Add condition"),form).addTo(form);
|
|
||||||
button(t("Back")).addTo(form).addTo(fieldset);
|
|
||||||
return fieldset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(ConditionalAction other) {
|
public boolean equals(ConditionalAction other) {
|
||||||
return (conditions()+":"+actions).equals(other.conditions()+":"+other.actions);
|
return (conditions+":"+actions).equals(other.conditions+":"+other.actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,10 +64,7 @@ public class ConditionalAction extends ActionList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
preForm.add(conditionForm());
|
preForm.add(conditions.list());
|
||||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
|
||||||
list().addTo(fieldset);
|
|
||||||
postForm.add(fieldset);
|
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -118,8 +76,8 @@ public class ConditionalAction extends ActionList {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (conditions.isEmpty()) return t("[Click here to add condition]");
|
if (conditions.isEmpty()) return "["+t("Click here to add conditions")+"]";
|
||||||
return t("if ({}):",conditions());
|
return t("if ({}):",conditions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -61,9 +61,6 @@ public class DelayedAction extends ActionList {
|
|||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
formInputs.add(t("Delay"),new Input(DELAY,delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
formInputs.add(t("Delay"),new Input(DELAY,delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
||||||
Fieldset fieldset = new Fieldset(t("Actions"));
|
|
||||||
list().addTo(fieldset);
|
|
||||||
postForm.add(fieldset);
|
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,10 +68,9 @@ public class SetDisplayText extends TextAction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
|
||||||
String displayId = params.get(TextDisplay.class.getSimpleName());
|
String displayId = params.get(TextDisplay.class.getSimpleName());
|
||||||
if (isSet(displayId)) display = (TextDisplay) plan.get(new Id(displayId), false);
|
if (isSet(displayId)) display = (TextDisplay) plan.get(new Id(displayId), false);
|
||||||
return properties();
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,6 @@ public abstract class TextAction extends Action {
|
|||||||
protected Object update(HashMap<String, String> params) {
|
protected Object update(HashMap<String, String> params) {
|
||||||
LOG.debug("update: {}",params);
|
LOG.debug("update: {}",params);
|
||||||
text = params.get(TEXT);
|
text = params.get(TEXT);
|
||||||
return properties();
|
return super.update(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ import de.srsoftware.web4rail.Application;
|
|||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
import de.srsoftware.web4rail.Plan;
|
import de.srsoftware.web4rail.Plan;
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.actions.Action;
|
||||||
import de.srsoftware.web4rail.tags.Checkbox;
|
import de.srsoftware.web4rail.tags.Checkbox;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
|
||||||
import de.srsoftware.web4rail.tags.Select;
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
|
||||||
public abstract class Condition extends BaseClass {
|
public abstract class Condition extends BaseClass {
|
||||||
@@ -40,48 +40,36 @@ public abstract class Condition extends BaseClass {
|
|||||||
String action = params.get(ACTION);
|
String action = params.get(ACTION);
|
||||||
if (action == null) return t("No action passed to Condition.action!");
|
if (action == null) return t("No action passed to Condition.action!");
|
||||||
|
|
||||||
Id cid = Id.from(params);
|
Id id = Id.from(params);
|
||||||
|
Condition condition = BaseClass.get(id);
|
||||||
if (isSet(cid)) {
|
|
||||||
Condition condition = BaseClass.get(cid);
|
|
||||||
if (isNull(condition)) return t("No condition with id {}!",cid);
|
|
||||||
|
|
||||||
switch (action) {
|
|
||||||
case ACTION_PROPS:
|
|
||||||
return condition.properties();
|
|
||||||
case ACTION_UPDATE:
|
|
||||||
condition.update(params);
|
|
||||||
return condition.parent().properties();
|
|
||||||
case ACTION_DROP:
|
|
||||||
condition.remove();
|
|
||||||
return condition.parent().properties();
|
|
||||||
}
|
|
||||||
return t("Unknown action: {}",action);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_ADD:
|
case ACTION_ADD:
|
||||||
return addCondition(params);
|
return addCondition(params);
|
||||||
|
case ACTION_DROP:
|
||||||
|
BaseClass context = condition.context();
|
||||||
|
condition.remove();
|
||||||
|
return context.properties();
|
||||||
|
case ACTION_PROPS:
|
||||||
|
return condition.properties();
|
||||||
|
case ACTION_UPDATE:
|
||||||
|
condition.update(params);
|
||||||
|
return condition.context().properties();
|
||||||
}
|
}
|
||||||
return t("Unknown action: {}",action);
|
return t("Unknown action: {}",action);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object addCondition(HashMap<String, String> params) {
|
private static Object addCondition(HashMap<String, String> params) {
|
||||||
String type = params.get(REALM_CONDITION);
|
String type = params.get(REALM_CONDITION);
|
||||||
if (isNull(type)) return t("No type supplied to addCondition!");
|
if (isNull(type)) return t("No type supplied to addCondition!");
|
||||||
|
|
||||||
Id parentId = Id.from(params, PARENT);
|
Id parentId = Id.from(params);
|
||||||
if (isNull(parentId)) return t("No parent id supplied to addCondition");
|
if (isNull(parentId)) return t("No parent id supplied to addCondition");
|
||||||
|
|
||||||
BaseClass parent = BaseClass.get(parentId);
|
ConditionList conditionList = BaseClass.get(parentId);
|
||||||
if (isNull(parent)) return t("No condition with id {} found!",parentId);
|
if (isNull(conditionList)) return t("No condition list with id {} found!",parentId);
|
||||||
|
|
||||||
Condition condition = Condition.create(type);
|
return conditionList.add(Condition.create(type)).properties();
|
||||||
if (isNull(condition)) return t("Unknown type \"{}\" of condition!",type);
|
|
||||||
|
|
||||||
return condition.parent(parent).properties();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Condition create(String type) {
|
public static Condition create(String type) {
|
||||||
@@ -94,6 +82,14 @@ public abstract class Condition extends BaseClass {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BaseClass context() {
|
||||||
|
BaseClass context = this;
|
||||||
|
while (isSet(context.parent()) && (context instanceof Condition || context instanceof Action)) {
|
||||||
|
context = context.parent();
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean fulfilledBy(Context context);
|
public abstract boolean fulfilledBy(Context context);
|
||||||
|
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
@@ -137,7 +133,7 @@ public abstract class Condition extends BaseClass {
|
|||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tag selector() {
|
public static Select selector() {
|
||||||
Select select = new Select(REALM_CONDITION);
|
Select select = new Select(REALM_CONDITION);
|
||||||
TreeMap<String, String> names = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
TreeMap<String, String> names = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
|
||||||
@@ -147,7 +143,7 @@ public abstract class Condition extends BaseClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<String, String> entry : names.entrySet()) select.addOption(entry.getValue(), entry.getKey());
|
for (Entry<String, String> entry : names.entrySet()) select.addOption(entry.getValue(), entry.getKey());
|
||||||
return select.addTo(new Label(t("Condition type:")+NBSP));
|
return select;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String t(String text, Object...fills) {
|
public static String t(String text, Object...fills) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.srsoftware.web4rail.conditions;
|
package de.srsoftware.web4rail.conditions;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -9,6 +10,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.BaseClass;
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
@@ -18,8 +20,10 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
|||||||
|
|
||||||
private Vector<Condition> conditions = new Vector<Condition>();
|
private Vector<Condition> conditions = new Vector<Condition>();
|
||||||
|
|
||||||
public void add(Condition condition) {
|
public ConditionList add(Condition condition) {
|
||||||
conditions.add(condition);
|
conditions.add(condition);
|
||||||
|
condition.parent(this);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(ConditionList conditions) {
|
public void addAll(ConditionList conditions) {
|
||||||
@@ -34,6 +38,10 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String glue() {
|
||||||
|
return t("and");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return conditions.isEmpty();
|
return conditions.isEmpty();
|
||||||
}
|
}
|
||||||
@@ -62,14 +70,26 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
|||||||
public Fieldset list(String caption) {
|
public Fieldset list(String caption) {
|
||||||
Fieldset fieldset = new Fieldset(t("Conditions"));
|
Fieldset fieldset = new Fieldset(t("Conditions"));
|
||||||
if (caption != null) new Tag("p").content(caption).addTo(fieldset);
|
if (caption != null) new Tag("p").content(caption).addTo(fieldset);
|
||||||
Tag list = new Tag("ul");
|
listInternal().addTo(fieldset);
|
||||||
newConditionForm().addTo(new Tag("li")).addTo(list);
|
|
||||||
conditions.forEach(condition -> condition.link("li", condition).addTo(list));
|
|
||||||
list.addTo(fieldset);
|
|
||||||
return fieldset;
|
return fieldset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tag listInternal() {
|
||||||
|
Tag list = new Tag("ul");
|
||||||
|
for (Condition condition : conditions) {
|
||||||
|
Tag item = new Tag("li");
|
||||||
|
condition.link("span", condition).addTo(item);
|
||||||
|
condition.button(t("delete"), Map.of(ACTION,ACTION_DROP)).addTo(item.content(NBSP)).addTo(list);
|
||||||
|
if (condition instanceof ConditionList) {
|
||||||
|
((ConditionList)condition).listInternal().addTo(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newConditionForm().addTo(new Tag("li")).addTo(list);
|
||||||
|
return list;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void load(JSONArray arr) {
|
public ConditionList load(JSONArray arr) {
|
||||||
for (int i=0; i<arr.length(); i++) {
|
for (int i=0; i<arr.length(); i++) {
|
||||||
JSONObject json = arr.getJSONObject(i);
|
JSONObject json = arr.getJSONObject(i);
|
||||||
Condition condition = Condition.create(json.getString(TYPE));
|
Condition condition = Condition.create(json.getString(TYPE));
|
||||||
@@ -78,18 +98,26 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
|||||||
conditions.add(condition.load(json));
|
conditions.add(condition.load(json));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Form newConditionForm() {
|
private Form newConditionForm() {
|
||||||
Form form = new Form("add-condition-form");
|
Form form = new Form("new-condition-form-"+id());
|
||||||
new Input(REALM, REALM_CONDITION).hideIn(form);
|
new Input(REALM, REALM_CONDITION).hideIn(form);
|
||||||
new Input(ACTION,ACTION_ADD).hideIn(form);
|
new Input(ACTION,ACTION_ADD).hideIn(form);
|
||||||
new Input(PARENT,id());
|
new Input(ID,id()).hideIn(form);
|
||||||
Condition.selector().addTo(form);
|
Condition.selector().addTo(form);
|
||||||
new Button(t("Add condition"), form).addTo(form);
|
new Button(t("Add condition"), form).addTo(form);
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window properties() {
|
||||||
|
BaseClass parent = parent();
|
||||||
|
if (isSet(parent)) return parent.properties();
|
||||||
|
return super.properties();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BaseClass remove() {
|
public BaseClass remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
@@ -110,4 +138,13 @@ public class ConditionList extends Condition implements Iterable<Condition>{
|
|||||||
public Stream<Condition> stream() {
|
public Stream<Condition> stream() {
|
||||||
return conditions.stream();
|
return conditions.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (conditions.isEmpty()) return "["+t("Click here to add conditions")+"]";
|
||||||
|
StringBuffer sb = new StringBuffer(conditions.firstElement().toString());
|
||||||
|
String glue = glue();
|
||||||
|
for (int i=1; i<conditions.size(); i++) sb.append(" ").append(glue).append(" "+conditions.get(i));
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.conditions;
|
package de.srsoftware.web4rail.conditions;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class OrCondition extends ConditionList{
|
public class OrCondition extends ConditionList{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -11,9 +9,9 @@ public class OrCondition extends ConditionList{
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
protected String glue() {
|
||||||
return isEmpty() ? t("Click here to select conditions") : String.join(" "+t("OR")+" ", stream().map(Object::toString).collect(Collectors.toList()));
|
return t("or");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class TrainHasTag extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (tag == null) return t("[Click to setup tag]");
|
if (tag == null) return "["+t("Click to setup tag")+"]";
|
||||||
return t(inverted ? "train does not have tag \"{}\"" : "train has tag \"{}\"",tag) ;
|
return t(inverted ? "train does not have tag \"{}\"" : "train has tag \"{}\"",tag) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class TrainSelect extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
formInputs.add(t("Select train"),Train.selector(train, null));
|
formInputs.add(t("Select train")+":",Train.selector(train, null));
|
||||||
return super.properties(preForm, formInputs, postForm);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public class TrainSelect extends Condition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (train == null) return t("[Click here to select train!]");
|
if (train == null) return "["+t("Click here to select train!")+"]";
|
||||||
return t("Train")+ (inverted?"≠":"=") + train;
|
return t("Train")+ (inverted?"≠":"=") + train;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import de.srsoftware.web4rail.tags.Select;
|
|||||||
* @author Stephan Richter, SRSoftware
|
* @author Stephan Richter, SRSoftware
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class Block extends StretchableTile implements Comparable<Block>{
|
public abstract class Block extends StretchableTile{
|
||||||
private static final String ALLOW_TURN = "allowTurn";
|
private static final String ALLOW_TURN = "allowTurn";
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
private static final String NO_TAG = "[default]";
|
private static final String NO_TAG = "[default]";
|
||||||
@@ -127,7 +127,6 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
|||||||
return super.click();
|
return super.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Block other) {
|
public int compareTo(Block other) {
|
||||||
return name.compareTo(other.name);
|
return name.compareTo(other.name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ public class Shadow extends Tile{
|
|||||||
return super.connections(from);
|
return super.connections(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shadow(Tile overlay) {
|
public Shadow(Tile overlay, int x, int y) {
|
||||||
this.overlay = overlay;
|
this.overlay = overlay;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
overlay.addShadow(this);
|
overlay.addShadow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.Vector;
|
|||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Plan.Direction;
|
import de.srsoftware.web4rail.Plan.Direction;
|
||||||
|
|
||||||
public abstract class Signal extends Tile implements Comparable<Signal>{
|
public abstract class Signal extends Tile {
|
||||||
public static final String STATE = "state";
|
public static final String STATE = "state";
|
||||||
public static final String STOP = "stop";
|
public static final String STOP = "stop";
|
||||||
public static final String GO = "go";
|
public static final String GO = "go";
|
||||||
@@ -29,13 +29,6 @@ public abstract class Signal extends Tile implements Comparable<Signal>{
|
|||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Signal other) {
|
|
||||||
Id tid = this.id();
|
|
||||||
Id oid = other.id();
|
|
||||||
return tid.compareTo(oid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract boolean isAffectedFrom(Direction dir);
|
public abstract boolean isAffectedFrom(Direction dir);
|
||||||
|
|
||||||
public boolean state(String state) {
|
public boolean state(String state) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -37,7 +36,7 @@ import de.srsoftware.web4rail.tags.Radio;
|
|||||||
* @author Stephan Richter, SRSoftware
|
* @author Stephan Richter, SRSoftware
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class Tile extends BaseClass{
|
public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
||||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||||
private static int DEFAUT_LENGTH = 100; // 10cm
|
private static int DEFAUT_LENGTH = 100; // 10cm
|
||||||
|
|
||||||
@@ -57,7 +56,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
protected Direction oneWay = null;
|
protected Direction oneWay = null;
|
||||||
protected Route route = null;
|
protected Route route = null;
|
||||||
private TreeSet<Route> routes = new TreeSet<>();
|
private TreeSet<Route> routes = new TreeSet<>();
|
||||||
protected HashSet<Shadow> shadows = new HashSet<>();
|
protected TreeSet<Shadow> shadows = new TreeSet<>();
|
||||||
protected Train train = null;
|
protected Train train = null;
|
||||||
public Integer x = null;
|
public Integer x = null;
|
||||||
public Integer y = null;
|
public Integer y = null;
|
||||||
@@ -85,6 +84,12 @@ public abstract class Tile extends BaseClass{
|
|||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Tile other) {
|
||||||
|
if (x == other.x) return y-other.y;
|
||||||
|
return x - other.x;
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject config() {
|
public JSONObject config() {
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
}
|
}
|
||||||
@@ -207,14 +212,14 @@ public abstract class Tile extends BaseClass{
|
|||||||
} else fieldset = new Fieldset(t("Train"));
|
} else fieldset = new Fieldset(t("Train"));
|
||||||
train.link("span", t("Train")+":"+NBSP+train+NBSP).addTo(fieldset);
|
train.link("span", t("Train")+":"+NBSP+train+NBSP).addTo(fieldset);
|
||||||
if (isSet(train.route)) {
|
if (isSet(train.route)) {
|
||||||
train.button(t("stop"), contextAction(ACTION_STOP)).addTo(fieldset);
|
train.button(t("stop"), Map.of(ACTION,ACTION_STOP)).addTo(fieldset);
|
||||||
} else {
|
} else {
|
||||||
train.button(t("start"), contextAction(ACTION_START)).addTo(fieldset);
|
train.button(t("start"), Map.of(ACTION,ACTION_START)).addTo(fieldset);
|
||||||
}
|
}
|
||||||
if (train.usesAutopilot()) {
|
if (train.usesAutopilot()) {
|
||||||
train.button(t("quit autopilot"), contextAction(ACTION_QUIT)).addTo(fieldset);
|
train.button(t("quit autopilot"), Map.of(ACTION,ACTION_QUIT)).addTo(fieldset);
|
||||||
} else {
|
} else {
|
||||||
train.button(t("auto"), contextAction(ACTION_AUTO)).addTo(fieldset);
|
train.button(t("auto"), Map.of(ACTION,ACTION_AUTO)).addTo(fieldset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +246,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
Tag routeList = new Tag("ol");
|
Tag routeList = new Tag("ol");
|
||||||
for (Route route : routes) {
|
for (Route route : routes) {
|
||||||
Tag li = route.link("span", route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
|
Tag li = route.link("span", route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
|
||||||
route.button(t("delete route"),contextAction(ACTION_DROP)).addTo(li);
|
route.button(t("delete route"),Map.of(ACTION,ACTION_DROP)).addTo(li);
|
||||||
li.addTo(routeList);
|
li.addTo(routeList);
|
||||||
}
|
}
|
||||||
routeList.addTo(fieldset);
|
routeList.addTo(fieldset);
|
||||||
@@ -376,12 +381,8 @@ public abstract class Tile extends BaseClass{
|
|||||||
@Override
|
@Override
|
||||||
public BaseClass remove() {
|
public BaseClass remove() {
|
||||||
super.remove();
|
super.remove();
|
||||||
routes.forEach(route -> {
|
while (!routes.isEmpty()) routes.first().remove();
|
||||||
route.remove();
|
while (!shadows.isEmpty()) shadows.first().remove();
|
||||||
});
|
|
||||||
shadows.forEach(shadow -> {
|
|
||||||
shadow.remove();
|
|
||||||
});
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user