altered Action "DisableEnableBlock":
this action now is able to disable/enable any tile
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.5.6</version>
|
<version>1.5.7</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>
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ disable : deaktivieren
|
|||||||
disabled : deaktiviert
|
disabled : deaktiviert
|
||||||
disable {} : {} deaktivieren
|
disable {} : {} deaktivieren
|
||||||
disabled routes : deaktivierte Fahrstraßen
|
disabled routes : deaktivierte Fahrstraßen
|
||||||
DisableEnableBlock : Block (de)aktivieren
|
DisableEnableTile : Kachel (de)aktivieren
|
||||||
dismount : ausbauen
|
dismount : ausbauen
|
||||||
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
Display "{}" on {}. : „{}“ auf {} anzeigen.
|
||||||
Do you know, what you are doing? : Weißt du, was du da tust?
|
Do you know, what you are doing? : Weißt du, was du da tust?
|
||||||
|
|||||||
@@ -910,20 +910,22 @@ public class Plan extends BaseClass{
|
|||||||
|
|
||||||
public void sensor(int addr, boolean active) {
|
public void sensor(int addr, boolean active) {
|
||||||
Contact contact = Contact.get(addr);
|
Contact contact = Contact.get(addr);
|
||||||
if (active && isSet(learningContact)) {
|
if (active && isSet(learningContact)) learnContact(addr,contact);
|
||||||
if (isSet(contact)) {
|
|
||||||
contact.addr(0);
|
|
||||||
LOG.debug("unsibscribed {} from {}",contact,addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
stream(learningContact.addr(addr).properties().toString());
|
|
||||||
LOG.debug("learned: {} = {}",addr,learningContact);
|
|
||||||
learningContact = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isSet(contact)) contact.activate(active);
|
if (isSet(contact)) contact.activate(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void learnContact(int addr, Contact contact) {
|
||||||
|
if (isSet(contact)) {
|
||||||
|
contact.addr(0);
|
||||||
|
LOG.debug("unsibscribed {} from {}",contact,addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream(learningContact.addr(addr).properties().toString());
|
||||||
|
LOG.debug("learned: {} = {}",addr,learningContact);
|
||||||
|
learningContact = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAppConfig(Configuration config) {
|
public void setAppConfig(Configuration config) {
|
||||||
appConfig = config;
|
appConfig = config;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public abstract class Action extends BaseClass {
|
|||||||
CoupleTrain.class,
|
CoupleTrain.class,
|
||||||
DelayedAction.class,
|
DelayedAction.class,
|
||||||
DetermineTrainInBlock.class,
|
DetermineTrainInBlock.class,
|
||||||
DisableEnableBlock.class,
|
DisableEnableTile.class,
|
||||||
EngageDecoupler.class,
|
EngageDecoupler.class,
|
||||||
FinishRoute.class,
|
FinishRoute.class,
|
||||||
Loop.class,
|
Loop.class,
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case "AddDestination":
|
case "AddDestination":
|
||||||
return AddRemoveDestination.class.getSimpleName();
|
return AddRemoveDestination.class.getSimpleName();
|
||||||
|
case "DisableEnableBlock":
|
||||||
|
return DisableEnableTile.class.getSimpleName();
|
||||||
default:
|
default:
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,34 +16,34 @@ import de.srsoftware.web4rail.tiles.Block;
|
|||||||
import de.srsoftware.web4rail.tiles.Shadow;
|
import de.srsoftware.web4rail.tiles.Shadow;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
public class DisableEnableBlock extends Action {
|
public class DisableEnableTile extends Action {
|
||||||
|
|
||||||
public DisableEnableBlock(BaseClass parent) {
|
public DisableEnableTile(BaseClass parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Block block = null;
|
private Tile tile = null;
|
||||||
private boolean disable = true;
|
private boolean disable = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) {
|
public boolean fire(Context context) {
|
||||||
if (isNull(block)) block = context.block();
|
if (isNull(tile)) tile = context.block();
|
||||||
if (isNull(block)) return false;
|
if (isNull(tile)) return false;
|
||||||
block.setEnabled(!disable);
|
tile.setEnabled(!disable);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
JSONObject json = super.json();
|
JSONObject json = super.json();
|
||||||
if (isSet(block)) json.put(BLOCK, block.id());
|
if (isSet(tile)) json.put(BLOCK, tile.id());
|
||||||
json.put(STATE, !disable);
|
json.put(STATE, !disable);
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String highlightId() {
|
protected String highlightId() {
|
||||||
return isSet(block) ? block.id().toString() : null;
|
return isSet(tile) ? tile.id().toString() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ public class DisableEnableBlock extends Action {
|
|||||||
if (json.has(BLOCK)) new LoadCallback() {
|
if (json.has(BLOCK)) new LoadCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void afterLoad() {
|
public void afterLoad() {
|
||||||
block = Block.get(Id.from(json,BLOCK));
|
tile = Block.get(Id.from(json,BLOCK));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return super.load(json);
|
return super.load(json);
|
||||||
@@ -62,7 +62,7 @@ public class DisableEnableBlock extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
||||||
formInputs.add(t("Block")+": "+(isNull(block) ? t("block from context") : block),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,Block.class.getSimpleName())));
|
formInputs.add(t("Block")+": "+(isNull(tile) ? t("tile from context") : tile),button(t("Select from plan"),Map.of(ACTION,ACTION_UPDATE,ASSIGN,Tile.class.getSimpleName())));
|
||||||
Tag radios = new Tag("p");
|
Tag radios = new Tag("p");
|
||||||
new Radio(STATE, "enable", t("enable"), !disable).addTo(radios);
|
new Radio(STATE, "enable", t("enable"), !disable).addTo(radios);
|
||||||
new Radio(STATE, "disable", t("disable"), disable).addTo(radios);
|
new Radio(STATE, "disable", t("disable"), disable).addTo(radios);
|
||||||
@@ -72,22 +72,22 @@ public class DisableEnableBlock extends Action {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void removeChild(BaseClass child) {
|
protected void removeChild(BaseClass child) {
|
||||||
if (child == block) block = null;
|
if (child == tile) tile = null;
|
||||||
super.removeChild(child);
|
super.removeChild(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String blk = isSet(block) ? block.toString() : t("block from context");
|
String blk = isSet(tile) ? tile.toString() : t("block from context");
|
||||||
return t(disable ? "disable {}" : "enable {}",blk);
|
return t(disable ? "disable {}" : "enable {}",blk);
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object update(Params params) {
|
protected Object update(Params params) {
|
||||||
LOG.debug("update: {}",params);
|
LOG.debug("update: {}",params);
|
||||||
Id blockId = Id.from(params,Block.class.getSimpleName());
|
Id tileId = Id.from(params,Tile.class.getSimpleName());
|
||||||
Tile tile = isSet(blockId) ? BaseClass.get(blockId) : null;
|
Tile newTile = BaseClass.get(tileId);;
|
||||||
if (tile instanceof Shadow) tile = ((Shadow)tile).overlay();
|
if (newTile instanceof Shadow) newTile = ((Shadow)newTile).overlay();
|
||||||
if (tile instanceof Block) block = (Block) tile;
|
if (isSet(newTile)) tile = newTile;
|
||||||
disable = !"enable".equals(params.get(STATE));
|
disable = !"enable".equals(params.get(STATE));
|
||||||
return properties();
|
return properties();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user