working on stretchable tiles
This commit is contained in:
@@ -6,8 +6,13 @@ html{
|
||||
height: 100%;
|
||||
}
|
||||
body{
|
||||
min-height: 100%;
|
||||
background: #c6dbd2;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
#plan{
|
||||
background: #c6dbd2;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.tile{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const ADD = 'add';
|
||||
const MOVE = 'move';
|
||||
const SQUARE = 30;
|
||||
const BODY = 'body';
|
||||
const BODY = '#plan';
|
||||
const DIV = 'DIV';
|
||||
const SVG = 'svg';
|
||||
const PLAN = 'plan';
|
||||
@@ -137,6 +137,7 @@ function savePlan(ev){
|
||||
|
||||
window.onload = function () {
|
||||
var isDragging = false;
|
||||
console.log($(BODY).each(function(){console.log(this)}));
|
||||
$('.menu > div').click(closeMenu);
|
||||
$('.menu .addtile .list svg').click(enableAdding);
|
||||
$('.menu .move .list div').click(enableMove);
|
||||
|
||||
@@ -3,5 +3,6 @@ Added {} : {} hinzugefügt
|
||||
Add tile : Kachel hinzufügen
|
||||
Plan saved as "{}". : Plan als „{}“ gespeichert.
|
||||
Properties : Eigenschaften
|
||||
Properties of {} @ ({},{}) : Eigenschaften von {} @ ({},{})
|
||||
Save plan : Plan speichern
|
||||
Unknown action\: {} : Unbekannte Aktion: {}
|
||||
@@ -107,7 +107,7 @@ public class Application {
|
||||
try {
|
||||
if (!params.isEmpty()) {
|
||||
send(client,plan.process(params));
|
||||
} else send(client,plan.html().style("css/style.css").js("js/jquery-3.5.1.min.js").js("js/plan.js"));
|
||||
} else send(client,plan.html());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error during sendPlan(): {}",e);
|
||||
send(client,new Page().append(e.getMessage()));
|
||||
|
||||
@@ -56,6 +56,7 @@ public class Plan {
|
||||
private static final String WEST = "west";
|
||||
private static final String SOUTH = "south";
|
||||
private static final String NORTH = "north";
|
||||
private static final String ACTION_UPDATE = "update";
|
||||
|
||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||
|
||||
@@ -74,8 +75,6 @@ public class Plan {
|
||||
clazz = tc.getName().replace(".Tile", "."+clazz);
|
||||
Tile tile = (Tile) tc.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
||||
set(x, y, tile);
|
||||
for (int i=1; i<tile.len(); i++) set(x+i,y,new Shadow(tile));
|
||||
for (int i=1; i<tile.height(); i++) set(x,y+1,new Shadow(tile));
|
||||
|
||||
return tile;
|
||||
}
|
||||
@@ -86,7 +85,7 @@ public class Plan {
|
||||
}
|
||||
|
||||
public Page html() throws IOException {
|
||||
Page page = new Page();
|
||||
Page page = new Page().append("<div id=\"plan\">");
|
||||
for (Entry<Integer, HashMap<Integer, Tile>> column : tiles.entrySet()) {
|
||||
int x = column.getKey();
|
||||
for (Entry<Integer, Tile> row : column.getValue().entrySet()) {
|
||||
@@ -95,7 +94,7 @@ public class Plan {
|
||||
if (tile != null) page.append("\t\t"+tile.tag()+"\n");
|
||||
}
|
||||
}
|
||||
return page.append(menu()).append(messages());
|
||||
return page.append(menu()).append(messages()).append("</div>").style("css/style.css").js("js/jquery-3.5.1.min.js").js("js/plan.js");
|
||||
}
|
||||
|
||||
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
@@ -195,6 +194,8 @@ public class Plan {
|
||||
return propMenu(params.get(X),params.get(Y));
|
||||
case ACTION_SAVE:
|
||||
return saveTo(params.get(NAME));
|
||||
case ACTION_UPDATE:
|
||||
return update(params);
|
||||
default:
|
||||
LOG.warn("Unknown action: {}",action);
|
||||
}
|
||||
@@ -204,6 +205,16 @@ public class Plan {
|
||||
}
|
||||
}
|
||||
|
||||
private Page update(HashMap<String, String> params) throws IOException {
|
||||
return update(Integer.parseInt(params.get("x")),Integer.parseInt(params.get("y")),params);
|
||||
}
|
||||
|
||||
private Page update(int x,int y, HashMap<String, String> params) throws IOException {
|
||||
Tile tile = get(x,y);
|
||||
if (tile != null) set(x,y,tile.update(params));
|
||||
return this.html();
|
||||
}
|
||||
|
||||
private Tag propMenu(String x, String y) {
|
||||
return propMenu(Integer.parseInt(x),Integer.parseInt(y));
|
||||
}
|
||||
@@ -239,7 +250,11 @@ public class Plan {
|
||||
tiles.put(x, column);
|
||||
}
|
||||
old = column.remove(y);
|
||||
if (tile != null && !(tile instanceof Eraser)) column.put(y,tile.position(x, y));
|
||||
if (tile != null && !(tile instanceof Eraser)) {
|
||||
column.put(y,tile.position(x, y));
|
||||
for (int i=1; i<tile.len(); i++) set(x+i,y,new Shadow(tile));
|
||||
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
|
||||
}
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
14
src/main/java/de/srsoftware/web4rail/tags/Form.java
Normal file
14
src/main/java/de/srsoftware/web4rail/tags/Form.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package de.srsoftware.web4rail.tags;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class Form extends Tag {
|
||||
|
||||
private static final long serialVersionUID = 3518580733330482303L;
|
||||
|
||||
public Form() {
|
||||
super("form");
|
||||
attr("method","POST");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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