refactoring properties framework
This commit is contained in:
@@ -102,6 +102,7 @@ Locomotives\: : Lokomotiven:
|
|||||||
Manage cars : Waggons verwalten
|
Manage cars : Waggons verwalten
|
||||||
Manage locos : Lokomotiven verwalten
|
Manage locos : Lokomotiven verwalten
|
||||||
Manage trains : Züge verwalten
|
Manage trains : Züge verwalten
|
||||||
|
Maximum Speed : Höchstgeschwindigkeit
|
||||||
Maximum train length\: : maximale Zug-Länge
|
Maximum train length\: : maximale Zug-Länge
|
||||||
Minimum and maximum times (in Miliseconds) trains with the respective tag have to wait in this block. : Minamle und maximale Block-Haltezeit (in Millisekunden) für Züge mit der entsprchender Markierung.
|
Minimum and maximum times (in Miliseconds) trains with the respective tag have to wait in this block. : Minamle und maximale Block-Haltezeit (in Millisekunden) für Züge mit der entsprchender Markierung.
|
||||||
Move tiles : Kacheln verschieben
|
Move tiles : Kacheln verschieben
|
||||||
@@ -113,6 +114,7 @@ new train : neuer Zug
|
|||||||
No : keine
|
No : keine
|
||||||
No free routes from {} : keine Route von {} frei
|
No free routes from {} : keine Route von {} frei
|
||||||
NORTH : Norden
|
NORTH : Norden
|
||||||
|
Notes : Notizen
|
||||||
{} now heading for {} : {} ist nun unterweg nach {}
|
{} now heading for {} : {} ist nun unterweg nach {}
|
||||||
{} now in auto-mode : {} ist nun im Automatikmodus
|
{} now in auto-mode : {} ist nun im Automatikmodus
|
||||||
Occupied area\: : Belegte Abschnitte:
|
Occupied area\: : Belegte Abschnitte:
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package de.srsoftware.web4rail;
|
|||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -21,7 +23,7 @@ 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;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
import de.srsoftware.web4rail.tags.TextArea;
|
import de.srsoftware.web4rail.tags.TextArea;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
import de.srsoftware.web4rail.tiles.Contact;
|
import de.srsoftware.web4rail.tiles.Contact;
|
||||||
@@ -225,6 +227,23 @@ public abstract class BaseClass implements Constants{
|
|||||||
return Map.of(ACTION,action,CONTEXT,realm()+":"+id());
|
return Map.of(ACTION,action,CONTEXT,realm()+":"+id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Form form(String id,List<Map.Entry<String, Tag>> elements) {
|
||||||
|
Form form = new Form(id);
|
||||||
|
|
||||||
|
Table table = new Table();
|
||||||
|
for (Map.Entry<String, Tag>entry : elements) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Tag val = entry.getValue();
|
||||||
|
if (isNull(key) && val instanceof Input) ((Input)val).hideIn(form);
|
||||||
|
table.addRow(isSet(key)?key:"",entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
table.addTo(form);
|
||||||
|
|
||||||
|
new Button(t("Apply"),form).addTo(form);
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
public Id id() {
|
public Id id() {
|
||||||
if (isNull(id)) id = new Id();
|
if (isNull(id)) id = new Id();
|
||||||
return id;
|
return id;
|
||||||
@@ -276,26 +295,24 @@ public abstract class BaseClass implements Constants{
|
|||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Window properties(List<Fieldset> preForm,List<Tag> formInputs,List<Fieldset> postForm) {
|
public Window properties() {
|
||||||
|
return properties(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Window properties(List<Fieldset> preForm,List<Map.Entry<String, Tag>> 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));
|
||||||
|
|
||||||
preForm.forEach(fieldset -> fieldset.addTo(win));
|
preForm.forEach(fieldset -> fieldset.addTo(win));
|
||||||
|
|
||||||
|
formInputs.add(new AbstractMap.SimpleEntry<String, Tag>(null,new Input(ACTION, ACTION_UPDATE)));
|
||||||
|
formInputs.add(new AbstractMap.SimpleEntry<String, Tag>(null,new Input(REALM,realm())));
|
||||||
|
formInputs.add(new AbstractMap.SimpleEntry<String, Tag>(null,new Input(ID,id())));
|
||||||
|
|
||||||
Form form = new Form(getClass().getSimpleName()+"-prop-form");
|
formInputs.add(new AbstractMap.SimpleEntry<String, Tag>(t("Notes"),new TextArea(NOTES,notes)));
|
||||||
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
|
||||||
new Input(REALM,realm()).hideIn(form);
|
|
||||||
new Input(ID,id()).hideIn(form);
|
|
||||||
|
|
||||||
formInputs.forEach(tag -> tag.addTo(form));
|
form(getClass().getSimpleName()+"-prop-form",formInputs)
|
||||||
|
.addTo(new Fieldset(t("Basic properties")))
|
||||||
new TextArea(NOTES,notes)
|
|
||||||
.addTo(new Label(t("Notes")+NBSP))
|
|
||||||
.addTo(form);
|
|
||||||
|
|
||||||
new Button(t("Apply"),form)
|
|
||||||
.addTo(form)
|
|
||||||
.addTo(new Fieldset("Basic properties"))
|
|
||||||
.addTo(win);
|
.addTo(win);
|
||||||
|
|
||||||
postForm.forEach(fieldset -> fieldset.addTo(win));
|
postForm.forEach(fieldset -> fieldset.addTo(win));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -198,20 +199,20 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Window properties() {
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
|
||||||
List<Tag> formInputs = List.of(
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Name"),new Input(NAME,name)));
|
||||||
new Input(NAME,name).addTo(new Label(t("Name")+NBSP)),
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Stock ID"),new Input(STOCK_ID,stockId)));
|
||||||
new Input(STOCK_ID,stockId).addTo(new Label(t("Stock ID")+NBSP)),
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Length"),new Input(LENGTH,length).attr("type", "number").addTo(new Tag("span")).content(NBSP+lengthUnit)));
|
||||||
new Input(LENGTH,length).attr("type", "number").addTo(new Label(t("Length")+NBSP)).content(NBSP+lengthUnit),
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Tag"), new Input(TAGS,String.join(", ", tags))));
|
||||||
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP)),
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Maximum Speed"),new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Tag("span")).content(NBSP+speedUnit)));
|
||||||
new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Label(t("Maximum speed")+":"+NBSP)).content(NBSP+speedUnit)
|
|
||||||
);
|
|
||||||
|
|
||||||
Fieldset fieldset = new Fieldset(t("Train"));
|
Fieldset fieldset = new Fieldset(t("Train"));
|
||||||
if (train != null) train.link().addTo(fieldset);
|
if (train != null) train.link().addTo(fieldset);
|
||||||
|
|
||||||
return super.properties(List.of(),formInputs,List.of(fieldset));
|
postForm.add(fieldset);
|
||||||
|
|
||||||
|
return super.properties(preForm,formInputs,postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveAll(String filename) throws IOException {
|
public static void saveAll(String filename) throws IOException {
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package de.srsoftware.web4rail.moving;
|
package de.srsoftware.web4rail.moving;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -260,33 +263,16 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window properties() {
|
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
|
||||||
Window win = super.properties();
|
preForm.add(cockpit(this));
|
||||||
Tag cockpit = cockpit(this);
|
Tag div = new Tag("div");
|
||||||
win.children().insertElementAt(cockpit, 2);
|
|
||||||
return win;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @Override
|
|
||||||
public Form propertyForm() {
|
|
||||||
Form form = super.propertyForm();
|
|
||||||
|
|
||||||
for (Tag tag : form.children()) {
|
|
||||||
if (REALM.equals(tag.get(Input.NAME)) && REALM_CAR.equals(tag.get(Input.VALUE))) {
|
|
||||||
tag.attr("value", REALM_LOCO);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Fieldset fieldset = new Fieldset("Decoder settings");
|
|
||||||
Label protocol = new Label(t("Protocol:"));
|
|
||||||
for (Protocol proto : Protocol.values()) {
|
for (Protocol proto : Protocol.values()) {
|
||||||
new Radio(PROTOCOL, proto.toString(), t(proto.toString()), proto == this.proto).addTo(protocol);
|
new Radio(PROTOCOL, proto.toString(), t(proto.toString()), proto == this.proto).addTo(div);
|
||||||
}
|
}
|
||||||
protocol.addTo(fieldset);
|
formInputs.add(new AbstractMap.SimpleEntry<String,Tag>(t("Protocol"),div));
|
||||||
new Input(ADDRESS, address).attr("type", "number").addTo(new Label(t("Address:"))).addTo(fieldset);
|
formInputs.add(new AbstractMap.SimpleEntry<String,Tag>(t("Address"),new Input(ADDRESS, address).numeric()));
|
||||||
fieldset.addTo(form);
|
return super.properties(preForm, formInputs, postForm);
|
||||||
return form;
|
}
|
||||||
}*/
|
|
||||||
|
|
||||||
private void queue() {
|
private void queue() {
|
||||||
int step = proto.steps * speed / (maxSpeed == 0 ? 100 : maxSpeed);
|
int step = proto.steps * speed / (maxSpeed == 0 ? 100 : maxSpeed);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.AbstractMap;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -503,8 +504,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Window properties() {
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
|
||||||
Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
|
Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
|
||||||
|
|
||||||
Tag propList = new Tag("ul").clazz("proplist");
|
Tag propList = new Tag("ul").clazz("proplist");
|
||||||
@@ -534,7 +535,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
for (String tag : allTags) new Tag("li").content(tag).addTo(tagList);
|
for (String tag : allTags) new Tag("li").content(tag).addTo(tagList);
|
||||||
tagList.addTo(new Tag("li").content(t("Tags"))).addTo(propList);
|
tagList.addTo(new Tag("li").content(t("Tags"))).addTo(propList);
|
||||||
}
|
}
|
||||||
new Tag("li").content(t("length: {}",length())).addTo(propList);
|
new Tag("li").content(t("length: {}",length())+NBSP+lengthUnit).addTo(propList);
|
||||||
|
|
||||||
if (!trace.isEmpty()) {
|
if (!trace.isEmpty()) {
|
||||||
Tag li = new Tag("li").content(t("Occupied area:"));
|
Tag li = new Tag("li").content(t("Occupied area:"));
|
||||||
@@ -545,13 +546,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
propList.addTo(otherTrainProsps);
|
propList.addTo(otherTrainProsps);
|
||||||
|
|
||||||
List<Tag> formInputs = List.of(
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Name"), new Input(NAME,name)));
|
||||||
new Input(NAME,name),
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Push-pull train"),new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull)));
|
||||||
new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull),
|
formInputs.add(new AbstractMap.SimpleEntry<>(t("Tags"), new Input(TAGS,String.join(", ", tags))));
|
||||||
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP))
|
|
||||||
);
|
|
||||||
|
|
||||||
return super.properties(List.of(Locomotive.cockpit(this)), formInputs, List.of(otherTrainProsps));
|
preForm.add(Locomotive.cockpit(this));
|
||||||
|
postForm.add(otherTrainProsps);
|
||||||
|
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object quitAutopilot() {
|
public Object quitAutopilot() {
|
||||||
|
|||||||
Reference in New Issue
Block a user