working on svg
@@ -7,8 +7,8 @@
|
||||
|
||||
svg polygon,
|
||||
svg rect{
|
||||
fill:rgb(0,0,255);
|
||||
stroke-width:3;
|
||||
fill:rgb(0,255,255);
|
||||
stroke-width:5;
|
||||
stroke:rgb(0,0,0);
|
||||
}
|
||||
|
||||
|
||||
64
pom.xml
Normal file
@@ -0,0 +1,64 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<name>Web4Rail</name>
|
||||
<description>Java Model Railway Control</description>
|
||||
<url>https://github.com/StephanRichter/Web4Rail</url>
|
||||
<organization>
|
||||
<name>SRSoftware</name>
|
||||
<url>https://srsoftware.de</url>
|
||||
</organization>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Stephan Richter</name>
|
||||
<email>s.richter@srsoftware.de</email>
|
||||
<organization>SRSoftware</organization>
|
||||
<organizationUrl>http://www.srsoftware.de</organizationUrl>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>tools</artifactId>
|
||||
<version>1.1.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>local-config</artifactId>
|
||||
<version>0.0.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>tools.translations</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<release>11</release>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -20,6 +20,7 @@ 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.TurnoutSE;
|
||||
@@ -42,6 +43,7 @@ public class Application {
|
||||
plan.set(3, 1, new TurnoutSE());
|
||||
plan.set(3, 0, new TurnoutSW());
|
||||
plan.set(2, 0, new EndE());
|
||||
plan.set(4, 1, new EndW());
|
||||
InetSocketAddress addr = new InetSocketAddress(config.getOrAdd("port", 8080));
|
||||
HttpServer server = HttpServer.create(addr, 0);
|
||||
server.createContext("/plan", client -> sendPlan(client));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.srsoftware.web4rail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class Plan {
|
||||
return column == null ? null : column.get(y);
|
||||
}
|
||||
|
||||
public Page html() {
|
||||
public Page html() throws IOException {
|
||||
Page page = new Page();
|
||||
for (Entry<Integer, HashMap<Integer, Tile>> column : tiles.entrySet()) {
|
||||
int x = column.getKey();
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class DiagNE extends Tile{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("polygon")
|
||||
.attr("points","35,0 65,0 100,35 100,65")
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,5 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class DiagSW extends Tile{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("polygon")
|
||||
.attr("points","0,35 65,100 35,100 0,65")
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,4 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class DiagWN extends Tile{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("polygon")
|
||||
.attr("points","35,0 65,0 0,65 0,35")
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,4 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class EndE extends Tile{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("rect")
|
||||
.size(60,30)
|
||||
.pos(40,35)
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
5
src/main/java/de/srsoftware/web4rail/tiles/EndW.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class EndW extends Tile{}
|
||||
@@ -1,21 +1,4 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class StraightH extends StretchableTile{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("rect")
|
||||
.size(100,30)
|
||||
.pos(0,35)
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class StraightV extends StretchableTile{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("rect")
|
||||
.size(30,100)
|
||||
.pos(35,0)
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
@@ -21,20 +25,33 @@ public abstract class Tile {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String html() {
|
||||
public String html() throws IOException {
|
||||
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
new Tag("title").content(t("No display defined for this tile ({})",getClass().getSimpleName())).addTo(svg);
|
||||
|
||||
new Tag("text")
|
||||
File file = new File(System.getProperty("user.dir")+"/svg/"+getClass().getSimpleName()+".svg");
|
||||
if (file.exists()) {
|
||||
Scanner scanner = new Scanner(file, StandardCharsets.UTF_8);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("<svg") || line.endsWith("svg>")) continue;
|
||||
sb.append(line+"\n");
|
||||
}
|
||||
scanner.close();
|
||||
svg.content(sb.toString());
|
||||
} else {
|
||||
new Tag("title").content(t("No display defined for this tile ({})",getClass().getSimpleName())).addTo(svg);
|
||||
new Tag("text")
|
||||
.pos(35,70)
|
||||
.content("?")
|
||||
.addTo(svg);
|
||||
|
||||
}
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
@@ -1,25 +1,4 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class TurnoutSE extends Turnout{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("rect")
|
||||
.size(30,100)
|
||||
.pos(35,0)
|
||||
.addTo(svg);
|
||||
|
||||
new Tag("polygon")
|
||||
.attr("points","35,100 100,35 100,65 65,100")
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,5 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class TurnoutSW extends Turnout{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("rect")
|
||||
.size(30,100)
|
||||
.pos(35,0)
|
||||
.addTo(svg);
|
||||
|
||||
new Tag("polygon")
|
||||
.attr("points","0,35 65,100 35,100 0,65")
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,5 @@
|
||||
package de.srsoftware.web4rail.tiles;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class TurnoutWS extends Turnout{
|
||||
public String html() {
|
||||
Tag svg = new Tag("svg")
|
||||
.id("tile-"+x+"-"+y)
|
||||
.clazz(classes)
|
||||
.size(100,100)
|
||||
.attr("viewbox", "0 0 100 100")
|
||||
.style("left: "+(30*x)+"px; top: "+(30*y)+"px");
|
||||
|
||||
new Tag("rect")
|
||||
.size(100,30)
|
||||
.pos(0,35)
|
||||
.addTo(svg);
|
||||
|
||||
new Tag("polygon")
|
||||
.attr("points","0,35 65,100 35,100 0,65")
|
||||
.addTo(svg);
|
||||
|
||||
return svg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
3
svg/DiagNE.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<polygon points="35,0 65,0 100,35 100,65" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 105 B |
3
svg/DiagSW.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<polygon points="0,35 65,100 35,100 0,65" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 105 B |
3
svg/DiagWN.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<polygon points="35,0 65,0 0,65 0,35" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 101 B |
3
svg/EndE.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="40" y="35" width="60" height="30" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 107 B |
3
svg/EndW.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="60" height="30" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 106 B |
3
svg/StraightH.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="100" height="30" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 107 B |
3
svg/StraightV.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="35" height="100" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 107 B |
4
svg/TurnoutSE.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="30" height="100" />
|
||||
<polygon points="35,100 100,35 100,65 65,100" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 156 B |
4
svg/TurnoutSW.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="35" y="0" width="30" height="100" />
|
||||
<polygon points="0,35 65,100 35,100 0,65" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 152 B |
4
svg/TurnoutWS.svg
Normal file
@@ -0,0 +1,4 @@
|
||||
<svg width="100" height="100" viewbox="0 0 100 100">
|
||||
<rect x="0" y="35" width="100" height="30" />
|
||||
<polygon points="0,35 65,100 35,100 0,65" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 152 B |