started refactoring properties windows
This commit is contained in:
@@ -4,6 +4,7 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -20,6 +21,7 @@ import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.TextArea;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
@@ -274,28 +276,31 @@ public abstract class BaseClass implements Constants{
|
||||
return merged;
|
||||
}
|
||||
|
||||
public Window properties() {
|
||||
public Window properties(List<Fieldset> preForm,List<Tag> formInputs,List<Fieldset> postForm) {
|
||||
Window win = new Window(getClass().getSimpleName()+"-properties", t("Properties of {}",this));
|
||||
|
||||
Form form = propertyForm();
|
||||
if (form!=null && form.children().size()>2) {
|
||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||
} else win.content(t("This tile ({}) has no editable properties",getClass().getSimpleName()));
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
public Form propertyForm() {
|
||||
|
||||
preForm.forEach(fieldset -> fieldset.addTo(win));
|
||||
|
||||
|
||||
Form form = new Form(getClass().getSimpleName()+"-prop-form");
|
||||
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
||||
new Input(REALM,realm()).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
Fieldset fieldset = new Fieldset("Basic properties");
|
||||
fieldset.addTo(form);
|
||||
|
||||
fieldset = new Fieldset(t("Notes"));
|
||||
new TextArea(NOTES,notes).addTo(fieldset.clazz("notes")).addTo(form);
|
||||
return form;
|
||||
formInputs.forEach(tag -> tag.addTo(form));
|
||||
|
||||
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);
|
||||
|
||||
postForm.forEach(fieldset -> fieldset.addTo(win));
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
public Map<String,String> props(Map<String,String> additionalProps){
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user