implemented stop train
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>0.7.4</version>
|
||||
<version>0.7.5</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -17,6 +17,7 @@ public interface Constants {
|
||||
public static final String ACTION_MOVE = "move";
|
||||
public static final String ACTION_POWER = "power";
|
||||
public static final String ACTION_PROPS = "props";
|
||||
public static final String ACTION_QUIT = "quit";
|
||||
public static final String ACTION_SAVE = "save";
|
||||
public static final String ACTION_SLOWER10 = "slower10";
|
||||
public static final String ACTION_START = "start";
|
||||
@@ -27,8 +28,6 @@ public interface Constants {
|
||||
public static final String ACTION_TOGGLE_F4 = "f4";
|
||||
public static final String ACTION_TURN = "turn";
|
||||
public static final String ACTION_UPDATE = "update";
|
||||
|
||||
|
||||
|
||||
public static final String REALM = "realm";
|
||||
public static final String REALM_CAR = "car";
|
||||
@@ -43,5 +42,6 @@ public interface Constants {
|
||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
public static final String CONTACT = "contact";
|
||||
public static final String TYPE = "type";
|
||||
public static final String NBSP = " ";
|
||||
|
||||
}
|
||||
|
||||
@@ -208,8 +208,8 @@ public class Route implements Constants{
|
||||
new Input(REALM,REALM_ROUTE).hideIn(form);
|
||||
new Input(ID,id()).hideIn(form);
|
||||
|
||||
Tag label = new Tag("label").content(t("name:"));
|
||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name()).addTo(label);
|
||||
Tag label = new Tag("label").content(t("name:")+NBSP);
|
||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name()).style("width: 80%").addTo(label);
|
||||
label.addTo(form);
|
||||
|
||||
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
||||
@@ -305,6 +305,10 @@ public class Route implements Constants{
|
||||
return properties();
|
||||
}
|
||||
|
||||
public Block endBlock() {
|
||||
return endBlock;
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
startBlock.train(null);
|
||||
train.route = null;
|
||||
@@ -563,7 +567,7 @@ public class Route implements Constants{
|
||||
}
|
||||
|
||||
public Block startBlock() {
|
||||
return (Block) path.get(0);
|
||||
return startBlock;
|
||||
}
|
||||
|
||||
protected static String t(String txt, Object...fills) {
|
||||
|
||||
@@ -135,10 +135,12 @@ public class Train implements Constants {
|
||||
return train.automatic();
|
||||
case ACTION_PROPS:
|
||||
return train.props();
|
||||
case ACTION_QUIT:
|
||||
return train.quitAutopilot();
|
||||
case ACTION_START:
|
||||
return train.start();
|
||||
case ACTION_STOP:
|
||||
return train.stop();
|
||||
return train.stopNow();
|
||||
case ACTION_TURN:
|
||||
return train.turn();
|
||||
case ACTION_UPDATE:
|
||||
@@ -147,7 +149,6 @@ public class Train implements Constants {
|
||||
return t("Unknown action: {}",params.get(ACTION));
|
||||
}
|
||||
|
||||
|
||||
private Object addCar(HashMap<String, String> params) {
|
||||
LOG.debug("addCar({})",params);
|
||||
if (!params.containsKey(CAR_ID)) return t("No car id passed to Train.addCar!");
|
||||
@@ -346,7 +347,7 @@ public class Train implements Constants {
|
||||
if (autopilot == null) {
|
||||
new Button(t("auto"),"train("+id+",'"+ACTION_AUTO+"')").addTo(actions);
|
||||
} else {
|
||||
new Button(t("stop"),"train("+id+",'"+ACTION_STOP+"')").addTo(actions);
|
||||
new Button(t("quit autopilot"),"train("+id+",'"+ACTION_QUIT+"')").addTo(actions);
|
||||
}
|
||||
actions.addTo(propList);
|
||||
|
||||
@@ -361,6 +362,14 @@ public class Train implements Constants {
|
||||
return window;
|
||||
}
|
||||
|
||||
private Object quitAutopilot() {
|
||||
if (autopilot != null) {
|
||||
autopilot.stop = true;
|
||||
autopilot = null;
|
||||
return t("{} stopping at next block.",this);
|
||||
} else return t("autopilot not active.");
|
||||
}
|
||||
|
||||
public static void saveAll(String filename) throws IOException {
|
||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||
for (Entry<Long, Train> entry:trains.entrySet()) {
|
||||
@@ -414,10 +423,17 @@ public class Train implements Constants {
|
||||
return error;
|
||||
}
|
||||
|
||||
private Object stop() {
|
||||
autopilot.stop = true;
|
||||
autopilot = null;
|
||||
return t("{} stopping at next block.",this);
|
||||
private Object stopNow() {
|
||||
setSpeed(0);
|
||||
if (route != null) try {
|
||||
route.unlock();
|
||||
route.endBlock().train(null);
|
||||
route.startBlock().train(this);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
route = null;
|
||||
return t("Stopped {}.",this);
|
||||
}
|
||||
|
||||
private static String t(String message, Object...fills) {
|
||||
|
||||
@@ -82,9 +82,10 @@ public abstract class Block extends StretchableTile{
|
||||
Tag window = super.propMenu();
|
||||
|
||||
if (train != null) {
|
||||
new Tag("h4").content(t("Train:")).addTo(window);
|
||||
train.link("span").addTo(window);
|
||||
new Button(t("start"),"train("+train.id+",'"+ACTION_START+"')").addTo(window);
|
||||
window.children().insertElementAt(new Button(t("stop"),"train("+train.id+",'"+ACTION_STOP+"')"), 1);
|
||||
window.children().insertElementAt(new Button(t("start"),"train("+train.id+",'"+ACTION_START+"')"), 1);
|
||||
window.children().insertElementAt(train.link("span"), 1);
|
||||
window.children().insertElementAt(new Tag("h4").content(t("Train:")), 1);
|
||||
}
|
||||
return window;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user