]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.maps/src/org/simantics/maps/prefs/MapsClientPreferences.java
Some cleaning and fixing of district functionalities
[simantics/district.git] / org.simantics.district.maps / src / org / simantics / maps / prefs / MapsClientPreferences.java
1 package org.simantics.maps.prefs;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5
6 import org.eclipse.core.runtime.preferences.InstanceScope;
7 import org.osgi.service.prefs.Preferences;
8
9 public class MapsClientPreferences {
10
11     public static final String P_NODE = "org.simantics.district.maps";
12     
13     public static final String P_TILESERVER_URL = "org.simantics.district.maps.prefs.tileserverURL";
14     public static final String P_USE_BUILTIN = "org.simantics.district.maps.prefs.tileserverURL";
15     
16     // TODO: fix this, currently copied from MapsServerPreferences
17     public static final String P_DEFAULT_PORT = "org.simantics.maps.server.defaultPort";
18     public static final String P_CURRENT_TM2STYLE = "org.simantics.maps.server.currentTM2Style";
19     public static final String P_SERVER_NODE = "org.simantics.maps.server";
20     public static Preferences getServerPreferences() {
21         return InstanceScope.INSTANCE.getNode(P_SERVER_NODE);
22     }
23     
24     public static Preferences getPreferences() {
25         return InstanceScope.INSTANCE.getNode(P_NODE);
26     }
27     
28     public static String tileserverURL() {
29         return getPreferences().get(P_TILESERVER_URL, "");
30     }
31
32     public static boolean useBuiltinServer() {
33         return getPreferences().getBoolean(P_USE_BUILTIN, true);
34     }
35     
36     public static String possibleBuiltinServerURL() {
37         int port = getServerPreferences().getInt(P_DEFAULT_PORT, -1);
38         String style = getServerPreferences().get(P_CURRENT_TM2STYLE, null);
39         if (port != -1 && style != null) {
40             try {
41                 return new URL("http", "localhost", port, "/" + style).toString();
42             } catch (MalformedURLException e) {
43                 throw new RuntimeException(e);
44             }
45         }
46         return null;
47     }
48
49 }