X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2FConfig.java;h=aa36c158930cc07e0d15a21ec98363cc1988030c;hp=d667b599e6748ed302d1e2a1f29e6c02d8442525;hb=54b9d8bc8f0025ccf97a67d9dd217ef1f9cf082f;hpb=52bf9e8686c916be37a26a0b75340393d4478b05 diff --git a/tim/prune/Config.java b/tim/prune/Config.java index d667b59..aa36c15 100644 --- a/tim/prune/Config.java +++ b/tim/prune/Config.java @@ -21,7 +21,16 @@ public abstract class Config private static String _povrayFont = null; /** True to use metric units */ private static boolean _metricUnits = true; + /** Path to gnuplot executable */ + private static String _gnuplotPath = null; + /** Index of selected map tile server */ + private static int _mapTileServerIndex = -1; + /** URL for freeform map tile server */ + private static String _mapTileServerUrl = null; + /** File from which Config was loaded */ + private static File _configFile = null; + // TODO: Need setters for all these parameters if want to make the config saveable /** Default config file */ private static final File DEFAULT_CONFIG_FILE = new File(".pruneconfig"); @@ -38,7 +47,12 @@ public abstract class Config private static final String KEY_POVRAY_FONT = "prune.povrayfont"; /** Key for metric/imperial */ private static final String KEY_METRIC_UNITS = "prune.metricunits"; - // TODO: Save config file location so save possible + /** Key for gpsbabel path */ + private static final String KEY_GNUPLOTPATH = "prune.gnuplotpath"; + /** Key for map server index */ + private static final String KEY_MAPSERVERINDEX = "prune.mapserverindex"; + /** Key for map server url */ + private static final String KEY_MAPSERVERURL = "prune.mapserverurl"; /** @@ -73,6 +87,7 @@ public abstract class Config /** * Load configuration from file * @param inFile file to load + * @throws ConfigException if specified file couldn't be read */ public static void loadFile(File inFile) throws ConfigException { @@ -80,14 +95,21 @@ public abstract class Config Properties props = getDefaultProperties(); // Try to load the file into a properties object boolean loadFailed = false; + FileInputStream fis = null; try { - props.load(new FileInputStream(inFile)); + fis = new FileInputStream(inFile); + props.load(fis); } - catch (Exception e) - { + catch (Exception e) { loadFailed = true; } + finally { + if (fis != null) try { + fis.close(); + } + catch (Exception e) {} + } // Save the properties we know about, ignore the rest _langCode = props.getProperty(KEY_LANGUAGE_CODE); String dir = props.getProperty(KEY_WORKING_DIR); @@ -97,9 +119,15 @@ public abstract class Config _povrayFont = props.getProperty(KEY_POVRAY_FONT); String useMetric = props.getProperty(KEY_METRIC_UNITS); _metricUnits = (useMetric == null || useMetric.equals("") || useMetric.toLowerCase().equals("y")); + _gnuplotPath = props.getProperty(KEY_GNUPLOTPATH); + if (_gnuplotPath == null || _gnuplotPath.equals("")) {_gnuplotPath = "gnuplot";} + _mapTileServerIndex = parseInt(props.getProperty(KEY_MAPSERVERINDEX)); + _mapTileServerUrl = props.getProperty(KEY_MAPSERVERURL); if (loadFailed) { throw new ConfigException(); } + // Store location of successfully loaded config file + _configFile = inFile; } /** @@ -115,6 +143,20 @@ public abstract class Config return props; } + /** + * @param inString String to parse + * @return int value of String, or 0 if unparseable + */ + private static int parseInt(String inString) + { + int val = 0; + try { + val = Integer.parseInt(inString); + } + catch (Exception e) {} // ignore, value stays zero + return val; + } + /** @return language code */ public static String getLanguageCode() { @@ -144,4 +186,52 @@ public abstract class Config { return _metricUnits; } + + /** @param inMetric true to use metric units */ + public static void setUseMetricUnits(boolean inMetric) + { + _metricUnits = inMetric; + } + + /** @return path to gnuplot */ + public static String getGnuplotPath() + { + return _gnuplotPath; + } + + /** @param inPath path to Gnuplot */ + public static void setGnuplotPath(String inPath) + { + _gnuplotPath = inPath; + } + + /** @return index of map server */ + public static int getMapServerIndex() + { + return _mapTileServerIndex; + } + + /** @param inIndex selected index */ + public static void setMapServerIndex(int inIndex) + { + _mapTileServerIndex = inIndex; + } + + /** @return url of map server */ + public static String getMapServerUrl() + { + return _mapTileServerUrl; + } + + /** @param inUrl url of map server */ + public static void setMapServerUrl(String inUrl) + { + _mapTileServerUrl = inUrl; + } + + /** @return File from which config was loaded (or null) */ + public static File getConfigFile() + { + return _configFile; + } }