still overhauling class hierarchy
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.2.0</version>
|
<version>1.2.1</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ import de.srsoftware.web4rail.moving.Car;
|
|||||||
import de.srsoftware.web4rail.moving.Locomotive;
|
import de.srsoftware.web4rail.moving.Locomotive;
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
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.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;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
@@ -28,6 +32,8 @@ public abstract class BaseClass implements Constants{
|
|||||||
public static String lengthUnit = DEFAULT_LENGTH_UNIT;
|
public static String lengthUnit = DEFAULT_LENGTH_UNIT;
|
||||||
private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
|
private static final char[] HEX_CHARS = "0123456789ABCDEF".toCharArray();
|
||||||
protected Id id = null;
|
protected Id id = null;
|
||||||
|
protected String notes;
|
||||||
|
|
||||||
|
|
||||||
public static class Context {
|
public static class Context {
|
||||||
private BaseClass main = null;
|
private BaseClass main = null;
|
||||||
@@ -199,20 +205,22 @@ public abstract class BaseClass implements Constants{
|
|||||||
return button(text,null);
|
return button(text,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,String> contextAction(String action){
|
public String realm() {
|
||||||
String realm = REALM_PLAN;
|
if (this instanceof Tile) return REALM_PLAN;
|
||||||
if (this instanceof Tile) realm = REALM_PLAN;
|
if (this instanceof Contact) return REALM_CONTACT;
|
||||||
if (this instanceof Contact) realm = REALM_CONTACT;
|
|
||||||
|
|
||||||
if (this instanceof Car) realm = REALM_CAR;
|
if (this instanceof Car) return REALM_CAR;
|
||||||
if (this instanceof Locomotive) realm = REALM_LOCO;
|
if (this instanceof Locomotive) return REALM_LOCO;
|
||||||
|
|
||||||
if (this instanceof Action) realm = REALM_ACTIONS;
|
if (this instanceof Action) return REALM_ACTIONS;
|
||||||
if (this instanceof Condition) realm = REALM_CONDITION;
|
if (this instanceof Condition) return REALM_CONDITION;
|
||||||
if (this instanceof Route) realm = REALM_ROUTE;
|
if (this instanceof Route) return REALM_ROUTE;
|
||||||
if (this instanceof Train) realm = REALM_TRAIN;
|
if (this instanceof Train) return REALM_TRAIN;
|
||||||
|
return REALM_PLAN;
|
||||||
return Map.of(ACTION,action,CONTEXT,realm+":"+id());
|
}
|
||||||
|
|
||||||
|
public Map<String,String> contextAction(String action){
|
||||||
|
return Map.of(ACTION,action,CONTEXT,realm()+":"+id());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Id id() {
|
public Id id() {
|
||||||
@@ -229,7 +237,10 @@ public abstract class BaseClass implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
return new JSONObject().put(ID, id().toString());
|
JSONObject json = new JSONObject();
|
||||||
|
if (isSet(id)) json.put(ID, id().toString());
|
||||||
|
if (isSet(notes) && !notes.isEmpty()) json.put(NOTES, notes);
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag link(String tagClass,Object caption) {
|
public Tag link(String tagClass,Object caption) {
|
||||||
@@ -264,7 +275,27 @@ public abstract class BaseClass implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Window properties() {
|
public Window properties() {
|
||||||
return new Window(getClass().getSimpleName()+"-properties", t("Properties of {}",this));
|
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() {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,String> props(Map<String,String> additionalProps){
|
public Map<String,String> props(Map<String,String> additionalProps){
|
||||||
@@ -288,4 +319,15 @@ public abstract class BaseClass implements Constants{
|
|||||||
protected static String t(String txt, Object...fills) {
|
protected static String t(String txt, Object...fills) {
|
||||||
return Translation.get(Application.class, txt, fills);
|
return Translation.get(Application.class, txt, fills);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
if (params.containsKey(NOTES)) notes = params.get(NOTES).trim();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BaseClass load(JSONObject json) {
|
||||||
|
if (json.has(ID)) id = Id.from(json);
|
||||||
|
if (json.has(NOTES)) notes = json.getString(NOTES);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,10 +69,7 @@ public class PathFinder extends BaseClass{
|
|||||||
} else {
|
} else {
|
||||||
LOG.debug("{}- Candidate: {}",inset,routeCandidate.shortName());
|
LOG.debug("{}- Candidate: {}",inset,routeCandidate.shortName());
|
||||||
Context forwardContext = new Context(train);
|
Context forwardContext = new Context(train);
|
||||||
forwardContext
|
forwardContext.block(routeCandidate.endBlock()).route(null);
|
||||||
.block(routeCandidate.endBlock())
|
|
||||||
.direction(routeCandidate.endDirection)
|
|
||||||
.route(null);
|
|
||||||
visitedRoutes.add(routeCandidate);
|
visitedRoutes.add(routeCandidate);
|
||||||
TreeMap<Integer, List<Route>> forwardRoutes = availableRoutes(forwardContext,visitedRoutes);
|
TreeMap<Integer, List<Route>> forwardRoutes = availableRoutes(forwardContext,visitedRoutes);
|
||||||
visitedRoutes.remove(routeCandidate);
|
visitedRoutes.remove(routeCandidate);
|
||||||
|
|||||||
@@ -920,7 +920,8 @@ public class Plan extends BaseClass{
|
|||||||
* @return
|
* @return
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private Object update(HashMap<String, String> params) throws IOException {
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
Tile tile = get(Id.from(params),true);
|
Tile tile = get(Id.from(params),true);
|
||||||
if (isSet(tile)) return tile.update(params);
|
if (isSet(tile)) return tile.update(params);
|
||||||
|
|
||||||
|
|||||||
@@ -780,7 +780,7 @@ public class Route extends BaseClass implements Comparable<Route>{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object update(HashMap<String, String> params,Plan plan) {
|
protected Object update(HashMap<String, String> params,Plan plan) {
|
||||||
LOG.debug("update({})",params);
|
LOG.debug("update({})",params);
|
||||||
String name = params.get(NAME);
|
String name = params.get(NAME);
|
||||||
if (isSet(name)) name(name);
|
if (isSet(name)) name(name);
|
||||||
|
|||||||
@@ -65,5 +65,4 @@ public class DetermineTrainInBlock extends Action {
|
|||||||
if (isSet(blockId)) block = Block.get(blockId);
|
if (isSet(blockId)) block = Block.get(blockId);
|
||||||
return properties(params);
|
return properties(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ 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.Label;
|
||||||
import de.srsoftware.web4rail.tags.Table;
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
import de.srsoftware.web4rail.tags.TextArea;
|
|
||||||
|
|
||||||
public class Car extends BaseClass implements Comparable<Car>{
|
public class Car extends BaseClass implements Comparable<Car>{
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
||||||
@@ -47,7 +46,6 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
private Train train;
|
private Train train;
|
||||||
protected Plan plan;
|
protected Plan plan;
|
||||||
protected int maxSpeed = 0;
|
protected int maxSpeed = 0;
|
||||||
private String notes;
|
|
||||||
|
|
||||||
public Car(String name) {
|
public Car(String name) {
|
||||||
this(name,null);
|
this(name,null);
|
||||||
@@ -102,7 +100,6 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
json.put(NAME, name);
|
json.put(NAME, name);
|
||||||
json.put(LENGTH, length);
|
json.put(LENGTH, length);
|
||||||
if (maxSpeed != 0) json.put(MAX_SPEED, maxSpeed);
|
if (maxSpeed != 0) json.put(MAX_SPEED, maxSpeed);
|
||||||
if (isSet(notes) && !notes.isEmpty()) json.put(NOTES, notes);
|
|
||||||
json.put(STOCK_ID, stockId);
|
json.put(STOCK_ID, stockId);
|
||||||
if (!tags.isEmpty()) json.put(TAGS, tags);
|
if (!tags.isEmpty()) json.put(TAGS, tags);
|
||||||
return json;
|
return json;
|
||||||
@@ -145,11 +142,10 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Car load(JSONObject json) {
|
public Car load(JSONObject json) {
|
||||||
if (json.has(ID)) id = Id.from(json);
|
super.load(json);
|
||||||
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
||||||
if (json.has(MAX_SPEED)) maxSpeed = json.getInt(MAX_SPEED);
|
if (json.has(MAX_SPEED)) maxSpeed = json.getInt(MAX_SPEED);
|
||||||
if (json.has(NOTES)) notes = json.getString(NOTES);
|
|
||||||
if (json.has(STOCK_ID)) stockId = json.getString(STOCK_ID);
|
if (json.has(STOCK_ID)) stockId = json.getString(STOCK_ID);
|
||||||
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); });
|
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); });
|
||||||
return this;
|
return this;
|
||||||
@@ -202,32 +198,20 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Form propertyForm() {
|
public Form propertyForm() {
|
||||||
Form form = new Form("car-prop-form");
|
Form form = super.propertyForm();
|
||||||
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
Fieldset fieldset = form.children().stream().filter(tag -> tag instanceof Fieldset).map(tag -> (Fieldset)tag).findFirst().get();
|
||||||
new Input(REALM,REALM_CAR).hideIn(form);
|
|
||||||
new Input(ID,id()).hideIn(form);
|
|
||||||
Fieldset fieldset = new Fieldset("Basic properties");
|
|
||||||
new Input(NAME,name).addTo(new Label(t("Name")+NBSP)).addTo(fieldset);
|
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(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(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(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);
|
new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Label(t("Maximum speed")+":"+NBSP)).content(NBSP+speedUnit).addTo(fieldset);
|
||||||
fieldset.addTo(form);
|
|
||||||
|
|
||||||
fieldset = new Fieldset(t("Notes"));
|
|
||||||
new TextArea(NOTES,notes).addTo(fieldset.clazz("notes")).addTo(form);
|
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Window properties() {
|
public Window properties() {
|
||||||
Window win = new Window("car-props", t("Properties of {}",this));
|
Window win = super.properties();
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Tag list = new Tag("ul");
|
Tag list = new Tag("ul");
|
||||||
if (train != null) train.link().addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
if (train != null) train.link().addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
||||||
@@ -262,9 +246,9 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
this.train = train;
|
this.train = train;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Car update(HashMap<String, String> params) {
|
protected Car update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
if (params.containsKey(NAME)) name = params.get(NAME).trim();
|
if (params.containsKey(NAME)) name = params.get(NAME).trim();
|
||||||
if (params.containsKey(NOTES)) notes = params.get(NOTES).trim();
|
|
||||||
if (params.containsKey(LENGTH)) length = Integer.parseInt(params.get(LENGTH));
|
if (params.containsKey(LENGTH)) length = Integer.parseInt(params.get(LENGTH));
|
||||||
if (params.containsKey(MAX_SPEED)) maxSpeed = Integer.parseInt(params.get(MAX_SPEED));
|
if (params.containsKey(MAX_SPEED)) maxSpeed = Integer.parseInt(params.get(MAX_SPEED));
|
||||||
if (params.containsKey(STOCK_ID)) stockId = params.get(STOCK_ID);
|
if (params.containsKey(STOCK_ID)) stockId = params.get(STOCK_ID);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Car load(JSONObject json) {
|
public Car load(JSONObject json) {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
if (json.has(LOCOMOTIVE)) {
|
if (json.has(LOCOMOTIVE)) {
|
||||||
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
JSONObject loco = json.getJSONObject(LOCOMOTIVE);
|
||||||
@@ -353,7 +353,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Car update(HashMap<String, String> params) {
|
protected Car update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
super.update(params);
|
||||||
if (params.containsKey(PROTOCOL)) proto = Protocol.valueOf(params.get(PROTOCOL));
|
if (params.containsKey(PROTOCOL)) proto = Protocol.valueOf(params.get(PROTOCOL));
|
||||||
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
|
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Train load(JSONObject json) {
|
public Train load(JSONObject json) {
|
||||||
pushPull = json.getBoolean(PUSH_PULL);
|
pushPull = json.getBoolean(PUSH_PULL);
|
||||||
if (json.has(DIRECTION)) direction = Direction.valueOf(json.getString(DIRECTION));
|
if (json.has(DIRECTION)) direction = Direction.valueOf(json.getString(DIRECTION));
|
||||||
if (json.has(NAME)) name = json.getString(NAME);
|
if (json.has(NAME)) name = json.getString(NAME);
|
||||||
@@ -395,6 +395,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (json.has(BLOCK)) currentBlock = (Block) plan.get(new Id(json.getString(BLOCK)), false).set(this); // do not move this up! during set, other fields will be referenced!
|
if (json.has(BLOCK)) currentBlock = (Block) plan.get(new Id(json.getString(BLOCK)), false).set(this); // do not move this up! during set, other fields will be referenced!
|
||||||
for (Object id : json.getJSONArray(CARS)) add(Car.get(id));
|
for (Object id : json.getJSONArray(CARS)) add(Car.get(id));
|
||||||
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id));
|
for (Object id : json.getJSONArray(LOCOS)) add((Locomotive) Car.get(id));
|
||||||
|
super.load(json);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,23 +505,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Window properties() {
|
public Window properties() {
|
||||||
Window window = new Window("train-properties",t("Properties of {}",this));
|
Window window = super.properties();
|
||||||
|
|
||||||
Locomotive.cockpit(this).addTo(window);
|
window.children().insertElementAt(Locomotive.cockpit(this), 2);
|
||||||
|
|
||||||
Fieldset fieldset = new Fieldset(t("editable train properties"));
|
Fieldset fieldset = new Fieldset(t("other train properties"));
|
||||||
Form form = new Form();
|
|
||||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
|
||||||
new Input(REALM,REALM_TRAIN).hideIn(form);
|
|
||||||
new Input(ID,id).hideIn(form);
|
|
||||||
new Input(NAME,name).addTo(form);
|
|
||||||
new Checkbox(PUSH_PULL, t("Push-pull train"), pushPull).addTo(form);
|
|
||||||
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP)).addTo(form);
|
|
||||||
new Button(t("Apply")).addTo(form).addTo(fieldset);
|
|
||||||
|
|
||||||
fieldset.addTo(window);
|
|
||||||
|
|
||||||
fieldset = new Fieldset(t("other train properties"));
|
|
||||||
|
|
||||||
Tag propList = new Tag("ul").clazz("proplist");
|
Tag propList = new Tag("ul").clazz("proplist");
|
||||||
|
|
||||||
@@ -561,6 +550,16 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
propList.addTo(fieldset).addTo(window);
|
propList.addTo(fieldset).addTo(window);
|
||||||
return 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;
|
||||||
|
}
|
||||||
|
|
||||||
public Object quitAutopilot() {
|
public Object quitAutopilot() {
|
||||||
if (isSet(nextRoute)) {
|
if (isSet(nextRoute)) {
|
||||||
@@ -579,10 +578,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reserveNext() {
|
public void reserveNext() {
|
||||||
Context context = new Context(this)
|
Context context = new Context(this).route(route).block(route.endBlock());
|
||||||
.route(route)
|
|
||||||
.block(route.endBlock())
|
|
||||||
.direction(route.endDirection);
|
|
||||||
Route nextRoute = PathFinder.chooseRoute(context);
|
Route nextRoute = PathFinder.chooseRoute(context);
|
||||||
if (isNull(nextRoute)) return;
|
if (isNull(nextRoute)) return;
|
||||||
|
|
||||||
@@ -794,7 +790,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Train update(HashMap<String, String> params) {
|
protected Train update(HashMap<String, String> params) {
|
||||||
LOG.debug("update({})",params);
|
LOG.debug("update({})",params);
|
||||||
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on");
|
pushPull = params.containsKey(PUSH_PULL) && params.get(PUSH_PULL).equals("on");
|
||||||
if (params.containsKey(NAME)) name = params.get(NAME);
|
if (params.containsKey(NAME)) name = params.get(NAME);
|
||||||
|
|||||||
@@ -199,8 +199,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
super.load(json);
|
|
||||||
name = json.has(NAME) ? json.getString(NAME) : "Block";
|
name = json.has(NAME) ? json.getString(NAME) : "Block";
|
||||||
turnAllowed = json.has(ALLOW_TURN) && json.getBoolean(ALLOW_TURN);
|
turnAllowed = json.has(ALLOW_TURN) && json.getBoolean(ALLOW_TURN);
|
||||||
if (json.has(WAIT_TIMES)) {
|
if (json.has(WAIT_TIMES)) {
|
||||||
@@ -210,7 +209,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
|||||||
if (object instanceof JSONObject) waitTimes.add(new WaitTime(null).load((JSONObject) object));
|
if (object instanceof JSONObject) waitTimes.add(new WaitTime(null).load((JSONObject) object));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this;
|
return super.load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -345,7 +344,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||||
if (params.containsKey(Train.class.getSimpleName())) {
|
if (params.containsKey(Train.class.getSimpleName())) {
|
||||||
Id trainId = Id.from(params,Train.class.getSimpleName());
|
Id trainId = Id.from(params,Train.class.getSimpleName());
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public abstract class Bridge extends Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
if (json.has(COUNTERPART)) {
|
if (json.has(COUNTERPART)) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -117,11 +117,10 @@ public class Contact extends Tile{
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
super.load(json);
|
|
||||||
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
|
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
|
||||||
if (json.has(REALM_ACTIONS)) actions = ActionList.load(json.getJSONArray(REALM_ACTIONS));
|
if (json.has(REALM_ACTIONS)) actions = ActionList.load(json.getJSONArray(REALM_ACTIONS));
|
||||||
return this;
|
return super.load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -213,7 +212,7 @@ public class Contact extends Tile{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(ADDRESS)) addr(Integer.parseInt(params.get(ADDRESS)));
|
if (params.containsKey(ADDRESS)) addr(Integer.parseInt(params.get(ADDRESS)));
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class Relay extends Tile implements Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
if (json.has(ADDRESS)) address = json.getInt(ADDRESS);
|
if (json.has(ADDRESS)) address = json.getInt(ADDRESS);
|
||||||
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
|
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
|
||||||
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
|
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
|
||||||
@@ -227,7 +227,7 @@ public class Relay extends Tile implements Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
|
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
|
||||||
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
|
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
|
||||||
if (params.containsKey(PORT_A)) portA = Integer.parseInt(params.get(PORT_A));
|
if (params.containsKey(PORT_A)) portA = Integer.parseInt(params.get(PORT_A));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
@@ -30,10 +29,9 @@ public abstract class StretchableTile extends Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
super.load(json);
|
|
||||||
if (json.has(STRETCH_LENGTH)) stretch = json.getInt(STRETCH_LENGTH);
|
if (json.has(STRETCH_LENGTH)) stretch = json.getInt(STRETCH_LENGTH);
|
||||||
return this;
|
return super.load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,7 +59,7 @@ public abstract class StretchableTile extends Tile {
|
|||||||
protected abstract String stretchType();
|
protected abstract String stretchType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
for (Entry<String, String> entry : params.entrySet()) {
|
for (Entry<String, String> entry : params.entrySet()) {
|
||||||
switch (entry.getKey()) {
|
switch (entry.getKey()) {
|
||||||
case STRETCH_LENGTH:
|
case STRETCH_LENGTH:
|
||||||
|
|||||||
@@ -25,10 +25,9 @@ public class TextDisplay extends StretchableTile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
super.load(json);
|
|
||||||
if (json.has(TEXT)) text = json.getString(TEXT);
|
if (json.has(TEXT)) text = json.getString(TEXT);
|
||||||
return this;
|
return super.load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,7 +72,7 @@ public class TextDisplay extends StretchableTile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
for (Entry<String, String> entry : params.entrySet()) {
|
for (Entry<String, String> entry : params.entrySet()) {
|
||||||
switch (entry.getKey()) {
|
switch (entry.getKey()) {
|
||||||
case TEXT:
|
case TEXT:
|
||||||
|
|||||||
@@ -169,7 +169,8 @@ public abstract class Tile extends BaseClass{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
JSONObject pos = json.getJSONObject(POS);
|
JSONObject pos = json.getJSONObject(POS);
|
||||||
x = pos.getInt(X);
|
x = pos.getInt(X);
|
||||||
y = pos.getInt(Y);
|
y = pos.getInt(Y);
|
||||||
@@ -394,7 +395,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
plan.place(this);
|
plan.place(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
||||||
String oneWayDir = params.get("oneway");
|
String oneWayDir = params.get("oneway");
|
||||||
if (isSet(oneWayDir)) {
|
if (isSet(oneWayDir)) {
|
||||||
@@ -407,7 +408,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
disabled = "on".equals(params.get(DISABLED));
|
disabled = "on".equals(params.get(DISABLED));
|
||||||
String len = params.get(LENGTH);
|
String len = params.get(LENGTH);
|
||||||
if (isSet(len)) length(Integer.parseInt(len));
|
if (isSet(len)) length(Integer.parseInt(len));
|
||||||
plan.stream(tag(null).toString());
|
plan.place(this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public abstract class Turnout extends Tile implements Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
public Tile load(JSONObject json) {
|
||||||
if (json.has(ADDRESS)) address = json.getInt(ADDRESS);
|
if (json.has(ADDRESS)) address = json.getInt(ADDRESS);
|
||||||
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
|
if (json.has(PORT_A)) portA = json.getInt(PORT_A);
|
||||||
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
|
if (json.has(PORT_B)) portB = json.getInt(PORT_B);
|
||||||
@@ -201,7 +201,7 @@ public abstract class Turnout extends Tile implements Device{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
|
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
|
||||||
if (params.containsKey(ADDRESS)) {
|
if (params.containsKey(ADDRESS)) {
|
||||||
int newAddress = Integer.parseInt(params.get(ADDRESS));
|
int newAddress = Integer.parseInt(params.get(ADDRESS));
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class TurnoutL extends Turnout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(STRAIGHT)) portA = Integer.parseInt(params.get(STRAIGHT));
|
if (params.containsKey(STRAIGHT)) portA = Integer.parseInt(params.get(STRAIGHT));
|
||||||
if (params.containsKey(LEFT)) portB = Integer.parseInt(params.get(LEFT));
|
if (params.containsKey(LEFT)) portB = Integer.parseInt(params.get(LEFT));
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class TurnoutR extends Turnout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) {
|
||||||
if (params.containsKey(STRAIGHT)) portA = Integer.parseInt(params.get(STRAIGHT));
|
if (params.containsKey(STRAIGHT)) portA = Integer.parseInt(params.get(STRAIGHT));
|
||||||
if (params.containsKey(RIGHT)) portB = Integer.parseInt(params.get(RIGHT));
|
if (params.containsKey(RIGHT)) portB = Integer.parseInt(params.get(RIGHT));
|
||||||
return super.update(params);
|
return super.update(params);
|
||||||
|
|||||||
Reference in New Issue
Block a user