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");
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";
/**
/**
* 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
{
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);
_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;
}
/**
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()
{
{
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;
+ }
}