working on route properties
This commit is contained in:
@@ -88,6 +88,10 @@ public class Plan {
|
||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||
}
|
||||
|
||||
public static void addLink(Tile tile,String content,Tag list) {
|
||||
new Tag("li").clazz("link").attr("onclick", "return clickTile("+tile.x+","+tile.y+");").content(content).addTo(list);
|
||||
}
|
||||
|
||||
private Tile addTile(String clazz, String xs, String ys, String configJson) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
int x = Integer.parseInt(xs);
|
||||
int y = Integer.parseInt(ys);
|
||||
@@ -103,12 +107,14 @@ public class Plan {
|
||||
private String analyze() {
|
||||
Vector<Route> routes = new Vector<Route>();
|
||||
for (Block block : blocks) {
|
||||
block.routes().clear();
|
||||
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().start(block),con));
|
||||
}
|
||||
this.routes.clear();
|
||||
for (HashMap<Integer, Tile> column: tiles.values()) {
|
||||
for (Tile tile : column.values()) tile.routes().clear();
|
||||
}
|
||||
for (Route route : routes) {
|
||||
route.start().add(route);
|
||||
for (Tile tile: route.path()) tile.add(route);
|
||||
this.routes.put(route.id(), route);
|
||||
}
|
||||
return t("Found {} routes.",routes.size());
|
||||
|
||||
@@ -75,22 +75,29 @@ public class Route {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Vector<Tile> path() {
|
||||
return new Vector<Tile>(path);
|
||||
}
|
||||
|
||||
public Window properties() {
|
||||
Window win = new Window("route-properties",t("Properties of {})",this));
|
||||
Window win = new Window("route-properties",t("Properties of {}",this));
|
||||
|
||||
new Tag("h4").content(t("Signals")).addTo(win);
|
||||
Tag list = new Tag("ul");
|
||||
for (Signal s : signals) new Tag("li").content(s.toString()).addTo(list);
|
||||
for (Signal s : signals) Plan.addLink(s,s.toString(),list);
|
||||
list.addTo(win);
|
||||
|
||||
new Tag("h4").content(t("Contacts")).addTo(win);
|
||||
list = new Tag("ul");
|
||||
for (Contact c : contacts) new Tag("li").content(c.toString()).addTo(list);
|
||||
for (Contact c : contacts) Plan.addLink(c,c.toString(),list);
|
||||
list.addTo(win);
|
||||
|
||||
new Tag("h4").content(t("Turnouts")).addTo(win);
|
||||
list = new Tag("ul");
|
||||
for (Entry<Turnout, State> entry : turnouts.entrySet()) new Tag("li").content(entry.getKey()+" : "+entry.getValue()).addTo(list);
|
||||
for (Entry<Turnout, State> entry : turnouts.entrySet()) {
|
||||
Turnout turnout = entry.getKey();
|
||||
Plan.addLink(turnout, turnout+": "+entry.getValue(), list);
|
||||
}
|
||||
list.addTo(win);
|
||||
|
||||
return win;
|
||||
@@ -110,7 +117,7 @@ public class Route {
|
||||
return getClass().getSimpleName()+"("+name()+")";
|
||||
}
|
||||
|
||||
public Block start() {
|
||||
public Block startBlock() {
|
||||
return (Block) path.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,21 +2,17 @@ package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
|
||||
public abstract class Block extends StretchableTile{
|
||||
private static final String NAME = "name";
|
||||
public String name = "Block";
|
||||
private HashSet<Route> routes = new HashSet<Route>();
|
||||
|
||||
@Override
|
||||
public JSONObject config() {
|
||||
@@ -31,16 +27,8 @@ public abstract class Block extends StretchableTile{
|
||||
if (config.has(NAME)) name = config.getString(NAME);
|
||||
}
|
||||
|
||||
public Set<Route> routes(){
|
||||
return routes;
|
||||
}
|
||||
|
||||
public abstract List<Connector> startPoints();
|
||||
|
||||
public void add(Route route) {
|
||||
routes.add(route);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag propForm() {
|
||||
Tag form = super.propForm();
|
||||
@@ -49,13 +37,6 @@ public abstract class Block extends StretchableTile{
|
||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
||||
label.addTo(form);
|
||||
|
||||
new Tag("h4").content(t("Routes from here:")).addTo(form);
|
||||
Tag routeList = new Tag("ul");
|
||||
for (Route route : routes) {
|
||||
new Tag("li").content(route.id()).attr("onclick","openRoute('"+route.id()+"')").addTo(routeList);
|
||||
}
|
||||
routeList.addTo(form);
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.Map.Entry;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
|
||||
public abstract class StretchableTile extends Tile {
|
||||
private static final String LENGTH = "length";
|
||||
@@ -27,10 +26,7 @@ public abstract class StretchableTile extends Tile {
|
||||
|
||||
@Override
|
||||
public Tag propForm() {
|
||||
Form form = new Form();
|
||||
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
||||
new Tag("input").attr("type", "hidden").attr("name","x").attr("value", x).addTo(form);
|
||||
new Tag("input").attr("type", "hidden").attr("name","y").attr("value", y).addTo(form);
|
||||
Tag form = super.propForm();
|
||||
|
||||
Tag label = new Tag("label").content(t("length:"));
|
||||
new Tag("input").attr("type", "number").attr("name","length").attr("value", length).addTo(label);
|
||||
|
||||
@@ -5,11 +5,9 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Scanner;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
@@ -19,14 +17,18 @@ import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.Route;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
|
||||
public abstract class Tile {
|
||||
|
||||
public int x = -1,y = -1;
|
||||
protected HashSet<String> classes = new HashSet<String>();
|
||||
protected HashSet<Shadow> shadows = new HashSet<Shadow>();
|
||||
protected HashSet<String> classes = new HashSet<>();
|
||||
protected HashSet<Shadow> shadows = new HashSet<>();
|
||||
private HashSet<Route> routes = new HashSet<>();
|
||||
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
|
||||
public Tile() {
|
||||
@@ -64,7 +66,21 @@ public abstract class Tile {
|
||||
}
|
||||
|
||||
public Tag propForm() {
|
||||
return null;
|
||||
Form form = new Form();
|
||||
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
|
||||
new Tag("input").attr("type", "hidden").attr("name","x").attr("value", x).addTo(form);
|
||||
new Tag("input").attr("type", "hidden").attr("name","y").attr("value", y).addTo(form);
|
||||
|
||||
if (!routes.isEmpty()) {
|
||||
new Tag("h4").content(t("Routes using this tile:")).addTo(form);
|
||||
Tag routeList = new Tag("ul");
|
||||
for (Route route : routes) {
|
||||
new Tag("li").clazz("link").attr("onclick","openRoute('"+route.id()+"')").content(route.id()).addTo(routeList);
|
||||
}
|
||||
routeList.addTo(form);
|
||||
}
|
||||
|
||||
return form;
|
||||
}
|
||||
|
||||
public Tag propMenu() {
|
||||
@@ -153,5 +169,13 @@ public abstract class Tile {
|
||||
public Tile update(HashMap<String, String> params) {
|
||||
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HashSet<Route> routes() {
|
||||
return routes;
|
||||
}
|
||||
|
||||
public void add(Route route) {
|
||||
this.routes.add(route);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user