working on route properties
This commit is contained in:
@@ -141,3 +141,7 @@ h2{
|
|||||||
.sig_b{
|
.sig_b{
|
||||||
fill: black;
|
fill: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.link{
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ function addMessage(txt){
|
|||||||
|
|
||||||
function addTile(x,y){
|
function addTile(x,y){
|
||||||
console.log("addTile:",selected.id,x,y);
|
console.log("addTile:",selected.id,x,y);
|
||||||
x = Math.floor(x/SQUARE);
|
|
||||||
y = Math.floor(y/SQUARE);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : PLAN,
|
url : PLAN,
|
||||||
method: POST,
|
method: POST,
|
||||||
@@ -33,35 +31,28 @@ function addTile(x,y){
|
|||||||
|
|
||||||
function bodyClick(ev){
|
function bodyClick(ev){
|
||||||
console.log('bodyClick:',ev);
|
console.log('bodyClick:',ev);
|
||||||
|
var x = Math.floor(ev.clientX/SQUARE);
|
||||||
|
var y = Math.floor(ev.clientY/SQUARE);
|
||||||
|
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case undefined:
|
case undefined:
|
||||||
case null:
|
case null:
|
||||||
return clickTile(ev.clientX,ev.clientY);
|
return clickTile(x,y);
|
||||||
case ADD:
|
case ADD:
|
||||||
return addTile(ev.clientX,ev.clientY);
|
return addTile(x,y);
|
||||||
case MOVE:
|
case MOVE:
|
||||||
return moveTile(ev.clientX,ev.clientY);
|
return moveTile(x,y);
|
||||||
}
|
}
|
||||||
console.log('unknown action "'+mode+'" @ ('+ev.clientX+','+ev.clientY+')');
|
console.log('unknown action "'+mode+'" @ ('+ev.clientX+','+ev.clientY+')');
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickTile(x,y){
|
function clickTile(x,y){
|
||||||
console.log("clickTile:",x,y);
|
console.log("clickTile:",x,y);
|
||||||
x = Math.floor(x/SQUARE);
|
if ($('#tile-'+x+'-'+y).length > 0) request({action:'openProps',x:x,y:y});
|
||||||
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));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function closeMenu(ev){
|
function closeMenu(ev){
|
||||||
console.log('closeMenu:',ev);
|
console.log('closeMenu:',ev);
|
||||||
if (selected != null) $(selected).css('border','');
|
if (selected != null) $(selected).css('border','');
|
||||||
@@ -107,8 +98,6 @@ function enableMove(ev){
|
|||||||
|
|
||||||
function moveTile(x,y){
|
function moveTile(x,y){
|
||||||
console.log("moveTile:",selected.id,x,y);
|
console.log("moveTile:",selected.id,x,y);
|
||||||
x = Math.floor(x/SQUARE);
|
|
||||||
y = Math.floor(y/SQUARE);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : PLAN,
|
url : PLAN,
|
||||||
method: POST,
|
method: POST,
|
||||||
@@ -130,20 +119,26 @@ function moveTile(x,y){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openRoute(id){
|
function openRoute(id){
|
||||||
closeWindows();
|
request({action:'openRoute',id:id});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function request(data){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : PLAN,
|
url : PLAN,
|
||||||
method : POST,
|
method : POST,
|
||||||
data : {action:'openRoute',id:id},
|
data : data,
|
||||||
success: function(resp){
|
success: function(resp){
|
||||||
|
closeWindows();
|
||||||
if (resp.startsWith('<')){
|
if (resp.startsWith('<')){
|
||||||
$('body').append($(resp));
|
$('body').append($(resp));
|
||||||
} else {
|
} else {
|
||||||
addMessage(resp);
|
addMessage(resp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function runAction(ev){
|
function runAction(ev){
|
||||||
console.log("runAction: ",ev.target.id);
|
console.log("runAction: ",ev.target.id);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
Actions : Aktionen
|
Actions : Aktionen
|
||||||
Added {} : {} hinzugefügt
|
Added {} : {} hinzugefügt
|
||||||
Add tile : Kachel hinzufügen
|
Add tile : Kachel hinzufügen
|
||||||
|
Analyze plan : Plan analysieren
|
||||||
|
Contacts : Kontakte
|
||||||
|
length\: : Länge:
|
||||||
|
name\: : Name:
|
||||||
Plan saved as "{}". : Plan als „{}“ gespeichert.
|
Plan saved as "{}". : Plan als „{}“ gespeichert.
|
||||||
Properties : Eigenschaften
|
Properties : Eigenschaften
|
||||||
|
Properties of {} : Eigenschaften von {}
|
||||||
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
||||||
|
Routes using this tile\: : Fahrstraßen, die diesen Abschnitt verwenden:
|
||||||
|
save : speichern
|
||||||
Save plan : Plan speichern
|
Save plan : Plan speichern
|
||||||
|
Signals : Signale
|
||||||
|
Turnouts : Weichen
|
||||||
Unknown action\: {} : Unbekannte Aktion: {}
|
Unknown action\: {} : Unbekannte Aktion: {}
|
||||||
@@ -88,6 +88,10 @@ public class Plan {
|
|||||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
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 {
|
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 x = Integer.parseInt(xs);
|
||||||
int y = Integer.parseInt(ys);
|
int y = Integer.parseInt(ys);
|
||||||
@@ -103,12 +107,14 @@ public class Plan {
|
|||||||
private String analyze() {
|
private String analyze() {
|
||||||
Vector<Route> routes = new Vector<Route>();
|
Vector<Route> routes = new Vector<Route>();
|
||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
block.routes().clear();
|
|
||||||
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().start(block),con));
|
for (Connector con : block.startPoints()) routes.addAll(follow(new Route().start(block),con));
|
||||||
}
|
}
|
||||||
this.routes.clear();
|
this.routes.clear();
|
||||||
|
for (HashMap<Integer, Tile> column: tiles.values()) {
|
||||||
|
for (Tile tile : column.values()) tile.routes().clear();
|
||||||
|
}
|
||||||
for (Route route : routes) {
|
for (Route route : routes) {
|
||||||
route.start().add(route);
|
for (Tile tile: route.path()) tile.add(route);
|
||||||
this.routes.put(route.id(), route);
|
this.routes.put(route.id(), route);
|
||||||
}
|
}
|
||||||
return t("Found {} routes.",routes.size());
|
return t("Found {} routes.",routes.size());
|
||||||
|
|||||||
@@ -75,22 +75,29 @@ public class Route {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector<Tile> path() {
|
||||||
|
return new Vector<Tile>(path);
|
||||||
|
}
|
||||||
|
|
||||||
public Window properties() {
|
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);
|
new Tag("h4").content(t("Signals")).addTo(win);
|
||||||
Tag list = new Tag("ul");
|
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);
|
list.addTo(win);
|
||||||
|
|
||||||
new Tag("h4").content(t("Contacts")).addTo(win);
|
new Tag("h4").content(t("Contacts")).addTo(win);
|
||||||
list = new Tag("ul");
|
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);
|
list.addTo(win);
|
||||||
|
|
||||||
new Tag("h4").content(t("Turnouts")).addTo(win);
|
new Tag("h4").content(t("Turnouts")).addTo(win);
|
||||||
list = new Tag("ul");
|
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);
|
list.addTo(win);
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
@@ -110,7 +117,7 @@ public class Route {
|
|||||||
return getClass().getSimpleName()+"("+name()+")";
|
return getClass().getSimpleName()+"("+name()+")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block start() {
|
public Block startBlock() {
|
||||||
return (Block) path.get(0);
|
return (Block) path.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,17 @@ package de.srsoftware.web4rail.tiles;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
import de.srsoftware.web4rail.Route;
|
|
||||||
|
|
||||||
public abstract class Block extends StretchableTile{
|
public abstract class Block extends StretchableTile{
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
public String name = "Block";
|
public String name = "Block";
|
||||||
private HashSet<Route> routes = new HashSet<Route>();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject config() {
|
public JSONObject config() {
|
||||||
@@ -31,16 +27,8 @@ public abstract class Block extends StretchableTile{
|
|||||||
if (config.has(NAME)) name = config.getString(NAME);
|
if (config.has(NAME)) name = config.getString(NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Route> routes(){
|
|
||||||
return routes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract List<Connector> startPoints();
|
public abstract List<Connector> startPoints();
|
||||||
|
|
||||||
public void add(Route route) {
|
|
||||||
routes.add(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag propForm() {
|
public Tag propForm() {
|
||||||
Tag form = super.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);
|
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
||||||
label.addTo(form);
|
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;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.util.Map.Entry;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
|
||||||
|
|
||||||
public abstract class StretchableTile extends Tile {
|
public abstract class StretchableTile extends Tile {
|
||||||
private static final String LENGTH = "length";
|
private static final String LENGTH = "length";
|
||||||
@@ -27,10 +26,7 @@ public abstract class StretchableTile extends Tile {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag propForm() {
|
public Tag propForm() {
|
||||||
Form form = new Form();
|
Tag form = super.propForm();
|
||||||
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 label = new Tag("label").content(t("length:"));
|
Tag label = new Tag("label").content(t("length:"));
|
||||||
new Tag("input").attr("type", "number").attr("name","length").attr("value", length).addTo(label);
|
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.nio.charset.StandardCharsets;
|
||||||
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.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -19,14 +17,18 @@ import de.keawe.tools.translations.Translation;
|
|||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Application;
|
import de.srsoftware.web4rail.Application;
|
||||||
import de.srsoftware.web4rail.Connector;
|
import de.srsoftware.web4rail.Connector;
|
||||||
import de.srsoftware.web4rail.Window;
|
|
||||||
import de.srsoftware.web4rail.Plan.Direction;
|
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 abstract class Tile {
|
||||||
|
|
||||||
public int x = -1,y = -1;
|
public int x = -1,y = -1;
|
||||||
protected HashSet<String> classes = new HashSet<String>();
|
protected HashSet<String> classes = new HashSet<>();
|
||||||
protected HashSet<Shadow> shadows = new HashSet<Shadow>();
|
protected HashSet<Shadow> shadows = new HashSet<>();
|
||||||
|
private HashSet<Route> routes = new HashSet<>();
|
||||||
|
|
||||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||||
|
|
||||||
public Tile() {
|
public Tile() {
|
||||||
@@ -64,7 +66,21 @@ public abstract class Tile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tag propForm() {
|
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() {
|
public Tag propMenu() {
|
||||||
@@ -153,5 +169,13 @@ public abstract class Tile {
|
|||||||
public Tile update(HashMap<String, String> params) {
|
public Tile update(HashMap<String, String> params) {
|
||||||
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
||||||
return this;
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<Route> routes() {
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(Route route) {
|
||||||
|
this.routes.add(route);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user