]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/config/Config.java
Version 16, February 2014
[GpsPrune.git] / tim / prune / config / Config.java
index 412f408b803c79055ffbe7eb100ab9d707d606c2..655847cf338cf9b4900cb426c850f1a8248d8681 100644 (file)
@@ -5,6 +5,9 @@ import java.io.FileInputStream;
 import java.util.Properties;
 
 import tim.prune.data.RecentFileList;
+import tim.prune.data.UnitSet;
+import tim.prune.data.UnitSetLibrary;
+import tim.prune.gui.map.MapSourceLibrary;
 
 
 /**
@@ -16,11 +19,13 @@ public abstract class Config
        private static File _configFile = null;
 
        /** Hashtable containing all config values */
-       private static Properties _configValues = new Properties();
+       private static Properties _configValues = null;
        /** Colour scheme object is also part of config */
        private static ColourScheme _colourScheme = new ColourScheme();
        /** Recently-used file list */
        private static RecentFileList _recentFiles = new RecentFileList();
+       /** Current unit set */
+       private static UnitSet _unitSet = UnitSetLibrary.getUnitSet(null);
 
        /** Default config file */
        public static final File DEFAULT_CONFIG_FILE = new File(".pruneconfig");
@@ -38,12 +43,16 @@ public abstract class Config
        public static final String KEY_GPS_DEVICE = "prune.gpsdevice";
        /** Key for GPS format */
        public static final String KEY_GPS_FORMAT = "prune.gpsformat";
+       /** Key for GPSBabel filter string */
+       public static final String KEY_GPSBABEL_FILTER = "prune.gpsbabelfilter";
        /** Key for Povray font */
        public static final String KEY_POVRAY_FONT = "prune.povrayfont";
-       /** Key for metric/imperial */
-       public static final String KEY_METRIC_UNITS = "prune.metricunits";
+       /** Key for the selected unit set */
+       public static final String KEY_UNITSET_KEY  = "prune.unitsetkey";
        /** Key for index of map source */
        public static final String KEY_MAPSOURCE_INDEX = "prune.mapsource";
+       /** Key for number of fixed map sources */
+       public static final String KEY_NUM_FIXED_MAPS = "prune.numfixedmapsources";
        /** Key for String containing custom map sources */
        public static final String KEY_MAPSOURCE_LIST = "prune.mapsourcelist";
        /** Key for show map flag */
@@ -53,9 +62,7 @@ public abstract class Config
        /** Key for working online flag */
        public static final String KEY_ONLINE_MODE = "prune.onlinemode";
        /** Key for width of thumbnails in kmz */
-       public static final String KEY_KMZ_IMAGE_WIDTH = "prune.kmzimagewidth";
-       /** Key for height of thumbnails in kmz */
-       public static final String KEY_KMZ_IMAGE_HEIGHT = "prune.kmzimageheight";
+       public static final String KEY_KMZ_IMAGE_SIZE = "prune.kmzimagewidth";
        /** Key for gpsbabel path */
        public static final String KEY_GPSBABEL_PATH = "prune.gpsbabelpath";
        /** Key for gnuplot path */
@@ -72,8 +79,18 @@ public abstract class Config
        public static final String KEY_AUTOSAVE_SETTINGS = "prune.autosavesettings";
        /** Key for recently used files */
        public static final String KEY_RECENT_FILES = "prune.recentfiles";
+       /** Key for estimation parameters */
+       public static final String KEY_ESTIMATION_PARAMS = "prune.estimationparams";
+       /** Key for 3D exaggeration factor */
+       public static final String KEY_HEIGHT_EXAGGERATION = "prune.heightexaggeration";
 
 
+       /** Initialise the default properties */
+       static
+       {
+               _configValues = getDefaultProperties();
+       }
+
        /**
         * Load the default configuration file
         */
@@ -127,6 +144,10 @@ public abstract class Config
                _configValues.putAll(props);
                _colourScheme.loadFromHex(_configValues.getProperty(KEY_COLOUR_SCHEME));
                _recentFiles = new RecentFileList(_configValues.getProperty(KEY_RECENT_FILES));
+               _unitSet = UnitSetLibrary.getUnitSet(_configValues.getProperty(KEY_UNITSET_KEY));
+               // Adjust map source index if necessary
+               adjustSelectedMap();
+
                if (loadFailed) {
                        throw new ConfigException();
                }
@@ -148,12 +169,33 @@ public abstract class Config
                props.put(KEY_EXIFTOOL_PATH, "exiftool");
                props.put(KEY_GNUPLOT_PATH, "gnuplot");
                props.put(KEY_GPSBABEL_PATH, "gpsbabel");
-               props.put(KEY_KMZ_IMAGE_WIDTH, "240");
-               props.put(KEY_KMZ_IMAGE_HEIGHT, "240");
+               props.put(KEY_KMZ_IMAGE_SIZE, "240");
                props.put(KEY_AUTOSAVE_SETTINGS, "0"); // autosave false by default
+               props.put(KEY_UNITSET_KEY, "unitset.kilometres"); // metric by default
+               props.put(KEY_HEIGHT_EXAGGERATION, "100"); // 100%, no exaggeration
                return props;
        }
 
+       /**
+        * Adjust the index of the selected map
+        * (only required if config was loaded from a previous version of GpsPrune)
+        */
+       private static void adjustSelectedMap()
+       {
+               int sourceNum = getConfigInt(Config.KEY_MAPSOURCE_INDEX);
+               int prevNumFixed = getConfigInt(Config.KEY_NUM_FIXED_MAPS);
+               // Number of fixed maps not specified in version <=13, default to 6
+               if (prevNumFixed == 0) prevNumFixed = 6;
+               int currNumFixed = MapSourceLibrary.getNumFixedSources();
+               // Only need to do something if the number has changed
+               if (currNumFixed != prevNumFixed && (sourceNum >= prevNumFixed || sourceNum >= currNumFixed))
+               {
+                       sourceNum += (currNumFixed - prevNumFixed);
+                       setConfigInt(Config.KEY_MAPSOURCE_INDEX, sourceNum);
+               }
+               setConfigInt(Config.KEY_NUM_FIXED_MAPS, currNumFixed);
+       }
+
        /**
         * @param inString String to parse
         * @return int value of String, or 0 if unparseable
@@ -279,9 +321,9 @@ public abstract class Config
         */
        public static boolean isKeyBoolean(String inKey)
        {
-               // Only two boolean keys so far
+               // Only one boolean key so far (after metric flag was removed)
                return inKey != null && (
-                       inKey.equals(KEY_METRIC_UNITS) || inKey.equals(KEY_SHOW_MAP));
+                       inKey.equals(KEY_SHOW_MAP));
        }
 
        /**
@@ -291,4 +333,18 @@ public abstract class Config
        {
                setConfigString(KEY_COLOUR_SCHEME, _colourScheme.toString());
        }
+
+       /**
+        * @return the current unit set
+        */
+       public static UnitSet getUnitSet() {
+               return _unitSet;
+       }
+
+       public static void selectUnitSet(int inIndex)
+       {
+               _unitSet = UnitSetLibrary.getUnitSet(inIndex);
+               // Set name of set in config
+               setConfigString(KEY_UNITSET_KEY, _unitSet.getNameKey());
+       }
 }