added new action AddRemoveTag
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.2.65</version>
|
<version>1.2.66</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ add new car : neuen Waggon anlegen
|
|||||||
Add new custom field : neues benutzerdefiniertes Feld hinzufügen
|
Add new custom field : neues benutzerdefiniertes Feld hinzufügen
|
||||||
add new locomotive : neue Lok anlegen
|
add new locomotive : neue Lok anlegen
|
||||||
add new train : neuen Zug anlegen
|
add new train : neuen Zug anlegen
|
||||||
|
Add tag "{}" to train : Markierung "{}" zu Zug hinzufügen
|
||||||
Add tile : Kachel hinzufügen
|
Add tile : Kachel hinzufügen
|
||||||
|
AddRemoveTag : Markierung hinzufügen/entfernen
|
||||||
Address : Adresse
|
Address : Adresse
|
||||||
Address\: : Adresse:
|
Address\: : Adresse:
|
||||||
analyze : analysieren
|
analyze : analysieren
|
||||||
@@ -188,6 +190,7 @@ ReactivateContact : Kontakt reaktivieren
|
|||||||
Relay : Relais
|
Relay : Relais
|
||||||
Relays and Turnouts : Relais und Weichen
|
Relays and Turnouts : Relais und Weichen
|
||||||
Relay/Turnout : Relais/Weiche
|
Relay/Turnout : Relais/Weiche
|
||||||
|
Remove tag "{}" from train : Markierung "{}" von Zug entfernen
|
||||||
Report Issue : Problem melden
|
Report Issue : Problem melden
|
||||||
reverse : wenden
|
reverse : wenden
|
||||||
Reversed {}. : {} umgedreht.
|
Reversed {}. : {} umgedreht.
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ public abstract class Action extends BaseClass {
|
|||||||
|
|
||||||
public static List<Class<? extends Action>> classes() {
|
public static List<Class<? extends Action>> classes() {
|
||||||
return List.of(
|
return List.of(
|
||||||
|
AddRemoveTag.class,
|
||||||
|
BrakeCancel.class,
|
||||||
BrakeStart.class,
|
BrakeStart.class,
|
||||||
BrakeStop.class,
|
BrakeStop.class,
|
||||||
BrakeCancel.class,
|
|
||||||
ConditionalAction.class,
|
ConditionalAction.class,
|
||||||
DelayedAction.class,
|
DelayedAction.class,
|
||||||
DetermineTrainInBlock.class,
|
DetermineTrainInBlock.class,
|
||||||
@@ -85,7 +86,7 @@ public abstract class Action extends BaseClass {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean corresponsTo(Action other) {
|
public boolean correspondsTo(Action other) {
|
||||||
return this.toString().equals(other.toString());
|
return this.toString().equals(other.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class ActionList extends Action implements Iterable<Action>{
|
|||||||
public void merge(ActionList oldActions) {
|
public void merge(ActionList oldActions) {
|
||||||
for (Action oldAction : oldActions.actions) {
|
for (Action oldAction : oldActions.actions) {
|
||||||
for (Action newAction : actions) {
|
for (Action newAction : actions) {
|
||||||
if (oldAction.corresponsTo(newAction)) {
|
if (oldAction.correspondsTo(newAction)) {
|
||||||
actions.remove(newAction);
|
actions.remove(newAction);
|
||||||
LOG.debug("new action {} replaced by {}",newAction,oldAction);
|
LOG.debug("new action {} replaced by {}",newAction,oldAction);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package de.srsoftware.web4rail.actions;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.BaseClass;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
import de.srsoftware.web4rail.tags.Fieldset;
|
||||||
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
|
import de.srsoftware.web4rail.tags.Radio;
|
||||||
|
|
||||||
|
public class AddRemoveTag extends Action{
|
||||||
|
|
||||||
|
private static final String TAG = "tag";
|
||||||
|
|
||||||
|
public AddRemoveTag(BaseClass parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String tag = "test";
|
||||||
|
private boolean add = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean fire(Context context) {
|
||||||
|
if (isNull(context.train())) return false;
|
||||||
|
if (add) {
|
||||||
|
context.train().tags().add(tag);
|
||||||
|
} else {
|
||||||
|
context.train().tags().remove(tag);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject json() {
|
||||||
|
JSONObject json = super.json();
|
||||||
|
json.put(TAG, tag);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action load(JSONObject json) {
|
||||||
|
super.load(json);
|
||||||
|
tag = json.getString(TAG);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Window properties(List<Fieldset> preForm, FormInput formInputs, List<Fieldset> postForm) {
|
||||||
|
formInputs.add(t("Tag"),new Input(TAG, tag));
|
||||||
|
Tag div = new Tag("div");
|
||||||
|
new Radio(TYPE, ACTION_ADD, t("add"), add).addTo(div);
|
||||||
|
new Radio(TYPE, ACTION_DROP, t("delete"), !add).addTo(div);
|
||||||
|
formInputs.add(t("Action"),div);
|
||||||
|
return super.properties(preForm, formInputs, postForm);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return add ? t("Add tag \"{}\" to train",tag) : t("Remove tag \"{}\" from train",tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object update(HashMap<String, String> params) {
|
||||||
|
tag = params.get(TAG);
|
||||||
|
add = ACTION_ADD.equals(params.get(TYPE));
|
||||||
|
return super.update(params);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ public class SetSpeed extends Action{
|
|||||||
private int speed = 0;
|
private int speed = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean corresponsTo(Action other) {
|
public boolean correspondsTo(Action other) {
|
||||||
return other instanceof SetSpeed;
|
return other instanceof SetSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user