GUI improvements
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.5.24</version>
|
<version>1.5.25</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -310,6 +310,7 @@ function runAction(ev){
|
|||||||
|
|
||||||
function stream(ev){
|
function stream(ev){
|
||||||
var data = ev.data;
|
var data = ev.data;
|
||||||
|
data = data.replace(/%newline%/g,"\n");
|
||||||
console.log("received: ",data);
|
console.log("received: ",data);
|
||||||
if (data.startsWith('<svg')) return place(data);
|
if (data.startsWith('<svg')) return place(data);
|
||||||
if (data.startsWith("heartbeat")) return heartbeat(data);
|
if (data.startsWith("heartbeat")) return heartbeat(data);
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ Swap order : Reihenfolge umkehren
|
|||||||
Swap order of trains : Reihenfolge der Züge tauschen
|
Swap order of trains : Reihenfolge der Züge tauschen
|
||||||
Switch : Schalter
|
Switch : Schalter
|
||||||
SwitchFunction : Funktion schalten
|
SwitchFunction : Funktion schalten
|
||||||
SwitchIsOn : Schalter is an
|
SwitchIsOn : Schalter ist an
|
||||||
Switch power off : Strom ausschalten
|
Switch power off : Strom ausschalten
|
||||||
Switch power on : Strom anschalten
|
Switch power on : Strom anschalten
|
||||||
SYSTEM : Betriebssystem
|
SYSTEM : Betriebssystem
|
||||||
|
|||||||
@@ -976,7 +976,7 @@ public class Plan extends BaseClass{
|
|||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
public synchronized void stream(String data) {
|
public synchronized void stream(String data) {
|
||||||
String fixedData = data.replaceAll("\n", "").replaceAll("\r", "");
|
String fixedData = data.replaceAll("\n", "%newline%").replaceAll("\r", "");
|
||||||
new Thread("Plan") {
|
new Thread("Plan") {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
public void coupleWith(Train parkingTrain,boolean swap) {
|
public void coupleWith(Train parkingTrain,boolean swap) {
|
||||||
if (isSet(direction) && isSet(parkingTrain.direction) && parkingTrain.direction != direction) parkingTrain.turn();
|
if (isSet(direction) && isSet(parkingTrain.direction) && parkingTrain.direction != direction) parkingTrain.turn();
|
||||||
|
boolean locoOnly = !cars.stream().anyMatch(car -> !(car instanceof Locomotive));
|
||||||
if (swap) {
|
if (swap) {
|
||||||
Vector<Car> dummy = new Vector<Car>();
|
Vector<Car> dummy = new Vector<Car>();
|
||||||
for (Car car : parkingTrain.cars) dummy.add(car.train(this));
|
for (Car car : parkingTrain.cars) dummy.add(car.train(this));
|
||||||
@@ -329,9 +330,9 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
cars.add(car.train(this));
|
cars.add(car.train(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (locoOnly && isSet(parkingTrain.name)) name = parkingTrain.name;
|
||||||
parkingTrain.remove();
|
parkingTrain.remove();
|
||||||
updateEnds();
|
updateEnds();
|
||||||
if (isSet(currentBlock)) currentBlock.setTrain(this);
|
if (isSet(currentBlock)) currentBlock.setTrain(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,6 +412,10 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public Direction direction() {
|
public Direction direction() {
|
||||||
return direction;
|
return direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disableShunting() {
|
||||||
|
shunting = false;
|
||||||
|
}
|
||||||
|
|
||||||
private Object dropCar(Params params) {
|
private Object dropCar(Params params) {
|
||||||
String carId = params.getString(CAR_ID);
|
String carId = params.getString(CAR_ID);
|
||||||
@@ -457,7 +462,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
direction = endedRoute.endDirection; // muss vor der Auswertung des Destination-Tags stehen!
|
direction = endedRoute.endDirection; // muss vor der Auswertung des Destination-Tags stehen!
|
||||||
Block endBlock = endedRoute.endBlock();
|
Block endBlock = endedRoute.endBlock();
|
||||||
Block startBlock = endedRoute.startBlock();
|
Block startBlock = endedRoute.startBlock();
|
||||||
if (endBlock == destination) {
|
boolean resetDest = endBlock == destination;
|
||||||
|
if (resetDest){
|
||||||
destination = null;
|
destination = null;
|
||||||
|
|
||||||
String destTag = destinationTag();
|
String destTag = destinationTag();
|
||||||
@@ -507,7 +513,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if ((!autopilot) || isNull(nextPreparedRoute) || (isSet(waitTime) && waitTime > 0)) setSpeed(0);
|
if ((!autopilot) || isNull(nextPreparedRoute) || (isSet(waitTime) && waitTime > 0)) setSpeed(0);
|
||||||
route = null;
|
route = null;
|
||||||
endBlock.setTrain(this);
|
endBlock.setTrain(this);
|
||||||
shunting = false; // wird in setTrain verwendet, muss also danach stehen
|
shunting = false; // is used in endBlock.setTrain(…), this it must be set thereafter
|
||||||
|
if (resetDest) destination = null; // destination is called during endBlock.setTrain(…)
|
||||||
currentBlock = endBlock;
|
currentBlock = endBlock;
|
||||||
trace.add(endBlock);
|
trace.add(endBlock);
|
||||||
if (!trace.contains(startBlock)) startBlock.dropTrain(this);
|
if (!trace.contains(startBlock)) startBlock.dropTrain(this);
|
||||||
@@ -724,13 +731,27 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
|
|
||||||
public String name() {
|
public String name() {
|
||||||
if (isSet(name)) return name;
|
if (isSet(name) && !name.isEmpty()) return name;
|
||||||
if (cars.isEmpty()) return t("emtpy train");
|
if (cars.isEmpty()) return t("emtpy train");
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
String lastName = null;
|
||||||
|
int count = 0;
|
||||||
for (Car car : cars) {
|
for (Car car : cars) {
|
||||||
String name = car.name();
|
String carName = car.name();
|
||||||
if (isSet(name)) return name;
|
if (isNull(carName)) continue;
|
||||||
|
if (carName.equals(lastName)) {
|
||||||
|
count++;
|
||||||
|
} else {
|
||||||
|
if (count>1) sb.append("x").append(count);
|
||||||
|
count = 1;
|
||||||
|
lastName = carName;
|
||||||
|
sb.append(", ").append(carName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return t("empty train");
|
if (count>1) sb.append("x").append(count);
|
||||||
|
if (sb.length()>2) sb.delete(0, 2);
|
||||||
|
return sb.toString();
|
||||||
|
//return t("empty train");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Train name(String newName) {
|
private Train name(String newName) {
|
||||||
@@ -955,17 +976,13 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public boolean splitAfter(int position) {
|
public boolean splitAfter(int position) {
|
||||||
if (isNull(currentBlock)) return false; // can only split within blocks!
|
if (isNull(currentBlock)) return false; // can only split within blocks!
|
||||||
Train remaining = new Train();
|
Train remaining = new Train();
|
||||||
|
remaining.name = name;
|
||||||
int len = cars.size();
|
int len = cars.size();
|
||||||
for (int i=0; i<len; i++) {
|
for (int i=0; i<len; i++) {
|
||||||
if (i>=position) {
|
if (i>=position) {
|
||||||
Car car = cars.remove(position);
|
Car car = cars.remove(position);
|
||||||
LOG.debug("Moving {} from {} to {}",car,this,remaining);
|
LOG.debug("Moving {} from {} to {}",car,this,remaining);
|
||||||
remaining.add(car);
|
remaining.add(car);
|
||||||
if (isNull(remaining.name)) {
|
|
||||||
remaining.name = car.name();
|
|
||||||
} else if (remaining.name.length()+car.name().length()<30){
|
|
||||||
remaining.name += ", "+car.name();
|
|
||||||
}
|
|
||||||
} else LOG.debug("Skipping {}",cars.get(i));
|
} else LOG.debug("Skipping {}",cars.get(i));
|
||||||
}
|
}
|
||||||
if (remaining.cars.isEmpty()) return false;
|
if (remaining.cars.isEmpty()) return false;
|
||||||
@@ -1159,23 +1176,23 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
for (Tile tile : reversedPath) {
|
for (Tile tile : reversedPath) {
|
||||||
if (isNull(remainingLength) && onTrace(tile)) remainingLength = length();
|
if (isNull(remainingLength) && onTrace(tile)) remainingLength = length();
|
||||||
if (remainingLength == null) { // ahead of train
|
if (remainingLength == null) { // ahead of train
|
||||||
LOG.debug("{} is ahead of train and will not be touched.",tile);
|
//LOG.debug("{} is ahead of train and will not be touched.",tile);
|
||||||
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
|
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
|
||||||
} else if (remainingLength > 0) { // within train
|
} else if (remainingLength > 0) { // within train
|
||||||
LOG.debug("{} is occupied by train and will be marked as \"occupied\"",tile);
|
//LOG.debug("{} is occupied by train and will be marked as \"occupied\"",tile);
|
||||||
remainingLength -= tile.length();
|
remainingLength -= tile.length();
|
||||||
newTrace.add(tile);
|
newTrace.add(tile);
|
||||||
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
|
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
|
||||||
tile.setTrain(this);
|
tile.setTrain(this);
|
||||||
LOG.debug("remaining length: {}",remainingLength);
|
//LOG.debug("remaining length: {}",remainingLength);
|
||||||
} else { // behind train
|
} else { // behind train
|
||||||
if (Route.freeBehindTrain) {
|
if (Route.freeBehindTrain) {
|
||||||
LOG.debug("{} is behind train and will be freed in the next step",tile);
|
//LOG.debug("{} is behind train and will be freed in the next step",tile);
|
||||||
if (tile != route.endBlock()) { // if train is shorter than contact after endblock, the endblock would be cleared…
|
if (tile != route.endBlock()) { // if train is shorter than contact after endblock, the endblock would be cleared…
|
||||||
trace.add(tile); // old trace will be cleared afterwards
|
trace.add(tile); // old trace will be cleared afterwards
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("{} is behind train and will be reset to \"locked\" state",tile);
|
//LOG.debug("{} is behind train and will be reset to \"locked\" state",tile);
|
||||||
tile.lockFor(context,true);
|
tile.lockFor(context,true);
|
||||||
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
|
trace.remove(tile); // old trace will be cleared afterwards. but this tile shall not be cleared, so remove it from old trace
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -468,7 +468,7 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
|
|||||||
if (isSet(reservingTrain) && newTrain != reservingTrain) return false;
|
if (isSet(reservingTrain) && newTrain != reservingTrain) return false;
|
||||||
if (isSet(lockingTrain) && newTrain != lockingTrain) return false;
|
if (isSet(lockingTrain) && newTrain != lockingTrain) return false;
|
||||||
if (isSet(occupyingTrain) && (newTrain != occupyingTrain) && !newTrain.isShunting()) return false;
|
if (isSet(occupyingTrain) && (newTrain != occupyingTrain) && !newTrain.isShunting()) return false;
|
||||||
reservingTrain = lockingTrain = null;
|
lockingTrain = reservingTrain = null;
|
||||||
if (occupyingTrain == newTrain) return true;
|
if (occupyingTrain == newTrain) return true;
|
||||||
occupyingTrain = newTrain;
|
occupyingTrain = newTrain;
|
||||||
plan.place(this);
|
plan.place(this);
|
||||||
@@ -539,12 +539,9 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
|
|||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(y);
|
sb.append(y);
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
if (isSet(occupyingTrain)) {
|
if (isSet(occupyingTrain))
|
||||||
sb.append("\n");
|
sb.append(title(occupyingTrain));
|
||||||
sb.append(occupyingTrain);
|
|
||||||
sb.append(":\n");
|
|
||||||
occupyingTrain.cars().forEach(car -> sb.append("\t"+car+"\n"));
|
|
||||||
}
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,8 +552,11 @@ public abstract class Tile extends BaseClass implements Comparable<Tile> {
|
|||||||
sb.append(train.length());
|
sb.append(train.length());
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
sb.append(t(lengthUnit));
|
sb.append(t(lengthUnit));
|
||||||
sb.append("):\n");
|
sb.append(")");
|
||||||
train.cars().forEach(car -> sb.append("\t"+car+"\n"));
|
Block dest = train.destination();
|
||||||
|
if (isSet(dest)) sb.append(" → ").append(dest);
|
||||||
|
sb.append(":\n");
|
||||||
|
train.cars().forEach(car -> sb.append("\t- ").append(car).append("\n"));
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user