1 package tim.prune.gui.map;
3 import java.net.MalformedURLException;
6 import tim.prune.Config;
9 * Class to hold the config for the map tiles
10 * and retrieve the correct URL prefix
12 public class MapTileConfig
14 /** Index of map server */
15 private int _index = 0;
17 private String _url = null;
19 /** server urls for known maps */
20 private static final String[] SERVER_URLS = {
21 "http://tile.openstreetmap.org/", // mapnik
22 "http://tah.openstreetmap.org/Tiles/tile/", // osma
23 "http://andy.sandbox.cloudmade.com/tiles/cycle/" // cyclemap
25 /** Index of 'other' server with freeform url */
26 private static final int OTHER_SERVER_NUM = 3;
30 * Default constructor using Config
32 public MapTileConfig()
34 _index = Config.getConfigInt(Config.KEY_MAPSERVERINDEX);
35 _url = fixUrl(Config.getConfigString(Config.KEY_MAPSERVERURL));
36 // reset index wrong or if other url too short
37 if (_index < 0 || _index > OTHER_SERVER_NUM ||
38 (_index == OTHER_SERVER_NUM && (_url == null || _url.length() < 5)))
47 public String getUrl()
49 if (_index == OTHER_SERVER_NUM) {return _url;}
50 return SERVER_URLS[_index];
54 * Checks the given url for having the right prefix and trailing slash
55 * @param inUrl url to check
56 * @return validated url with correct prefix and trailing slash, or null
58 private static String fixUrl(String inUrl)
60 if (inUrl == null || inUrl.equals("")) {return null;}
66 catch (MalformedURLException e) {
67 // add the http protocol
68 url = "http://" + url;
71 if (!url.endsWith("/")) {
78 * @param inOther other config object
79 * @return true if the objects are exactly the same
81 public boolean equals(MapTileConfig inOther)
83 // Other object must be non-null and must have same index
84 if (inOther == null || inOther._index != _index) {return false;}
85 // Check url if other selected
86 if (_index == OTHER_SERVER_NUM) {
87 return inOther._url.equals(_url);
89 // Not other so must match