improved car management
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.0.9</version>
|
<version>1.0.10</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>
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Car get(Object id) {
|
public static Car get(Object id) {
|
||||||
return cars.get(Integer.parseInt(""+id)); // try to get by 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() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Train train() {
|
||||||
|
return train;
|
||||||
|
}
|
||||||
|
|
||||||
public void train(Train train) {
|
public void train(Train train) {
|
||||||
this.train = train;
|
this.train = train;
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
|
|
||||||
public Object faster(int steps) {
|
public Object faster(int steps) {
|
||||||
return setSpeed(speed + steps);
|
setSpeed(speed + steps);
|
||||||
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Locomotive get(Object id) {
|
public static Locomotive get(Object id) {
|
||||||
@@ -286,7 +287,7 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
|
|
||||||
public Object stop() {
|
public Object stop() {
|
||||||
setSpeed(0);
|
setSpeed(0);
|
||||||
return t("Stopped {}",this);
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object toggleFunction(int f) {
|
private Object toggleFunction(int f) {
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
if (car instanceof Locomotive) {
|
if (car instanceof Locomotive) {
|
||||||
locos.add((Locomotive) car);
|
locos.add((Locomotive) car);
|
||||||
} else cars.add(car);
|
} else cars.add(car);
|
||||||
|
car.train(this);
|
||||||
return props();
|
return props();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +224,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
new Input(ID,id).hideIn(addCarForm);
|
new Input(ID,id).hideIn(addCarForm);
|
||||||
Select select = new Select(CAR_ID);
|
Select select = new Select(CAR_ID);
|
||||||
for (Car car : Car.list()) {
|
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()) {
|
if (!select.children().isEmpty()) {
|
||||||
select.addTo(addCarForm);
|
select.addTo(addCarForm);
|
||||||
@@ -283,10 +284,16 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Object dropCar(HashMap<String, String> params) {
|
private Object dropCar(HashMap<String, String> params) {
|
||||||
String carId = params.get(CAR_ID);
|
Car car = Car.get(params.get(CAR_ID));
|
||||||
if (isSet(carId)) cars.remove(Car.get(carId));
|
if (isSet(car)) {
|
||||||
String locoId = params.get(LOCO_ID);
|
cars.remove(car);
|
||||||
if (isSet(locoId)) locos.remove(Car.get(locoId));
|
car.train(null);
|
||||||
|
}
|
||||||
|
Locomotive loco = Locomotive.get(params.get(LOCO_ID));
|
||||||
|
if (isSet(loco)) {
|
||||||
|
locos.remove(loco);
|
||||||
|
loco.train(null);
|
||||||
|
}
|
||||||
return props();
|
return props();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +418,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
new Input(ID,id).hideIn(addLocoForm);
|
new Input(ID,id).hideIn(addLocoForm);
|
||||||
Select select = new Select(CAR_ID);
|
Select select = new Select(CAR_ID);
|
||||||
for (Car loco : Locomotive.list()) {
|
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()) {
|
if (!select.children().isEmpty()) {
|
||||||
select.addTo(addLocoForm);
|
select.addTo(addLocoForm);
|
||||||
|
|||||||
Reference in New Issue
Block a user