6 changed files with 110 additions and 128 deletions
@ -1,13 +1,80 @@
@@ -1,13 +1,80 @@
|
||||
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{ |
||||
public abstract Set<Route> routes(); |
||||
private static final String NAME = "name"; |
||||
public String name = "Block"; |
||||
private HashSet<Route> routes = new HashSet<Route>(); |
||||
|
||||
@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); |
||||
} |
||||
|
||||
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(); |
||||
|
||||
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); |
||||
|
||||
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()).addTo(routeList); |
||||
} |
||||
routeList.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 String toString() { |
||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")"; |
||||
} |
||||
|
||||
@Override |
||||
public Tile update(HashMap<String, String> params) { |
||||
super.update(params); |
||||
if (params.containsKey(NAME)) name=params.get(NAME); |
||||
return this; |
||||
} |
||||
} |
||||
|
@ -1,78 +1,20 @@
@@ -1,78 +1,20 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
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.Plan.Direction; |
||||
import de.srsoftware.web4rail.Route; |
||||
|
||||
public class BlockH extends Block{ |
||||
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 int len() { |
||||
return length; |
||||
} |
||||
|
||||
@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 Set<Route> routes() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public List<Connector> startPoints() { |
||||
return List.of(new Connector(x-1, y, Direction.EAST),new Connector(x+len(), y, Direction.WEST)); |
||||
} |
||||
|
||||
@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 String toString() { |
||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")"; |
||||
} |
||||
|
||||
@Override |
||||
public Tile update(HashMap<String, String> params) { |
||||
super.update(params); |
||||
if (params.containsKey(NAME)) name=params.get(NAME); |
||||
return this; |
||||
} |
||||
} |
||||
|
@ -1,79 +1,20 @@
@@ -1,79 +1,20 @@
|
||||
package de.srsoftware.web4rail.tiles; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.HashMap; |
||||
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.Plan.Direction; |
||||
import de.srsoftware.web4rail.Route; |
||||
|
||||
public class BlockV extends Block{ |
||||
private static final String NAME = "name"; |
||||
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 int height() { |
||||
return length; |
||||
} |
||||
|
||||
@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 Set<Route> routes() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public List<Connector> startPoints() { |
||||
return List.of(new Connector(x,y-1,Direction.SOUTH),new Connector(x,y+height(),Direction.NORTH)); |
||||
} |
||||
|
||||
@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 String toString() { |
||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")"; |
||||
} |
||||
|
||||
@Override |
||||
public Tile update(HashMap<String, String> params) { |
||||
super.update(params); |
||||
if (params.containsKey(NAME)) name=params.get(NAME); |
||||
return this; |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue