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; } }