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