new feature on clicking tiles: actions of tile now skipped, when shift is pressed during click
This commit is contained in:
@@ -152,9 +152,9 @@ public abstract class Block extends StretchableTile{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
if (isSet(train) && train.currentBlock() == this) return train.properties();
|
||||
return super.click();
|
||||
public Object click(boolean shift) throws IOException {
|
||||
if (isSet(train) && !shift) return train.properties();
|
||||
return super.click(false);
|
||||
}
|
||||
|
||||
public int compareTo(Block other) {
|
||||
|
||||
@@ -21,9 +21,9 @@ public abstract class Bridge extends Tile {
|
||||
protected Bridge counterpart = null;
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
public Object click(boolean shift) throws IOException {
|
||||
if (pendingConnection != null) return connect();
|
||||
return super.click();
|
||||
return super.click(shift);
|
||||
}
|
||||
|
||||
private Object connect() {
|
||||
|
||||
@@ -116,9 +116,9 @@ public class Contact extends Tile{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
trigger(200);
|
||||
return super.click();
|
||||
public Object click(boolean shift) throws IOException {
|
||||
if (!shift) trigger(200);
|
||||
return super.click(shift);
|
||||
}
|
||||
|
||||
public static Contact get(int addr) {
|
||||
|
||||
@@ -34,9 +34,9 @@ public abstract class Decoupler extends Tile implements Device{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
Object o = super.click();
|
||||
engage();
|
||||
public Object click(boolean shift) throws IOException {
|
||||
Object o = super.click(shift);
|
||||
if (!shift) engage();
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Command;
|
||||
import de.srsoftware.web4rail.Command.Reply;
|
||||
import de.srsoftware.web4rail.Device;
|
||||
@@ -19,11 +16,9 @@ import de.srsoftware.web4rail.Protocol;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Radio;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
import de.srsoftware.web4rail.tags.Window;
|
||||
|
||||
public class Relay extends Tile implements Device{
|
||||
public static final String STATE = "state";
|
||||
private static final String PORT_A = "port_a";
|
||||
private static final String PORT_B = "port_b";
|
||||
protected static final String STRAIGHT = "straight";
|
||||
@@ -51,9 +46,9 @@ public class Relay extends Tile implements Device{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
Object o = super.click();
|
||||
state(!state);
|
||||
public Object click(boolean shift) throws IOException {
|
||||
Object o = super.click(shift);
|
||||
if (!shift) state(!state);
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -159,18 +154,6 @@ public class Relay extends Tile implements Device{
|
||||
return 'P';
|
||||
}
|
||||
}
|
||||
|
||||
public static Select selector(Relay preselected, Collection<Relay> exclude) {
|
||||
if (isNull(exclude)) exclude = new Vector<Relay>();
|
||||
Select select = new Select(Relay.class.getSimpleName());
|
||||
new Tag("option").attr("value","0").content(t("unset")).addTo(select);
|
||||
for (Relay relay : BaseClass.listElements(Relay.class)) {
|
||||
if (exclude.contains(relay)) continue;
|
||||
Tag opt = select.addOption(relay.id(), relay);
|
||||
if (relay == preselected) opt.attr("selected", "selected");
|
||||
}
|
||||
return select;
|
||||
}
|
||||
|
||||
public Relay setLabel(boolean state, String tx) {
|
||||
if (state) {
|
||||
|
||||
@@ -40,20 +40,9 @@ public class Switch extends Tile{
|
||||
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
state = !state;
|
||||
Application.threadPool.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Context context = new Context(Switch.this);
|
||||
if (state) {
|
||||
actionsOn.fire(context);
|
||||
} else actionsOff.fire(context);
|
||||
}
|
||||
});
|
||||
stream();
|
||||
return super.click();
|
||||
public Object click(boolean shift) throws IOException {
|
||||
if (!shift) state(!state);
|
||||
return super.click(shift);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -172,6 +161,21 @@ public class Switch extends Tile{
|
||||
return state;
|
||||
}
|
||||
|
||||
public void state(boolean newState) {
|
||||
state = newState;
|
||||
Application.threadPool.execute(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Context context = new Context(Switch.this);
|
||||
if (state) {
|
||||
actionsOn.fire(context);
|
||||
} else actionsOff.fire(context);
|
||||
}
|
||||
});
|
||||
stream();
|
||||
}
|
||||
|
||||
public void stream() {
|
||||
try {
|
||||
Tag tag = tag(null);
|
||||
|
||||
@@ -76,8 +76,9 @@ public abstract class Tile extends BaseClass implements Comparable<Tile>{
|
||||
return classes;
|
||||
}
|
||||
|
||||
public Object click() throws IOException {
|
||||
public Object click(boolean shift) throws IOException {
|
||||
LOG.debug("{}.click()",getClass().getSimpleName());
|
||||
if (isSet(train) && shift) return train.properties();
|
||||
return properties();
|
||||
}
|
||||
|
||||
|
||||
@@ -49,10 +49,10 @@ public abstract class Turnout extends Tile implements Device{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
public Object click(boolean shift) throws IOException {
|
||||
LOG.debug(getClass().getSimpleName()+".click()");
|
||||
init();
|
||||
return super.click();
|
||||
if (!shift) init();
|
||||
return super.click(shift);
|
||||
}
|
||||
|
||||
protected abstract String commandFor(State newState);
|
||||
|
||||
@@ -13,11 +13,13 @@ public abstract class TurnoutL extends Turnout {
|
||||
private static final String LEFT = "left";
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
Object o = super.click();
|
||||
if (route != null) {
|
||||
plan.stream(t("{} is locked by {}!",this,route));
|
||||
} else state(state == State.STRAIGHT ? State.LEFT : State.STRAIGHT);
|
||||
public Object click(boolean shift) throws IOException {
|
||||
Object o = super.click(shift);
|
||||
if (!shift) {
|
||||
if (route != null) {
|
||||
plan.stream(t("{} is locked by {}!",this,route));
|
||||
} else state(state == State.STRAIGHT ? State.LEFT : State.STRAIGHT);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,13 @@ public abstract class TurnoutR extends Turnout {
|
||||
private static final String RIGHT = "right";
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
Object o = super.click();
|
||||
if (route != null) {
|
||||
plan.stream(t("{} is locked by {}!",this,route));
|
||||
} else state(state == State.STRAIGHT ? State.RIGHT : State.STRAIGHT);
|
||||
public Object click(boolean shift) throws IOException {
|
||||
Object o = super.click(shift);
|
||||
if (!shift) {
|
||||
if (route != null) {
|
||||
plan.stream(t("{} is locked by {}!",this,route));
|
||||
} else state(state == State.STRAIGHT ? State.RIGHT : State.STRAIGHT);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user