implemented cockpit with large buttons for locos and trains
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.7</version>
|
<version>1.0.8</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>
|
||||||
|
|||||||
@@ -270,4 +270,13 @@ svg.disabled rect{
|
|||||||
|
|
||||||
#train-wait-form td{
|
#train-wait-form td{
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cockpit button{
|
||||||
|
padding: 15px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cockpit .stop{
|
||||||
|
min-width: 150px;
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ Analyze : analysieren
|
|||||||
Apply : Übernehmen
|
Apply : Übernehmen
|
||||||
Auto pilot : Autopilot
|
Auto pilot : Autopilot
|
||||||
Availability : Verfügbarkeit
|
Availability : Verfügbarkeit
|
||||||
|
Basic properties : Grundlegende Eigenschaften
|
||||||
BlockFree : Blockbelegung
|
BlockFree : Blockbelegung
|
||||||
Block {} is free : Block {} ist frei
|
Block {} is free : Block {} ist frei
|
||||||
Block {} is occupied : Block {} ist belegt
|
Block {} is occupied : Block {} ist belegt
|
||||||
@@ -29,6 +30,7 @@ Click on a name to edit the entry. : Klicke auf einen Namen, um einen Eintrag zu
|
|||||||
ConditionalAction : bedingte Aktion
|
ConditionalAction : bedingte Aktion
|
||||||
Conditions : Bedingungen
|
Conditions : Bedingungen
|
||||||
Condition type\: : Bedingungs-Typ:
|
Condition type\: : Bedingungs-Typ:
|
||||||
|
Control : Steuerung
|
||||||
Control unit : Zentrale
|
Control unit : Zentrale
|
||||||
Current location\: : Aktueller Ort:
|
Current location\: : Aktueller Ort:
|
||||||
[Click here to select block!] : [Hier klicken, um Block auszuwählen!]
|
[Click here to select block!] : [Hier klicken, um Block auszuwählen!]
|
||||||
@@ -39,6 +41,7 @@ Command to send to control unit\: : Kommando, welches zur Zentrale gesendet werd
|
|||||||
Create action : Aktion erzeugen
|
Create action : Aktion erzeugen
|
||||||
Current location : Aufenthaltsort
|
Current location : Aufenthaltsort
|
||||||
Current location\: {} : Aufenthaltsort: {}
|
Current location\: {} : Aufenthaltsort: {}
|
||||||
|
Current velocity\: {} km/h : Aktuelle Geschwindigkeit: {} km/h
|
||||||
Delay : Verzögerung
|
Delay : Verzögerung
|
||||||
DelayedAction : verzögerte Aktion
|
DelayedAction : verzögerte Aktion
|
||||||
delete : entfernen
|
delete : entfernen
|
||||||
|
|||||||
@@ -80,10 +80,6 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Tag cockpit() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Car get(Object id) {
|
public static Car get(Object id) {
|
||||||
return cars.get(Integer.parseInt(""+id)); // try to get by id
|
return cars.get(Integer.parseInt(""+id)); // try to get by id
|
||||||
}
|
}
|
||||||
@@ -194,12 +190,9 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object properties() {
|
public Window properties() {
|
||||||
Window win = new Window("car-props", t("Properties of {}",this));
|
Window win = new Window("car-props", t("Properties of {}",this));
|
||||||
|
|
||||||
Tag cockpit = cockpit();
|
|
||||||
if (cockpit != null) cockpit.addTo(win);
|
|
||||||
|
|
||||||
Form form = propertyForm();
|
Form form = propertyForm();
|
||||||
if (form!=null && form.children().size()>2) {
|
if (form!=null && form.children().size()>2) {
|
||||||
new Button(t("Apply"),form).addTo(form).addTo(win);
|
new Button(t("Apply"),form).addTo(form).addTo(win);
|
||||||
@@ -208,9 +201,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Tag list = new Tag("ul");
|
Tag list = new Tag("ul");
|
||||||
if (train != null) {
|
if (train != null) train.link().addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
||||||
train.link("span").addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
|
||||||
}
|
|
||||||
list.addTo(win);
|
list.addTo(win);
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.srsoftware.web4rail.moving;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -12,10 +13,10 @@ import de.srsoftware.web4rail.Command;
|
|||||||
import de.srsoftware.web4rail.Constants;
|
import de.srsoftware.web4rail.Constants;
|
||||||
import de.srsoftware.web4rail.Device;
|
import de.srsoftware.web4rail.Device;
|
||||||
import de.srsoftware.web4rail.Plan;
|
import de.srsoftware.web4rail.Plan;
|
||||||
import de.srsoftware.web4rail.Protocol;
|
|
||||||
import de.srsoftware.web4rail.Window;
|
import de.srsoftware.web4rail.Window;
|
||||||
import de.srsoftware.web4rail.tags.Button;
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Fieldset;
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.Protocol;
|
||||||
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;
|
||||||
@@ -75,46 +76,49 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object toggleFunction(int f) {
|
public static Tag cockpit(Object locoOrTrain) {
|
||||||
boolean active;
|
String realm = null;
|
||||||
switch (f) {
|
int id = 0;
|
||||||
case 1:
|
int speed = 0;
|
||||||
f1 =! f1;
|
if (locoOrTrain instanceof Locomotive) {
|
||||||
active = f1;
|
Locomotive loco = (Locomotive) locoOrTrain;
|
||||||
break;
|
realm = REALM_LOCO;
|
||||||
case 2:
|
id = loco.id();
|
||||||
f2 =! f2;
|
speed = loco.speed;
|
||||||
active = f2;
|
} else if (locoOrTrain instanceof Train) {
|
||||||
break;
|
Train train = (Train)locoOrTrain;
|
||||||
case 3:
|
realm = REALM_TRAIN;
|
||||||
f3 =! f3;
|
id = train.id;
|
||||||
active = f3;
|
speed = train.speed;
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
f4 =! f4;
|
|
||||||
active = f4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return t("Unknown function: {}",f);
|
|
||||||
}
|
}
|
||||||
queue();
|
|
||||||
return t("{} F{}",t(active?"Activated":"Deavtivated"),f);
|
HashMap<String,Object> params = new HashMap<String, Object>(Map.of(REALM,realm,ID,id));
|
||||||
}
|
|
||||||
|
|
||||||
protected Tag cockpit() {
|
|
||||||
Fieldset fieldset = new Fieldset(t("Control"));
|
Fieldset fieldset = new Fieldset(t("Control"));
|
||||||
String request = "return request({realm:'"+REALM_LOCO+"',id:"+id()+",action:'{}'})";
|
|
||||||
new Button(t("Turn"), request.replace("{}", ACTION_TURN)).addTo(fieldset);
|
new Tag("span").content(t("Current velocity: {} km/h",speed)).addTo(fieldset);
|
||||||
new Button(t("Faster (10 steps)"), request.replace("{}", ACTION_FASTER10)).addTo(fieldset);
|
|
||||||
new Button(t("Slower (10 steps)"), request.replace("{}", ACTION_SLOWER10)).addTo(fieldset);
|
Tag par = new Tag("p");
|
||||||
new Button(t("Stop"), request.replace("{}", ACTION_STOP)).addTo(fieldset);
|
Map.of("Slower (10 steps)",ACTION_SLOWER10,"Faster (10 steps)",ACTION_FASTER10).entrySet().forEach(e -> {
|
||||||
Tag span = new Tag("p");
|
params.put(ACTION, e.getValue());
|
||||||
new Button(t("F1"),request.replace("{}", ACTION_TOGGLE_F1)).addTo(span);
|
new Button(t(e.getKey()),params).addTo(par);
|
||||||
new Button(t("F2"),request.replace("{}", ACTION_TOGGLE_F2)).addTo(span);
|
});
|
||||||
new Button(t("F3"),request.replace("{}", ACTION_TOGGLE_F3)).addTo(span);
|
par.addTo(fieldset);
|
||||||
new Button(t("F4"),request.replace("{}", ACTION_TOGGLE_F4)).addTo(span);
|
|
||||||
span.addTo(fieldset);
|
Tag direction = new Tag("p");
|
||||||
return fieldset;
|
Map.of("Turn",ACTION_TURN,"Stop",ACTION_STOP).entrySet().forEach(e -> {
|
||||||
|
params.put(ACTION, e.getValue());
|
||||||
|
new Button(t(e.getKey()),params).clazz(e.getValue()).addTo(direction);
|
||||||
|
});
|
||||||
|
direction.addTo(fieldset);
|
||||||
|
|
||||||
|
Tag functions = new Tag("p");
|
||||||
|
Map.of("F1",ACTION_TOGGLE_F1,"F2",ACTION_TOGGLE_F2,"F3",ACTION_TOGGLE_F3,"F4",ACTION_TOGGLE_F4).entrySet().forEach(e -> {
|
||||||
|
params.put(ACTION, e.getValue());
|
||||||
|
new Button(t(e.getKey()),params).addTo(functions);
|
||||||
|
});
|
||||||
|
functions.addTo(fieldset);
|
||||||
|
return fieldset.clazz("cockpit");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String detail() {
|
private String detail() {
|
||||||
@@ -230,6 +234,14 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window properties() {
|
||||||
|
Window win = super.properties();
|
||||||
|
Tag cockpit = cockpit(this);
|
||||||
|
win.children().insertElementAt(cockpit, 2);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Form propertyForm() {
|
public Form propertyForm() {
|
||||||
Form form = super.propertyForm();
|
Form form = super.propertyForm();
|
||||||
@@ -277,6 +289,32 @@ public class Locomotive extends Car implements Constants,Device{
|
|||||||
return t("Stopped {}",this);
|
return t("Stopped {}",this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object toggleFunction(int f) {
|
||||||
|
boolean active;
|
||||||
|
switch (f) {
|
||||||
|
case 1:
|
||||||
|
f1 =! f1;
|
||||||
|
active = f1;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
f2 =! f2;
|
||||||
|
active = f2;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
f3 =! f3;
|
||||||
|
active = f3;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
f4 =! f4;
|
||||||
|
active = f4;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return t("Unknown function: {}",f);
|
||||||
|
}
|
||||||
|
queue();
|
||||||
|
return t("{} F{}",t(active?"Activated":"Deavtivated"),f);
|
||||||
|
}
|
||||||
|
|
||||||
public Object turn() {
|
public Object turn() {
|
||||||
reverse = !reverse;
|
reverse = !reverse;
|
||||||
stop();
|
stop();
|
||||||
|
|||||||
@@ -142,12 +142,16 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return train.automatic();
|
return train.automatic();
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
return train.dropCar(params);
|
return train.dropCar(params);
|
||||||
|
case ACTION_FASTER10:
|
||||||
|
return train.faster(10);
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
return train.setDestination(params);
|
return train.setDestination(params);
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return train.props();
|
return train.props();
|
||||||
case ACTION_QUIT:
|
case ACTION_QUIT:
|
||||||
return train.quitAutopilot();
|
return train.quitAutopilot();
|
||||||
|
case ACTION_SLOWER10:
|
||||||
|
return train.slower(10);
|
||||||
case ACTION_START:
|
case ACTION_START:
|
||||||
return train.start();
|
return train.start();
|
||||||
case ACTION_STOP:
|
case ACTION_STOP:
|
||||||
@@ -290,6 +294,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
while (!trace.isEmpty()) trace.removeFirst().set(null);
|
while (!trace.isEmpty()) trace.removeFirst().set(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tag faster(int steps) {
|
||||||
|
setSpeed(speed+steps);
|
||||||
|
return props();
|
||||||
|
}
|
||||||
|
|
||||||
public static Train get(int id) {
|
public static Train get(int id) {
|
||||||
return trains.get(id);
|
return trains.get(id);
|
||||||
}
|
}
|
||||||
@@ -470,6 +479,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
public Tag props() {
|
public Tag props() {
|
||||||
Window window = new Window("train-properties",t("Properties of {}",this));
|
Window window = new Window("train-properties",t("Properties of {}",this));
|
||||||
|
|
||||||
|
Locomotive.cockpit(this).addTo(window);
|
||||||
|
|
||||||
Fieldset fieldset = new Fieldset(t("editable train properties"));
|
Fieldset fieldset = new Fieldset(t("editable train properties"));
|
||||||
Form form = new Form();
|
Form form = new Form();
|
||||||
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
new Input(ACTION,ACTION_UPDATE).hideIn(form);
|
||||||
@@ -607,10 +618,12 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return t("{} is not a block!",tile);
|
return t("{} is not a block!",tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpeed(int v) {
|
public void setSpeed(int newSpeed) {
|
||||||
for (Locomotive loco : locos) loco.setSpeed(v);
|
speed = newSpeed;
|
||||||
plan.stream(t("Set {} to {} km/h",this,v));
|
if (speed > 128) speed = 128;
|
||||||
this.speed = v;
|
if (speed < 0) speed = 0;
|
||||||
|
for (Locomotive loco : locos) loco.setSpeed(speed);
|
||||||
|
plan.stream(t("Set {} to {} km/h",this,speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWaitTime(Range waitTime) {
|
public void setWaitTime(Range waitTime) {
|
||||||
@@ -638,6 +651,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tag slower(int steps) {
|
||||||
|
setSpeed(speed-steps);
|
||||||
|
return props();
|
||||||
|
}
|
||||||
|
|
||||||
public String start() throws IOException {
|
public String start() throws IOException {
|
||||||
if (isNull(currentBlock)) return t("{} not in a block",this);
|
if (isNull(currentBlock)) return t("{} not in a block",this);
|
||||||
if (isSet(route)) route.reset(); // reset route previously chosen
|
if (isSet(route)) route.reset(); // reset route previously chosen
|
||||||
@@ -705,7 +723,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
route.reset();
|
route.reset();
|
||||||
route = null;
|
route = null;
|
||||||
}
|
}
|
||||||
return t("Stopped {}.",this);
|
return props();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String t(String message, Object...fills) {
|
private static String t(String message, Object...fills) {
|
||||||
@@ -725,7 +743,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
return isSet(name) ? name : locos.firstElement().name();
|
return isSet(name) ? name : locos.firstElement().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object turn() {
|
public Tag turn() {
|
||||||
LOG.debug("train.turn()");
|
LOG.debug("train.turn()");
|
||||||
if (isSet(direction)) {
|
if (isSet(direction)) {
|
||||||
direction = direction.inverse();
|
direction = direction.inverse();
|
||||||
@@ -733,7 +751,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
|||||||
reverseTrace();
|
reverseTrace();
|
||||||
if (isSet(currentBlock)) plan.place(currentBlock);
|
if (isSet(currentBlock)) plan.place(currentBlock);
|
||||||
}
|
}
|
||||||
return t("{} turned.",this);
|
return props();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Train update(HashMap<String, String> params) {
|
public Train update(HashMap<String, String> params) {
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ public abstract class Tile extends BaseClass{
|
|||||||
window.children().insertElementAt(new Button(t("auto"),props),2);
|
window.children().insertElementAt(new Button(t("auto"),props),2);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.children().insertElementAt(train.link("span"), 1);
|
window.children().insertElementAt(train.link(), 1);
|
||||||
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
|
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user