overhauled actions
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.10</version>
|
<version>1.0.11</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>
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ svg .block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
svg circle{
|
svg circle{
|
||||||
fill: gray;
|
fill: #d3d7cf;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu{
|
.menu{
|
||||||
@@ -223,7 +223,7 @@ svg.straight .right{
|
|||||||
}
|
}
|
||||||
|
|
||||||
.active circle{
|
.active circle{
|
||||||
fill: #ffcc88;
|
fill: #f57900;
|
||||||
}
|
}
|
||||||
|
|
||||||
polygon.oneway{
|
polygon.oneway{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ Actions : Aktionen
|
|||||||
Actions\: : Aktionen:
|
Actions\: : Aktionen:
|
||||||
Actions and contacts : Aktionen und Kontakte
|
Actions and contacts : Aktionen und Kontakte
|
||||||
Action type\: : Aktions-Typ
|
Action type\: : Aktions-Typ
|
||||||
|
Actions will only fire, if all conditions are fullfilled. : Aktionen werden nur ausgeführt, wenn alle Bedingungen erfüllt sind.
|
||||||
ActivateRoute : Route aktivieren
|
ActivateRoute : Route aktivieren
|
||||||
add : hinzufügen
|
add : hinzufügen
|
||||||
Added {} : {} hinzugefügt
|
Added {} : {} hinzugefügt
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -107,7 +106,7 @@ public abstract class Action extends BaseClass {
|
|||||||
return this.toString().equals(other.toString());
|
return this.toString().equals(other.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean fire(Context context) throws IOException;
|
public abstract boolean fire(Context context);
|
||||||
|
|
||||||
public static Action get(int actionId) {
|
public static Action get(int actionId) {
|
||||||
return actions.get(actionId);
|
return actions.get(actionId);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -145,16 +144,10 @@ public class ActionList extends Vector<Action> implements Constants{
|
|||||||
|
|
||||||
public boolean fire(Context context) {
|
public boolean fire(Context context) {
|
||||||
if (!isEmpty()) LOG.debug(t("Firing {}"),this);
|
if (!isEmpty()) LOG.debug(t("Firing {}"),this);
|
||||||
boolean success = true;
|
|
||||||
for (Action action : this) {
|
for (Action action : this) {
|
||||||
try {
|
if (!action.fire(context)) return false;
|
||||||
success &= action.fire(context);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.warn("Action did not fire properly: {}",action,e);
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return success;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int id() {
|
public int id() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
@@ -36,7 +35,7 @@ public class ConditionalAction extends Action {
|
|||||||
private StringBuffer conditions() {
|
private StringBuffer conditions() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (int i = 0; i<conditions.size(); i++) {
|
for (int i = 0; i<conditions.size(); i++) {
|
||||||
if (i>0) sb.append(t(" or "));
|
if (i>0) sb.append(t(" and "));
|
||||||
sb.append(conditions.get(i).toString());
|
sb.append(conditions.get(i).toString());
|
||||||
}
|
}
|
||||||
return sb;
|
return sb;
|
||||||
@@ -45,6 +44,7 @@ public class ConditionalAction extends Action {
|
|||||||
private Tag conditionForm(HashMap<String, String> params) {
|
private Tag conditionForm(HashMap<String, String> params) {
|
||||||
Fieldset fieldset = new Fieldset(t("Conditions"));
|
Fieldset fieldset = new Fieldset(t("Conditions"));
|
||||||
|
|
||||||
|
new Tag("p").content(t("Actions will only fire, if all conditions are fullfilled.")).addTo(fieldset);
|
||||||
if (!conditions.isEmpty()) {
|
if (!conditions.isEmpty()) {
|
||||||
Tag list = new Tag("ul");
|
Tag list = new Tag("ul");
|
||||||
for (Condition condition : conditions) {
|
for (Condition condition : conditions) {
|
||||||
@@ -68,11 +68,11 @@ public class ConditionalAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
for (Condition condition : conditions) {
|
for (Condition condition : conditions) {
|
||||||
if (condition.fulfilledBy(context)) return actions.fire(context);
|
if (!condition.fulfilledBy(context)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return actions.fire(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -50,7 +49,7 @@ public class DelayedAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -18,7 +17,7 @@ public class DetermineTrainInBlock extends Action {
|
|||||||
private Block block = null;
|
private Block block = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
context.block = block;
|
context.block = block;
|
||||||
context.train = block.train();
|
context.train = block.train();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import de.srsoftware.web4rail.Route;
|
import de.srsoftware.web4rail.Route;
|
||||||
|
|
||||||
public class FinishRoute extends Action {
|
public class FinishRoute extends Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
Route route = context.route;
|
Route route = context.route;
|
||||||
if (isSet(route)) route.finish();
|
if (isSet(route)) route.finish();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -21,12 +20,10 @@ public class SetRelay extends Action {
|
|||||||
private boolean state = false;
|
private boolean state = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
if (relay != null) {
|
if (isNull(relay)) return false;
|
||||||
relay.state(state);
|
relay.state(state);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -22,7 +21,7 @@ public class SetSignal extends Action {
|
|||||||
private String state = Signal.STOP;
|
private String state = Signal.STOP;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
if (isNull(signal)) return false;
|
if (isNull(signal)) return false;
|
||||||
return signal.state(state);
|
return signal.state(state);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
|
|
||||||
public class StopAllTrains extends Action {
|
public class StopAllTrains extends Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
Train.list().forEach(train -> train.stopNow());
|
Train.list().forEach(train -> train.stopNow());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class StopAuto extends Action {
|
public class StopAuto extends Action {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
if (context.train != null) {
|
if (isNull(context.train)) return false;
|
||||||
context.train.quitAutopilot();
|
context.train.quitAutopilot();
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.srsoftware.web4rail.actions;
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -18,7 +17,7 @@ public class TriggerContact extends Action {
|
|||||||
private Contact contact = null;
|
private Contact contact = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean fire(Context context) throws IOException {
|
public boolean fire(Context context) {
|
||||||
if (isSet(contact)) return contact.trigger(200);
|
if (isSet(contact)) return contact.trigger(200);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ public class Contact extends Tile{
|
|||||||
return trigger;
|
return trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean trigger(int duration) throws IOException {
|
public boolean trigger(int duration) {
|
||||||
activate(true);
|
activate(true);
|
||||||
new Thread() {
|
new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class Relay extends Tile implements Device{
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Reply state(boolean newState) throws IOException {
|
public Reply state(boolean newState) {
|
||||||
Reply reply = init();
|
Reply reply = init();
|
||||||
if (reply != null && !reply.succeeded()) return reply;
|
if (reply != null && !reply.succeeded()) return reply;
|
||||||
LOG.debug("Setting {} to {}",this,newState);
|
LOG.debug("Setting {} to {}",this,newState);
|
||||||
@@ -196,9 +196,7 @@ public class Relay extends Tile implements Device{
|
|||||||
} catch (TimeoutException e) {
|
} catch (TimeoutException e) {
|
||||||
LOG.warn(e.getMessage());
|
LOG.warn(e.getMessage());
|
||||||
}
|
}
|
||||||
return new Reply(417,t("Timeout while trying to switch {}.",this));
|
return new Reply(417,t("Timeout while trying to switch {}.",this));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void success() {
|
public void success() {
|
||||||
|
|||||||
Reference in New Issue
Block a user