lookup tables should be functional now. testing is needed soon.
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>1.5.22</version>
|
||||
<version>1.5.23</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -142,6 +142,7 @@ Destination : Ziel
|
||||
Destination\: {} from {} : Ziel: {} von {}
|
||||
DetermineCarAtPosition : Fahrzeug im Zug bestimmen
|
||||
DetermineTrainInBlock : Zug im Block bestimmen
|
||||
Determine, which car is at position {} of the current train : Bestimmen, welches Fahrzeug sich an Position {} des Zuges befindet
|
||||
Determine, which train is in {} : Bestimmen, welcher Zug sich in {} befindet
|
||||
Direction : Richtung
|
||||
Direction\: heading {} : Richtung: nach {}
|
||||
@@ -234,6 +235,7 @@ Locomotive manager : Lok-Verwaltung
|
||||
Locomotives : Lokomotiven
|
||||
Locomotives and cars : Lokomotiven und Waggons
|
||||
lookup tables : Wertetabellen
|
||||
Lookup table : Wertetabelle
|
||||
LookupTable : Wertetabelle
|
||||
Loop : Wiederholung
|
||||
Lower speed limit : Minimale Geschwindigkeit
|
||||
@@ -312,6 +314,8 @@ PWM rate : PWM-Frequenz
|
||||
quit autopilot : Autopilot beenden
|
||||
{} reached it`s destination! : {} ist am Ziel angekommen!
|
||||
ReactivateContact : Kontakt reaktivieren
|
||||
Read delay from store\: : Wartezeit aus Speicher laden:
|
||||
Read delay from "{}", wait, then : Zeit aus „{}“ lesen, warten, dann
|
||||
Relay : Relais
|
||||
Relay/Signal/Turnout : Relais/Signal/Weiche
|
||||
Remove tag "{}" from train : Markierung "{}" von Zug entfernen
|
||||
@@ -368,6 +372,7 @@ SetSpeed : Geschwindigkeit ändern
|
||||
Set {} to {} {} : {} auf {} {} gesetzt
|
||||
Set speed to {} {} : Geschwindigkeit auf {} {} setzen
|
||||
Set {} to {} : {} auf {} setzen
|
||||
Set "{}" to value from {} : Setze „{}“ auf Wert von {}
|
||||
setting : Einstellung
|
||||
SetPower : Strom schalten
|
||||
Set speed to : Geschwindigkeit setzen
|
||||
@@ -392,6 +397,7 @@ SRCP daemon : SRCP-Dienst
|
||||
Start actions : Start-Aktionen
|
||||
Stock ID : Inventarnummer
|
||||
Stop settings : Halte-Einstellungen
|
||||
Store : Speicher
|
||||
Start autopilot : Autopilot starten
|
||||
Start delay : Start-Verzögerung
|
||||
Started {} : {} gestartet
|
||||
|
||||
@@ -155,14 +155,22 @@ public class LookupTable extends BaseClass{
|
||||
if (isSet(car ))colKey = car.id();
|
||||
break;
|
||||
case LENGTH:
|
||||
if (isSet(train)) colKey = train.length();
|
||||
if (isSet(train)) {
|
||||
int len = train.length();
|
||||
Vector<Object> cols = new Vector<>(this.cols);
|
||||
Collections.reverse(cols);
|
||||
for (Object col : cols) {
|
||||
try {
|
||||
int val = Integer.parseInt(col.toString());
|
||||
if (len < val) colKey = col;
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isSet(colKey,rowKey)) throw new NullPointerException();
|
||||
TreeMap<Object, Integer> dummy = values.get(rowKey.toString());
|
||||
|
||||
return dummy.get(colKey.toString());
|
||||
return values.get(rowKey.toString()).get(colKey.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,8 +2,15 @@ package de.srsoftware.web4rail;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.tags.Select;
|
||||
|
||||
public class Store {
|
||||
|
||||
private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(Store.class);
|
||||
|
||||
private static HashMap<String,Store> stores = new HashMap<>();
|
||||
private String name;
|
||||
private Integer value = null;
|
||||
@@ -23,17 +30,32 @@ public class Store {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer value() {
|
||||
return value;
|
||||
|
||||
public static Select selector(Store store) {
|
||||
Select selector = new Select(Store.class.getSimpleName());
|
||||
selector.addOption("",t("unset"));
|
||||
stores.keySet().forEach(name -> {
|
||||
Tag option = selector.addOption(name);
|
||||
if (BaseClass.isSet(store) && name.equals(store.name)) option.attr("selected", "selected");
|
||||
});
|
||||
return selector;
|
||||
}
|
||||
|
||||
private static String t(String txt, Object...fills) {
|
||||
return BaseClass.t(txt, fills);
|
||||
}
|
||||
|
||||
public void setValue(int newVal) {
|
||||
LOG.debug("Updating {}: {} → {}",name,value,newVal);
|
||||
value = newVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name+"("+(BaseClass.isNull(value) ? BaseClass.t("no value") : value)+")";
|
||||
return name+" ("+(BaseClass.isNull(value) ? t("no value") : value)+")";
|
||||
}
|
||||
|
||||
public Integer value() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.json.JSONObject;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.Params;
|
||||
import de.srsoftware.web4rail.Store;
|
||||
import de.srsoftware.web4rail.tags.Fieldset;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Window;
|
||||
@@ -20,6 +21,7 @@ public class DelayedAction extends ActionList {
|
||||
private static final int DEFAULT_DELAY = 1000;
|
||||
private int min_delay = DEFAULT_DELAY;
|
||||
private int max_delay = DEFAULT_DELAY;
|
||||
private Store store = null;
|
||||
|
||||
public DelayedAction(BaseClass parent) {
|
||||
super(parent);
|
||||
@@ -31,24 +33,30 @@ public class DelayedAction extends ActionList {
|
||||
|
||||
@Override
|
||||
public boolean fire(Context context) {
|
||||
int delay = min_delay + (min_delay < max_delay ? random.nextInt(max_delay - min_delay) : 0);
|
||||
try {
|
||||
int delay = isSet(store) ? store.value() : min_delay + (min_delay < max_delay ? random.nextInt(max_delay - min_delay) : 0);
|
||||
|
||||
new DelayedExecution(delay,this) {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
LOG.debug("{} ms passed by, firing actions:",delay);
|
||||
if (context.invalidated()) return;
|
||||
DelayedAction.super.fire(context);
|
||||
plan.alter();
|
||||
}
|
||||
};
|
||||
new DelayedExecution(delay,this) {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
LOG.debug("{} ms passed by, firing actions:",delay);
|
||||
if (context.invalidated()) return;
|
||||
DelayedAction.super.fire(context);
|
||||
plan.alter();
|
||||
}
|
||||
};
|
||||
} catch (NullPointerException npe) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
return super.json().put(MIN_DELAY, min_delay).put(MAX_DELAY, max_delay);
|
||||
JSONObject json = super.json().put(MIN_DELAY, min_delay).put(MAX_DELAY, max_delay);
|
||||
if (isSet(store)) json.put(Store.class.getSimpleName(), store.name());
|
||||
return json;
|
||||
}
|
||||
|
||||
public DelayedAction load(JSONObject json) {
|
||||
@@ -59,13 +67,17 @@ public class DelayedAction extends ActionList {
|
||||
}
|
||||
if (json.has(MIN_DELAY)) min_delay = json.getInt(MIN_DELAY);
|
||||
if (json.has(MAX_DELAY)) max_delay = json.getInt(MAX_DELAY);
|
||||
if (json.has(Store.class.getSimpleName())) store = Store.get(json.getString(Store.class.getSimpleName()));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
||||
formInputs.add(t("Minimum delay"),new Input(MIN_DELAY,min_delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
||||
formInputs.add(t("Maximum delay"),new Input(MAX_DELAY,max_delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
||||
formInputs.add(t("Read delay from store:"),Store.selector(store));
|
||||
if (isNull(store)) {
|
||||
formInputs.add(t("Minimum delay"),new Input(MIN_DELAY,min_delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
||||
formInputs.add(t("Maximum delay"),new Input(MAX_DELAY,max_delay).numeric().addTo(new Tag("span")).content(NBSP+"ms"));
|
||||
}
|
||||
return super.properties(preForm, formInputs, postForm,errors);
|
||||
}
|
||||
|
||||
@@ -81,6 +93,7 @@ public class DelayedAction extends ActionList {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isSet(store)) return t("Read delay from \"{}\", wait, then",store.name());
|
||||
return t("Wait {} ms, then",min_delay < max_delay ? min_delay+"…"+max_delay : min_delay)+COL;
|
||||
}
|
||||
|
||||
@@ -96,6 +109,10 @@ public class DelayedAction extends ActionList {
|
||||
props.children().insertElementAt(new Tag("div").content(nfe.getMessage()), 2);
|
||||
return props;
|
||||
}
|
||||
|
||||
d = params.getString(Store.class.getSimpleName());
|
||||
if (isSet(d)) store = d.isEmpty() ? null : Store.get(d);
|
||||
|
||||
d = params.getString(MAX_DELAY);
|
||||
if (isSet(d)) try {
|
||||
int ms = Integer.parseInt(d);
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.BaseClass;
|
||||
import de.srsoftware.web4rail.LoadCallback;
|
||||
import de.srsoftware.web4rail.LookupTable;
|
||||
@@ -61,14 +62,17 @@ public class LookupValue extends Action {
|
||||
|
||||
@Override
|
||||
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm,String...errors) {
|
||||
formInputs.add(t("Lookup table"),LookupTable.selector(lookupTable, null));
|
||||
Tag div = new Tag("div");
|
||||
LookupTable.selector(lookupTable, null).addTo(div);
|
||||
if (isSet(lookupTable)) lookupTable.button(t("show")).addTo(div);
|
||||
formInputs.add(t("Lookup table"),div);
|
||||
formInputs.add(t("Store"), new Input(STORE,isSet(store)?store.name():""));
|
||||
return super.properties(preForm, formInputs, postForm,errors);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (isSet(store,lookupTable)) return t("Set {} to value from {}",store.name(),lookupTable);
|
||||
if (isSet(store,lookupTable)) return t("Set \"{}\" to value from {}",store.name(),lookupTable);
|
||||
return t("[Click here to setup look-up]");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user