working on stretchable tiles

This commit is contained in:
Stephan Richter
2020-09-14 01:41:01 +02:00
parent 44abb92ed5
commit 10837473ce
10 changed files with 146 additions and 11 deletions

View File

@@ -1,5 +1,54 @@
package de.srsoftware.web4rail.tiles;
import java.util.HashMap;
import java.util.Map.Entry;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Window;
import de.srsoftware.web4rail.tags.Form;
public abstract class StretchableTile extends Tile {
private static final String LENGTH = "length";
public int length = 1;
public Tag propMenu() {
Window menu = new Window("tile-properties",t("Properties of {} @ ({},{})",getClass().getSimpleName(),x,y));
Form form = new Form();
new Tag("input").attr("type", "hidden").attr("name","action").attr("value", "update").addTo(form);
new Tag("input").attr("type", "hidden").attr("name","x").attr("value", x).addTo(form);
new Tag("input").attr("type", "hidden").attr("name","y").attr("value", y).addTo(form);
Tag label = new Tag("label").content(t("length:"));
new Tag("input").attr("type", "number").attr("name","length").attr("value", length).addTo(label);
label.addTo(form);
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
form.addTo(menu);
return menu;
}
private void setLength(String value) {
try {
setLength(Integer.parseInt(value));
} catch (NumberFormatException nfe) {
LOG.warn("{} is not a valid length!",value);
}
}
public void setLength(int len) {
this.length = Math.max(1, len);
}
@Override
public Tile update(HashMap<String, String> params) {
super.update(params);
for (Entry<String, String> entry : params.entrySet()) {
switch (entry.getKey()) {
case LENGTH:
setLength(entry.getValue());
break;
}
}
return this;
}
}