working on route properties
This commit is contained in:
@@ -141,3 +141,7 @@ h2{
|
||||
.sig_b{
|
||||
fill: black;
|
||||
}
|
||||
|
||||
.link{
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ function addMessage(txt){
|
||||
|
||||
function addTile(x,y){
|
||||
console.log("addTile:",selected.id,x,y);
|
||||
x = Math.floor(x/SQUARE);
|
||||
y = Math.floor(y/SQUARE);
|
||||
$.ajax({
|
||||
url : PLAN,
|
||||
method: POST,
|
||||
@@ -33,35 +31,28 @@ function addTile(x,y){
|
||||
|
||||
function bodyClick(ev){
|
||||
console.log('bodyClick:',ev);
|
||||
var x = Math.floor(ev.clientX/SQUARE);
|
||||
var y = Math.floor(ev.clientY/SQUARE);
|
||||
|
||||
switch (mode){
|
||||
case undefined:
|
||||
case null:
|
||||
return clickTile(ev.clientX,ev.clientY);
|
||||
return clickTile(x,y);
|
||||
case ADD:
|
||||
return addTile(ev.clientX,ev.clientY);
|
||||
return addTile(x,y);
|
||||
case MOVE:
|
||||
return moveTile(ev.clientX,ev.clientY);
|
||||
return moveTile(x,y);
|
||||
}
|
||||
console.log('unknown action "'+mode+'" @ ('+ev.clientX+','+ev.clientY+')');
|
||||
}
|
||||
|
||||
function clickTile(x,y){
|
||||
console.log("clickTile:",x,y);
|
||||
x = Math.floor(x/SQUARE);
|
||||
y = Math.floor(y/SQUARE);
|
||||
if ($('#tile-'+x+'-'+y).length > 0){
|
||||
$.ajax({
|
||||
url : PLAN,
|
||||
method : POST,
|
||||
data : {action:'openProps',x:x,y:y},
|
||||
success: function(resp){
|
||||
$('body').append($(resp));
|
||||
}
|
||||
});
|
||||
}
|
||||
if ($('#tile-'+x+'-'+y).length > 0) request({action:'openProps',x:x,y:y});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function closeMenu(ev){
|
||||
console.log('closeMenu:',ev);
|
||||
if (selected != null) $(selected).css('border','');
|
||||
@@ -107,8 +98,6 @@ function enableMove(ev){
|
||||
|
||||
function moveTile(x,y){
|
||||
console.log("moveTile:",selected.id,x,y);
|
||||
x = Math.floor(x/SQUARE);
|
||||
y = Math.floor(y/SQUARE);
|
||||
$.ajax({
|
||||
url : PLAN,
|
||||
method: POST,
|
||||
@@ -130,12 +119,17 @@ function moveTile(x,y){
|
||||
}
|
||||
|
||||
function openRoute(id){
|
||||
closeWindows();
|
||||
request({action:'openRoute',id:id});
|
||||
return false;
|
||||
}
|
||||
|
||||
function request(data){
|
||||
$.ajax({
|
||||
url : PLAN,
|
||||
method : POST,
|
||||
data : {action:'openRoute',id:id},
|
||||
data : data,
|
||||
success: function(resp){
|
||||
closeWindows();
|
||||
if (resp.startsWith('<')){
|
||||
$('body').append($(resp));
|
||||
} else {
|
||||
@@ -144,6 +138,7 @@ function openRoute(id){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function runAction(ev){
|
||||
console.log("runAction: ",ev.target.id);
|
||||
$.ajax({
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
Actions : Aktionen
|
||||
Added {} : {} hinzugefügt
|
||||
Add tile : Kachel hinzufügen
|
||||
Analyze plan : Plan analysieren
|
||||
Contacts : Kontakte
|
||||
length\: : Länge:
|
||||
name\: : Name:
|
||||
Plan saved as "{}". : Plan als „{}“ gespeichert.
|
||||
Properties : Eigenschaften
|
||||
Properties of {} : Eigenschaften von {}
|
||||
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
||||
Routes using this tile\: : Fahrstraßen, die diesen Abschnitt verwenden:
|
||||
save : speichern
|
||||
Save plan : Plan speichern
|
||||
Signals : Signale
|
||||
Turnouts : Weichen
|
||||
Unknown action\: {} : Unbekannte Aktion: {}
|
||||
@@ -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() {
|
||||
@@ -154,4 +170,12 @@ public abstract class Tile {
|
||||
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