preparing js
@@ -1,17 +0,0 @@
|
|||||||
.tile{
|
|
||||||
border: 1px solid black;
|
|
||||||
width: 30px;
|
|
||||||
height: 30px;
|
|
||||||
position: absolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg polygon,
|
|
||||||
svg rect{
|
|
||||||
fill:rgb(0,255,255);
|
|
||||||
stroke-width:5;
|
|
||||||
stroke:rgb(0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
svg text{
|
|
||||||
font-size: 50px;
|
|
||||||
}
|
|
||||||
44
resources/css/style.css
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
.tile{
|
||||||
|
border: 1px solid black;
|
||||||
|
width: 30px;
|
||||||
|
height: 30px;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
svg polygon,
|
||||||
|
svg rect{
|
||||||
|
fill:rgb(0,255,255);
|
||||||
|
stroke-width:5;
|
||||||
|
stroke:rgb(0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
svg text{
|
||||||
|
font-size: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu{
|
||||||
|
position: fixed;
|
||||||
|
bottom: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu .tile{
|
||||||
|
background: white;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu .tile .list{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu .tile:hover .list{
|
||||||
|
position: fixed;
|
||||||
|
right: 0;
|
||||||
|
height: 30px;
|
||||||
|
left: 0;
|
||||||
|
bottom: 40px;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu .tile .list .tile{
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
2
resources/js/jquery-3.5.1.slim.min.js
vendored
Normal file
1
resources/js/plan.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
alert('hallo!');
|
||||||
|
Before Width: | Height: | Size: 105 B After Width: | Height: | Size: 105 B |
|
Before Width: | Height: | Size: 105 B After Width: | Height: | Size: 105 B |
|
Before Width: | Height: | Size: 101 B After Width: | Height: | Size: 101 B |
|
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 107 B |
|
Before Width: | Height: | Size: 106 B After Width: | Height: | Size: 106 B |
|
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 107 B |
|
Before Width: | Height: | Size: 107 B After Width: | Height: | Size: 107 B |
|
Before Width: | Height: | Size: 156 B After Width: | Height: | Size: 156 B |
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 152 B |
|
Before Width: | Height: | Size: 152 B After Width: | Height: | Size: 152 B |
@@ -1,5 +1,6 @@
|
|||||||
package de.srsoftware.web4rail;
|
package de.srsoftware.web4rail;
|
||||||
|
|
||||||
|
import java.awt.Desktop;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -30,9 +31,11 @@ import de.srsoftware.web4rail.tiles.TurnoutWS;
|
|||||||
public class Application {
|
public class Application {
|
||||||
private static Plan plan;
|
private static Plan plan;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Application.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Application.class);
|
||||||
|
private static final String PORT = "port";
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
||||||
|
LOG.debug("Config: {}",config);
|
||||||
plan = new Plan();
|
plan = new Plan();
|
||||||
plan.set(0, 0, new StraightH());
|
plan.set(0, 0, new StraightH());
|
||||||
plan.set(1, 0, new DiagSW());
|
plan.set(1, 0, new DiagSW());
|
||||||
@@ -44,18 +47,20 @@ public class Application {
|
|||||||
plan.set(3, 0, new TurnoutSW());
|
plan.set(3, 0, new TurnoutSW());
|
||||||
plan.set(2, 0, new EndE());
|
plan.set(2, 0, new EndE());
|
||||||
plan.set(4, 1, new EndW());
|
plan.set(4, 1, new EndW());
|
||||||
InetSocketAddress addr = new InetSocketAddress(config.getOrAdd("port", 8080));
|
InetSocketAddress addr = new InetSocketAddress(config.getOrAdd(PORT, 8080));
|
||||||
HttpServer server = HttpServer.create(addr, 0);
|
HttpServer server = HttpServer.create(addr, 0);
|
||||||
server.createContext("/plan", client -> sendPlan(client));
|
server.createContext("/plan", client -> sendPlan(client));
|
||||||
server.createContext("/css" , client -> sendFile(client));
|
server.createContext("/css" , client -> sendFile(client));
|
||||||
server.createContext("/svg" , client -> sendFile(client));
|
server.createContext("/js" , client -> sendFile(client));
|
||||||
server.setExecutor(java.util.concurrent.Executors.newCachedThreadPool());
|
server.setExecutor(java.util.concurrent.Executors.newCachedThreadPool());
|
||||||
server.start();
|
server.start();
|
||||||
|
Desktop.getDesktop().browse(URI.create("http://localhost:"+config.getInt(PORT)+"/plan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendFile(HttpExchange client) throws IOException {
|
private static void sendFile(HttpExchange client) throws IOException {
|
||||||
URI uri = client.getRequestURI();
|
URI uri = client.getRequestURI();
|
||||||
File file = new File(System.getProperty("user.dir")+uri);
|
File file = new File(System.getProperty("user.dir")+"/resources"+uri);
|
||||||
|
LOG.debug("requesting file: {}",file);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
client.sendResponseHeaders(200, file.length());
|
client.sendResponseHeaders(200, file.length());
|
||||||
OutputStream out = client.getResponseBody();
|
OutputStream out = client.getResponseBody();
|
||||||
@@ -70,6 +75,7 @@ public class Application {
|
|||||||
|
|
||||||
private static void sendError(HttpExchange client, int code, String msg) throws IOException {
|
private static void sendError(HttpExchange client, int code, String msg) throws IOException {
|
||||||
client.sendResponseHeaders(code, msg.length());
|
client.sendResponseHeaders(code, msg.length());
|
||||||
|
LOG.error(msg);
|
||||||
OutputStream out = client.getResponseBody();
|
OutputStream out = client.getResponseBody();
|
||||||
out.write(msg.getBytes(StandardCharsets.UTF_8));
|
out.write(msg.getBytes(StandardCharsets.UTF_8));
|
||||||
out.close();
|
out.close();
|
||||||
@@ -80,7 +86,7 @@ public class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void sendPlan(HttpExchange client) throws IOException {
|
private static void sendPlan(HttpExchange client) throws IOException {
|
||||||
send(client,plan.html().style("css/style.css"));
|
send(client,plan.html().style("css/style.css").js("jquery-3.5.1.slim.min.js").js("js/plan.js"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void send(HttpExchange client, Page response) throws IOException {
|
private static void send(HttpExchange client, Page response) throws IOException {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import de.srsoftware.tools.Tag;
|
|||||||
public class Page {
|
public class Page {
|
||||||
private StringBuffer buf;
|
private StringBuffer buf;
|
||||||
private Vector<String> cssFiles = new Vector<String>();
|
private Vector<String> cssFiles = new Vector<String>();
|
||||||
|
private Vector<String> jsFiles = new Vector<String>();
|
||||||
|
|
||||||
public Page() {
|
public Page() {
|
||||||
buf = new StringBuffer();
|
buf = new StringBuffer();
|
||||||
@@ -26,6 +27,9 @@ public class Page {
|
|||||||
for (String cssFile : cssFiles) {
|
for (String cssFile : cssFiles) {
|
||||||
sb.append("\t\t"+new Tag("link").attr("rel", "stylesheet").attr("type", "text/css").attr("href", cssFile)+"\n");
|
sb.append("\t\t"+new Tag("link").attr("rel", "stylesheet").attr("type", "text/css").attr("href", cssFile)+"\n");
|
||||||
}
|
}
|
||||||
|
for (String jsFile : jsFiles) {
|
||||||
|
sb.append("\t\t"+new Tag("script").attr("type", "text/javascript").attr("src", jsFile).content("")+"\n");
|
||||||
|
}
|
||||||
return sb.append("\t</head>\n");
|
return sb.append("\t</head>\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,4 +54,9 @@ public class Page {
|
|||||||
cssFiles.add(cssPath);
|
cssFiles.add(cssPath);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Page js(String jsPath) {
|
||||||
|
jsFiles.add(jsPath);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ import java.io.IOException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.tiles.StraightH;
|
||||||
|
import de.srsoftware.web4rail.tiles.StraightV;
|
||||||
import de.srsoftware.web4rail.tiles.Tile;
|
import de.srsoftware.web4rail.tiles.Tile;
|
||||||
|
|
||||||
public class Plan {
|
public class Plan {
|
||||||
@@ -36,6 +39,19 @@ public class Plan {
|
|||||||
page.append("\t\t"+tile.html()+"\n");
|
page.append("\t\t"+tile.html()+"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
page.append(menu());
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Tag menu() throws IOException {
|
||||||
|
Tag menu = new Tag("div").clazz("menu");
|
||||||
|
Tag tileMenu = new Tag("div").clazz("tile").content("Add tile");
|
||||||
|
|
||||||
|
StringBuffer tiles = new StringBuffer();
|
||||||
|
tiles.append(new StraightH().html());
|
||||||
|
tiles.append(new StraightV().html());
|
||||||
|
new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu).addTo(menu);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,11 @@ public abstract class Tile {
|
|||||||
.id("tile-"+x+"-"+y)
|
.id("tile-"+x+"-"+y)
|
||||||
.clazz(classes)
|
.clazz(classes)
|
||||||
.size(100,100)
|
.size(100,100)
|
||||||
|
.attr("name", getClass().getSimpleName())
|
||||||
.attr("viewbox", "0 0 100 100")
|
.attr("viewbox", "0 0 100 100")
|
||||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||||
|
|
||||||
File file = new File(System.getProperty("user.dir")+"/svg/"+getClass().getSimpleName()+".svg");
|
File file = new File(System.getProperty("user.dir")+"/resources/svg/"+getClass().getSimpleName()+".svg");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
Scanner scanner = new Scanner(file, StandardCharsets.UTF_8);
|
Scanner scanner = new Scanner(file, StandardCharsets.UTF_8);
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|||||||