X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.maps%2Fsrc%2Forg%2Fsimantics%2Fmaps%2Fprefs%2FMapsClientPreferences.java;h=75ad19d6471004b0206a006b46c6d6d0a4222c8e;hb=00e4eca98cef6d77d5023f4b424f9e8da0487463;hp=5ecfe052dd30ffb78571e8cd12c32ff54ebab7e4;hpb=02ecca5e61d2eb17de40cc058be678b414aaad00;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java b/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java index 5ecfe052..75ad19d6 100644 --- a/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java +++ b/org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java @@ -1,8 +1,49 @@ package org.simantics.maps.prefs; +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.osgi.service.prefs.Preferences; + public class MapsClientPreferences { public static final String P_NODE = "org.simantics.district.maps"; public static final String P_TILESERVER_URL = "org.simantics.district.maps.prefs.tileserverURL"; + public static final String P_USE_BUILTIN = "org.simantics.district.maps.prefs.tileserverURL"; + + // TODO: fix this, currently copied from MapsServerPreferences + public static final String P_DEFAULT_PORT = "org.simantics.maps.server.defaultPort"; + public static final String P_CURRENT_TM2STYLE = "org.simantics.maps.server.currentTM2Style"; + public static final String P_SERVER_NODE = "org.simantics.maps.server"; + public static Preferences getServerPreferences() { + return InstanceScope.INSTANCE.getNode(P_SERVER_NODE); + } + + public static Preferences getPreferences() { + return InstanceScope.INSTANCE.getNode(P_NODE); + } + + public static String tileserverURL() { + return getPreferences().get(P_TILESERVER_URL, ""); + } + + public static boolean useBuiltinServer() { + return getPreferences().getBoolean(P_USE_BUILTIN, true); + } + + public static String possibleBuiltinServerURL() { + int port = getServerPreferences().getInt(P_DEFAULT_PORT, -1); + String style = getServerPreferences().get(P_CURRENT_TM2STYLE, null); + if (port != -1 && style != null) { + try { + return new URL("http", "localhost", port, "/" + style).toString(); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + return null; + } + }