started major refactoring
This commit is contained in:
@@ -151,7 +151,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Block get(String blockId) {
|
||||
public static Block get(Id blockId) {
|
||||
Tile tile = plan.get(blockId, false);
|
||||
if (tile instanceof Block) return (Block) tile;
|
||||
return null;
|
||||
@@ -195,7 +195,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
||||
public Tag link(String...args) {
|
||||
String tx = args.length<1 ? name+NBSP : args[0];
|
||||
String type = args.length<2 ? "span" : args[1];
|
||||
return link(type, Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_PROPS), tx).clazz("link","block");
|
||||
return link(type, tx).clazz("link","block");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,7 +267,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
||||
new Input("min."+wt.tag+"."+dB,wt.get(dB).min).numeric().addTo(new Tag("td")).addTo(row);
|
||||
new Input("max."+wt.tag+"."+dB,wt.get(dB).max).numeric().addTo(new Tag("td")).addTo(row);
|
||||
Tag actions = new Tag("td");
|
||||
Map<String, String> props = Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_TIMES);
|
||||
Map<String, String> props = Map.of(REALM,REALM_PLAN,ID,id().toString(),ACTION,ACTION_TIMES);
|
||||
switch (count) {
|
||||
case 1:
|
||||
actions.content(""); break;
|
||||
@@ -348,8 +348,8 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
||||
public Tile update(HashMap<String, String> params) throws IOException {
|
||||
if (params.containsKey(NAME)) name=params.get(NAME);
|
||||
if (params.containsKey(Train.class.getSimpleName())) {
|
||||
int trainId = Integer.parseInt(params.get(Train.class.getSimpleName()));
|
||||
if (trainId == 0) {
|
||||
Id trainId = Id.from(params,Train.class.getSimpleName());
|
||||
if (trainId == null) { // TODO: this is rubbish
|
||||
if (isSet(train)) train.dropTrace();
|
||||
train = null;
|
||||
} else {
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.Map;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
|
||||
public abstract class Bridge extends Tile {
|
||||
private static Bridge pendingConnection = null;
|
||||
@@ -37,10 +36,9 @@ public abstract class Bridge extends Tile {
|
||||
@Override
|
||||
public Window propMenu() {
|
||||
Window win = super.propMenu();
|
||||
Map<String, String> props = Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_CONNECT);
|
||||
new Tag("h4").content("Counterpart").addTo(win);
|
||||
new Tag("p").content(isSet(counterpart) ? t("Connected to {}.",counterpart) : t("Not connected to other bridge part!")).addTo(win);
|
||||
new Button(t("Select counterpart"), props).addTo(win);
|
||||
button(t("Select counterpart"),Map.of(ACTION,ACTION_CONNECT)).addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.actions.ActionList;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
@@ -22,7 +20,7 @@ import de.srsoftware.web4rail.tags.Select;
|
||||
public class Contact extends Tile{
|
||||
|
||||
private static final String ADDRESS = "address";
|
||||
private static final HashMap<String, Contact> contactsById = new HashMap<String, Contact>();
|
||||
private static final HashMap<Id, Contact> contactsById = new HashMap<Id, Contact>();
|
||||
private static final HashMap<Integer, Contact> contactsByAddr = new HashMap<Integer, Contact>();
|
||||
private boolean state = false;
|
||||
private String trigger = null;
|
||||
@@ -101,7 +99,7 @@ public class Contact extends Tile{
|
||||
return contactsByAddr.get(addr);
|
||||
}
|
||||
|
||||
public static Contact get(String contactId) {
|
||||
public static Contact get(Id contactId) {
|
||||
return contactsById.get(contactId);
|
||||
}
|
||||
|
||||
@@ -135,7 +133,7 @@ public class Contact extends Tile{
|
||||
|
||||
public static Object process(HashMap<String, String> params) {
|
||||
String action = params.get(ACTION);
|
||||
String id = params.get(ID);
|
||||
Id id = Id.from(params);
|
||||
if (action == null) return t("Missing ACTION on call to {}.process()",Contact.class.getSimpleName());
|
||||
Contact contact;
|
||||
switch (action) {
|
||||
@@ -157,9 +155,7 @@ public class Contact extends Tile{
|
||||
Form form = super.propForm(formId);
|
||||
new Tag("h4").content(t("Hardware settings")).addTo(form);
|
||||
Tag label = new Input(ADDRESS, addr).numeric().addTo(new Label(t("Address:")+NBSP));
|
||||
Map<String, String> props = Map.of(REALM,REALM_CONTACT,ID,id(),ACTION,ACTION_ANALYZE);
|
||||
new Button(t("learn"), props).addTo(label).addTo(form);
|
||||
|
||||
button(t("learn"),Map.of(ACTION,ACTION_ANALYZE)).addTo(label).addTo(form);
|
||||
return form;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class Relay extends Tile implements Device{
|
||||
private String name = t("Relay");
|
||||
protected boolean state = true;
|
||||
|
||||
private static final HashMap<String,Relay> relays = new HashMap<String, Relay>();
|
||||
private static final HashMap<Id,Relay> relays = new HashMap<Id, Relay>();
|
||||
public static final boolean STATE_A = true,STATE_B=false;
|
||||
private static final String LABEL_A = "label_a";
|
||||
private static final String LABEL_B = "label_b";
|
||||
@@ -242,7 +242,7 @@ public class Relay extends Tile implements Device{
|
||||
return relays.values();
|
||||
}
|
||||
|
||||
public static Relay get(String relayId) {
|
||||
public static Relay get(Id relayId) {
|
||||
return relays.get(relayId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ public abstract class Signal extends Tile implements Comparable<Signal>{
|
||||
|
||||
@Override
|
||||
public int compareTo(Signal other) {
|
||||
String tid = this.id();
|
||||
String oid = other.id();
|
||||
Id tid = this.id();
|
||||
Id oid = other.id();
|
||||
return tid.compareTo(oid);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Application;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Connector;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
@@ -101,12 +99,12 @@ public abstract class Tile extends BaseClass{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String id() {
|
||||
public Id id() {
|
||||
return Tile.id(x, y);
|
||||
}
|
||||
|
||||
public static String id(int x, int y) {
|
||||
return x+"-"+y;
|
||||
public static Id id(int x, int y) {
|
||||
return new Id(x+"-"+y);
|
||||
}
|
||||
|
||||
private static void inflate(String clazz, JSONObject json, Plan plan) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, ClassNotFoundException, IOException {
|
||||
@@ -131,7 +129,7 @@ public abstract class Tile extends BaseClass{
|
||||
if (isSet(route)) json.put(ROUTE, route.id());
|
||||
if (isSet(oneWay)) json.put(ONEW_WAY, oneWay);
|
||||
if (disabled) json.put(DISABLED, true);
|
||||
if (isSet(train)) json.put(REALM_TRAIN, train.id);
|
||||
if (isSet(train)) json.put(REALM_TRAIN, train.id());
|
||||
json.put(LENGTH, length);
|
||||
return json;
|
||||
}
|
||||
@@ -155,7 +153,7 @@ public abstract class Tile extends BaseClass{
|
||||
public Tag link(String...args) {
|
||||
String tx = args.length<1 ? id()+NBSP : args[0];
|
||||
String type = args.length<2 ? "span" : args[1];
|
||||
return link(type, Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_CLICK), tx);
|
||||
return super.link(type, tx, Map.of(ACTION,ACTION_CLICK));
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +214,7 @@ public abstract class Tile extends BaseClass{
|
||||
Window window = new Window("tile-properties",t("Properties of {} @ ({},{})",title(),x,y));
|
||||
|
||||
if (isSet(train)) {
|
||||
HashMap<String, Object> props = new HashMap<String,Object>(Map.of(REALM,REALM_TRAIN,ID,train.id));
|
||||
HashMap<String, Object> props = new HashMap<String,Object>(Map.of(REALM,REALM_TRAIN,ID,train.id()));
|
||||
if (isSet(train.route)) {
|
||||
props.put(ACTION, ACTION_STOP);
|
||||
window.children().insertElementAt(new Button(t("stop"),props), 1);
|
||||
@@ -236,7 +234,7 @@ public abstract class Tile extends BaseClass{
|
||||
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
|
||||
}
|
||||
|
||||
if (isSet(route)) link("p",Map.of(REALM,REALM_ROUTE,ID,route.id(),ACTION,ACTION_PROPS),t("Locked by {}",route)).addTo(window);
|
||||
if (isSet(route)) link("p",t("Locked by {}",route)).addTo(window);
|
||||
|
||||
Form form = propForm("tile-properties-"+id());
|
||||
if (isTrack) {
|
||||
@@ -295,7 +293,7 @@ public abstract class Tile extends BaseClass{
|
||||
return routes;
|
||||
}
|
||||
|
||||
public static void saveAll(HashMap<String, Tile> tiles ,String filename) throws IOException {
|
||||
public static void saveAll(HashMap<Id, Tile> tiles ,String filename) throws IOException {
|
||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||
for (Tile tile : tiles.values()) {
|
||||
if (isNull(tile) || tile instanceof Shadow) continue;
|
||||
@@ -317,10 +315,6 @@ public abstract class Tile extends BaseClass{
|
||||
return plan.place(this);
|
||||
}
|
||||
|
||||
protected static String t(String txt, Object...fills) {
|
||||
return Translation.get(Application.class, txt, fills);
|
||||
}
|
||||
|
||||
public Tag tag(Map<String,Object> replacements) throws IOException {
|
||||
int width = 100*width();
|
||||
int height = 100*height();
|
||||
@@ -329,7 +323,7 @@ public abstract class Tile extends BaseClass{
|
||||
replacements.put("%height%",height);
|
||||
String style = "";
|
||||
Tag svg = new Tag("svg")
|
||||
.id(isSet(x) && isSet(y) ? id() : getClass().getSimpleName())
|
||||
.id(isSet(x) && isSet(y) ? id().toString() : getClass().getSimpleName())
|
||||
.clazz(classes())
|
||||
.size(100,100)
|
||||
.attr("name", getClass().getSimpleName())
|
||||
|
||||
Reference in New Issue
Block a user