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>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.0.7</version>
|
||||
<version>1.0.8</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -271,3 +271,12 @@ svg.disabled rect{
|
||||
#train-wait-form td{
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.cockpit button{
|
||||
padding: 15px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.cockpit .stop{
|
||||
min-width: 150px;
|
||||
}
|
||||
@@ -18,6 +18,7 @@ Analyze : analysieren
|
||||
Apply : Übernehmen
|
||||
Auto pilot : Autopilot
|
||||
Availability : Verfügbarkeit
|
||||
Basic properties : Grundlegende Eigenschaften
|
||||
BlockFree : Blockbelegung
|
||||
Block {} is free : Block {} ist frei
|
||||
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
|
||||
Conditions : Bedingungen
|
||||
Condition type\: : Bedingungs-Typ:
|
||||
Control : Steuerung
|
||||
Control unit : Zentrale
|
||||
Current location\: : Aktueller Ort:
|
||||
[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
|
||||
Current location : Aufenthaltsort
|
||||
Current location\: {} : Aufenthaltsort: {}
|
||||
Current velocity\: {} km/h : Aktuelle Geschwindigkeit: {} km/h
|
||||
Delay : Verzögerung
|
||||
DelayedAction : verzögerte Aktion
|
||||
delete : entfernen
|
||||
|
||||
@@ -80,10 +80,6 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
return t("Unknown action: {}",params.get(ACTION));
|
||||
}
|
||||
|
||||
protected Tag cockpit() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Car get(Object 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;
|
||||
}
|
||||
|
||||
public Object properties() {
|
||||
public Window properties() {
|
||||
Window win = new Window("car-props", t("Properties of {}",this));
|
||||
|
||||
Tag cockpit = cockpit();
|
||||
if (cockpit != null) cockpit.addTo(win);
|
||||
|
||||
Form form = propertyForm();
|
||||
if (form!=null && form.children().size()>2) {
|
||||
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");
|
||||
if (train != null) {
|
||||
train.link("span").addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
||||
}
|
||||
if (train != null) train.link().addTo(new Tag("li").content(t("Train:")+NBSP)).addTo(list);
|
||||
list.addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.srsoftware.web4rail.moving;
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.json.JSONObject;
|
||||
@@ -12,10 +13,10 @@ import de.srsoftware.web4rail.Command;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
import de.srsoftware.web4rail.Device;
|
||||
import de.srsoftware.web4rail.Plan;
|
||||
import de.srsoftware.web4rail.Protocol;
|
||||
import de.srsoftware.web4rail.Window;
|
||||
import de.srsoftware.web4rail.tags.Button;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.Protocol;
|
||||
import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
public static Tag cockpit(Object locoOrTrain) {
|
||||
String realm = null;
|
||||
int id = 0;
|
||||
int speed = 0;
|
||||
if (locoOrTrain instanceof Locomotive) {
|
||||
Locomotive loco = (Locomotive) locoOrTrain;
|
||||
realm = REALM_LOCO;
|
||||
id = loco.id();
|
||||
speed = loco.speed;
|
||||
} else if (locoOrTrain instanceof Train) {
|
||||
Train train = (Train)locoOrTrain;
|
||||
realm = REALM_TRAIN;
|
||||
id = train.id;
|
||||
speed = train.speed;
|
||||
}
|
||||
queue();
|
||||
return t("{} F{}",t(active?"Activated":"Deavtivated"),f);
|
||||
}
|
||||
|
||||
protected Tag cockpit() {
|
||||
HashMap<String,Object> params = new HashMap<String, Object>(Map.of(REALM,realm,ID,id));
|
||||
|
||||
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 Button(t("Faster (10 steps)"), request.replace("{}", ACTION_FASTER10)).addTo(fieldset);
|
||||
new Button(t("Slower (10 steps)"), request.replace("{}", ACTION_SLOWER10)).addTo(fieldset);
|
||||
new Button(t("Stop"), request.replace("{}", ACTION_STOP)).addTo(fieldset);
|
||||
Tag span = new Tag("p");
|
||||
new Button(t("F1"),request.replace("{}", ACTION_TOGGLE_F1)).addTo(span);
|
||||
new Button(t("F2"),request.replace("{}", ACTION_TOGGLE_F2)).addTo(span);
|
||||
new Button(t("F3"),request.replace("{}", ACTION_TOGGLE_F3)).addTo(span);
|
||||
new Button(t("F4"),request.replace("{}", ACTION_TOGGLE_F4)).addTo(span);
|
||||
span.addTo(fieldset);
|
||||
return fieldset;
|
||||
|
||||
new Tag("span").content(t("Current velocity: {} km/h",speed)).addTo(fieldset);
|
||||
|
||||
Tag par = new Tag("p");
|
||||
Map.of("Slower (10 steps)",ACTION_SLOWER10,"Faster (10 steps)",ACTION_FASTER10).entrySet().forEach(e -> {
|
||||
params.put(ACTION, e.getValue());
|
||||
new Button(t(e.getKey()),params).addTo(par);
|
||||
});
|
||||
par.addTo(fieldset);
|
||||
|
||||
Tag direction = new Tag("p");
|
||||
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() {
|
||||
@@ -230,6 +234,14 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
return win;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties() {
|
||||
Window win = super.properties();
|
||||
Tag cockpit = cockpit(this);
|
||||
win.children().insertElementAt(cockpit, 2);
|
||||
return win;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Form propertyForm() {
|
||||
Form form = super.propertyForm();
|
||||
@@ -277,6 +289,32 @@ public class Locomotive extends Car implements Constants,Device{
|
||||
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() {
|
||||
reverse = !reverse;
|
||||
stop();
|
||||
|
||||
@@ -142,12 +142,16 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
return train.automatic();
|
||||
case ACTION_DROP:
|
||||
return train.dropCar(params);
|
||||
case ACTION_FASTER10:
|
||||
return train.faster(10);
|
||||
case ACTION_MOVE:
|
||||
return train.setDestination(params);
|
||||
case ACTION_PROPS:
|
||||
return train.props();
|
||||
case ACTION_QUIT:
|
||||
return train.quitAutopilot();
|
||||
case ACTION_SLOWER10:
|
||||
return train.slower(10);
|
||||
case ACTION_START:
|
||||
return train.start();
|
||||
case ACTION_STOP:
|
||||
@@ -290,6 +294,11 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
while (!trace.isEmpty()) trace.removeFirst().set(null);
|
||||
}
|
||||
|
||||
private Tag faster(int steps) {
|
||||
setSpeed(speed+steps);
|
||||
return props();
|
||||
}
|
||||
|
||||
public static Train get(int id) {
|
||||
return trains.get(id);
|
||||
}
|
||||
@@ -470,6 +479,8 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
public Tag props() {
|
||||
Window window = new Window("train-properties",t("Properties of {}",this));
|
||||
|
||||
Locomotive.cockpit(this).addTo(window);
|
||||
|
||||
Fieldset fieldset = new Fieldset(t("editable train properties"));
|
||||
Form form = new 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);
|
||||
}
|
||||
|
||||
public void setSpeed(int v) {
|
||||
for (Locomotive loco : locos) loco.setSpeed(v);
|
||||
plan.stream(t("Set {} to {} km/h",this,v));
|
||||
this.speed = v;
|
||||
public void setSpeed(int newSpeed) {
|
||||
speed = newSpeed;
|
||||
if (speed > 128) speed = 128;
|
||||
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) {
|
||||
@@ -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 {
|
||||
if (isNull(currentBlock)) return t("{} not in a block",this);
|
||||
if (isSet(route)) route.reset(); // reset route previously chosen
|
||||
@@ -705,7 +723,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
route.reset();
|
||||
route = null;
|
||||
}
|
||||
return t("Stopped {}.",this);
|
||||
return props();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public Object turn() {
|
||||
public Tag turn() {
|
||||
LOG.debug("train.turn()");
|
||||
if (isSet(direction)) {
|
||||
direction = direction.inverse();
|
||||
@@ -733,7 +751,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
reverseTrace();
|
||||
if (isSet(currentBlock)) plan.place(currentBlock);
|
||||
}
|
||||
return t("{} turned.",this);
|
||||
return props();
|
||||
}
|
||||
|
||||
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(train.link("span"), 1);
|
||||
window.children().insertElementAt(train.link(), 1);
|
||||
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user