added new action DisableEnableBlock
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.17</version>
|
<version>1.3.18</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>
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ Back : zurück
|
|||||||
backward : rückwärts
|
backward : rückwärts
|
||||||
Basic properties : Grundlegende Eigenschaften
|
Basic properties : Grundlegende Eigenschaften
|
||||||
BlockFree : Blockbelegung
|
BlockFree : Blockbelegung
|
||||||
|
block from context : Block aus Kontext
|
||||||
Block {} is free : Block {} ist frei
|
Block {} is free : Block {} ist frei
|
||||||
Block {} is occupied : Block {} ist belegt
|
Block {} is occupied : Block {} ist belegt
|
||||||
Block properties : Block-Eigenschaften
|
Block properties : Block-Eigenschaften
|
||||||
@@ -99,9 +100,11 @@ DetermineTrainInBlock : Zug im Block bestimmen
|
|||||||
Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
||||||
Direction : Richtung
|
Direction : Richtung
|
||||||
Direction\: heading {} : Richtung: nach {}
|
Direction\: heading {} : Richtung: nach {}
|
||||||
|
disable : deaktivieren
|
||||||
disabled : deaktiviert
|
disabled : deaktiviert
|
||||||
disable {} : {} deaktivieren
|
disable {} : {} deaktivieren
|
||||||
disabled routes : deaktivierte Fahrstraßen
|
disabled routes : deaktivierte Fahrstraßen
|
||||||
|
DisableEnableBlock : Block (de)aktivieren
|
||||||
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
||||||
Drop : Verwerfen
|
Drop : Verwerfen
|
||||||
Dropped destination of {}. : Ziel von {} verworfen.
|
Dropped destination of {}. : Ziel von {} verworfen.
|
||||||
@@ -112,6 +115,7 @@ editable train properties : veränderliche Zug-Eigenschaften
|
|||||||
Edit json : JSON bearbeiten
|
Edit json : JSON bearbeiten
|
||||||
Effect : Effekt
|
Effect : Effekt
|
||||||
Emergency : Notfall
|
Emergency : Notfall
|
||||||
|
enable : aktivieren
|
||||||
enable {} : {} aktivieren
|
enable {} : {} aktivieren
|
||||||
Engage {} : {} aktivieren
|
Engage {} : {} aktivieren
|
||||||
EngageDecoupler : Entkuppler aktivieren
|
EngageDecoupler : Entkuppler aktivieren
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public interface Constants {
|
|||||||
public static final String PORT = "port";
|
public static final String PORT = "port";
|
||||||
public static final String RELAY = "relay";
|
public static final String RELAY = "relay";
|
||||||
public static final String ROUTE = "route";
|
public static final String ROUTE = "route";
|
||||||
|
public static final String STATE = "state";
|
||||||
public static final String TURNOUT = "turnout";
|
public static final String TURNOUT = "turnout";
|
||||||
public static final String TYPE = "type";
|
public static final String TYPE = "type";
|
||||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public abstract class Action extends BaseClass {
|
|||||||
ConditionalAction.class,
|
ConditionalAction.class,
|
||||||
DelayedAction.class,
|
DelayedAction.class,
|
||||||
DetermineTrainInBlock.class,
|
DetermineTrainInBlock.class,
|
||||||
|
DisableEnableBlock.class,
|
||||||
EngageDecoupler.class,
|
EngageDecoupler.class,
|
||||||
FinishRoute.class,
|
FinishRoute.class,
|
||||||
Loop.class,
|
Loop.class,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
if (isNull(type)) return actionTypeForm();
|
if (isNull(type)) return actionTypeForm();
|
||||||
Action action = Action.create(type,this);
|
Action action = Action.create(type,this);
|
||||||
if (action instanceof Action) {
|
if (action instanceof Action) {
|
||||||
prepend(action);
|
add(action);
|
||||||
return context().properties();
|
return context().properties();
|
||||||
}
|
}
|
||||||
return new Tag("span").content(t("Unknown action type: {}",type)).addTo(actionTypeForm());
|
return new Tag("span").content(t("Unknown action type: {}",type)).addTo(actionTypeForm());
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Application;
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tags.Radio;
|
||||||
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
|
|
||||||
|
public class DisableEnableBlock extends Action {
|
||||||
|
|
||||||
|
public DisableEnableBlock(BaseClass parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Block block = null;
|
||||||
|
private boolean disable = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
if (isNull(block)) block = context.block();
|
||||||
|
if (isNull(block)) return false;
|
||||||
|
block.setEnabled(!disable);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
if (isSet(block)) json.put(BLOCK, block.id());
|
||||||
|
json.put(STATE, !disable);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
Id blockId = Id.from(json,BLOCK);
|
||||||
|
if (isSet(blockId)) {
|
||||||
|
block = Block.get(blockId);
|
||||||
|
if (isNull(block)) {
|
||||||
|
Application.threadPool.execute(new Thread() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
block = Block.get(blockId);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (json.has(STATE)) {
|
||||||
|
disable = !json.getBoolean(STATE);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
formInputs.add(t("Select block"),Block.selector(isSet(block) ? block : t("block from context"), null));
|
||||||
|
Tag radios = new Tag("p");
|
||||||
|
new Radio(STATE, "enable", t("enable"), !disable).addTo(radios);
|
||||||
|
new Radio(STATE, "disable", t("disable"), disable).addTo(radios);
|
||||||
|
formInputs.add(t("Action"),radios);
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void removeChild(BaseClass child) {
|
||||||
|
if (child == block) block = null;
|
||||||
|
super.removeChild(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
String blk = isSet(block) ? block.toString() : t("block from context");
|
||||||
|
return t(disable ? "disable {}" : "enable {}",blk);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
LOG.debug("update: {}",params);
|
||||||
|
Id blockId = Id.from(params,Block.class.getSimpleName());
|
||||||
|
if (isSet(blockId)) block = Block.get(blockId);
|
||||||
|
disable = !"enable".equals(params.get(STATE));
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,7 +47,7 @@ public class CarInTrain extends Condition {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (isNull(car)) return "["+t("Click here to select car!")+"]";
|
if (isNull(car)) return "["+t("Click here to select car!")+"]";
|
||||||
return t(inverted ? "train does not contain {}" : "train cotains {}",car) ;
|
return t(inverted ? "train does not contain {}" : "train contains {}",car) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -297,10 +297,12 @@ public abstract class Block extends StretchableTile{
|
|||||||
internalContacts.remove(blockContact);
|
internalContacts.remove(blockContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Select selector(Block preselected,Collection<Block> exclude) {
|
public static Select selector(Object preset,Collection<Block> exclude) {
|
||||||
|
Block preselected = preset instanceof Block ? (Block) preset : null;
|
||||||
|
String firstEntry = preset instanceof String ? (String) preset : t("unset");
|
||||||
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(firstEntry).addTo(select);
|
||||||
List<Block> blocks = BaseClass.listElements(Block.class);
|
List<Block> blocks = BaseClass.listElements(Block.class);
|
||||||
Collections.sort(blocks, (b1,b2) -> b1.name.compareTo(b2.name));
|
Collections.sort(blocks, (b1,b2) -> b1.name.compareTo(b2.name));
|
||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
|||||||
public Map<Connector,Turnout.State> connections(Direction from){
|
public Map<Connector,Turnout.State> connections(Direction from){
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int height() {
|
public int height() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -477,6 +477,11 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
|||||||
plan.place(this);
|
plan.place(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean newState) {
|
||||||
|
disabled = !newState;
|
||||||
|
plan.place(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void unlock() {
|
public void unlock() {
|
||||||
route = null;
|
route = null;
|
||||||
train = null;
|
train = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user