working on Java-Implementation

This commit is contained in:
Stephan Richter
2020-09-07 00:28:04 +02:00
parent a9e0f2b3a7
commit 3583a62667
26 changed files with 72417 additions and 147 deletions

View File

@@ -2,15 +2,5 @@ package de.srsoftware.web4rail.tiles;
public class DiagES extends Tile{
@Override
public boolean hasConnector(Direction direction) {
switch (direction) {
case SOUTH:
case EAST:
return true;
default:
return false;
}
}
}

View File

@@ -1,16 +1,20 @@
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");
@Override
public boolean hasConnector(Direction direction) {
switch (direction) {
case NORTH:
case EAST:
return true;
default:
return false;
}
}
new Tag("polygon")
.attr("points","35,0 65,0 100,35 100,65")
.addTo(svg);
return svg.toString();
}
}

View File

@@ -1,16 +1,20 @@
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");
@Override
public boolean hasConnector(Direction direction) {
switch (direction) {
case SOUTH:
case WEST:
return true;
default:
return false;
}
}
new Tag("polygon")
.attr("points","0,35 65,100 35,100 0,65")
.addTo(svg);
return svg.toString();
}
}

View File

@@ -1,16 +1,20 @@
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");
@Override
public boolean hasConnector(Direction direction) {
switch (direction) {
case NORTH:
case WEST:
return true;
default:
return false;
}
}
new Tag("polygon")
.attr("points","35,0 65,0 0,65 0,35")
.addTo(svg);
return svg.toString();
}
}

View File

@@ -0,0 +1,22 @@
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();
}
}

View File

@@ -1,14 +1,21 @@
package de.srsoftware.web4rail.tiles;
import de.srsoftware.tools.Tag;
public class StraightH extends StretchableTile{
@Override
public boolean hasConnector(Direction direction) {
switch (direction) {
case EAST:
case WEST:
return true;
default:
return false;
}
}
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();
}
}

View File

@@ -1,15 +1,21 @@
package de.srsoftware.web4rail.tiles;
public class StraightV extends StretchableTile{
import de.srsoftware.tools.Tag;
@Override
public boolean hasConnector(Direction direction) {
switch (direction) {
case NORTH:
case SOUTH:
return true;
default:
return false;
}
}
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();
}
}

View File

@@ -1,55 +1,46 @@
package de.srsoftware.web4rail.tiles;
import java.util.HashMap;
import java.util.HashSet;
import de.keawe.tools.translations.Translation;
import de.srsoftware.tools.Tag;
import de.srsoftware.web4rail.Application;
public abstract class Tile {
public enum Direction{
NORTH,SOUTH,EAST,WEST;
}
private class Position {
int x,y;
protected int x,y;
protected HashSet<String> classes = new HashSet<String>();
public Tile() {
classes.add("tile");
}
Position position;
private HashMap<Direction,Tile> neighbours = new HashMap();
public abstract boolean hasConnector(Direction direction);
public boolean connect(Direction direction, Tile neighbour) {
if (hasConnector(direction)) {
switch (direction) {
case NORTH:
neighbour.neighbours.put(Direction.SOUTH, this);
neighbour.position.x = position.x;
neighbour.position.y = position.y-1;
case SOUTH:
neighbour.neighbours.put(Direction.NORTH, this);
neighbour.position.x = position.x;
neighbour.position.y = position.y+1;
case EAST:
neighbour.neighbours.put(Direction.WEST, this);
neighbour.position.x = position.x+1;
neighbour.position.y = position.y;
case WEST:
neighbour.neighbours.put(Direction.EAST, this);
neighbour.position.x = position.x-1;
neighbour.position.y = position.y;
}
neighbours.put(direction, neighbour);
return true;
}
return false;
}
public Tile neighbour(Direction direction) {
return neighbours.get(direction);
public Tile position(int x, int y) {
this.x = x;
this.y = y;
return this;
}
public Tile position(int x, int y) {
position.x = x;
position.y = y;
return this;
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("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();
}
private String t(String txt, Object...fills) {
return Translation.get(Application.class, txt, fills);
}
}

View File

@@ -2,9 +2,5 @@ package de.srsoftware.web4rail.tiles;
public class TurnoutEN extends Turnout{
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.SOUTH;
}
}

View File

@@ -2,9 +2,4 @@ package de.srsoftware.web4rail.tiles;
public class TurnoutES extends Turnout{
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.NORTH;
}
}

View File

@@ -2,9 +2,5 @@ package de.srsoftware.web4rail.tiles;
public class TurnoutNE extends Turnout{
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.WEST;
}
}

View File

@@ -2,9 +2,5 @@ package de.srsoftware.web4rail.tiles;
public class TurnoutNW extends Turnout{
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.EAST;
}
}

View File

@@ -1,10 +1,25 @@
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");
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.WEST;
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();
}
}

View File

@@ -1,10 +1,25 @@
package de.srsoftware.web4rail.tiles;
public class TurnoutSW extends Turnout{
import de.srsoftware.tools.Tag;
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.EAST;
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();
}
}

View File

@@ -2,9 +2,6 @@ package de.srsoftware.web4rail.tiles;
public class TurnoutWN extends Turnout{
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.SOUTH;
}
}

View File

@@ -1,10 +1,25 @@
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");
@Override
public boolean hasConnector(Direction direction) {
return direction != Direction.NORTH;
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();
}
}