added new tiles and actions:
* Tile displaying text * TextDisplay: an action that sends text to clients * DetermineTrainInBlock: action that alters the context by requesting the train in a specific block
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.0.8</version>
|
<version>1.0.9</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>
|
||||||
|
|||||||
3
resources/svg/TextDisplay.svg
Normal file
3
resources/svg/TextDisplay.svg
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||||
|
<text x="10" y="65">%text%</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 94 B |
@@ -49,9 +49,11 @@ delete route : Route löschen
|
|||||||
Destination : Ziel
|
Destination : Ziel
|
||||||
Destination\: : Ziel:
|
Destination\: : Ziel:
|
||||||
Destination\: {} from {} : Ziel: {} von {}
|
Destination\: {} from {} : Ziel: {} von {}
|
||||||
|
DetermineTrainInBlock : Zug im Block bestimmen
|
||||||
Direction : Richtung
|
Direction : Richtung
|
||||||
Direction\: heading {} : Richtung: nach {}
|
Direction\: heading {} : Richtung: nach {}
|
||||||
disabled : deaktiviert
|
disabled : deaktiviert
|
||||||
|
Display "{}" on clients. : „{}“ auf den Clients anzeigen.
|
||||||
Drop : Verwerfen
|
Drop : Verwerfen
|
||||||
Dropped destination of {}. : Ziel von {} verworfen.
|
Dropped destination of {}. : Ziel von {} verworfen.
|
||||||
EAST : Osten
|
EAST : Osten
|
||||||
@@ -120,7 +122,7 @@ Select from plan : Auf Plan auswählen
|
|||||||
Select relay\: : Relais auswählen:
|
Select relay\: : Relais auswählen:
|
||||||
Select train\: : Zug auswählen:
|
Select train\: : Zug auswählen:
|
||||||
SendCommand : Kommando senden
|
SendCommand : Kommando senden
|
||||||
Send command \"{}\" to control unit : Kommando „{}“ an Zentrale senden
|
Send command "{}" to control unit : Kommando „{}“ an Zentrale senden
|
||||||
SetRelay : Relais schalten
|
SetRelay : Relais schalten
|
||||||
SetSignal : Signal stellen
|
SetSignal : Signal stellen
|
||||||
SetSignalsToStop : Signale auf Halt stellen
|
SetSignalsToStop : Signale auf Halt stellen
|
||||||
@@ -131,6 +133,7 @@ Set {} to {} : {} auf {} setzen
|
|||||||
SetPower : Strom schalten
|
SetPower : Strom schalten
|
||||||
Set speed to : Geschwindigkeit setzen
|
Set speed to : Geschwindigkeit setzen
|
||||||
Setup actions : Aktivierungs-Aktionen
|
Setup actions : Aktivierungs-Aktionen
|
||||||
|
ShowText : Text anzeigen
|
||||||
Signals : Signale
|
Signals : Signale
|
||||||
Simulating movement of {}... : Simuliere Fahrt von {}...
|
Simulating movement of {}... : Simuliere Fahrt von {}...
|
||||||
SOUTH : Süden
|
SOUTH : Süden
|
||||||
@@ -147,6 +150,7 @@ Switch power off : Strom ausschalten
|
|||||||
Switch power on : Strom anschalten
|
Switch power on : Strom anschalten
|
||||||
Tag : Markierung
|
Tag : Markierung
|
||||||
Tags : Markierungen
|
Tags : Markierungen
|
||||||
|
Text to display on clients\: : Text, welcher auf den Clients angezeigt werden soll:
|
||||||
Toggle : umschalten
|
Toggle : umschalten
|
||||||
Toggle power : Stom umschalten
|
Toggle power : Stom umschalten
|
||||||
Train : Zug
|
Train : Zug
|
||||||
|
|||||||
@@ -50,6 +50,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.TextDisplay;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
import de.srsoftware.web4rail.tiles.Turnout.State;
|
import de.srsoftware.web4rail.tiles.Turnout.State;
|
||||||
import de.srsoftware.web4rail.tiles.Turnout3E;
|
import de.srsoftware.web4rail.tiles.Turnout3E;
|
||||||
@@ -804,6 +805,7 @@ public class Plan extends BaseClass{
|
|||||||
new Turnout3E().tag(null).addTo(tiles);
|
new Turnout3E().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 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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,12 +125,14 @@ public abstract class Action extends BaseClass {
|
|||||||
return List.of(
|
return List.of(
|
||||||
ConditionalAction.class,
|
ConditionalAction.class,
|
||||||
DelayedAction.class,
|
DelayedAction.class,
|
||||||
|
DetermineTrainInBlock.class,
|
||||||
FinishRoute.class,
|
FinishRoute.class,
|
||||||
SendCommand.class,
|
SendCommand.class,
|
||||||
SetPower.class,
|
SetPower.class,
|
||||||
SetRelay.class,
|
SetRelay.class,
|
||||||
SetSignal.class,
|
SetSignal.class,
|
||||||
SetSpeed.class,
|
SetSpeed.class,
|
||||||
|
ShowText.class,
|
||||||
StopAllTrains.class,
|
StopAllTrains.class,
|
||||||
StopAuto.class,
|
StopAuto.class,
|
||||||
TriggerContact.class,
|
TriggerContact.class,
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
|
||||||
|
public class DetermineTrainInBlock extends Action {
|
||||||
|
|
||||||
|
private Block block = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) throws IOException {
|
||||||
|
context.block = block;
|
||||||
|
context.train = block.train();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
if (isSet(block)) json.put(BLOCK, block.id());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
String blockId = json.getString(BLOCK);
|
||||||
|
if (isSet(blockId)) block = Block.get(blockId);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window properties(HashMap<String, String> params) {
|
||||||
|
Window win = super.properties(params);
|
||||||
|
Form form = new Form("action-prop-form-"+id);
|
||||||
|
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||||
|
new Input(ID,params.get(ID)).hideIn(form);
|
||||||
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
|
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||||
|
|
||||||
|
Select select = Block.selector(block, null);
|
||||||
|
select.addTo(new Label(t("Select block:")+NBSP)).addTo(form);
|
||||||
|
|
||||||
|
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return isSet(block) ? t("Determine, which train is in {}",block) : "["+t("click here to setup block")+"]";
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
LOG.debug("update: {}",params);
|
||||||
|
String blockId = params.get(Block.class.getSimpleName());
|
||||||
|
if (isSet(blockId)) block = Block.get(blockId);
|
||||||
|
return properties(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -28,7 +28,7 @@ public class SendCommand extends Action{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
23
src/main/java/de/srsoftware/web4rail/actions/ShowText.java
Normal file
23
src/main/java/de/srsoftware/web4rail/actions/ShowText.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
|
||||||
|
public class ShowText extends TextAction{
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
plan.stream(fill(text,context));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Label label() {
|
||||||
|
return new Label(t("Text to display on clients:")+NBSP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return t("Display \"{}\" on clients.",text);
|
||||||
|
}
|
||||||
|
}
|
||||||
66
src/main/java/de/srsoftware/web4rail/actions/TextAction.java
Normal file
66
src/main/java/de/srsoftware/web4rail/actions/TextAction.java
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
|
||||||
|
public abstract class TextAction extends Action {
|
||||||
|
|
||||||
|
public static final String TEXT = "text";
|
||||||
|
protected String text = "Hello, world!";
|
||||||
|
|
||||||
|
|
||||||
|
public String fill(String tx,Context context) {
|
||||||
|
if (isSet(context.block)) tx = tx.replace("%block%", context.block.name);
|
||||||
|
if (isSet(context.contact)) tx = tx.replace("%contact%", context.contact.id());
|
||||||
|
if (isSet(context.direction)) tx = tx.replace("%dir%", context.direction.name());
|
||||||
|
if (isSet(context.route)) tx = tx.replace("%route%", context.route.name());
|
||||||
|
if (isSet(context.train)) tx = tx.replace("%train%", context.train.name());
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
json.put(TEXT, text);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Label label();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
text = json.getString(TEXT);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window properties(HashMap<String, String> params) {
|
||||||
|
Window win = super.properties(params);
|
||||||
|
Form form = new Form("action-prop-form-"+id);
|
||||||
|
new Input(REALM,REALM_ACTIONS).hideIn(form);
|
||||||
|
new Input(ID,params.get(ID)).hideIn(form);
|
||||||
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
|
new Input(CONTEXT,params.get(CONTEXT)).hideIn(form);
|
||||||
|
new Input(TEXT, text).addTo(label()).addTo(form);
|
||||||
|
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
LOG.debug("update: {}",params);
|
||||||
|
String error = null;
|
||||||
|
text = params.get(TEXT);
|
||||||
|
Window win = properties(params);
|
||||||
|
return new Tag("span").content(error).addTo(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,10 +19,7 @@ public class TriggerContact extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) throws IOException {
|
||||||
if (isSet(contact)) {
|
if (isSet(contact)) return contact.trigger(200);
|
||||||
System.err.println("triggering "+contact);
|
|
||||||
contact.trigger(200);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tag selector(Block preselected,Collection<Block> exclude) {
|
public static Select selector(Block preselected,Collection<Block> exclude) {
|
||||||
if (isNull(exclude)) exclude = new Vector<Block>();
|
if (isNull(exclude)) exclude = new Vector<Block>();
|
||||||
Select select = new Select(Block.class.getSimpleName());
|
Select select = new Select(Block.class.getSimpleName());
|
||||||
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ public class Contact extends Tile{
|
|||||||
return trigger;
|
return trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trigger(int duration) throws IOException {
|
public boolean trigger(int duration) throws IOException {
|
||||||
activate(true);
|
activate(true);
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -214,6 +214,7 @@ public class Contact extends Tile{
|
|||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) throws IOException {
|
public Tile update(HashMap<String, String> params) throws IOException {
|
||||||
|
|||||||
75
src/main/java/de/srsoftware/web4rail/tiles/TextDisplay.java
Normal file
75
src/main/java/de/srsoftware/web4rail/tiles/TextDisplay.java
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
|
||||||
|
public class TextDisplay extends StretchableTile {
|
||||||
|
private static final String TEXT = "text";
|
||||||
|
private String text = "Hello, world!";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
return super.json().put(TEXT, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Tile load(JSONObject json) throws IOException {
|
||||||
|
super.load(json);
|
||||||
|
if (json.has(TEXT)) text = json.getString(TEXT);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
|
if (isNull(replacements)) replacements = new HashMap<String, Object>();
|
||||||
|
replacements.put("%text%",text);
|
||||||
|
return super.tag(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Form propForm(String id) {
|
||||||
|
noTrack();
|
||||||
|
Form form = super.propForm(id);
|
||||||
|
new Tag("h4").content(t("Text")).addTo(form);
|
||||||
|
|
||||||
|
new Input(TEXT, text).addTo(new Label(t("Text")+":"+NBSP)).addTo(new Tag("p")).addTo(form);
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String stretchType() {
|
||||||
|
return t("Width");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextDisplay text(String tx) {
|
||||||
|
text = tx;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile update(HashMap<String, String> params) throws IOException {
|
||||||
|
for (Entry<String, String> entry : params.entrySet()) {
|
||||||
|
switch (entry.getKey()) {
|
||||||
|
case TEXT:
|
||||||
|
text(entry.getValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.update(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int width() {
|
||||||
|
return stretch;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
private static final String Y = "y";
|
private static final String Y = "y";
|
||||||
|
|
||||||
private boolean disabled = false;
|
private boolean disabled = false;
|
||||||
|
private boolean isTrack = true;
|
||||||
private int length = DEFAUT_LENGTH;
|
private int length = DEFAUT_LENGTH;
|
||||||
protected Direction oneWay = null;
|
protected Direction oneWay = null;
|
||||||
protected Route route = null;
|
protected Route route = null;
|
||||||
@@ -142,7 +143,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Tile length(int newLength) {
|
public Tile length(int newLength) {
|
||||||
length = newLength;
|
length = Math.max(0, newLength);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,6 +188,10 @@ public abstract class Tile extends BaseClass{
|
|||||||
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
|
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void noTrack() {
|
||||||
|
isTrack = false;
|
||||||
|
}
|
||||||
|
|
||||||
public Tile position(int x, int y) {
|
public Tile position(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@@ -242,12 +247,14 @@ public abstract class Tile extends BaseClass{
|
|||||||
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",Map.of(REALM,REALM_ROUTE,ID,route.id(),ACTION,ACTION_PROPS),t("Locked by {}",route)).addTo(window);
|
||||||
|
|
||||||
Form form = propForm("tile-properties-"+id());
|
Form form = propForm("tile-properties-"+id());
|
||||||
new Tag("h4").content(t("Length")).addTo(form);
|
if (isTrack) {
|
||||||
new Input(LENGTH,length).numeric().addTo(new Label(t("Length")+":"+NBSP)).addTo(form);
|
new Tag("h4").content(t("Length")).addTo(form);
|
||||||
new Tag("h4").content(t("Availability")).addTo(form);
|
new Input(LENGTH,length).numeric().addTo(new Label(t("Length")+":"+NBSP)).addTo(form);
|
||||||
Checkbox cb = new Checkbox(DISABLED, t("disabled"), disabled);
|
new Tag("h4").content(t("Availability")).addTo(form);
|
||||||
if (disabled) cb.clazz("disabled");
|
Checkbox cb = new Checkbox(DISABLED, t("disabled"), disabled);
|
||||||
cb.addTo(form);
|
if (disabled) cb.clazz("disabled");
|
||||||
|
cb.addTo(form);
|
||||||
|
}
|
||||||
new Button(t("Apply"),form).addTo(form);
|
new Button(t("Apply"),form).addTo(form);
|
||||||
form.addTo(window);
|
form.addTo(window);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user