improved car management
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.0.9</version>
|
||||
<version>1.0.10</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -80,8 +80,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
return t("Unknown action: {}",params.get(ACTION));
|
||||
}
|
||||
|
||||
public static Car get(Object id) {
|
||||
return cars.get(Integer.parseInt(""+id)); // try to get by id
|
||||
public static Car get(Object id) {
|
||||
return isNull(id) ? null : cars.get(Integer.parseInt(""+id)); // try to get by id
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,10 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Train train() {
|
||||
return train;
|
||||
}
|
||||
|
||||
public void train(Train train) {
|
||||
this.train = train;
|
||||
|
||||
@@ -127,7 +127,8 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
|
||||
|
||||
public Object faster(int steps) {
|
||||
return setSpeed(speed + steps);
|
||||
setSpeed(speed + steps);
|
||||
return properties();
|
||||
}
|
||||
|
||||
public static Locomotive get(Object id) {
|
||||
@@ -286,7 +287,7 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
|
||||
public Object stop() {
|
||||
setSpeed(0);
|
||||
return t("Stopped {}",this);
|
||||
return properties();
|
||||
}
|
||||
|
||||
private Object toggleFunction(int f) {
|
||||
|
||||
@@ -185,6 +185,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
if (car instanceof Locomotive) {
|
||||
locos.add((Locomotive) car);
|
||||
} else cars.add(car);
|
||||
car.train(this);
|
||||
return props();
|
||||
}
|
||||
|
||||
@@ -223,7 +224,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
new Input(ID,id).hideIn(addCarForm);
|
||||
Select select = new Select(CAR_ID);
|
||||
for (Car car : Car.list()) {
|
||||
if (!this.cars.contains(car)) select.addOption(car.id(), car+(car.stockId.isEmpty()?"":" ("+car.stockId+")"));
|
||||
if (isNull(car.train())) select.addOption(car.id(), car+(car.stockId.isEmpty()?"":" ("+car.stockId+")"));
|
||||
}
|
||||
if (!select.children().isEmpty()) {
|
||||
select.addTo(addCarForm);
|
||||
@@ -283,10 +284,16 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
}
|
||||
|
||||
private Object dropCar(HashMap<String, String> params) {
|
||||
String carId = params.get(CAR_ID);
|
||||
if (isSet(carId)) cars.remove(Car.get(carId));
|
||||
String locoId = params.get(LOCO_ID);
|
||||
if (isSet(locoId)) locos.remove(Car.get(locoId));
|
||||
Car car = Car.get(params.get(CAR_ID));
|
||||
if (isSet(car)) {
|
||||
cars.remove(car);
|
||||
car.train(null);
|
||||
}
|
||||
Locomotive loco = Locomotive.get(params.get(LOCO_ID));
|
||||
if (isSet(loco)) {
|
||||
locos.remove(loco);
|
||||
loco.train(null);
|
||||
}
|
||||
return props();
|
||||
}
|
||||
|
||||
@@ -411,7 +418,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
new Input(ID,id).hideIn(addLocoForm);
|
||||
Select select = new Select(CAR_ID);
|
||||
for (Car loco : Locomotive.list()) {
|
||||
if (!this.locos.contains(loco)) select.addOption(loco.id(), loco);
|
||||
if (isNull(loco.train())) select.addOption(loco.id(), loco);
|
||||
}
|
||||
if (!select.children().isEmpty()) {
|
||||
select.addTo(addLocoForm);
|
||||
|
||||
Reference in New Issue
Block a user