more refactoring

This commit is contained in:
Stephan Richter
2020-12-03 16:04:21 +01:00
parent 5aa66099fe
commit 4180d72d43
20 changed files with 156 additions and 177 deletions

View File

@@ -30,7 +30,7 @@ import de.srsoftware.web4rail.tags.Select;
* @author Stephan Richter, SRSoftware
*
*/
public abstract class Block extends StretchableTile implements Comparable<Block>{
public abstract class Block extends StretchableTile{
private static final String ALLOW_TURN = "allowTurn";
private static final String NAME = "name";
private static final String NO_TAG = "[default]";
@@ -127,7 +127,6 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
return super.click();
}
@Override
public int compareTo(Block other) {
return name.compareTo(other.name);
}

View File

@@ -20,8 +20,10 @@ public class Shadow extends Tile{
return super.connections(from);
}
public Shadow(Tile overlay) {
public Shadow(Tile overlay, int x, int y) {
this.overlay = overlay;
this.x = x;
this.y = y;
overlay.addShadow(this);
}

View File

@@ -9,7 +9,7 @@ import java.util.Vector;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Plan.Direction;
public abstract class Signal extends Tile implements Comparable<Signal>{
public abstract class Signal extends Tile {
public static final String STATE = "state";
public static final String STOP = "stop";
public static final String GO = "go";
@@ -29,13 +29,6 @@ public abstract class Signal extends Tile implements Comparable<Signal>{
return classes;
}
@Override
public int compareTo(Signal other) {
Id tid = this.id();
Id oid = other.id();
return tid.compareTo(oid);
}
public abstract boolean isAffectedFrom(Direction dir);
public boolean state(String state) {

View File

@@ -7,7 +7,6 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -37,7 +36,7 @@ import de.srsoftware.web4rail.tags.Radio;
* @author Stephan Richter, SRSoftware
*
*/
public abstract class Tile extends BaseClass{
public abstract class Tile extends BaseClass implements Comparable<Tile>{
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
private static int DEFAUT_LENGTH = 100; // 10cm
@@ -57,7 +56,7 @@ public abstract class Tile extends BaseClass{
protected Direction oneWay = null;
protected Route route = null;
private TreeSet<Route> routes = new TreeSet<>();
protected HashSet<Shadow> shadows = new HashSet<>();
protected TreeSet<Shadow> shadows = new TreeSet<>();
protected Train train = null;
public Integer x = null;
public Integer y = null;
@@ -85,6 +84,12 @@ public abstract class Tile extends BaseClass{
return properties();
}
@Override
public int compareTo(Tile other) {
if (x == other.x) return y-other.y;
return x - other.x;
}
public JSONObject config() {
return new JSONObject();
}
@@ -207,14 +212,14 @@ public abstract class Tile extends BaseClass{
} else fieldset = new Fieldset(t("Train"));
train.link("span", t("Train")+":"+NBSP+train+NBSP).addTo(fieldset);
if (isSet(train.route)) {
train.button(t("stop"), contextAction(ACTION_STOP)).addTo(fieldset);
train.button(t("stop"), Map.of(ACTION,ACTION_STOP)).addTo(fieldset);
} else {
train.button(t("start"), contextAction(ACTION_START)).addTo(fieldset);
train.button(t("start"), Map.of(ACTION,ACTION_START)).addTo(fieldset);
}
if (train.usesAutopilot()) {
train.button(t("quit autopilot"), contextAction(ACTION_QUIT)).addTo(fieldset);
train.button(t("quit autopilot"), Map.of(ACTION,ACTION_QUIT)).addTo(fieldset);
} else {
train.button(t("auto"), contextAction(ACTION_AUTO)).addTo(fieldset);
train.button(t("auto"), Map.of(ACTION,ACTION_AUTO)).addTo(fieldset);
}
}
@@ -241,7 +246,7 @@ public abstract class Tile extends BaseClass{
Tag routeList = new Tag("ol");
for (Route route : routes) {
Tag li = route.link("span", route.name()+(route.isDisabled()?" ["+t("disabled")+"]" : "")+NBSP).addTo(new Tag("li").clazz("link"));
route.button(t("delete route"),contextAction(ACTION_DROP)).addTo(li);
route.button(t("delete route"),Map.of(ACTION,ACTION_DROP)).addTo(li);
li.addTo(routeList);
}
routeList.addTo(fieldset);
@@ -376,12 +381,8 @@ public abstract class Tile extends BaseClass{
@Override
public BaseClass remove() {
super.remove();
routes.forEach(route -> {
route.remove();
});
shadows.forEach(shadow -> {
shadow.remove();
});
while (!routes.isEmpty()) routes.first().remove();
while (!shadows.isEmpty()) shadows.first().remove();
return this;
}