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:
Stephan Richter
2020-11-19 19:07:23 +01:00
parent 6f5b2f677c
commit 9ea3d7a65b
14 changed files with 266 additions and 16 deletions

View File

@@ -304,7 +304,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
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>();
Select select = new Select(Block.class.getSimpleName());
new Tag("option").attr("value","0").content(t("unset")).addTo(select);

View File

@@ -204,7 +204,7 @@ public class Contact extends Tile{
return trigger;
}
public void trigger(int duration) throws IOException {
public boolean trigger(int duration) throws IOException {
activate(true);
new Thread() {
public void run() {
@@ -214,6 +214,7 @@ public class Contact extends Tile{
} catch (Exception e) {}
}
}.start();
return true;
}
@Override
public Tile update(HashMap<String, String> params) throws IOException {

View 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;
}
}

View File

@@ -58,6 +58,7 @@ public abstract class Tile extends BaseClass{
private static final String Y = "y";
private boolean disabled = false;
private boolean isTrack = true;
private int length = DEFAUT_LENGTH;
protected Direction oneWay = null;
protected Route route = null;
@@ -142,7 +143,7 @@ public abstract class Tile extends BaseClass{
}
public Tile length(int newLength) {
length = newLength;
length = Math.max(0, newLength);
return this;
}
@@ -187,6 +188,10 @@ public abstract class Tile extends BaseClass{
if (json.has(ONEW_WAY)) oneWay = Direction.valueOf(json.getString(ONEW_WAY));
return this;
}
protected void noTrack() {
isTrack = false;
}
public Tile position(int x, int y) {
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);
Form form = propForm("tile-properties-"+id());
new Tag("h4").content(t("Length")).addTo(form);
new Input(LENGTH,length).numeric().addTo(new Label(t("Length")+":"+NBSP)).addTo(form);
new Tag("h4").content(t("Availability")).addTo(form);
Checkbox cb = new Checkbox(DISABLED, t("disabled"), disabled);
if (disabled) cb.clazz("disabled");
cb.addTo(form);
if (isTrack) {
new Tag("h4").content(t("Length")).addTo(form);
new Input(LENGTH,length).numeric().addTo(new Label(t("Length")+":"+NBSP)).addTo(form);
new Tag("h4").content(t("Availability")).addTo(form);
Checkbox cb = new Checkbox(DISABLED, t("disabled"), disabled);
if (disabled) cb.clazz("disabled");
cb.addTo(form);
}
new Button(t("Apply"),form).addTo(form);
form.addTo(window);