added new action DisableEnableBlock
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.3.17</version>
|
||||
<version>1.3.18</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -44,6 +44,7 @@ Back : zurück
|
||||
backward : rückwärts
|
||||
Basic properties : Grundlegende Eigenschaften
|
||||
BlockFree : Blockbelegung
|
||||
block from context : Block aus Kontext
|
||||
Block {} is free : Block {} ist frei
|
||||
Block {} is occupied : Block {} ist belegt
|
||||
Block properties : Block-Eigenschaften
|
||||
@@ -99,9 +100,11 @@ DetermineTrainInBlock : Zug im Block bestimmen
|
||||
Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
||||
Direction : Richtung
|
||||
Direction\: heading {} : Richtung: nach {}
|
||||
disable : deaktivieren
|
||||
disabled : deaktiviert
|
||||
disable {} : {} deaktivieren
|
||||
disabled routes : deaktivierte Fahrstraßen
|
||||
DisableEnableBlock : Block (de)aktivieren
|
||||
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
||||
Drop : Verwerfen
|
||||
Dropped destination of {}. : Ziel von {} verworfen.
|
||||
@@ -112,6 +115,7 @@ editable train properties : veränderliche Zug-Eigenschaften
|
||||
Edit json : JSON bearbeiten
|
||||
Effect : Effekt
|
||||
Emergency : Notfall
|
||||
enable : aktivieren
|
||||
enable {} : {} aktivieren
|
||||
Engage {} : {} aktivieren
|
||||
EngageDecoupler : Entkuppler aktivieren
|
||||
|
||||
@@ -65,6 +65,7 @@ public interface Constants {
|
||||
public static final String PORT = "port";
|
||||
public static final String RELAY = "relay";
|
||||
public static final String ROUTE = "route";
|
||||
public static final String STATE = "state";
|
||||
public static final String TURNOUT = "turnout";
|
||||
public static final String TYPE = "type";
|
||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
@@ -48,6 +48,7 @@ public abstract class Action extends BaseClass {
|
||||
ConditionalAction.class,
|
||||
DelayedAction.class,
|
||||
DetermineTrainInBlock.class,
|
||||
DisableEnableBlock.class,
|
||||
EngageDecoupler.class,
|
||||
FinishRoute.class,
|
||||
Loop.class,
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ActionList extends Action implements Iterable<Action>{
|
||||
if (isNull(type)) return actionTypeForm();
|
||||
Action action = Action.create(type,this);
|
||||
if (action instanceof Action) {
|
||||
prepend(action);
|
||||
add(action);
|
||||
return context().properties();
|
||||
}
|
||||
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
|
||||
public String toString() {
|
||||
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
|
||||
|
||||
@@ -297,10 +297,12 @@ public abstract class Block extends StretchableTile{
|
||||
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>();
|
||||
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);
|
||||
Collections.sort(blocks, (b1,b2) -> b1.name.compareTo(b2.name));
|
||||
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){
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
public int height() {
|
||||
return 1;
|
||||
}
|
||||
@@ -477,6 +477,11 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
||||
plan.place(this);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean newState) {
|
||||
disabled = !newState;
|
||||
plan.place(this);
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
route = null;
|
||||
train = null;
|
||||
|
||||
Reference in New Issue
Block a user