preparing property dialog
This commit is contained in:
@@ -75,6 +75,23 @@ svg text{
|
|||||||
background: yellow;
|
background: yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tile-properties{
|
||||||
|
position: fixed;
|
||||||
|
top: 10px;
|
||||||
|
bottom: 10px;
|
||||||
|
left: 10px;
|
||||||
|
right: 10px;
|
||||||
|
background: yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.closebtn{
|
||||||
|
position: absolute;
|
||||||
|
right: 10px;
|
||||||
|
font-size: 30px;
|
||||||
|
background: gray;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
#Eraser polygon{
|
#Eraser polygon{
|
||||||
stroke: red;
|
stroke: red;
|
||||||
}
|
}
|
||||||
@@ -31,16 +31,34 @@ function addTile(x,y){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function bodyClick(ev){
|
function bodyClick(ev){
|
||||||
console.log('bodyClick:',ev);
|
//console.log('bodyClick:',ev);
|
||||||
switch (mode){
|
switch (mode){
|
||||||
case undefined:
|
case undefined:
|
||||||
case null: return;
|
case null:
|
||||||
|
return clickTile(ev.clientX,ev.clientY);
|
||||||
case ADD:
|
case ADD:
|
||||||
return addTile(ev.clientX,ev.clientY);
|
return addTile(ev.clientX,ev.clientY);
|
||||||
}
|
}
|
||||||
console.log(ev.clientX,ev.clientY);
|
console.log(ev.clientX,ev.clientY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clickTile(x,y){
|
||||||
|
console.log("clickTile:",x,y);
|
||||||
|
x = Math.floor(x/SQUARE);
|
||||||
|
y = Math.floor(y/SQUARE);
|
||||||
|
if ($('#tile-'+x+'-'+y).length > 0){
|
||||||
|
$.ajax({
|
||||||
|
url : PLAN,
|
||||||
|
method : POST,
|
||||||
|
data : {action:'openProps',x:x,y:y},
|
||||||
|
success: function(resp){
|
||||||
|
$('body').append($(resp));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function closeMenu(ev){
|
function closeMenu(ev){
|
||||||
console.log('closeMenu:',ev);
|
console.log('closeMenu:',ev);
|
||||||
if (selected != null) $(selected).css('border','');
|
if (selected != null) $(selected).css('border','');
|
||||||
|
|||||||
@@ -22,16 +22,6 @@ import com.sun.net.httpserver.HttpServer;
|
|||||||
|
|
||||||
import de.keawe.localconfig.Configuration;
|
import de.keawe.localconfig.Configuration;
|
||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
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;
|
|
||||||
import de.srsoftware.web4rail.tiles.TurnoutSW;
|
|
||||||
import de.srsoftware.web4rail.tiles.TurnoutWS;
|
|
||||||
|
|
||||||
public class Application {
|
public class Application {
|
||||||
private static Plan plan;
|
private static Plan plan;
|
||||||
@@ -42,18 +32,6 @@ public class Application {
|
|||||||
public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||||
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
||||||
LOG.debug("Config: {}",config);
|
LOG.debug("Config: {}",config);
|
||||||
plan = Plan.load("default.plan");
|
|
||||||
/*plan = new Plan();
|
|
||||||
plan.set(0, 0, new StraightH());
|
|
||||||
plan.set(1, 0, new DiagSW());
|
|
||||||
plan.set(1, 1, new StraightV());
|
|
||||||
plan.set(1, 2, new DiagNE());
|
|
||||||
plan.set(2, 2, new TurnoutWS());
|
|
||||||
plan.set(3, 2, new DiagWN());
|
|
||||||
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));
|
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));
|
||||||
@@ -61,6 +39,7 @@ public class Application {
|
|||||||
server.createContext("/js" , 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();
|
||||||
|
plan = Plan.load("default.plan");
|
||||||
Desktop.getDesktop().browse(URI.create("http://localhost:"+config.getInt(PORT)+"/plan"));
|
Desktop.getDesktop().browse(URI.create("http://localhost:"+config.getInt(PORT)+"/plan"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,18 +86,16 @@ public class Application {
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void send(HttpExchange client, Page response) throws IOException {
|
private static void send(HttpExchange client, Object response) throws IOException {
|
||||||
byte[] html = response.html().toString().getBytes(UTF8);
|
byte[] html;
|
||||||
client.getResponseHeaders().add("content-type", "text/html");
|
if (response instanceof Page) {
|
||||||
client.sendResponseHeaders(200, html.length);
|
html = ((Page)response).html().toString().getBytes(UTF8);
|
||||||
OutputStream os = client.getResponseBody();
|
client.getResponseHeaders().add("content-type", "text/html");
|
||||||
os.write(html);
|
} else {
|
||||||
os.close();
|
html = response.toString().getBytes(UTF8);
|
||||||
}
|
client.getResponseHeaders().add("content-type", "text/plain");
|
||||||
|
}
|
||||||
private static void send(HttpExchange client, String response) throws IOException {
|
|
||||||
byte[] html = response.getBytes(UTF8);
|
|
||||||
client.getResponseHeaders().add("content-type", "text/plain");
|
|
||||||
client.sendResponseHeaders(200, html.length);
|
client.sendResponseHeaders(200, html.length);
|
||||||
OutputStream os = client.getResponseBody();
|
OutputStream os = client.getResponseBody();
|
||||||
os.write(html);
|
os.write(html);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class Plan {
|
|||||||
private static final String X = "x";
|
private static final String X = "x";
|
||||||
private static final String Y = "y";
|
private static final String Y = "y";
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
|
private static final String ACTION_PROPS = "openProps";
|
||||||
|
|
||||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ public class Plan {
|
|||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String process(HashMap<String, String> params) {
|
public Object process(HashMap<String, String> params) {
|
||||||
try {
|
try {
|
||||||
String action = params.get(ACTION);
|
String action = params.get(ACTION);
|
||||||
|
|
||||||
@@ -116,6 +117,8 @@ public class Plan {
|
|||||||
return t("Added {}",tile.getClass().getSimpleName());
|
return t("Added {}",tile.getClass().getSimpleName());
|
||||||
case ACTION_SAVE:
|
case ACTION_SAVE:
|
||||||
return saveTo(params.get(NAME));
|
return saveTo(params.get(NAME));
|
||||||
|
case ACTION_PROPS:
|
||||||
|
return Tile.propMenu();
|
||||||
default:
|
default:
|
||||||
LOG.warn("Unknown action: {}",action);
|
LOG.warn("Unknown action: {}",action);
|
||||||
}
|
}
|
||||||
@@ -175,6 +178,4 @@ public class Plan {
|
|||||||
tiles.append(new Eraser().html());
|
tiles.append(new Eraser().html());
|
||||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/main/java/de/srsoftware/web4rail/Window.java
Normal file
14
src/main/java/de/srsoftware/web4rail/Window.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package de.srsoftware.web4rail;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
|
public class Window extends Tag{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 9035075889261889575L;
|
||||||
|
|
||||||
|
public Window(String id) {
|
||||||
|
super("div");
|
||||||
|
id(id);
|
||||||
|
new Tag("div").clazz("closebtn").attr("onclick", "$('#"+id+"').remove(); return false").content("×").addTo(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import java.util.Scanner;
|
|||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
import de.srsoftware.web4rail.Application;
|
import de.srsoftware.web4rail.Application;
|
||||||
|
import de.srsoftware.web4rail.Window;
|
||||||
|
|
||||||
public abstract class Tile {
|
public abstract class Tile {
|
||||||
|
|
||||||
@@ -60,5 +61,9 @@ public abstract class Tile {
|
|||||||
private String t(String txt, Object...fills) {
|
private String t(String txt, Object...fills) {
|
||||||
return Translation.get(Application.class, txt, fills);
|
return Translation.get(Application.class, txt, fills);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Tag propMenu() {
|
||||||
|
return new Window("tile-properties").content("Eigenschaften...");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user