implemented tables for locos, trains and cars
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.4</version>
|
<version>1.0.5</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,6 +16,7 @@ Add tile : Kachel hinzufügen
|
|||||||
Address\: : Adresse:
|
Address\: : Adresse:
|
||||||
Analyze : analysieren
|
Analyze : analysieren
|
||||||
Apply : Übernehmen
|
Apply : Übernehmen
|
||||||
|
Auto pilot : Autopilot
|
||||||
Availability : Verfügbarkeit
|
Availability : Verfügbarkeit
|
||||||
BlockFree : Blockbelegung
|
BlockFree : Blockbelegung
|
||||||
Block {} is free : Block {} ist frei
|
Block {} is free : Block {} ist frei
|
||||||
@@ -23,6 +24,7 @@ Block {} is occupied : Block {} ist belegt
|
|||||||
Block properties : Block-Eigenschaften
|
Block properties : Block-Eigenschaften
|
||||||
{}bound : nach {}
|
{}bound : nach {}
|
||||||
Cars\: : Waggons:
|
Cars\: : Waggons:
|
||||||
|
Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu bearbeiten.
|
||||||
ConditionalAction : bedingte Aktion
|
ConditionalAction : bedingte Aktion
|
||||||
Conditions : Bedingungen
|
Conditions : Bedingungen
|
||||||
Condition type\: : Bedingungs-Typ:
|
Condition type\: : Bedingungs-Typ:
|
||||||
@@ -34,11 +36,13 @@ click here to setup contact : Hier klicken, um Kontakt auszuwählen
|
|||||||
click here to setup relay : Hier klicken, um Relais einzurichten
|
click here to setup relay : Hier klicken, um Relais einzurichten
|
||||||
Command to send to control unit\: : Kommando, welches zur Zentrale gesendet werden soll:
|
Command to send to control unit\: : Kommando, welches zur Zentrale gesendet werden soll:
|
||||||
Create action : Aktion erzeugen
|
Create action : Aktion erzeugen
|
||||||
|
Current location : Aufenthaltsort
|
||||||
Current location\: {} : Aufenthaltsort: {}
|
Current location\: {} : Aufenthaltsort: {}
|
||||||
Delay : Verzögerung
|
Delay : Verzögerung
|
||||||
DelayedAction : verzögerte Aktion
|
DelayedAction : verzögerte Aktion
|
||||||
delete : entfernen
|
delete : entfernen
|
||||||
delete route : Route löschen
|
delete route : Route löschen
|
||||||
|
Destination : Ziel
|
||||||
Destination\: : Ziel:
|
Destination\: : Ziel:
|
||||||
Destination\: {} from {} : Ziel: {} von {}
|
Destination\: {} from {} : Ziel: {} von {}
|
||||||
Direction : Richtung
|
Direction : Richtung
|
||||||
@@ -61,6 +65,7 @@ if ({})\: : falls ({}):
|
|||||||
inverted : invertiert
|
inverted : invertiert
|
||||||
known cars : bekannte Waggons
|
known cars : bekannte Waggons
|
||||||
known locomotives : bekannte Lokomotiven
|
known locomotives : bekannte Lokomotiven
|
||||||
|
knwon trains : bekannte Züge
|
||||||
learn : lernen
|
learn : lernen
|
||||||
LEFT : links
|
LEFT : links
|
||||||
Left port\: : Port für links
|
Left port\: : Port für links
|
||||||
@@ -125,6 +130,7 @@ Signals : Signale
|
|||||||
Simulating movement of {}... : Simuliere Fahrt von {}...
|
Simulating movement of {}... : Simuliere Fahrt von {}...
|
||||||
SOUTH : Süden
|
SOUTH : Süden
|
||||||
Start actions : Start-Aktionen
|
Start actions : Start-Aktionen
|
||||||
|
Stock ID : Inventarnummer
|
||||||
Started {} : {} gestartet
|
Started {} : {} gestartet
|
||||||
StopAllTrains : Alle Züge stoppen
|
StopAllTrains : Alle Züge stoppen
|
||||||
StopAuto : Automatikmodus abschalten
|
StopAuto : Automatikmodus abschalten
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
|||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
|
|
||||||
public class Car extends BaseClass implements Comparable<Car>{
|
public class Car extends BaseClass implements Comparable<Car>{
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
||||||
@@ -102,8 +103,17 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag link(String tagClass) {
|
/**
|
||||||
return link(tagClass, Map.of(REALM,REALM_CAR,ID,id,ACTION,ACTION_PROPS), name()+(stockId.isEmpty()?"":" "+t("(id: {}, length: {})",stockId,length)));
|
* If arguments are given, the first is taken as content, the second as tag type.
|
||||||
|
* If no content is supplied, name is set as content.
|
||||||
|
* If no type is supplied, "span" is preset.
|
||||||
|
* @param args
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Tag link(String...args) {
|
||||||
|
String tx = args.length<1 ? name()+NBSP : args[0];
|
||||||
|
String type = args.length<2 ? "span" : args[1];
|
||||||
|
return link(type, Map.of(REALM,REALM_CAR,ID,id,ACTION,ACTION_PROPS), tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Vector<Car> list() {
|
static Vector<Car> list() {
|
||||||
@@ -141,11 +151,11 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
public static Object manager() {
|
public static Object manager() {
|
||||||
Window win = new Window("car-manager", t("Car manager"));
|
Window win = new Window("car-manager", t("Car manager"));
|
||||||
new Tag("h4").content(t("known cars")).addTo(win);
|
new Tag("h4").content(t("known cars")).addTo(win);
|
||||||
Tag list = new Tag("ul");
|
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||||
for (Car car : new TreeSet<Car>(cars.values())) {
|
|
||||||
if (!(car instanceof Locomotive)) car.link("li").addTo(list);
|
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Length"),t("Tags"));
|
||||||
}
|
cars.values().stream().filter(car -> !(car instanceof Locomotive)).forEach(car -> table.addRow(car.stockId,car.link(),car.length,String.join(", ", car.tags())));
|
||||||
list.addTo(win);
|
table.addTo(win);
|
||||||
|
|
||||||
Form form = new Form("add-car-form");
|
Form form = new Form("add-car-form");
|
||||||
new Input(ACTION, ACTION_ADD).hideIn(form);
|
new Input(ACTION, ACTION_ADD).hideIn(form);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package de.srsoftware.web4rail.moving;
|
package de.srsoftware.web4rail.moving;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -20,6 +20,7 @@ import de.srsoftware.web4rail.tags.Form;
|
|||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tags.Radio;
|
import de.srsoftware.web4rail.tags.Radio;
|
||||||
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
|
|
||||||
public class Locomotive extends Car implements Constants,Device{
|
public class Locomotive extends Car implements Constants,Device{
|
||||||
|
|
||||||
@@ -205,14 +206,19 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
public static Window manager() {
|
public static Window manager() {
|
||||||
Window win = new Window("loco-manager", t("Locomotive manager"));
|
Window win = new Window("loco-manager", t("Locomotive manager"));
|
||||||
new Tag("h4").content(t("known locomotives")).addTo(win);
|
new Tag("h4").content(t("known locomotives")).addTo(win);
|
||||||
Tag list = new Tag("ul");
|
|
||||||
for (Car car : new TreeSet<Car>(cars.values())) {
|
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||||
if (car instanceof Locomotive) {
|
|
||||||
Locomotive loco = (Locomotive) car;
|
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Protocol"),t("Address"),t("Length"),t("Tags"));
|
||||||
loco.link("li").addTo(list);
|
cars.values()
|
||||||
}
|
.stream()
|
||||||
}
|
.filter(car -> car instanceof Locomotive)
|
||||||
list.addTo(win);
|
.map(car -> (Locomotive)car)
|
||||||
|
.sorted(Comparator.comparing(loco -> loco.address))
|
||||||
|
.sorted(Comparator.comparing(loco -> loco.stockId))
|
||||||
|
.forEach(loco -> table.addRow(loco.stockId,loco.link(),loco.proto,loco.address,loco.length,String.join(", ", loco.tags())));
|
||||||
|
table.addTo(win);
|
||||||
|
|
||||||
|
|
||||||
Form form = new Form("add-loco-form");
|
Form form = new Form("add-loco-form");
|
||||||
new Input(ACTION, ACTION_ADD).hideIn(form);
|
new Input(ACTION, ACTION_ADD).hideIn(form);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import de.srsoftware.web4rail.tags.Form;
|
|||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tags.Label;
|
import de.srsoftware.web4rail.tags.Label;
|
||||||
import de.srsoftware.web4rail.tags.Select;
|
import de.srsoftware.web4rail.tags.Select;
|
||||||
|
import de.srsoftware.web4rail.tags.Table;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
import de.srsoftware.web4rail.tiles.Contact;
|
import de.srsoftware.web4rail.tiles.Contact;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
@@ -205,7 +206,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
for (Car car : this.cars) {
|
for (Car car : this.cars) {
|
||||||
Tag li = new Tag("li");
|
Tag li = new Tag("li");
|
||||||
car.link("span").addTo(li).content(NBSP);
|
car.link(car.name()+(car.stockId.isEmpty() ? "" : " ("+car.stockId+")")).addTo(li).content(NBSP);
|
||||||
Map<String, Object> params = Map.of(REALM,REALM_TRAIN,ID,id,ACTION,ACTION_DROP,CAR_ID,car.id());
|
Map<String, Object> params = Map.of(REALM,REALM_TRAIN,ID,id,ACTION,ACTION_DROP,CAR_ID,car.id());
|
||||||
new Button(t("delete"),params).addTo(li);
|
new Button(t("delete"),params).addTo(li);
|
||||||
li.addTo(locoList);
|
li.addTo(locoList);
|
||||||
@@ -336,8 +337,17 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag link(String tagClass) {
|
/**
|
||||||
return link(tagClass, Map.of(REALM, REALM_TRAIN,ID,id,ACTION,ACTION_PROPS),name()+NBSP);
|
* If arguments are given, the first is taken as content, the second as tag type.
|
||||||
|
* If no content is supplied, name is set as content.
|
||||||
|
* If no type is supplied, "span" is preset.
|
||||||
|
* @param args
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Tag link(String...args) {
|
||||||
|
String tx = args.length<1 ? name()+NBSP : args[0];
|
||||||
|
String type = args.length<2 ? "span" : args[1];
|
||||||
|
return link(type, Map.of(REALM,REALM_TRAIN,ID,id,ACTION,ACTION_PROPS), tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TreeSet<Train> list() {
|
public static TreeSet<Train> list() {
|
||||||
@@ -378,7 +388,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
|
|
||||||
for (Locomotive loco : this.locos) {
|
for (Locomotive loco : this.locos) {
|
||||||
Tag li = new Tag("li");
|
Tag li = new Tag("li");
|
||||||
loco.link("span").addTo(li);
|
loco.link(loco.name()+(loco.stockId.isEmpty() ? "" : " ("+loco.stockId+")")).addTo(li);
|
||||||
Map<String, Object> props = Map.of(REALM,REALM_LOCO,ID,loco.id(),ACTION,ACTION_TURN);
|
Map<String, Object> props = Map.of(REALM,REALM_LOCO,ID,loco.id(),ACTION,ACTION_TURN);
|
||||||
new Button(t("turn within train"),props).addTo(li).addTo(locoList);
|
new Button(t("turn within train"),props).addTo(li).addTo(locoList);
|
||||||
Map<String, Object> params = Map.of(REALM,REALM_TRAIN,ID,id,ACTION,ACTION_DROP,LOCO_ID,loco.id()+(loco.stockId.isEmpty()?"":" ("+loco.stockId+")"));
|
Map<String, Object> params = Map.of(REALM,REALM_TRAIN,ID,id,ACTION,ACTION_DROP,LOCO_ID,loco.id()+(loco.stockId.isEmpty()?"":" ("+loco.stockId+")"));
|
||||||
@@ -410,11 +420,21 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public static Object manager() {
|
public static Object manager() {
|
||||||
Window win = new Window("train-manager", t("Train manager"));
|
Window win = new Window("train-manager", t("Train manager"));
|
||||||
new Tag("h4").content(t("known trains")).addTo(win);
|
new Tag("h4").content(t("known trains")).addTo(win);
|
||||||
Tag list = new Tag("ul");
|
|
||||||
for (Train train : trains.values()) {
|
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||||
train.link("li").addTo(list);
|
|
||||||
}
|
Table table = new Table().addHead(t("Name"),t("Length"),t("Tags"),t("Route"),t("Current location"),t("Destination"),t("Auto pilot"));
|
||||||
list.addTo(win);
|
list().forEach(train -> table.addRow(
|
||||||
|
train.link(),
|
||||||
|
train.length(),
|
||||||
|
String.join(", ", train.tags()),
|
||||||
|
train.route,
|
||||||
|
isSet(train.currentBlock) ? train.currentBlock.link() : null,
|
||||||
|
train.destination(),
|
||||||
|
t(isSet(train.autopilot)?"On":"Off")
|
||||||
|
));
|
||||||
|
table.addTo(win);
|
||||||
|
|
||||||
|
|
||||||
Form form = new Form();
|
Form form = new Form();
|
||||||
new Input(ACTION, ACTION_ADD).hideIn(form);
|
new Input(ACTION, ACTION_ADD).hideIn(form);
|
||||||
|
|||||||
33
src/main/java/de/srsoftware/web4rail/tags/Table.java
Normal file
33
src/main/java/de/srsoftware/web4rail/tags/Table.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package de.srsoftware.web4rail.tags;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
|
public class Table extends Tag{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -5262135863426267225L;
|
||||||
|
|
||||||
|
public Table() {
|
||||||
|
super("table");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table addRow(Object...cols) {
|
||||||
|
Tag row = new Tag("tr");
|
||||||
|
for (Object column : cols) {
|
||||||
|
Tag col = null;
|
||||||
|
if (column instanceof Tag) {
|
||||||
|
Tag child = (Tag) column;
|
||||||
|
if (child.is("td") || child.is("th")) col = child;
|
||||||
|
if (col == null) col = child.addTo(new Tag("td"));
|
||||||
|
} else col = new Tag("td").content(column == null ? "" : column.toString());
|
||||||
|
col.addTo(row);
|
||||||
|
}
|
||||||
|
row.addTo(this);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Table addHead(Object...cols) {
|
||||||
|
Object[] tags = new Tag[cols.length];
|
||||||
|
for (int i=0; i<cols.length; i++) tags[i]= cols[i] instanceof Tag ? ((Tag)cols[i]).addTo(new Tag("th")) : new Tag("th").content(cols[i].toString());
|
||||||
|
return addRow(tags);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -179,6 +179,19 @@ public abstract class Block extends StretchableTile implements Comparable<Block>
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If arguments are given, the first is taken as content, the second as tag type.
|
||||||
|
* If no content is supplied, name is set as content.
|
||||||
|
* If no type is supplied, "span" is preset.
|
||||||
|
* @param args
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Tag link(String...args) {
|
||||||
|
String tx = args.length<1 ? name+NBSP : args[0];
|
||||||
|
String type = args.length<2 ? "span" : args[1];
|
||||||
|
return link(type, Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_CLICK), tx);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Tile load(JSONObject json) throws IOException {
|
protected Tile load(JSONObject json) throws IOException {
|
||||||
super.load(json);
|
super.load(json);
|
||||||
|
|||||||
@@ -146,6 +146,20 @@ public abstract class Tile extends BaseClass{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If arguments are given, the first is taken as content, the second as tag type.
|
||||||
|
* If no content is supplied, id() is set as content.
|
||||||
|
* If no type is supplied, "span" is preset.
|
||||||
|
* @param args
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Tag link(String...args) {
|
||||||
|
String tx = args.length<1 ? id()+NBSP : args[0];
|
||||||
|
String type = args.length<2 ? "span" : args[1];
|
||||||
|
return link(type, Map.of(REALM,REALM_PLAN,ID,id(),ACTION,ACTION_CLICK), tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void loadAll(String filename, Plan plan) throws IOException {
|
public static void loadAll(String filename, Plan plan) throws IOException {
|
||||||
BufferedReader file = new BufferedReader(new FileReader(filename));
|
BufferedReader file = new BufferedReader(new FileReader(filename));
|
||||||
String line = file.readLine();
|
String line = file.readLine();
|
||||||
|
|||||||
Reference in New Issue
Block a user