started refactoring properties windows

This commit is contained in:
Stephan Richter
2020-12-02 09:45:17 +01:00
parent c4f48ebb63
commit d461728353
4 changed files with 49 additions and 55 deletions

View File

@@ -7,6 +7,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeSet;
@@ -197,26 +198,20 @@ public class Car extends BaseClass implements Comparable<Car>{
return this;
}
public Form propertyForm() {
Form form = super.propertyForm();
Fieldset fieldset = form.children().stream().filter(tag -> tag instanceof Fieldset).map(tag -> (Fieldset)tag).findFirst().get();
new Input(NAME,name).addTo(new Label(t("Name")+NBSP)).addTo(fieldset);
new Input(STOCK_ID,stockId).addTo(new Label(t("Stock ID")+NBSP)).addTo(fieldset);
new Input(LENGTH,length).attr("type", "number").addTo(new Label(t("Length")+NBSP)).content(NBSP+lengthUnit).addTo(fieldset);
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP)).addTo(fieldset);
new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Label(t("Maximum speed")+":"+NBSP)).content(NBSP+speedUnit).addTo(fieldset);
return form;
}
public Window properties() {
Window win = super.properties();
Tag list = new Tag("ul");
if (train != null) train.link().addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
list.addTo(win);
return win;
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)
);
Fieldset fieldset = new Fieldset(t("Train"));
if (train != null) train.link().addTo(fieldset);
return super.properties(List.of(),formInputs,List.of(fieldset));
}
public static void saveAll(String filename) throws IOException {

View File

@@ -81,7 +81,7 @@ public class Locomotive extends Car implements Constants,Device{
return address;
}
public static Tag cockpit(Object locoOrTrain) {
public static Fieldset cockpit(Object locoOrTrain) {
Id id = null;
int speed = 0;
String realm = null;
@@ -102,6 +102,7 @@ public class Locomotive extends Car implements Constants,Device{
HashMap<String,Object> params = new HashMap<String, Object>(Map.of(REALM,realm,ID,id));
Fieldset fieldset = new Fieldset(t("Control"));
fieldset.clazz("cockpit");
new Tag("span").content(t("Current velocity: {} {}",speed,speedUnit)).addTo(fieldset);
@@ -147,7 +148,7 @@ public class Locomotive extends Car implements Constants,Device{
functions.addTo(fieldset);
return fieldset.clazz("cockpit");
return fieldset;
}
private String detail() {
@@ -266,7 +267,7 @@ public class Locomotive extends Car implements Constants,Device{
return win;
}
@Override
/* @Override
public Form propertyForm() {
Form form = super.propertyForm();
@@ -285,7 +286,7 @@ public class Locomotive extends Car implements Constants,Device{
new Input(ADDRESS, address).attr("type", "number").addTo(new Label(t("Address:"))).addTo(fieldset);
fieldset.addTo(form);
return form;
}
}*/
private void queue() {
int step = proto.steps * speed / (maxSpeed == 0 ? 100 : maxSpeed);

View File

@@ -503,13 +503,9 @@ public class Train extends BaseClass implements Comparable<Train> {
return this;
}
@Override
public Window properties() {
Window window = super.properties();
window.children().insertElementAt(Locomotive.cockpit(this), 2);
Fieldset fieldset = new Fieldset(t("other train properties"));
Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
Tag propList = new Tag("ul").clazz("proplist");
@@ -547,18 +543,15 @@ public class Train extends BaseClass implements Comparable<Train> {
ul.addTo(li).addTo(propList);
}
propList.addTo(fieldset).addTo(window);
return window;
}
@Override
public Form propertyForm() {
Form form = super.propertyForm();
Fieldset fieldset = form.children().stream().filter(tag -> tag instanceof Fieldset).map(tag -> (Fieldset)tag).findFirst().get();
new Input(NAME,name).addTo(fieldset);
new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull).addTo(fieldset);
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP)).addTo(fieldset);
return form;
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))
);
return super.properties(List.of(Locomotive.cockpit(this)), formInputs, List.of(otherTrainProsps));
}
public Object quitAutopilot() {