started refactoring properties windows
This commit is contained in:
@@ -4,6 +4,7 @@ import java.security.MessageDigest;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
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.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.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;
|
||||||
@@ -274,28 +276,31 @@ public abstract class BaseClass implements Constants{
|
|||||||
return merged;
|
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));
|
Window win = new Window(getClass().getSimpleName()+"-properties", t("Properties of {}",this));
|
||||||
|
|
||||||
Form form = propertyForm();
|
preForm.forEach(fieldset -> fieldset.addTo(win));
|
||||||
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() {
|
|
||||||
Form form = new Form(getClass().getSimpleName()+"-prop-form");
|
Form form = new Form(getClass().getSimpleName()+"-prop-form");
|
||||||
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
||||||
new Input(REALM,realm()).hideIn(form);
|
new Input(REALM,realm()).hideIn(form);
|
||||||
new Input(ID,id()).hideIn(form);
|
new Input(ID,id()).hideIn(form);
|
||||||
Fieldset fieldset = new Fieldset("Basic properties");
|
|
||||||
fieldset.addTo(form);
|
|
||||||
|
|
||||||
fieldset = new Fieldset(t("Notes"));
|
formInputs.forEach(tag -> tag.addTo(form));
|
||||||
new TextArea(NOTES,notes).addTo(fieldset.clazz("notes")).addTo(form);
|
|
||||||
return 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){
|
public Map<String,String> props(Map<String,String> additionalProps){
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@@ -197,26 +198,20 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return this;
|
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() {
|
public Window properties() {
|
||||||
Window win = super.properties();
|
|
||||||
|
|
||||||
Tag list = new Tag("ul");
|
List<Tag> formInputs = List.of(
|
||||||
if (train != null) train.link().addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
new Input(NAME,name).addTo(new Label(t("Name")+NBSP)),
|
||||||
list.addTo(win);
|
new Input(STOCK_ID,stockId).addTo(new Label(t("Stock ID")+NBSP)),
|
||||||
return win;
|
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 {
|
public static void saveAll(String filename) throws IOException {
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tag cockpit(Object locoOrTrain) {
|
public static Fieldset cockpit(Object locoOrTrain) {
|
||||||
Id id = null;
|
Id id = null;
|
||||||
int speed = 0;
|
int speed = 0;
|
||||||
String realm = null;
|
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));
|
HashMap<String,Object> params = new HashMap<String, Object>(Map.of(REALM,realm,ID,id));
|
||||||
|
|
||||||
Fieldset fieldset = new Fieldset(t("Control"));
|
Fieldset fieldset = new Fieldset(t("Control"));
|
||||||
|
fieldset.clazz("cockpit");
|
||||||
|
|
||||||
new Tag("span").content(t("Current velocity: {} {}",speed,speedUnit)).addTo(fieldset);
|
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);
|
functions.addTo(fieldset);
|
||||||
|
|
||||||
|
|
||||||
return fieldset.clazz("cockpit");
|
return fieldset;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String detail() {
|
private String detail() {
|
||||||
@@ -266,7 +267,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/* @Override
|
||||||
public Form propertyForm() {
|
public Form propertyForm() {
|
||||||
Form form = super.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);
|
new Input(ADDRESS, address).attr("type", "number").addTo(new Label(t("Address:"))).addTo(fieldset);
|
||||||
fieldset.addTo(form);
|
fieldset.addTo(form);
|
||||||
return form;
|
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);
|
||||||
|
|||||||
@@ -503,13 +503,9 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Window properties() {
|
public Window properties() {
|
||||||
Window window = super.properties();
|
|
||||||
|
|
||||||
window.children().insertElementAt(Locomotive.cockpit(this), 2);
|
Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
|
||||||
|
|
||||||
Fieldset fieldset = new Fieldset(t("other train properties"));
|
|
||||||
|
|
||||||
Tag propList = new Tag("ul").clazz("proplist");
|
Tag propList = new Tag("ul").clazz("proplist");
|
||||||
|
|
||||||
@@ -547,18 +543,15 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
ul.addTo(li).addTo(propList);
|
ul.addTo(li).addTo(propList);
|
||||||
}
|
}
|
||||||
|
|
||||||
propList.addTo(fieldset).addTo(window);
|
propList.addTo(otherTrainProsps);
|
||||||
return window;
|
|
||||||
}
|
List<Tag> formInputs = List.of(
|
||||||
|
new Input(NAME,name),
|
||||||
@Override
|
new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull),
|
||||||
public Form propertyForm() {
|
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP))
|
||||||
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);
|
return super.properties(List.of(Locomotive.cockpit(this)), formInputs, List.of(otherTrainProsps));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object quitAutopilot() {
|
public Object quitAutopilot() {
|
||||||
|
|||||||
Reference in New Issue
Block a user