working on stretchable tiles
This commit is contained in:
@@ -1,4 +1,24 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class StraightH extends StretchableTile{
|
||||
|
||||
@Override
|
||||
public int len() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag tag() throws IOException {
|
||||
Tag tag = super.tag();
|
||||
if (length>1) {
|
||||
String style = tag.get("style");
|
||||
tag.style(style.trim()+" width: "+(30*length)+"px;");
|
||||
tag.attr("preserveAspectRatio","none");
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class StraightV extends StretchableTile{
|
||||
|
||||
@Override
|
||||
public int height() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag tag() throws IOException {
|
||||
Tag tag = super.tag();
|
||||
if (length>1) {
|
||||
LOG.debug("{}.tag: length = {}",getClass().getSimpleName(),length);
|
||||
String style = tag.get("style");
|
||||
tag.style(style.trim()+" height: "+(30*length)+"px;");
|
||||
tag.attr("preserveAspectRatio","none");
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@ package de.srsoftware.web4rail.tiles;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Application;
|
||||
@@ -15,6 +19,7 @@ public abstract class Tile {
|
||||
|
||||
protected int x = -1,y = -1;
|
||||
protected HashSet<String> classes = new HashSet<String>();
|
||||
protected static Logger LOG = LoggerFactory.getLogger(Tile.class);
|
||||
|
||||
public Tile() {
|
||||
classes.add("tile");
|
||||
@@ -47,7 +52,7 @@ public abstract class Tile {
|
||||
.size(100,100)
|
||||
.attr("name", getClass().getSimpleName())
|
||||
.attr("viewbox", "0 0 100 100");
|
||||
if (x>-1) svg.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
if (x>-1) svg.style("left: "+(30*x)+"px; top: "+(30*y)+"px;");
|
||||
|
||||
File file = new File(System.getProperty("user.dir")+"/resources/svg/"+getClass().getSimpleName()+".svg");
|
||||
if (file.exists()) {
|
||||
@@ -71,7 +76,7 @@ public abstract class Tile {
|
||||
return svg;
|
||||
}
|
||||
|
||||
private static String t(String txt, Object...fills) {
|
||||
protected static String t(String txt, Object...fills) {
|
||||
return Translation.get(Application.class, txt, fills);
|
||||
}
|
||||
|
||||
@@ -79,4 +84,9 @@ public abstract class Tile {
|
||||
public String toString() {
|
||||
return t("{}({},{})",getClass().getSimpleName(),x,y) ;
|
||||
}
|
||||
|
||||
public Tile update(HashMap<String, String> params) {
|
||||
LOG.debug("{}.update({})",getClass().getSimpleName(),params);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user