sorting methods
This commit is contained in:
@@ -48,35 +48,37 @@ import de.srsoftware.web4rail.tiles.Turnout.State;
|
||||
*
|
||||
*/
|
||||
public class Route extends BaseClass{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Route.class);
|
||||
static final String NAME = "name";
|
||||
static final String PATH = "path";
|
||||
static final String SIGNALS = "signals";
|
||||
static final String TURNOUTS = "turnouts";
|
||||
private Vector<Tile> path;
|
||||
private Vector<Signal> signals;
|
||||
private Vector<Contact> contacts;
|
||||
private HashMap<Turnout,Turnout.State> turnouts;
|
||||
private HashMap<String,ActionList> triggers = new HashMap<String, ActionList>();
|
||||
private int id;
|
||||
private static HashMap<Integer, String> names = new HashMap<Integer, String>(); // maps id to name. needed to keep names during plan.analyze()
|
||||
public Train train;
|
||||
private Block startBlock = null,endBlock;
|
||||
private static final String START_DIRECTION = "direction_start";
|
||||
private static final String END_DIRECTION = "direction_end";
|
||||
private Vector<Condition> conditions = new Vector<Condition>();
|
||||
private ActionList setupActions = new ActionList();
|
||||
|
||||
public Direction startDirection;
|
||||
private Direction endDirection;
|
||||
private boolean disabled = false;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Route.class);
|
||||
|
||||
private static final String TRIGGER = "trigger";
|
||||
private static final String ACTIONS = "actions";
|
||||
private static final String ACTION_LISTS = "action_lists";
|
||||
private static final String ROUTES = "routes";
|
||||
private static final String ACTIONS = "actions";
|
||||
private static final String CONDITIONS = "conditions";
|
||||
private static final String DROP_CONDITION = "drop_condition";
|
||||
private static final String END_DIRECTION = "direction_end";
|
||||
private static final String ROUTES = "routes";
|
||||
private static final String START_DIRECTION = "direction_start";
|
||||
private static final String TRIGGER = "trigger";
|
||||
static final String NAME = "name";
|
||||
static final String PATH = "path";
|
||||
static final String SIGNALS = "signals";
|
||||
static final String TURNOUTS = "turnouts";
|
||||
|
||||
private static HashMap<Integer, String> names = new HashMap<Integer, String>(); // maps id to name. needed to keep names during plan.analyze()
|
||||
|
||||
private Vector<Condition> conditions = new Vector<Condition>();
|
||||
private Vector<Contact> contacts;
|
||||
private boolean disabled = false;
|
||||
private Block endBlock = null;
|
||||
private Direction endDirection;
|
||||
private int id;
|
||||
private Vector<Tile> path;
|
||||
private Vector<Signal> signals;
|
||||
public Train train;
|
||||
private HashMap<String,ActionList> triggers = new HashMap<String, ActionList>();
|
||||
private HashMap<Turnout,Turnout.State> turnouts;
|
||||
private ActionList setupActions = new ActionList();
|
||||
private Block startBlock = null;
|
||||
public Direction startDirection;
|
||||
|
||||
/**
|
||||
* process commands from the client
|
||||
@@ -109,20 +111,6 @@ public class Route extends BaseClass{
|
||||
return t("Unknown action: {}",params.get(ACTION));
|
||||
}
|
||||
|
||||
private Object dropCodition(HashMap<String, String> params) {
|
||||
String condId = params.get(REALM_CONDITION);
|
||||
if (isSet(condId)) {
|
||||
int cid = Integer.parseInt(condId);
|
||||
for (Condition condition : conditions) {
|
||||
if (condition.id() == cid) {
|
||||
conditions.remove(condition);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return properties(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* adds a tile to the route
|
||||
* @param tile
|
||||
@@ -323,6 +311,20 @@ public class Route extends BaseClass{
|
||||
public String context() {
|
||||
return REALM_ROUTE+":"+id();
|
||||
}
|
||||
|
||||
private Object dropCodition(HashMap<String, String> params) {
|
||||
String condId = params.get(REALM_CONDITION);
|
||||
if (isSet(condId)) {
|
||||
int cid = Integer.parseInt(condId);
|
||||
for (Condition condition : conditions) {
|
||||
if (condition.id() == cid) {
|
||||
conditions.remove(condition);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return properties(params);
|
||||
}
|
||||
|
||||
public Block endBlock() {
|
||||
return endBlock;
|
||||
@@ -344,13 +346,6 @@ public class Route extends BaseClass{
|
||||
return setupActions.fire(context);
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
for (int i=1; i<path.size(); i++) {
|
||||
if (!path.get(i).isFree()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private String generateName() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i=0; i<path.size();i++) {
|
||||
@@ -371,6 +366,13 @@ public class Route extends BaseClass{
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
for (int i=1; i<path.size(); i++) {
|
||||
if (!path.get(i).isFree()) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a json representation of this route
|
||||
* @return
|
||||
|
||||
@@ -23,6 +23,11 @@ import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
|
||||
/**
|
||||
* Base Class for all other actions
|
||||
* @author Stephan Richter, SRSoftware
|
||||
*
|
||||
*/
|
||||
public abstract class Action extends BaseClass {
|
||||
private static final HashMap<Integer,Action> actions = new HashMap<Integer, Action>();
|
||||
public static final Logger LOG = LoggerFactory.getLogger(Action.class);
|
||||
@@ -115,6 +120,19 @@ public abstract class Action extends BaseClass {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Tag selector() {
|
||||
Select select = new Select(TYPE);
|
||||
TreeMap<String, String> names = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (Class<? extends Action> clazz : Action.list()) {
|
||||
String s = t(clazz.getSimpleName());
|
||||
names.put(s, clazz.getSimpleName());
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : names.entrySet()) select.addOption(entry.getValue(), entry.getKey());
|
||||
return select.addTo(new Label(t("Action type:")+NBSP));
|
||||
}
|
||||
|
||||
public Window properties(HashMap<String, String> params) {
|
||||
return new Window("action-props-"+id, t("Properties of {}",this.getClass().getSimpleName()));
|
||||
}
|
||||
@@ -131,17 +149,4 @@ public abstract class Action extends BaseClass {
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
return t("Nothing changed");
|
||||
}
|
||||
|
||||
public static Tag selector() {
|
||||
Select select = new Select(TYPE);
|
||||
TreeMap<String, String> names = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (Class<? extends Action> clazz : Action.list()) {
|
||||
String s = t(clazz.getSimpleName());
|
||||
names.put(s, clazz.getSimpleName());
|
||||
}
|
||||
|
||||
for (Entry<String, String> entry : names.entrySet()) select.addOption(entry.getValue(), entry.getKey());
|
||||
return select.addTo(new Label(t("Action type:")+NBSP));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
|
||||
public class ActionList extends Vector<Action> implements Constants{
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActionList.class);
|
||||
|
||||
private static final long serialVersionUID = 4862000041987682112L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActionList.class);
|
||||
private int id;
|
||||
private static final HashMap<Integer, ActionList> actionLists = new HashMap<Integer, ActionList>();
|
||||
private int id;
|
||||
|
||||
public ActionList() {
|
||||
id = Application.createId();
|
||||
@@ -210,4 +210,4 @@ public class ActionList extends Vector<Action> implements Constants{
|
||||
}
|
||||
return t("No action with id {} found.",actionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,15 @@ import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
|
||||
/**
|
||||
* Base class for all kinds of Blocks
|
||||
* @author Stephan Richter, SRSoftware
|
||||
*
|
||||
*/
|
||||
public abstract class Block extends StretchableTile{
|
||||
private static final String NAME = "name";
|
||||
public String name = "Block";
|
||||
|
||||
private static final String ALLOW_TURN = "allowTurn";
|
||||
private static final String NAME = "name";
|
||||
public String name = "Block";
|
||||
public boolean turnAllowed = false;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,6 +36,11 @@ import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
|
||||
/**
|
||||
* Base class for all tiles
|
||||
* @author Stephan Richter, SRSoftware
|
||||
*
|
||||
*/
|
||||
public abstract class Tile extends BaseClass{
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
private static int DEFAUT_LENGTH = 5;
|
||||
@@ -50,8 +55,6 @@ public abstract class Tile extends BaseClass{
|
||||
private static final String TYPE = "type";
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
|
||||
|
||||
|
||||
private boolean disabled = false;
|
||||
private int length = DEFAUT_LENGTH;
|
||||
@@ -64,6 +67,14 @@ public abstract class Tile extends BaseClass{
|
||||
public Integer x = null;
|
||||
public Integer y = null;
|
||||
|
||||
public void add(Route route) {
|
||||
this.routes.add(route);
|
||||
}
|
||||
|
||||
public void addShadow(Shadow shadow) {
|
||||
shadows.add(shadow);
|
||||
}
|
||||
|
||||
protected Vector<String> classes(){
|
||||
Vector<String> classes = new Vector<String>();
|
||||
classes.add("tile");
|
||||
@@ -74,14 +85,6 @@ public abstract class Tile extends BaseClass{
|
||||
return classes;
|
||||
}
|
||||
|
||||
public void add(Route route) {
|
||||
this.routes.add(route);
|
||||
}
|
||||
|
||||
public void addShadow(Shadow shadow) {
|
||||
shadows.add(shadow);
|
||||
}
|
||||
|
||||
public Object click() throws IOException {
|
||||
LOG.debug("{}.click()",getClass().getSimpleName());
|
||||
return propMenu();
|
||||
@@ -95,14 +98,10 @@ public abstract class Tile extends BaseClass{
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
return !(disabled || isSet(route) || isSet(train));
|
||||
}
|
||||
|
||||
public int height() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
public String id() {
|
||||
return Tile.id(x, y);
|
||||
}
|
||||
@@ -119,6 +118,10 @@ public abstract class Tile extends BaseClass{
|
||||
plan.set(tile.x, tile.y, tile);
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
return !(disabled || isSet(route) || isSet(train));
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put(TYPE, getClass().getSimpleName());
|
||||
@@ -274,6 +277,12 @@ public abstract class Tile extends BaseClass{
|
||||
file.close();
|
||||
}
|
||||
|
||||
public Tile set(Train newTrain) {
|
||||
if (newTrain == train) return this; // nothing to update
|
||||
this.train = newTrain;
|
||||
return plan.place(this);
|
||||
}
|
||||
|
||||
public Tile setRoute(Route lockingRoute) {
|
||||
if (route == lockingRoute) return this; // nothing changed
|
||||
if (isSet(route) && isSet(lockingRoute)) throw new IllegalStateException(this.toString()); // tile already locked by other route
|
||||
@@ -360,12 +369,6 @@ public abstract class Tile extends BaseClass{
|
||||
return train;
|
||||
}
|
||||
|
||||
public Tile set(Train newTrain) {
|
||||
if (newTrain == train) return this; // nothing to update
|
||||
this.train = newTrain;
|
||||
return plan.place(this);
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
route = null;
|
||||
train = null;
|
||||
@@ -392,4 +395,4 @@ public abstract class Tile extends BaseClass{
|
||||
public int width() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,25 +17,29 @@ import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
|
||||
/**
|
||||
* Base class for Turnouts
|
||||
* @author Stephan Richter, SRSoftware
|
||||
*
|
||||
*/
|
||||
public abstract class Turnout extends Tile implements Device{
|
||||
public static final String STATE = "state";
|
||||
private static final String PORT_A = "port_a";
|
||||
private static final String PORT_B = "port_b";
|
||||
private static final String PORT_A = "port_a";
|
||||
private static final String PORT_B = "port_b";
|
||||
public static final String STATE = "state";
|
||||
protected static final String STRAIGHT = "straight";
|
||||
|
||||
private Protocol protocol = Protocol.DCC128;
|
||||
protected int address = 0;
|
||||
protected int portA = 0, portB = 1;
|
||||
protected int delay = 400;
|
||||
protected boolean initialized = false;
|
||||
protected boolean error = false;
|
||||
protected int address = 0;
|
||||
protected int delay = 400;
|
||||
protected boolean error = false;
|
||||
protected boolean initialized = false;
|
||||
private Protocol protocol = Protocol.DCC128;
|
||||
protected int portA = 0, portB = 1;
|
||||
protected State state = State.STRAIGHT;
|
||||
|
||||
public enum State{
|
||||
LEFT,STRAIGHT,RIGHT,UNDEF;
|
||||
}
|
||||
|
||||
protected State state = State.STRAIGHT;
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
LOG.debug(getClass().getSimpleName()+".click()");
|
||||
@@ -197,4 +201,4 @@ public abstract class Turnout extends Tile implements Device{
|
||||
if (params.containsKey(PORT_B)) portB = Integer.parseInt(params.get(PORT_B));
|
||||
return super.update(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user