sorting methods
This commit is contained in:
@@ -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