working on now property dialogs

This commit is contained in:
Stephan Richter
2020-12-02 15:11:46 +01:00
parent 0291523900
commit e8d79b71d9
14 changed files with 107 additions and 107 deletions

View File

@@ -40,6 +40,7 @@ public abstract class BaseClass implements Constants{
public static class Context {
private BaseClass main = null;
private Tile tile;
private Block block;
@@ -125,6 +126,16 @@ public abstract class BaseClass implements Constants{
}
}
public class FormInput extends ArrayList<Map.Entry<String, Tag>>{
private static final long serialVersionUID = -2371203388908395216L;
public FormInput add(String caption,Tag tag) {
add(new AbstractMap.SimpleEntry<String,Tag>(caption,tag));
return this;
}
}
public static class Id implements CharSequence, Comparable<Id>{
private String internalId;
@@ -296,11 +307,11 @@ public abstract class BaseClass implements Constants{
}
public Window properties() {
return properties(new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
return properties(new ArrayList<>(), new FormInput(), new ArrayList<>());
}
protected Window properties(List<Fieldset> preForm,List<Map.Entry<String, Tag>> formInputs,List<Fieldset> postForm) {
protected Window properties(List<Fieldset> preForm,FormInput formInputs,List<Fieldset> postForm) {
Window win = new Window(getClass().getSimpleName()+"-properties", t("Properties of {}",this));
preForm.forEach(fieldset -> fieldset.addTo(win));

View File

@@ -611,7 +611,7 @@ public class Plan extends BaseClass{
private Window properties(HashMap<String, String> params) {
if (params.containsKey(ID)) {
Tile tile = get(Id.from(params), true);
if (isSet(tile)) return tile.propMenu();
if (isSet(tile)) return tile.properties();
}
Window win = new Window("plan-properties", t("Properties"));
@@ -780,7 +780,7 @@ public class Plan extends BaseClass{
contact.addr(0);
LOG.debug("unsibscribed {} from {}",contact,addr);
}
stream(learningContact.addr(addr).propMenu().toString());
stream(learningContact.addr(addr).properties().toString());
learningContact = null;
LOG.debug("learned: {} = {}",addr,learningContact);
return;
@@ -804,7 +804,7 @@ public class Plan extends BaseClass{
case REALM_CONTACT:
case REALM_PLAN:
Tile tile = get(id, false);
return isNull(tile) ? null : tile.propMenu();
return isNull(tile) ? null : tile.properties();
case REALM_ACTIONS:
Action action = Action.get(id);
return (isSet(action)) ? action.properties(params) : null;
@@ -937,7 +937,7 @@ public class Plan extends BaseClass{
if (tile instanceof Block) {
Block block = (Block) tile;
place(block.updateTimes(params));
return tile.propMenu();
return tile.properties();
}
return t("updateTimes called on non-block tile!");
}

View File

@@ -19,6 +19,7 @@ import de.srsoftware.web4rail.Constants;
import de.srsoftware.web4rail.Plan;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.tags.Button;
import de.srsoftware.web4rail.tags.Fieldset;
import de.srsoftware.web4rail.tags.Form;
import de.srsoftware.web4rail.tags.Input;
@@ -132,6 +133,12 @@ public class ActionList extends Vector<Action> implements Constants{
}
}
public Fieldset properties() {
Fieldset fieldset = new Fieldset(t("Actions"));
new Tag("p").content("replace ActionList.addTo(...) by ActionsList.properties()!").addTo(fieldset);
return fieldset;
}
public boolean drop(Id actionId) {
for (Action action : this) {
if (action.id().equals(actionId)) {

View File

@@ -5,7 +5,6 @@ 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;
@@ -200,12 +199,12 @@ public class Car extends BaseClass implements Comparable<Car>{
}
@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)));
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
formInputs.add(t("Name"),new Input(NAME,name));
formInputs.add(t("Stock ID"),new Input(STOCK_ID,stockId));
formInputs.add(t("Length"),new Input(LENGTH,length).attr("type", "number").addTo(new Tag("span")).content(NBSP+lengthUnit));
formInputs.add(t("Tag"), new Input(TAGS,String.join(", ", tags)));
formInputs.add(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);

View File

@@ -1,13 +1,11 @@
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;
@@ -263,14 +261,14 @@ public class Locomotive extends Car implements Constants,Device{
}
@Override
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
protected Window properties(List<Fieldset> preForm, FormInput 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(div);
}
formInputs.add(new AbstractMap.SimpleEntry<String,Tag>(t("Protocol"),div));
formInputs.add(new AbstractMap.SimpleEntry<String,Tag>(t("Address"),new Input(ADDRESS, address).numeric()));
formInputs.add(t("Protocol"),div);
formInputs.add(t("Address"),new Input(ADDRESS, address).numeric());
return super.properties(preForm, formInputs, postForm);
}

View File

@@ -5,7 +5,6 @@ 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;
@@ -505,7 +504,7 @@ public class Train extends BaseClass implements Comparable<Train> {
}
@Override
protected Window properties(List<Fieldset> preForm, List<Entry<String, Tag>> formInputs, List<Fieldset> postForm) {
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
Fieldset otherTrainProsps = new Fieldset(t("other train properties"));
Tag propList = new Tag("ul").clazz("proplist");
@@ -546,9 +545,9 @@ public class Train extends BaseClass implements Comparable<Train> {
propList.addTo(otherTrainProsps);
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))));
formInputs.add(t("Name"), new Input(NAME,name));
formInputs.add(t("Push-pull train"),new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull));
formInputs.add(t("Tags"), new Input(TAGS,String.join(", ", tags)));
preForm.add(Locomotive.cockpit(this));
postForm.add(otherTrainProsps);

View File

@@ -227,9 +227,8 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
return form;
}
@Override
public Window propMenu() {
Window win = super.propMenu();
Window win = new Window("test", "Replace Block.propmenu by Block.properties!");
Form form = new Form("train-wait-form");
new Tag("h4").content(t("Stop settings")).addTo(win);
new Input(REALM,REALM_PLAN).hideIn(form);

View File

@@ -1,6 +1,7 @@
package de.srsoftware.web4rail.tiles;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
@@ -10,6 +11,7 @@ import de.srsoftware.web4rail.Connector;
import de.srsoftware.web4rail.Route;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tags.Fieldset;
public abstract class Bridge extends Tile {
private static final String COUNTERPART = "counterpart";
@@ -75,10 +77,18 @@ public abstract class Bridge extends Tile {
if (isSet(counterpart) && counterpart.route != route) counterpart.setRoute(route);
return this;
}
@Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
Fieldset fieldset = new Fieldset(t("Counterpart"));
new Tag("p").content(isSet(counterpart) ? t("Connected to {}.",counterpart) : t("Not connected to other bridge part!")).addTo(fieldset);
button(t("Select counterpart"),Map.of(ACTION,ACTION_CONNECT)).addTo(fieldset);
preForm.add(fieldset);
return super.properties(preForm, formInputs, postForm);
}
public Window propMenu() {
Window win = super.propMenu();
Window win = new Window("test", "test");
new Tag("h4").content("Counterpart").addTo(win);
new Tag("p").content(isSet(counterpart) ? t("Connected to {}.",counterpart) : t("Not connected to other bridge part!")).addTo(win);
button(t("Select counterpart"),Map.of(ACTION,ACTION_CONNECT)).addTo(win);

View File

@@ -3,6 +3,7 @@ package de.srsoftware.web4rail.tiles;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
@@ -12,9 +13,8 @@ import org.json.JSONObject;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.actions.ActionList;
import de.srsoftware.web4rail.tags.Form;
import de.srsoftware.web4rail.tags.Fieldset;
import de.srsoftware.web4rail.tags.Input;
import de.srsoftware.web4rail.tags.Label;
import de.srsoftware.web4rail.tags.Select;
public class Contact extends Tile{
@@ -140,7 +140,7 @@ public class Contact extends Tile{
if (id == null) return t("Missing ID on call to {}.process()",Contact.class.getSimpleName());
contact = contactsById.get(id);
if (contact == null) return t("No contact with id {} found!",id);
Tag propMenu = contact.propMenu();
Tag propMenu = contact.properties();
propMenu.children().insertElementAt(new Tag("div").content(t("Trigger a feedback sensor to assign it with this contact!")), 1);
plan.learn(contact);
return propMenu;
@@ -148,22 +148,15 @@ public class Contact extends Tile{
return t("Unknown action: {}",action);
}
@Override
public Form propForm(String formId) {
Form form = super.propForm(formId);
new Tag("h4").content(t("Hardware settings")).addTo(form);
Tag label = new Input(ADDRESS, addr).numeric().addTo(new Label(t("Address:")+NBSP));
button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(label).addTo(form);
return form;
}
@Override
public Window propMenu() {
Window win = super.propMenu();
new Tag("h4").content(t("Actions")).addTo(win);
actions.addTo(win, REALM_PLAN+":"+id());
return win;
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
Tag span = new Tag("span");
new Input(ADDRESS, addr).numeric().addTo(span).content(NBSP);
button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(span);
formInputs.add(t("Hardware settings"),span);
postForm.add(actions.properties());
return super.properties(preForm, formInputs, postForm);
}
public static Select selector(Contact preselect) {

View File

@@ -127,9 +127,8 @@ public class Relay extends Tile implements Device{
return this;
}
@Override
public Form propForm(String id) {
Form form = super.propForm(id);
Form form = new Form(id);
Fieldset fieldset = new Fieldset(t("Decoder settings"));
Label protocol = new Label(t("Protocol:"));
for (Protocol proto : Protocol.values()) {

View File

@@ -34,9 +34,8 @@ public abstract class StretchableTile extends Tile {
return super.load(json);
}
@Override
public Form propForm(String id) {
Form form = super.propForm(id);
Form form = new Form(id);
new Tag("h4").content(stretchType()).addTo(form);
new Input(STRETCH_LENGTH, stretch).numeric().addTo(new Label(stretchType()+":"+NBSP)).addTo(new Tag("p")).addTo(form);

View File

@@ -27,11 +27,9 @@ import de.srsoftware.web4rail.Plan.Direction;
import de.srsoftware.web4rail.Route;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.moving.Train;
import de.srsoftware.web4rail.tags.Button;
import de.srsoftware.web4rail.tags.Checkbox;
import de.srsoftware.web4rail.tags.Form;
import de.srsoftware.web4rail.tags.Fieldset;
import de.srsoftware.web4rail.tags.Input;
import de.srsoftware.web4rail.tags.Label;
import de.srsoftware.web4rail.tags.Radio;
/**
@@ -84,7 +82,7 @@ public abstract class Tile extends BaseClass{
public Object click() throws IOException {
LOG.debug("{}.click()",getClass().getSimpleName());
return propMenu();
return properties();
}
public JSONObject config() {
@@ -194,73 +192,58 @@ public abstract class Tile extends BaseClass{
return new Vector<Plan.Direction>();
}
public Form propForm(String formId) {
Form form = new Form(formId);
new Input(ACTION, ACTION_UPDATE).hideIn(form);
new Input(REALM, REALM_PLAN).hideIn(form);
new Input(ID,id()).hideIn(form);
@Override
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
Fieldset fieldset = new Fieldset(t("Route and Train"));
List<Direction> pd = possibleDirections();
if (!pd.isEmpty()) {
new Tag("h4").content(t("One way:")).addTo(form);
new Radio("oneway","none",t("No"),isNull(oneWay)).addTo(form);
for (Direction d:pd) {
new Radio("oneway",d.toString(),t(d.toString()),d == oneWay).addTo(form);
}
}
return form;
}
public Window propMenu() {
Window window = new Window("tile-properties",t("Properties of {} @ ({},{})",title(),x,y));
if (isSet(train)) {
HashMap<String, Object> props = new HashMap<String,Object>(Map.of(REALM,REALM_TRAIN,ID,train.id()));
train.link("span", train+NBSP).addTo(fieldset);
if (isSet(train.route)) {
props.put(ACTION, ACTION_STOP);
window.children().insertElementAt(new Button(t("stop"),props), 1);
train.button(t("stop"), contextAction(ACTION_STOP)).addTo(fieldset);
} else {
props.put(ACTION, ACTION_START);
window.children().insertElementAt(new Button(t("start"),props), 1);
train.button(t("start"), contextAction(ACTION_START)).addTo(fieldset);
}
if (train.usesAutopilot()) {
props.put(ACTION, ACTION_QUIT);
window.children().insertElementAt(new Button(t("quit autopilot"),props),2);
train.button(t("quit autopilot"), contextAction(ACTION_QUIT)).addTo(fieldset);
} else {
props.put(ACTION, ACTION_AUTO);
window.children().insertElementAt(new Button(t("auto"),props),2);
train.button(t("auto"), contextAction(ACTION_AUTO)).addTo(fieldset);
}
window.children().insertElementAt(train.link(), 1);
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
}
if (isSet(route)) route.link("p",t("Locked by {}",route)).addTo(window);
Form form = propForm("tile-properties-"+id());
if (isTrack) {
new Tag("h4").content(t("Length")).addTo(form);
new Input(LENGTH,length).numeric().addTo(new Label(t("Length")+":"+NBSP)).content(NBSP+lengthUnit).addTo(form);
new Tag("h4").content(t("Availability")).addTo(form);
Checkbox cb = new Checkbox(DISABLED, t("disabled"), disabled);
if (disabled) cb.clazz("disabled");
cb.addTo(form);
}
new Button(t("Apply"),form).addTo(form);
form.addTo(window);
if (isSet(route)) {
route.link("span",t("Locked by {}",route)).addTo(fieldset);
}
preForm.add(fieldset);
if (isTrack) {
formInputs.add(t("Length"),new Input(LENGTH,length).numeric().addTo(new Tag("span")).content(NBSP+lengthUnit));
formInputs.add(t("State"),new Checkbox(DISABLED, t("disabled"), disabled));
}
List<Direction> pd = possibleDirections();
if (!pd.isEmpty()) {
Tag div = new Tag("div");
new Radio("oneway","none",t("No"),isNull(oneWay)).addTo(div);
for (Direction d:pd) {
new Radio("oneway",d.toString(),t(d.toString()),d == oneWay).addTo(div);
}
formInputs.add(t("One way"),div);
}
if (!routes.isEmpty()) {
new Tag("h4").content(t("Routes using this tile:")).addTo(window);
fieldset = new Fieldset(t("Routes using this tile"));
Tag routeList = new Tag("ol");
for (Route route : routes) {
Tag li = route.link("span", route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
route.button(t("delete route"),contextAction(ACTION_DROP)).addTo(li);
li.addTo(routeList);
}
routeList.addTo(window);
}
return window;
routeList.addTo(fieldset);
postForm.add(fieldset);
}
return super.properties(preForm, formInputs, postForm);
}
public void remove(Route route) {
@@ -268,7 +251,7 @@ public abstract class Tile extends BaseClass{
}
private static String replace(String line, Entry<String, Object> replacement) {
String key = replacement.getKey();
String key = replacement.getKey();
Object val = replacement.getValue();
int start = line.indexOf(key);
int len = key.length();

View File

@@ -112,9 +112,8 @@ public abstract class Turnout extends Tile implements Device{
return super.load(json);
}
@Override
public Form propForm(String id) {
Form form = super.propForm(id);
Form form = new Form(id);
Fieldset fieldset = new Fieldset(t("Decoder settings"));
Label protocol = new Label(t("Protocol:"));
for (Protocol proto : Protocol.values()) {