setting turnouts for route now handeled by the setup actions

This commit is contained in:
Stephan Richter
2020-12-10 23:38:30 +01:00
parent 49185e79a2
commit 1e2edabcb1
10 changed files with 52 additions and 54 deletions

View File

@@ -1,7 +1,6 @@
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;
@@ -23,7 +22,6 @@ import de.srsoftware.web4rail.tags.Select;
public class Contact extends Tile{
private static final String ADDRESS = "address";
private static final HashMap<Id, Contact> contactsById = new HashMap<Id, Contact>();
private static final HashMap<Integer, Contact> contactsByAddr = new HashMap<Integer, Contact>();
private boolean state = false;
private String trigger = null;
@@ -113,10 +111,6 @@ public class Contact extends Tile{
return contactsByAddr.get(addr);
}
public static Contact get(Id contactId) {
return contactsById.get(contactId);
}
@Override
public JSONObject json() {
JSONObject json = super.json();
@@ -125,11 +119,6 @@ public class Contact extends Tile{
return json;
}
public static Collection<Contact> list() {
return contactsById.values();
}
@Override
public Tile load(JSONObject json) {
if (json.has(ADDRESS)) addr(json.getInt(ADDRESS));
@@ -159,7 +148,6 @@ public class Contact extends Tile{
@Override
public Tile position(int x, int y) {
super.position(x, y);
contactsById.put(id(), this);
return this;
}
@@ -171,12 +159,14 @@ public class Contact extends Tile{
switch (action) {
case ACTION_ANALYZE:
if (id == null) return t("Missing ID on call to {}.process()",Contact.class.getSimpleName());
contact = contactsById.get(id);
contact = BaseClass.get(id);
if (contact == null) return t("No contact with id {} found!",id);
Tag propMenu = contact.properties();
propMenu.children().insertElementAt(new Tag("div").content(t("Trigger a feedback sensor to assign it with this contact!")), 1);
plan.learn(contact);
return propMenu;
case ACTION_UPDATE:
return plan.update(params);
}
return t("Unknown action: {}",action);
}
@@ -202,7 +192,7 @@ public class Contact extends Tile{
public static Select selector(Contact preselect) {
TreeMap<String,Contact> sortedSet = new TreeMap<String, Contact>(); // Map from Name to Contact
for (Contact contact : contactsById.values()) sortedSet.put(contact.toString(), contact);
for (Contact contact : BaseClass.listElements(Contact.class)) sortedSet.put(contact.toString(), contact);
Select select = new Select(CONTACT);
for (Entry<String, Contact> entry : sortedSet.entrySet()) {
Contact contact = entry.getValue();

View File

@@ -159,6 +159,18 @@ 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) {
@@ -222,6 +234,11 @@ public class Relay extends Tile implements Device{
return name;
}
@Override
public String toString() {
return getClass().getSimpleName()+" ("+(isSet(name) && !name.isEmpty() ? name+")" : "")+" @("+x+", "+y+")";
}
@Override
public Tile update(HashMap<String, String> params) {
if (params.containsKey(PROTOCOL)) protocol = Protocol.valueOf(params.get(PROTOCOL));
@@ -233,16 +250,4 @@ public class Relay extends Tile implements Device{
if (params.containsKey(NAME)) name = params.get(NAME);
return super.update(params);
}
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;
}
}

View File

@@ -210,7 +210,7 @@ public abstract class Turnout extends Tile implements Device{
@Override
public String title() {
return getClass().getSimpleName()+t("(Address: {}, Ports {} and {})",address,portA,portB);
return getClass().getSimpleName()+t("(Address: {}, Ports {} and {}) @ ({}, {})",address,portA,portB,x,y);
}
@Override