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>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.0.4</version>
|
||||
<version>1.0.5</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -16,6 +16,7 @@ Add tile : Kachel hinzufügen
|
||||
Address\: : Adresse:
|
||||
Analyze : analysieren
|
||||
Apply : Übernehmen
|
||||
Auto pilot : Autopilot
|
||||
Availability : Verfügbarkeit
|
||||
BlockFree : Blockbelegung
|
||||
Block {} is free : Block {} ist frei
|
||||
@@ -23,6 +24,7 @@ Block {} is occupied : Block {} ist belegt
|
||||
Block properties : Block-Eigenschaften
|
||||
{}bound : nach {}
|
||||
Cars\: : Waggons:
|
||||
Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu bearbeiten.
|
||||
ConditionalAction : bedingte Aktion
|
||||
Conditions : Bedingungen
|
||||
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
|
||||
Command to send to control unit\: : Kommando, welches zur Zentrale gesendet werden soll:
|
||||
Create action : Aktion erzeugen
|
||||
Current location : Aufenthaltsort
|
||||
Current location\: {} : Aufenthaltsort: {}
|
||||
Delay : Verzögerung
|
||||
DelayedAction : verzögerte Aktion
|
||||
delete : entfernen
|
||||
delete route : Route löschen
|
||||
Destination : Ziel
|
||||
Destination\: : Ziel:
|
||||
Destination\: {} from {} : Ziel: {} von {}
|
||||
Direction : Richtung
|
||||
@@ -61,6 +65,7 @@ if ({})\: : falls ({}):
|
||||
inverted : invertiert
|
||||
known cars : bekannte Waggons
|
||||
known locomotives : bekannte Lokomotiven
|
||||
knwon trains : bekannte Züge
|
||||
learn : lernen
|
||||
LEFT : links
|
||||
Left port\: : Port für links
|
||||
@@ -125,6 +130,7 @@ Signals : Signale
|
||||
Simulating movement of {}... : Simuliere Fahrt von {}...
|
||||
SOUTH : Süden
|
||||
Start actions : Start-Aktionen
|
||||
Stock ID : Inventarnummer
|
||||
Started {} : {} gestartet
|
||||
StopAllTrains : Alle Züge stoppen
|
||||
StopAuto : Automatikmodus abschalten
|
||||
|
||||
@@ -27,6 +27,7 @@ import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Table;
|
||||
|
||||
public class Car extends BaseClass implements Comparable<Car>{
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
||||
@@ -102,8 +103,17 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
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() {
|
||||
@@ -141,11 +151,11 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
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 : new TreeSet<Car>(cars.values())) {
|
||||
if (!(car instanceof Locomotive)) car.link("li").addTo(list);
|
||||
}
|
||||
list.addTo(win);
|
||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||
|
||||
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())));
|
||||
table.addTo(win);
|
||||
|
||||
Form form = new Form("add-car-form");
|
||||
new Input(ACTION, ACTION_ADD).hideIn(form);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package de.srsoftware.web4rail.moving;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Vector;
|
||||
|
||||
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.Label;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
import de.srsoftware.web4rail.tags.Table;
|
||||
|
||||
public class Locomotive extends Car implements Constants,Device{
|
||||
|
||||
@@ -205,14 +206,19 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
public static Window manager() {
|
||||
Window win = new Window("loco-manager", t("Locomotive manager"));
|
||||
new Tag("h4").content(t("known locomotives")).addTo(win);
|
||||
Tag list = new Tag("ul");
|
||||
for (Car car : new TreeSet<Car>(cars.values())) {
|
||||
if (car instanceof Locomotive) {
|
||||
Locomotive loco = (Locomotive) car;
|
||||
loco.link("li").addTo(list);
|
||||
}
|
||||
}
|
||||
list.addTo(win);
|
||||
|
||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||
|
||||
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Protocol"),t("Address"),t("Length"),t("Tags"));
|
||||
cars.values()
|
||||
.stream()
|
||||
.filter(car -> car instanceof Locomotive)
|
||||
.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");
|
||||
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.Label;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tags.Table;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
import de.srsoftware.web4rail.tiles.Contact;
|
||||
import de.srsoftware.web4rail.tiles.Tile;
|
||||
@@ -205,7 +206,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
for (Car car : this.cars) {
|
||||
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());
|
||||
new Button(t("delete"),params).addTo(li);
|
||||
li.addTo(locoList);
|
||||
@@ -336,8 +337,17 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
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() {
|
||||
@@ -378,7 +388,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
for (Locomotive loco : this.locos) {
|
||||
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);
|
||||
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+")"));
|
||||
@@ -410,11 +420,21 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
public static Object manager() {
|
||||
Window win = new Window("train-manager", t("Train manager"));
|
||||
new Tag("h4").content(t("known trains")).addTo(win);
|
||||
Tag list = new Tag("ul");
|
||||
for (Train train : trains.values()) {
|
||||
train.link("li").addTo(list);
|
||||
}
|
||||
list.addTo(win);
|
||||
|
||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||
|
||||
Table table = new Table().addHead(t("Name"),t("Length"),t("Tags"),t("Route"),t("Current location"),t("Destination"),t("Auto pilot"));
|
||||
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();
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
protected Tile load(JSONObject json) throws IOException {
|
||||
super.load(json);
|
||||
|
||||
@@ -146,6 +146,20 @@ public abstract class Tile extends BaseClass{
|
||||
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 {
|
||||
BufferedReader file = new BufferedReader(new FileReader(filename));
|
||||
String line = file.readLine();
|
||||
|
||||
Reference in New Issue
Block a user