implemented methods to add cars to train.
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>0.9.11</version>
|
<version>0.9.12</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>
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ Destination\: {} from {} : Ziel: {} von {}
|
|||||||
Emergency : Notfall
|
Emergency : Notfall
|
||||||
FinishRoute : Route abschließen
|
FinishRoute : Route abschließen
|
||||||
FreeStartBlock : Start-Block freigeben
|
FreeStartBlock : Start-Block freigeben
|
||||||
|
Help : Hilfe
|
||||||
inverted : invertiert
|
inverted : invertiert
|
||||||
length\: : Länge:
|
length\: : Länge:
|
||||||
Maximum train length\: : maximale Zug-Länge
|
Maximum train length\: : maximale Zug-Länge
|
||||||
|
Move tiles : Kacheln verschieben
|
||||||
name\: : Name:
|
name\: : Name:
|
||||||
Origin and destination : Start und Ziel
|
Origin and destination : Start und Ziel
|
||||||
Origin\: {} to {} : Start: {} nach {}
|
Origin\: {} to {} : Start: {} nach {}
|
||||||
@@ -44,6 +46,7 @@ train does not have tag "{}" : Zug hat keine Markierung „{}“
|
|||||||
train has tag "{}" : Zug hat Markierung „{}“
|
train has tag "{}" : Zug hat Markierung „{}“
|
||||||
train is longer than {} : Zug ist länger als {}
|
train is longer than {} : Zug ist länger als {}
|
||||||
train is shorter than {} : Zug ist kürzer als {}
|
train is shorter than {} : Zug ist kürzer als {}
|
||||||
|
Trains : Züge
|
||||||
Trains\: : Züge:
|
Trains\: : Züge:
|
||||||
TrainHasTag : Zug mit Tag
|
TrainHasTag : Zug mit Tag
|
||||||
TrainLength : Zuglänge
|
TrainLength : Zuglänge
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class Application implements Constants{
|
|||||||
case REALM_ACTIONS:
|
case REALM_ACTIONS:
|
||||||
return ActionList.process(params,plan);
|
return ActionList.process(params,plan);
|
||||||
case REALM_CAR:
|
case REALM_CAR:
|
||||||
return Car.action(params);
|
return Car.action(params,plan);
|
||||||
case REALM_CONTACT:
|
case REALM_CONTACT:
|
||||||
return Contact.process(params);
|
return Contact.process(params);
|
||||||
case REALM_CONDITION:
|
case REALM_CONDITION:
|
||||||
|
|||||||
@@ -794,6 +794,7 @@ public class Plan implements Constants{
|
|||||||
Tag tiles = new Tag("div").clazz("list").content("");
|
Tag tiles = new Tag("div").clazz("list").content("");
|
||||||
new Div(ACTION_PROPS).clazz(REALM_TRAIN).content(t("Manage trains")).addTo(tiles);
|
new Div(ACTION_PROPS).clazz(REALM_TRAIN).content(t("Manage trains")).addTo(tiles);
|
||||||
new Div(ACTION_PROPS).clazz(REALM_LOCO).content(t("Manage locos")).addTo(tiles);
|
new Div(ACTION_PROPS).clazz(REALM_LOCO).content(t("Manage locos")).addTo(tiles);
|
||||||
|
new Div(ACTION_PROPS).clazz(REALM_CAR).content(t("Manage cars")).addTo(tiles);
|
||||||
return tiles.addTo(tileMenu);
|
return tiles.addTo(tileMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -60,19 +61,44 @@ public class Car implements Constants {
|
|||||||
cars.put(id, this);
|
cars.put(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object action(HashMap<String, String> params) throws IOException {
|
public static Object action(HashMap<String, String> params,Plan plan) throws IOException {
|
||||||
Car car = Car.get(params.get(Car.ID));
|
String id = params.get(ID);
|
||||||
if (car == null) return t("No car with id {} found!",params.get(Car.ID));
|
Car car = id == null ? null : Car.get(id);
|
||||||
|
|
||||||
switch (params.get(ACTION)) {
|
switch (params.get(ACTION)) {
|
||||||
|
case ACTION_ADD:
|
||||||
|
return new Car(params.get(Car.NAME)).plan(plan);
|
||||||
|
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return car.properties();
|
return car == null ? Car.manager() : car.properties();
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
return car.update(params);
|
return car.update(params);
|
||||||
}
|
}
|
||||||
if (car instanceof Locomotive) return Locomotive.action(params);
|
if (car instanceof Locomotive) return Locomotive.action(params,plan);
|
||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object manager() {
|
||||||
|
Window win = new Window("car-manager", t("Car manager"));
|
||||||
|
new Tag("h4").content(t("known cars")).addTo(win);
|
||||||
|
Tag list = new Tag("ul");
|
||||||
|
for (Car car : cars.values()) {
|
||||||
|
if (!(car instanceof Locomotive)) {
|
||||||
|
car.link("li").addTo(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.addTo(win);
|
||||||
|
|
||||||
|
Form form = new Form();
|
||||||
|
new Input(ACTION, ACTION_ADD).hideIn(form);
|
||||||
|
new Input(REALM,REALM_CAR).hideIn(form);
|
||||||
|
Fieldset fieldset = new Fieldset(t("add new car"));
|
||||||
|
new Input(Locomotive.NAME, t("new car")).addTo(new Label(t("Name:")+" ")).addTo(fieldset);
|
||||||
|
new Button(t("Apply")).addTo(fieldset);
|
||||||
|
fieldset.addTo(form).addTo(win);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
protected Tag cockpit() {
|
protected Tag cockpit() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -106,6 +132,14 @@ public class Car implements Constants {
|
|||||||
return new Tag(tagClass).clazz("link").attr("onclick","car("+id+",'"+ACTION_PROPS+"')").content(name());
|
return new Tag(tagClass).clazz("link").attr("onclick","car("+id+",'"+ACTION_PROPS+"')").content(name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Vector<Car> list() {
|
||||||
|
Vector<Car> cars = new Vector<Car>();
|
||||||
|
for (Car car : Car.cars.values()) {
|
||||||
|
if (!(car instanceof Locomotive)) cars.add(car);
|
||||||
|
}
|
||||||
|
return cars;
|
||||||
|
}
|
||||||
|
|
||||||
public static void loadAll(String filename, Plan plan) throws IOException {
|
public static void loadAll(String filename, Plan plan) throws IOException {
|
||||||
cars.clear();
|
cars.clear();
|
||||||
BufferedReader file = new BufferedReader(new FileReader(filename));
|
BufferedReader file = new BufferedReader(new FileReader(filename));
|
||||||
@@ -194,7 +228,7 @@ public class Car implements Constants {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getClass().getSimpleName()+"("+name()+")";
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void train(Train train) {
|
public void train(Train train) {
|
||||||
|
|||||||
@@ -177,8 +177,8 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector<Locomotive> list() {
|
static Vector<Car> list() {
|
||||||
Vector<Locomotive> locos = new Vector<Locomotive>();
|
Vector<Car> locos = new Vector<Car>();
|
||||||
for (Car car : Car.cars.values()) {
|
for (Car car : Car.cars.values()) {
|
||||||
if (car instanceof Locomotive) locos.add((Locomotive) car);
|
if (car instanceof Locomotive) locos.add((Locomotive) car);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,28 @@ public class Train implements Comparable<Train>,Constants {
|
|||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tag carList() {
|
||||||
|
Tag locoProp = new Tag("li").content(t("Cars:"));
|
||||||
|
Tag locoList = new Tag("ul").clazz("carlist");
|
||||||
|
|
||||||
|
for (Car car : this.cars) car.link("li").addTo(locoList);
|
||||||
|
|
||||||
|
Tag addCarForm = new Form().content(t("add car:")+" ");
|
||||||
|
new Input(REALM, REALM_TRAIN).hideIn(addCarForm);
|
||||||
|
new Input(ACTION, ACTION_ADD).hideIn(addCarForm);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
if (!select.children().isEmpty()) {
|
||||||
|
select.addTo(addCarForm);
|
||||||
|
new Button(t("add")).addTo(addCarForm);
|
||||||
|
addCarForm.addTo(new Tag("li")).addTo(locoList);
|
||||||
|
}
|
||||||
|
return locoList.addTo(locoProp);
|
||||||
|
}
|
||||||
|
|
||||||
private static Object create(HashMap<String, String> params, Plan plan) {
|
private static Object create(HashMap<String, String> params, Plan plan) {
|
||||||
Locomotive loco = (Locomotive) Locomotive.get(params.get(Train.LOCO_ID));
|
Locomotive loco = (Locomotive) Locomotive.get(params.get(Train.LOCO_ID));
|
||||||
if (loco == null) return t("unknown locomotive: {}",params.get(ID));
|
if (loco == null) return t("unknown locomotive: {}",params.get(ID));
|
||||||
@@ -273,7 +295,7 @@ public class Train implements Comparable<Train>,Constants {
|
|||||||
new Input(ACTION, ACTION_ADD).hideIn(addLocoForm);
|
new Input(ACTION, ACTION_ADD).hideIn(addLocoForm);
|
||||||
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 (Locomotive loco : Locomotive.list()) {
|
for (Car loco : Locomotive.list()) {
|
||||||
if (!this.locos.contains(loco)) select.addOption(loco.id(), loco);
|
if (!this.locos.contains(loco)) select.addOption(loco.id(), loco);
|
||||||
}
|
}
|
||||||
if (!select.children().isEmpty()) {
|
if (!select.children().isEmpty()) {
|
||||||
@@ -300,7 +322,7 @@ public class Train implements Comparable<Train>,Constants {
|
|||||||
new Input(Train.NAME, t("new train")).addTo(new Label(t("Name:")+" ")).addTo(fieldset);
|
new Input(Train.NAME, t("new train")).addTo(new Label(t("Name:")+" ")).addTo(fieldset);
|
||||||
|
|
||||||
Select select = new Select(LOCO_ID);
|
Select select = new Select(LOCO_ID);
|
||||||
for (Locomotive loco : Locomotive.list()) select.addOption(loco.id(),loco.name());
|
for (Car loco : Locomotive.list()) select.addOption(loco.id(),loco.name());
|
||||||
select.addTo(new Label(t("Locomotive:")+" ")).addTo(fieldset);
|
select.addTo(new Label(t("Locomotive:")+" ")).addTo(fieldset);
|
||||||
|
|
||||||
new Button(t("Apply")).addTo(fieldset);
|
new Button(t("Apply")).addTo(fieldset);
|
||||||
@@ -354,6 +376,8 @@ public class Train implements Comparable<Train>,Constants {
|
|||||||
Tag propList = new Tag("ul").clazz("proplist");
|
Tag propList = new Tag("ul").clazz("proplist");
|
||||||
|
|
||||||
locoList().addTo(propList);
|
locoList().addTo(propList);
|
||||||
|
carList().addTo(propList);
|
||||||
|
new Tag("li").content(t("length: {}",length())).addTo(propList);
|
||||||
|
|
||||||
if (block != null) {
|
if (block != null) {
|
||||||
new Tag("li").content(t("Current location: {}",block)).addTo(propList);
|
new Tag("li").content(t("Current location: {}",block)).addTo(propList);
|
||||||
|
|||||||
Reference in New Issue
Block a user