preparing contacts in blocks
This commit is contained in:
@@ -38,9 +38,11 @@ public abstract class Block extends StretchableTile{
|
||||
public static final String TAG = "tag";
|
||||
private static final String WAIT_TIMES = "wait_times";
|
||||
private static final String RAISE = "raise";
|
||||
public static final String ACTION_ADD_CONTACT = "add_contact";
|
||||
|
||||
public String name = "Block";
|
||||
public boolean turnAllowed = false;
|
||||
private Vector<BlockContact> internalContacts = new Vector<BlockContact>();
|
||||
|
||||
public Block() {
|
||||
super();
|
||||
@@ -120,6 +122,12 @@ public abstract class Block extends StretchableTile{
|
||||
|
||||
|
||||
private Vector<WaitTime> waitTimes = new Vector<WaitTime>();
|
||||
|
||||
public Object addContact() {
|
||||
BlockContact contact = new BlockContact(this);
|
||||
plan.learn(contact);
|
||||
return t("Trigger contact to learn new contact");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object click() throws IOException {
|
||||
@@ -138,6 +146,19 @@ public abstract class Block extends StretchableTile{
|
||||
return config;
|
||||
}
|
||||
|
||||
private Fieldset contactForm() {
|
||||
Fieldset fieldset = new Fieldset("internal contacts");
|
||||
this.button("new contact", Map.of(ACTION,ACTION_ADD_CONTACT)).addTo(fieldset);
|
||||
if (!internalContacts.isEmpty()) {
|
||||
Tag ul = new Tag("ul");
|
||||
for (BlockContact contact : internalContacts) {
|
||||
new Tag("li").content(contact.toString()).addTo(ul);
|
||||
}
|
||||
ul.addTo(fieldset);
|
||||
}
|
||||
return fieldset;
|
||||
}
|
||||
|
||||
public abstract Direction directionA();
|
||||
public abstract Direction directionB();
|
||||
|
||||
@@ -217,7 +238,8 @@ public abstract class Block extends StretchableTile{
|
||||
formInputs.add(t("Name"),new Input(NAME, name));
|
||||
formInputs.add("",new Checkbox(ALLOW_TURN,t("Turn allowed"),turnAllowed));
|
||||
formInputs.add(t("Train"),Train.selector(train, null));
|
||||
postForm.add(waitTimeForm());
|
||||
postForm.add(contactForm());
|
||||
postForm.add(waitTimeForm());
|
||||
return super.properties(preForm, formInputs, postForm);
|
||||
}
|
||||
|
||||
@@ -232,6 +254,11 @@ public abstract class Block extends StretchableTile{
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public BlockContact register(BlockContact contact) {
|
||||
internalContacts.add(contact);
|
||||
return contact;
|
||||
}
|
||||
|
||||
public static Select selector(Block preselected,Collection<Block> exclude) {
|
||||
if (isNull(exclude)) exclude = new Vector<Block>();
|
||||
@@ -397,5 +424,4 @@ public abstract class Block extends StretchableTile{
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
src/main/java/de/srsoftware/web4rail/tiles/BlockContact.java
Normal file
33
src/main/java/de/srsoftware/web4rail/tiles/BlockContact.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.web4rail.Window;
|
||||
|
||||
public class BlockContact extends Contact {
|
||||
|
||||
public BlockContact(Block parent) {
|
||||
parent(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contact addr(int address) {
|
||||
super.addr(address);
|
||||
Block block = (Block) parent();
|
||||
return block.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Id id() {
|
||||
if (id == null) id = new Id();
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Window properties() {
|
||||
return parent().properties();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"("+addr+")";
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public class Contact extends Tile{
|
||||
private static final HashMap<Integer, Contact> contactsByAddr = new HashMap<Integer, Contact>();
|
||||
private boolean state = false;
|
||||
private String trigger = null;
|
||||
private int addr = 0;
|
||||
protected int addr = 0;
|
||||
private ActionList actions;
|
||||
private OffTimer timer = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user