refactoring properties framework
This commit is contained in:
@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -198,20 +199,20 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
return this;
|
||||
}
|
||||
|
||||
public Window properties() {
|
||||
|
||||
List<Tag> formInputs = List.of(
|
||||
new Input(NAME,name).addTo(new Label(t("Name")+NBSP)),
|
||||
new Input(STOCK_ID,stockId).addTo(new Label(t("Stock ID")+NBSP)),
|
||||
new Input(LENGTH,length).attr("type", "number").addTo(new Label(t("Length")+NBSP)).content(NBSP+lengthUnit),
|
||||
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP)),
|
||||
new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Label(t("Maximum speed")+":"+NBSP)).content(NBSP+speedUnit)
|
||||
);
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Name"),new Input(NAME,name)));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Stock ID"),new Input(STOCK_ID,stockId)));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Length"),new Input(LENGTH,length).attr("type", "number").addTo(new Tag("span")).content(NBSP+lengthUnit)));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Tag"), new Input(TAGS,String.join(", ", tags))));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Maximum Speed"),new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Tag("span")).content(NBSP+speedUnit)));
|
||||
|
||||
Fieldset fieldset = new Fieldset(t("Train"));
|
||||
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 {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package de.srsoftware.web4rail.moving;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -260,33 +263,16 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties() {
|
||||
Window win = super.properties();
|
||||
Tag cockpit = cockpit(this);
|
||||
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:"));
|
||||
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
|
||||
preForm.add(cockpit(this));
|
||||
Tag div = new Tag("div");
|
||||
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);
|
||||
new Input(ADDRESS, address).attr("type", "number").addTo(new Label(t("Address:"))).addTo(fieldset);
|
||||
fieldset.addTo(form);
|
||||
return form;
|
||||
}*/
|
||||
formInputs.add(new AbstractMap.SimpleEntry<String,Tag>(t("Protocol"),div));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<String,Tag>(t("Address"),new Input(ADDRESS, address).numeric()));
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
private void queue() {
|
||||
int step = proto.steps * speed / (maxSpeed == 0 ? 100 : maxSpeed);
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -502,9 +503,9 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
this.plan = plan;
|
||||
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"));
|
||||
|
||||
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);
|
||||
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()) {
|
||||
Tag li = new Tag("li").content(t("Occupied area:"));
|
||||
@@ -545,13 +546,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
propList.addTo(otherTrainProsps);
|
||||
|
||||
List<Tag> formInputs = List.of(
|
||||
new Input(NAME,name),
|
||||
new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull),
|
||||
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP))
|
||||
);
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Name"), new Input(NAME,name)));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Push-pull train"),new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull)));
|
||||
formInputs.add(new AbstractMap.SimpleEntry<>(t("Tags"), new Input(TAGS,String.join(", ", tags))));
|
||||
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user