added new action SetDisplayText
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.11</version>
|
<version>1.0.12</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>
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ Control : Steuerung
|
|||||||
Control unit : Zentrale
|
Control unit : Zentrale
|
||||||
Current location\: : Aktueller Ort:
|
Current location\: : Aktueller Ort:
|
||||||
[Click here to select block!] : [Hier klicken, um Block auszuwählen!]
|
[Click here to select block!] : [Hier klicken, um Block auszuwählen!]
|
||||||
|
[Click here to add condition] : [Hier klicken, um Bedingung hinzuzufügen]
|
||||||
|
[Click here to select display!] : [Hier klicken, um Anzeige auszuwählen!]
|
||||||
[Click here to select train!] : [Hier klicken, um Zug auszuwählen!]
|
[Click here to select train!] : [Hier klicken, um Zug auszuwählen!]
|
||||||
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
||||||
click here to setup relay : Hier klicken, um Relais einzurichten
|
click here to setup relay : Hier klicken, um Relais einzurichten
|
||||||
@@ -51,6 +53,7 @@ Destination : Ziel
|
|||||||
Destination\: : Ziel:
|
Destination\: : Ziel:
|
||||||
Destination\: {} from {} : Ziel: {} von {}
|
Destination\: {} from {} : Ziel: {} von {}
|
||||||
DetermineTrainInBlock : Zug im Block bestimmen
|
DetermineTrainInBlock : Zug im Block bestimmen
|
||||||
|
Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
||||||
Direction : Richtung
|
Direction : Richtung
|
||||||
Direction\: heading {} : Richtung: nach {}
|
Direction\: heading {} : Richtung: nach {}
|
||||||
disabled : deaktiviert
|
disabled : deaktiviert
|
||||||
@@ -119,11 +122,13 @@ Route will only be available, if all conditions are fulfilled. : Route ist nur v
|
|||||||
Save : speichern
|
Save : speichern
|
||||||
Select block\: : Block auswählen:
|
Select block\: : Block auswählen:
|
||||||
Select contact\: : Kotakt auswählen:
|
Select contact\: : Kotakt auswählen:
|
||||||
|
Select display\: : Anzeige auswählen:
|
||||||
Select from plan : Auf Plan auswählen
|
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
|
||||||
|
SetDisplayText : Anzeige-Text setzen
|
||||||
SetRelay : Relais schalten
|
SetRelay : Relais schalten
|
||||||
SetSignal : Signal stellen
|
SetSignal : Signal stellen
|
||||||
SetSignalsToStop : Signale auf Halt stellen
|
SetSignalsToStop : Signale auf Halt stellen
|
||||||
@@ -152,6 +157,7 @@ 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:
|
Text to display on clients\: : Text, welcher auf den Clients angezeigt werden soll:
|
||||||
|
Text to show on display\: : Text, welcher in der Anzeige dargestellt werden soll:
|
||||||
Toggle : umschalten
|
Toggle : umschalten
|
||||||
Toggle power : Stom umschalten
|
Toggle power : Stom umschalten
|
||||||
Train : Zug
|
Train : Zug
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ public abstract class Action extends BaseClass {
|
|||||||
public Block block = null;
|
public Block block = null;
|
||||||
public Direction direction = null;
|
public Direction direction = null;
|
||||||
|
|
||||||
|
private Context(Contact c, Route r, Train t, Block b, Direction d) {
|
||||||
|
contact = c;
|
||||||
|
route = r;
|
||||||
|
train = t;
|
||||||
|
block = b;
|
||||||
|
direction = d;
|
||||||
|
}
|
||||||
|
|
||||||
public Context(Contact c) {
|
public Context(Contact c) {
|
||||||
contact = c;
|
contact = c;
|
||||||
setRoute(contact.route());
|
setRoute(contact.route());
|
||||||
@@ -52,6 +60,10 @@ public abstract class Action extends BaseClass {
|
|||||||
public Context(Route route) {
|
public Context(Route route) {
|
||||||
setRoute(route);
|
setRoute(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Context clone() {
|
||||||
|
return new Context(contact, route, train, block, direction);
|
||||||
|
}
|
||||||
|
|
||||||
private void setRoute(Route route) {
|
private void setRoute(Route route) {
|
||||||
this.route = route;
|
this.route = route;
|
||||||
@@ -127,6 +139,7 @@ public abstract class Action extends BaseClass {
|
|||||||
DetermineTrainInBlock.class,
|
DetermineTrainInBlock.class,
|
||||||
FinishRoute.class,
|
FinishRoute.class,
|
||||||
SendCommand.class,
|
SendCommand.class,
|
||||||
|
SetDisplayText.class,
|
||||||
SetPower.class,
|
SetPower.class,
|
||||||
SetRelay.class,
|
SetRelay.class,
|
||||||
SetSignal.class,
|
SetSignal.class,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class ConditionalAction extends Action {
|
|||||||
for (Condition condition : conditions) {
|
for (Condition condition : conditions) {
|
||||||
if (!condition.fulfilledBy(context)) return true;
|
if (!condition.fulfilledBy(context)) return true;
|
||||||
}
|
}
|
||||||
return actions.fire(context);
|
return actions.fire(context.clone()); // actions, that happen within the conditional action list must not modify the global context.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class DetermineTrainInBlock extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return isSet(block) ? t("Determine, which train is in {}",block) : "["+t("click here to setup block")+"]";
|
return isSet(block) ? t("Determine, which train is in {}",block) : t("[Click here to select block!]");
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
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.Form;
|
||||||
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
import de.srsoftware.web4rail.tiles.TextDisplay;
|
||||||
|
|
||||||
|
public class SetDisplayText extends TextAction{
|
||||||
|
|
||||||
|
private TextDisplay display;
|
||||||
|
private static final String DISPLAY = "display";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
plan.place(display.text(fill(text, context)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
return super.json().put(DISPLAY, display.id());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Label label() {
|
||||||
|
return new Label(t("Text to show on display:")+NBSP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
if (json.has(DISPLAY)) {
|
||||||
|
new Thread() { // load asynchronously, as referred tile may not be available,yet
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
sleep(1000);
|
||||||
|
display = (TextDisplay) plan.get(json.getString(DISPLAY), false);
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
};
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
return super.load(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window properties(HashMap<String, String> params) {
|
||||||
|
Window win = super.properties(params);
|
||||||
|
|
||||||
|
Select select = TextDisplay.selector(display, null);
|
||||||
|
Tag label = select.addTo(new Label(t("Select display:")+NBSP));
|
||||||
|
|
||||||
|
for (Tag tag : win.children()) {
|
||||||
|
if (tag instanceof Form) {
|
||||||
|
tag.children().insertElementAt(label, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return isNull(display) ? t("[Click here to select display!]") : t("Display \"{}\" on {}.",text,display);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
super.update(params);
|
||||||
|
String displayId = params.get(TextDisplay.class.getSimpleName());
|
||||||
|
if (isSet(displayId)) display = (TextDisplay) plan.get(displayId, false);
|
||||||
|
return properties(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package de.srsoftware.web4rail.tiles;
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Vector;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -11,6 +13,7 @@ import de.srsoftware.tools.Tag;
|
|||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
|
||||||
public class TextDisplay extends StretchableTile {
|
public class TextDisplay extends StretchableTile {
|
||||||
private static final String TEXT = "text";
|
private static final String TEXT = "text";
|
||||||
@@ -46,6 +49,19 @@ public class TextDisplay extends StretchableTile {
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Select selector(TextDisplay preselected,Collection<TextDisplay> exclude) {
|
||||||
|
if (isNull(exclude)) exclude = new Vector<TextDisplay>();
|
||||||
|
Select select = new Select(TextDisplay.class.getSimpleName());
|
||||||
|
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
||||||
|
for (Tile tile : plan.tiles.values()) {
|
||||||
|
if (!(tile instanceof TextDisplay)) continue;
|
||||||
|
if (exclude.contains(tile)) continue;
|
||||||
|
Tag opt = select.addOption(tile.id(), tile);
|
||||||
|
if (tile == preselected) opt.attr("selected", "selected");
|
||||||
|
}
|
||||||
|
return select;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String stretchType() {
|
protected String stretchType() {
|
||||||
return t("Width");
|
return t("Width");
|
||||||
|
|||||||
Reference in New Issue
Block a user