implemented action-based startup of routes
This commit is contained in:
@@ -6,7 +6,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONArray;
|
||||
@@ -291,11 +290,7 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
||||
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);
|
||||
TreeSet<Block> blocks = new TreeSet<Block>();
|
||||
for (Tile tile : plan.tiles.values()) {
|
||||
if (tile instanceof Block) blocks.add((Block) tile);
|
||||
}
|
||||
for (Block block : blocks) {
|
||||
for (Block block : plan.blocks()) {
|
||||
if (exclude.contains(block)) continue;
|
||||
Tag opt = select.addOption(block.id(), block);
|
||||
if (block == preselected) opt.attr("selected", "selected");
|
||||
|
||||
@@ -24,25 +24,59 @@ public class Contact extends Tile{
|
||||
private static final String ADDRESS = "address";
|
||||
private static final HashMap<String, Contact> contactsById = new HashMap<String, Contact>();
|
||||
private static final HashMap<Integer, Contact> contactsByAddr = new HashMap<Integer, Contact>();
|
||||
private boolean active = false;
|
||||
private boolean state = false;
|
||||
private String trigger = null;
|
||||
private int addr = 0;
|
||||
private ActionList actions = new ActionList();
|
||||
private OffTimer timer = null;
|
||||
|
||||
public void activate(boolean active) {
|
||||
this.active = active;
|
||||
if (active) {
|
||||
/**
|
||||
* Dieser Timer dient dazu, Merhfachauslösungen eines Kontakes innerhalb einer Sekunde zu unterbinden
|
||||
*
|
||||
*/
|
||||
private class OffTimer extends Thread {
|
||||
|
||||
boolean aborted = false;
|
||||
|
||||
public OffTimer() {
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
for (int ticks = 0; ticks<10; ticks++) {
|
||||
if (!aborted) sleep(100);
|
||||
}
|
||||
timer = null;
|
||||
if (aborted) return;
|
||||
state = false;
|
||||
stream();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
private void abort() {
|
||||
aborted = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void activate(boolean newState) {
|
||||
if (newState == state) return;
|
||||
|
||||
if (newState == false) {
|
||||
if (isSet(timer)) return;
|
||||
timer = new OffTimer();
|
||||
} else {
|
||||
LOG.debug("{} activated.",this);
|
||||
state = true;
|
||||
if (isSet(timer)) timer.abort();
|
||||
if (isSet(route)) {
|
||||
route.contact(this);
|
||||
} else if (getClass() != Contact.class) {
|
||||
plan.warn(this);
|
||||
}
|
||||
actions.fire(new Context(this));
|
||||
}
|
||||
try {
|
||||
stream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,10 +179,14 @@ public class Contact extends Tile{
|
||||
return select;
|
||||
}
|
||||
|
||||
public void stream() throws IOException {
|
||||
Tag tag = super.tag(null);
|
||||
if (active) tag.clazz(tag.get("class")+" active");
|
||||
plan.stream("place "+tag);
|
||||
public void stream() {
|
||||
try {
|
||||
Tag tag = super.tag(null);
|
||||
if (state) tag.clazz(tag.get("class")+" active");
|
||||
plan.stream("place "+tag);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Plan.Direction;
|
||||
|
||||
public abstract class Signal extends Tile{
|
||||
|
||||
public abstract class Signal extends Tile implements Comparable<Signal>{
|
||||
public static final String STATE = "state";
|
||||
public static final String STOP = "stop";
|
||||
public static final String GO = "go";
|
||||
|
||||
public static final TreeSet<String> knownStates = new TreeSet<String>(List.of(STOP, GO));
|
||||
|
||||
private String state = STOP;
|
||||
|
||||
public Signal() {
|
||||
@@ -24,15 +29,18 @@ public abstract class Signal extends Tile{
|
||||
return classes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Signal other) {
|
||||
String tid = this.id();
|
||||
String oid = other.id();
|
||||
return tid.compareTo(oid);
|
||||
}
|
||||
|
||||
public abstract boolean isAffectedFrom(Direction dir);
|
||||
|
||||
public boolean state(String state) {
|
||||
this.state = state;
|
||||
try {
|
||||
plan.stream("place "+tag(null));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
plan.place(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user