added switch tile and corresponding condition
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.3.35</version>
|
<version>1.3.36</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -406,4 +406,20 @@ svg.Block text{
|
|||||||
|
|
||||||
.plan-file{
|
.plan-file{
|
||||||
color: green;
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Switch rect{
|
||||||
|
fill:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Switch.off rect.enabled,
|
||||||
|
.Switch.on rect.disabled{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Switch.off rect.disabled{
|
||||||
|
fill: red;
|
||||||
|
}
|
||||||
|
.Switch.on rect.enabled{
|
||||||
|
fill: forestgreen;
|
||||||
}
|
}
|
||||||
5
resources/svg/Switch.svg
Normal file
5
resources/svg/Switch.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg width="100" height="100" viewbox="0 0 100 100" class="%state%">
|
||||||
|
<rect x="5" y="20" width="90" height="60" />
|
||||||
|
<rect x="45" y="20" width="50" height="60" class="enabled" />
|
||||||
|
<rect x="5" y="20" width="50" height="60" class="disabled" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 247 B |
@@ -1,6 +1,9 @@
|
|||||||
abort : abbrechen
|
abort : abbrechen
|
||||||
Accessory : Zubehör
|
Accessory : Zubehör
|
||||||
|
Action : Aktion
|
||||||
Actions : Aktionen
|
Actions : Aktionen
|
||||||
|
Actions (On) : Aktionen (Ein)
|
||||||
|
Actions (Off) : Aktionen (Aus)
|
||||||
Actions and contacts : Aktionen und Kontakte
|
Actions and contacts : Aktionen und Kontakte
|
||||||
Action type : Aktions-Typ
|
Action type : Aktions-Typ
|
||||||
Actions will only fire, if all conditions are fullfilled. : Aktionen werden nur ausgeführt, wenn alle Bedingungen erfüllt sind.
|
Actions will only fire, if all conditions are fullfilled. : Aktionen werden nur ausgeführt, wenn alle Bedingungen erfüllt sind.
|
||||||
@@ -164,6 +167,8 @@ Falls aktiviert, wird die Strecke anhand von Zug- und Kachel-Länge hinter dem Z
|
|||||||
internal contacts : interne Kontakte
|
internal contacts : interne Kontakte
|
||||||
inverted : invertiert
|
inverted : invertiert
|
||||||
Inverts the direction {} is heading to. : Kehrt die Richtung, in welche {} fährt, um.
|
Inverts the direction {} is heading to. : Kehrt die Richtung, in welche {} fährt, um.
|
||||||
|
{} is off : {} ist Aus
|
||||||
|
{} is on : {} ist Ein
|
||||||
{} is oriented {} : {} ist {} gerichtet
|
{} is oriented {} : {} ist {} gerichtet
|
||||||
known cars : bekannte Waggons
|
known cars : bekannte Waggons
|
||||||
known locomotives : bekannte Lokomotiven
|
known locomotives : bekannte Lokomotiven
|
||||||
@@ -276,6 +281,7 @@ Select from plan : Auf Plan auswählen
|
|||||||
Select object : Objekt auswählen
|
Select object : Objekt auswählen
|
||||||
Select relay : Relais auswählen
|
Select relay : Relais auswählen
|
||||||
Select state : Status auswählen
|
Select state : Status auswählen
|
||||||
|
Select switch : Schalter auswählen
|
||||||
Select train : Zug auswählen
|
Select train : Zug auswählen
|
||||||
Select turnout : Weiche wählen
|
Select turnout : Weiche wählen
|
||||||
SendCommand : Kommando senden
|
SendCommand : Kommando senden
|
||||||
@@ -330,6 +336,7 @@ STRAIGHT : gerade
|
|||||||
Swap order : Reihenfolge umkehren
|
Swap order : Reihenfolge umkehren
|
||||||
Swap order of trains : Reihenfolge der Züge tauschen
|
Swap order of trains : Reihenfolge der Züge tauschen
|
||||||
SwitchFunction : Funktion schalten
|
SwitchFunction : Funktion schalten
|
||||||
|
SwitchIsOn : Schalter is an
|
||||||
Switch power off : Strom ausschalten
|
Switch power off : Strom ausschalten
|
||||||
Switch power on : Strom anschalten
|
Switch power on : Strom anschalten
|
||||||
SYSTEM : Betriebssystem
|
SYSTEM : Betriebssystem
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ import de.srsoftware.web4rail.tiles.SignalS;
|
|||||||
import de.srsoftware.web4rail.tiles.SignalW;
|
import de.srsoftware.web4rail.tiles.SignalW;
|
||||||
import de.srsoftware.web4rail.tiles.StraightH;
|
import de.srsoftware.web4rail.tiles.StraightH;
|
||||||
import de.srsoftware.web4rail.tiles.StraightV;
|
import de.srsoftware.web4rail.tiles.StraightV;
|
||||||
|
import de.srsoftware.web4rail.tiles.Switch;
|
||||||
import de.srsoftware.web4rail.tiles.TextDisplay;
|
import de.srsoftware.web4rail.tiles.TextDisplay;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
import de.srsoftware.web4rail.tiles.TileWithShadow;
|
import de.srsoftware.web4rail.tiles.TileWithShadow;
|
||||||
@@ -938,6 +939,7 @@ public class Plan extends BaseClass{
|
|||||||
new DecouplerV().tag(null).addTo(tiles);
|
new DecouplerV().tag(null).addTo(tiles);
|
||||||
new Relay().setLabel(true,"RL").tag(null).addTo(tiles);
|
new Relay().setLabel(true,"RL").tag(null).addTo(tiles);
|
||||||
new Contact().tag(null).addTo(tiles);
|
new Contact().tag(null).addTo(tiles);
|
||||||
|
new Switch().tag(null).addTo(tiles);
|
||||||
new TextDisplay().text("tx").tag(null).addTo(tiles);
|
new TextDisplay().text("tx").tag(null).addTo(tiles);
|
||||||
new Eraser().tag(null).addTo(tiles);
|
new Eraser().tag(null).addTo(tiles);
|
||||||
return tiles.addTo(tileMenu);
|
return tiles.addTo(tileMenu);
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ public abstract class Condition extends BaseClass {
|
|||||||
OrCondition.class,
|
OrCondition.class,
|
||||||
PushPullTrain.class,
|
PushPullTrain.class,
|
||||||
RouteEndBlock.class,
|
RouteEndBlock.class,
|
||||||
|
SwitchIsOn.class,
|
||||||
TrainHasTag.class,
|
TrainHasTag.class,
|
||||||
TrainIsShunting.class,
|
TrainIsShunting.class,
|
||||||
TrainLength.class,
|
TrainLength.class,
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package de.srsoftware.web4rail.conditions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tags.Window;
|
||||||
|
import de.srsoftware.web4rail.tiles.Switch;
|
||||||
|
|
||||||
|
public class SwitchIsOn extends Condition {
|
||||||
|
|
||||||
|
private Switch swtch = null;
|
||||||
|
private static final String SWITCH = "switch";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fulfilledBy(Context context) {
|
||||||
|
if (isSet(swtch)) return swtch.isOn() != inverted;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
if (isSet(swtch)) json.put(SWITCH, swtch.id().toString());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Condition load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
if (json.has(SWITCH)) swtch = BaseClass.get(new Id(json.getString(SWITCH)));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
formInputs.add(t("Select switch"),Switch.selector(swtch));
|
||||||
|
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (isNull(SWITCH)) return "["+t("Click here to select switch!")+"]";
|
||||||
|
return t(inverted ? "{} is off" : "{} is on",swtch) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
String switchId = params.get(Switch.class.getSimpleName());
|
||||||
|
if (isSet(switchId)) swtch = BaseClass.get(new Id(switchId));
|
||||||
|
return super.update(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
194
src/main/java/de/srsoftware/web4rail/tiles/Switch.java
Normal file
194
src/main/java/de/srsoftware/web4rail/tiles/Switch.java
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
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.Entry;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Application;
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.actions.Action;
|
||||||
|
import de.srsoftware.web4rail.actions.ActionList;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
import de.srsoftware.web4rail.tags.Window;
|
||||||
|
|
||||||
|
public class Switch extends Tile{
|
||||||
|
|
||||||
|
private boolean state = false;
|
||||||
|
private ActionList actionsOn,actionsOff;
|
||||||
|
private static final String ON = "ON";
|
||||||
|
private static final String OFF = "OFF";
|
||||||
|
|
||||||
|
public Switch() {
|
||||||
|
actionsOn = new ActionList(this);
|
||||||
|
actionsOff = new ActionList(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HashSet<String> classes() {
|
||||||
|
HashSet<String> classes = super.classes();
|
||||||
|
classes.add(state?"on":"off");
|
||||||
|
return classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object click() throws IOException {
|
||||||
|
state = !state;
|
||||||
|
Application.threadPool.execute(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Context context = new Context(Switch.this);
|
||||||
|
if (state) {
|
||||||
|
actionsOn.fire(context);
|
||||||
|
} else actionsOff.fire(context);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
stream();
|
||||||
|
return super.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
if (!actionsOn.isEmpty()) json.put(ON, actionsOn.json());
|
||||||
|
if (!actionsOff.isEmpty()) json.put(OFF, actionsOff.json());
|
||||||
|
json.put(STATE, state);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile load(JSONObject json) {
|
||||||
|
if (json.has(ON)) {
|
||||||
|
Object dummy = json.get(ON);
|
||||||
|
if (dummy instanceof JSONArray) {
|
||||||
|
JSONArray jarr = (JSONArray) dummy;
|
||||||
|
for (Object o : jarr) {
|
||||||
|
if (o instanceof JSONObject) {
|
||||||
|
JSONObject jo = (JSONObject) o;
|
||||||
|
String type = jo.getString("type");
|
||||||
|
Action action = Action.create(type, actionsOn);
|
||||||
|
if (isSet(action)) {
|
||||||
|
action.load(jo);
|
||||||
|
actionsOn.add(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dummy instanceof JSONObject) {
|
||||||
|
actionsOn.load((JSONObject) dummy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (json.has(OFF)) {
|
||||||
|
Object dummy = json.get(OFF);
|
||||||
|
if (dummy instanceof JSONArray) {
|
||||||
|
JSONArray jarr = (JSONArray) dummy;
|
||||||
|
for (Object o : jarr) {
|
||||||
|
if (o instanceof JSONObject) {
|
||||||
|
JSONObject jo = (JSONObject) o;
|
||||||
|
String type = jo.getString("type");
|
||||||
|
Action action = Action.create(type, actionsOff);
|
||||||
|
if (isSet(action)) {
|
||||||
|
action.load(jo);
|
||||||
|
actionsOff.add(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dummy instanceof JSONObject) {
|
||||||
|
actionsOff.load((JSONObject) dummy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (json.has(STATE)) state =json.getBoolean(STATE);
|
||||||
|
return super.load(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile position(int x, int y) {
|
||||||
|
super.position(x, y);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object process(HashMap<String, String> params) {
|
||||||
|
String action = params.get(ACTION);
|
||||||
|
Id id = Id.from(params);
|
||||||
|
if (action == null) return t("Missing ACTION on call to {}.process()",Switch.class.getSimpleName());
|
||||||
|
Switch swtch = isSet(id) ? BaseClass.get(id) : null;
|
||||||
|
switch (action) {
|
||||||
|
case ACTION_DROP:
|
||||||
|
if (isNull(id)) return t("Missing ID on call to {}.process()",Switch.class.getSimpleName());
|
||||||
|
if (isNull(swtch)) return t("No contact with id {} found!",id);
|
||||||
|
swtch.remove();
|
||||||
|
return t("Removed {}.",id);
|
||||||
|
case ACTION_PROPS:
|
||||||
|
return swtch.properties();
|
||||||
|
case ACTION_UPDATE:
|
||||||
|
return plan.update(params);
|
||||||
|
}
|
||||||
|
return t("Unknown action: {}",action);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
Fieldset fieldset = new Fieldset(t("Actions (On)"));
|
||||||
|
fieldset.id("actionsOn");
|
||||||
|
actionsOn.list().addTo(fieldset);
|
||||||
|
postForm.add(fieldset);
|
||||||
|
fieldset = new Fieldset(t("Actions (Off)"));
|
||||||
|
fieldset.id("actionsOff");
|
||||||
|
actionsOff.list().addTo(fieldset);
|
||||||
|
postForm.add(fieldset);
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeChild(BaseClass child) {
|
||||||
|
if (child == actionsOn) actionsOn = null;
|
||||||
|
if (child == actionsOff) actionsOff = null;
|
||||||
|
super.removeChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Select selector(Switch preselect) {
|
||||||
|
TreeMap<String,Switch> sortedSet = new TreeMap<String, Switch>(); // Map from Name to Contact
|
||||||
|
for (Switch contact : BaseClass.listElements(Switch.class)) sortedSet.put(contact.toString(), contact);
|
||||||
|
Select select = new Select("Switch");
|
||||||
|
for (Entry<String, Switch> entry : sortedSet.entrySet()) {
|
||||||
|
Switch contact = entry.getValue();
|
||||||
|
Tag option = select.addOption(contact.id(),contact);
|
||||||
|
if (contact == preselect) option.attr("selected", "selected");
|
||||||
|
}
|
||||||
|
return select;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOn() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stream() {
|
||||||
|
try {
|
||||||
|
Tag tag = tag(null);
|
||||||
|
if (state) tag.clazz(tag.get("class")+" active");
|
||||||
|
plan.stream("place "+tag);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String title() {
|
||||||
|
return t("Switch @ ({}, {})",x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return t("Switch")+"("+x+","+y+")";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user