improved window tiling

This commit is contained in:
Stephan Richter
2020-10-11 12:06:14 +02:00
parent 3dc11c18e1
commit 8e747cb2a0
9 changed files with 154 additions and 111 deletions

View File

@@ -54,6 +54,18 @@ public class Car implements Constants {
}
this.id = id;
cars.put(id, this);
}
public static Object action(HashMap<String, String> params) throws IOException {
Car car = Car.get(params.get(Car.ID));
if (car == null) return t("No car with id {} found!",params.get(Car.ID));
switch (params.get(ACTION)) {
case ACTION_UPDATE:
return car.update(params);
case ACTION_PROPS:
return car.properties();
}
return t("Unknown action: {}",params.get(ACTION));
}
protected Tag cockpit(String realm) {
@@ -177,10 +189,10 @@ public class Car implements Constants {
this.train = train;
}
public Object update(HashMap<String, String> params) {
public Car update(HashMap<String, String> params) {
if (params.containsKey(NAME)) name = params.get(NAME);
if (params.containsKey(STOCK_ID)) stockId = params.get(STOCK_ID);
if (params.containsKey(LENGTH)) length = Integer.parseInt(params.get(LENGTH));
return null;
return this;
}
}

View File

@@ -1,5 +1,6 @@
package de.srsoftware.web4rail.moving;
import java.io.IOException;
import java.util.HashMap;
import java.util.Vector;
@@ -35,6 +36,27 @@ public class Locomotive extends Car implements Constants,Device{
super(name,id);
}
public static Object action(HashMap<String, String> params) throws IOException {
String id = params.get(ID);
Locomotive loco = id == null ? null : Locomotive.get(id);
switch (params.get(ACTION)) {
case ACTION_ADD:
return new Locomotive(params.get(Locomotive.NAME));
case ACTION_FASTER10:
return loco.faster(10);
case ACTION_PROPS:
return loco == null ? Locomotive.manager() : loco.properties();
case ACTION_SLOWER10:
return loco.faster(-10);
case ACTION_STOP:
return loco.stop();
case ACTION_TURN:
return loco.turn();
}
return Car.action(params);
}
protected Tag cockpit(String realm) {
Fieldset fieldset = new Fieldset(t("Control"));
String request = "return request({realm:'"+realm+"',id:"+id()+",action:'{}'})";
@@ -171,10 +193,10 @@ public class Locomotive extends Car implements Constants,Device{
}
@Override
public Object update(HashMap<String, String> params) {
public Car update(HashMap<String, String> params) {
super.update(params);
if (params.containsKey(PROTOCOL)) proto = Protocol.valueOf(params.get(PROTOCOL));
if (params.containsKey(ADDRESS)) address = Integer.parseInt(params.get(ADDRESS));
return t("Updated locomotive.");
return this;
}
}