implemented renamable blocks
This commit is contained in:
@@ -95,7 +95,7 @@ public class Plan {
|
|||||||
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
|
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
|
||||||
int y = row.getKey();
|
int y = row.getKey();
|
||||||
Tile tile = row.getValue().position(x, y);
|
Tile tile = row.getValue().position(x, y);
|
||||||
if (tile != null) page.append("\t\t"+tile.tag()+"\n");
|
if (tile != null) page.append("\t\t"+tile.tag(null)+"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return page.append(menu()).append(messages()).append("</div>").style("css/style.css").js("js/jquery-3.5.1.min.js").js("js/plan.js");
|
return page.append(menu()).append(messages()).append("</div>").style("css/style.css").js("js/jquery-3.5.1.min.js").js("js/plan.js");
|
||||||
@@ -167,7 +167,7 @@ public class Plan {
|
|||||||
if (!moved.isEmpty()) {
|
if (!moved.isEmpty()) {
|
||||||
set(x,y,null);
|
set(x,y,null);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Tile tile : moved) sb.append(tile.tag()+"\n");
|
for (Tile tile : moved) sb.append(tile.tag(null)+"\n");
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -278,29 +278,29 @@ public class Plan {
|
|||||||
Tag tileMenu = new Tag("div").clazz("addtile").title(t("Add tile")).content("◫");
|
Tag tileMenu = new Tag("div").clazz("addtile").title(t("Add tile")).content("◫");
|
||||||
|
|
||||||
StringBuffer tiles = new StringBuffer();
|
StringBuffer tiles = new StringBuffer();
|
||||||
tiles.append(new StraightH().tag());
|
tiles.append(new StraightH().tag(null));
|
||||||
tiles.append(new StraightV().tag());
|
tiles.append(new StraightV().tag(null));
|
||||||
tiles.append(new DiagES().tag());
|
tiles.append(new DiagES().tag(null));
|
||||||
tiles.append(new DiagSW().tag());
|
tiles.append(new DiagSW().tag(null));
|
||||||
tiles.append(new DiagNE().tag());
|
tiles.append(new DiagNE().tag(null));
|
||||||
tiles.append(new DiagWN().tag());
|
tiles.append(new DiagWN().tag(null));
|
||||||
tiles.append(new EndE().tag());
|
tiles.append(new EndE().tag(null));
|
||||||
tiles.append(new EndW().tag());
|
tiles.append(new EndW().tag(null));
|
||||||
tiles.append(new EndN().tag());
|
tiles.append(new EndN().tag(null));
|
||||||
tiles.append(new EndS().tag());
|
tiles.append(new EndS().tag(null));
|
||||||
tiles.append(new TurnoutSW().tag());
|
tiles.append(new TurnoutSW().tag(null));
|
||||||
tiles.append(new TurnoutSE().tag());
|
tiles.append(new TurnoutSE().tag(null));
|
||||||
tiles.append(new TurnoutNW().tag());
|
tiles.append(new TurnoutNW().tag(null));
|
||||||
tiles.append(new TurnoutNE().tag());
|
tiles.append(new TurnoutNE().tag(null));
|
||||||
tiles.append(new TurnoutES().tag());
|
tiles.append(new TurnoutES().tag(null));
|
||||||
tiles.append(new TurnoutEN().tag());
|
tiles.append(new TurnoutEN().tag(null));
|
||||||
tiles.append(new TurnoutWS().tag());
|
tiles.append(new TurnoutWS().tag(null));
|
||||||
tiles.append(new TurnoutWN().tag());
|
tiles.append(new TurnoutWN().tag(null));
|
||||||
tiles.append(new CrossH().tag());
|
tiles.append(new CrossH().tag(null));
|
||||||
tiles.append(new CrossV().tag());
|
tiles.append(new CrossV().tag(null));
|
||||||
tiles.append(new Eraser().tag());
|
tiles.append(new Eraser().tag(null));
|
||||||
tiles.append(new BlockH().tag());
|
tiles.append(new BlockH().tag(null));
|
||||||
tiles.append(new BlockV().tag());
|
tiles.append(new BlockV().tag(null));
|
||||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,54 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
public class BlockH extends StraightH{
|
public class BlockH extends StraightH{
|
||||||
private Contact north,center,south;
|
private static final String NAME = "name";
|
||||||
|
Contact north,center,south;
|
||||||
|
private String name = "Block";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject config() {
|
||||||
|
JSONObject config = super.config();
|
||||||
|
config.put(NAME, name);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(JSONObject config) {
|
||||||
|
super.configure(config);
|
||||||
|
if (config.has(NAME)) name = config.getString(NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag propForm() {
|
||||||
|
Tag form = super.propForm();
|
||||||
|
|
||||||
|
Tag label = new Tag("label").content(t("name:"));
|
||||||
|
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
||||||
|
label.addTo(form);
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
|
replacements.put("%text%",name);
|
||||||
|
return super.tag(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
|
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,55 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
public class BlockV extends StraightV{
|
public class BlockV extends StraightV{
|
||||||
|
private static final String NAME = "name";
|
||||||
Contact west,center,east;
|
Contact west,center,east;
|
||||||
|
private String name = "Block";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject config() {
|
||||||
|
JSONObject config = super.config();
|
||||||
|
config.put(NAME, name);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(JSONObject config) {
|
||||||
|
super.configure(config);
|
||||||
|
if (config.has(NAME)) name = config.getString(NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag propForm() {
|
||||||
|
Tag form = super.propForm();
|
||||||
|
|
||||||
|
Tag label = new Tag("label").content(t("name:"));
|
||||||
|
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name).addTo(label);
|
||||||
|
label.addTo(form);
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
|
replacements.put("%text%",name);
|
||||||
|
return super.tag(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
|
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ public class CrossH extends Tile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag tag() throws IOException {
|
public Tag tag(Map<String,Object> replacements) throws IOException {
|
||||||
return super.tag().size(200,100).attr("viewbox", "0 0 200 100");
|
return super.tag(replacements).size(200,100).attr("viewbox", "0 0 200 100");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ public class CrossV extends Tile{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag tag() throws IOException {
|
public Tag tag(Map<String,Object> replacements) throws IOException {
|
||||||
return super.tag().size(100,200).attr("viewbox", "0 0 100 200");
|
return super.tag(replacements).size(100,200).attr("viewbox", "0 0 100 200");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.Window;
|
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
|
|
||||||
public abstract class StretchableTile extends Tile {
|
public abstract class StretchableTile extends Tile {
|
||||||
@@ -26,8 +25,8 @@ public abstract class StretchableTile extends Tile {
|
|||||||
if (config.has(LENGTH)) setLength(config.getInt(LENGTH));
|
if (config.has(LENGTH)) setLength(config.getInt(LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag propMenu() {
|
@Override
|
||||||
Window menu = new Window("tile-properties",t("Properties of {} @ ({},{})",getClass().getSimpleName(),x,y));
|
public Tag propForm() {
|
||||||
Form form = new Form();
|
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","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","x").attr("value", x).addTo(form);
|
||||||
@@ -37,9 +36,7 @@ public abstract class StretchableTile extends Tile {
|
|||||||
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);
|
||||||
label.addTo(form);
|
label.addTo(form);
|
||||||
|
|
||||||
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
return form;
|
||||||
form.addTo(menu);
|
|
||||||
return menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLength(String value) {
|
private void setLength(String value) {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ 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.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -47,13 +49,28 @@ public abstract class Tile {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag propMenu() {
|
public Tag propForm() {
|
||||||
return new Window("tile-properties",t("Properties")).content(t("This tile ({}) has no properties",getClass().getSimpleName()));
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tag propMenu() {
|
||||||
|
Window menu = new Window("tile-properties",t("Properties of {} @ ({},{})",getClass().getSimpleName(),x,y));
|
||||||
|
Tag form = propForm();
|
||||||
|
if (form!=null) {
|
||||||
|
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
||||||
|
form.addTo(menu);
|
||||||
|
} else {
|
||||||
|
menu.content(t("This tile ({}) has no properties",getClass().getSimpleName()));
|
||||||
|
}
|
||||||
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag tag() throws IOException {
|
public Tag tag(Map<String,Object> replacements) throws IOException {
|
||||||
int width = 100*len();
|
int width = 100*len();
|
||||||
int height = 100*height();
|
int height = 100*height();
|
||||||
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
|
replacements.put("%width%",width);
|
||||||
|
replacements.put("%height%",height);
|
||||||
String style = "";
|
String style = "";
|
||||||
Tag svg = new Tag("svg")
|
Tag svg = new Tag("svg")
|
||||||
.id((x!=-1 && y!=-1)?("tile-"+x+"-"+y):(getClass().getSimpleName()))
|
.id((x!=-1 && y!=-1)?("tile-"+x+"-"+y):(getClass().getSimpleName()))
|
||||||
@@ -73,8 +90,9 @@ public abstract class Tile {
|
|||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine();
|
String line = scanner.nextLine();
|
||||||
if (line.startsWith("<svg") || line.endsWith("svg>")) continue;
|
if (line.startsWith("<svg") || line.endsWith("svg>")) continue;
|
||||||
line = replace(line,"%width%",width);
|
for (Entry<String, Object> replacement : replacements.entrySet()) {
|
||||||
line = replace(line,"%height%",height);
|
line = replace(line,replacement);
|
||||||
|
}
|
||||||
sb.append(line+"\n");
|
sb.append(line+"\n");
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
@@ -90,13 +108,20 @@ public abstract class Tile {
|
|||||||
return svg;
|
return svg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String replace(String line, String key, int val) {
|
private static String replace(String line, Entry<String, Object> replacement) {
|
||||||
|
String key = replacement.getKey();
|
||||||
|
Object val = replacement.getValue();
|
||||||
int start = line.indexOf(key);
|
int start = line.indexOf(key);
|
||||||
int len = key.length();
|
int len = key.length();
|
||||||
while (start>0) {
|
while (start>0) {
|
||||||
String tag = line.substring(start, line.indexOf("\"",start));
|
int end = line.indexOf("\"",start);
|
||||||
int summand = (tag.length()>len) ? Integer.parseInt(tag.substring(len)) : 0;
|
int end2 = line.indexOf("<",start);
|
||||||
line = line.replace(tag, ""+(val+summand));
|
if (end2>0 && (end<0 || end2<end)) end=end2;
|
||||||
|
String tag = line.substring(start, end);
|
||||||
|
if (tag.length()>len) {
|
||||||
|
val = Integer.parseInt(tag.substring(len)) + (int) val;
|
||||||
|
}
|
||||||
|
line = line.replace(tag, ""+val);
|
||||||
start = line.indexOf(key);
|
start = line.indexOf(key);
|
||||||
}
|
}
|
||||||
return line;
|
return line;
|
||||||
|
|||||||
Reference in New Issue
Block a user