implemented editing of layout in browser
This commit is contained in:
@@ -8,6 +8,7 @@ import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -62,6 +63,7 @@ public class Application {
|
||||
File file = new File(System.getProperty("user.dir")+"/resources"+uri);
|
||||
LOG.debug("requesting file: {}",file);
|
||||
if (file.exists()) {
|
||||
client.getResponseHeaders().add("Content-Type", Files.probeContentType(file.toPath()));
|
||||
client.sendResponseHeaders(200, file.length());
|
||||
OutputStream out = client.getResponseBody();
|
||||
FileInputStream in = new FileInputStream(file);
|
||||
@@ -86,7 +88,7 @@ public class Application {
|
||||
}
|
||||
|
||||
private static void sendPlan(HttpExchange client) throws IOException {
|
||||
send(client,plan.html().style("css/style.css").js("jquery-3.5.1.slim.min.js").js("js/plan.js"));
|
||||
send(client,plan.html().style("css/style.css").js("js/jquery-3.5.1.slim.min.js").js("js/plan.js"));
|
||||
}
|
||||
|
||||
private static void send(HttpExchange client, Page response) throws IOException {
|
||||
|
||||
@@ -24,6 +24,7 @@ public class Page {
|
||||
StringBuffer sb = new StringBuffer()
|
||||
.append("<html>\n")
|
||||
.append("\t<head>\n");
|
||||
sb.append("\t\t"+new Tag("meta").attr("charset", "UTF-8")+"\n");
|
||||
for (String cssFile : cssFiles) {
|
||||
sb.append("\t\t"+new Tag("link").attr("rel", "stylesheet").attr("type", "text/css").attr("href", cssFile)+"\n");
|
||||
}
|
||||
|
||||
@@ -5,9 +5,18 @@ import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.tiles.DiagES;
|
||||
import de.srsoftware.web4rail.tiles.DiagNE;
|
||||
import de.srsoftware.web4rail.tiles.DiagSW;
|
||||
import de.srsoftware.web4rail.tiles.DiagWN;
|
||||
import de.srsoftware.web4rail.tiles.EndE;
|
||||
import de.srsoftware.web4rail.tiles.EndW;
|
||||
import de.srsoftware.web4rail.tiles.StraightH;
|
||||
import de.srsoftware.web4rail.tiles.StraightV;
|
||||
import de.srsoftware.web4rail.tiles.Tile;
|
||||
import de.srsoftware.web4rail.tiles.TurnoutSE;
|
||||
import de.srsoftware.web4rail.tiles.TurnoutSW;
|
||||
import de.srsoftware.web4rail.tiles.TurnoutWS;
|
||||
|
||||
public class Plan {
|
||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||
@@ -50,6 +59,15 @@ public class Plan {
|
||||
StringBuffer tiles = new StringBuffer();
|
||||
tiles.append(new StraightH().html());
|
||||
tiles.append(new StraightV().html());
|
||||
tiles.append(new DiagES().html());
|
||||
tiles.append(new DiagSW().html());
|
||||
tiles.append(new DiagNE().html());
|
||||
tiles.append(new DiagWN().html());
|
||||
tiles.append(new EndE().html());
|
||||
tiles.append(new EndW().html());
|
||||
tiles.append(new TurnoutSE().html());
|
||||
tiles.append(new TurnoutWS().html());
|
||||
tiles.append(new TurnoutSW().html());
|
||||
new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu).addTo(menu);
|
||||
|
||||
return menu;
|
||||
|
||||
@@ -12,7 +12,7 @@ import de.srsoftware.web4rail.Application;
|
||||
|
||||
public abstract class Tile {
|
||||
|
||||
protected int x,y;
|
||||
protected int x = -1,y = -1;
|
||||
protected HashSet<String> classes = new HashSet<String>();
|
||||
|
||||
public Tile() {
|
||||
@@ -28,12 +28,12 @@ public abstract class Tile {
|
||||
public String html() throws IOException {
|
||||
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.id((x!=-1 && y!=-1)?("tile-"+x+"-"+y):(getClass().getSimpleName()))
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("name", getClass().getSimpleName())
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
.attr("viewbox", "0 0 100 100");
|
||||
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()) {
|
||||
|
||||
Reference in New Issue
Block a user