]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/config/Config.java
Version 19, May 2018
[GpsPrune.git] / tim / prune / config / Config.java
index 385a5d9f12dc64d387711cf54abc4fbbb5644633..cd23dbdc724ba5c738666774a1f186c9458b6cc5 100644 (file)
@@ -7,6 +7,9 @@ import java.util.Properties;
 import tim.prune.data.RecentFileList;
 import tim.prune.data.UnitSet;
 import tim.prune.data.UnitSetLibrary;
+import tim.prune.gui.colour.ColourerFactory;
+import tim.prune.gui.colour.PointColourer;
+import tim.prune.gui.map.MapSourceLibrary;
 
 
 /**
@@ -21,6 +24,8 @@ public abstract class Config
        private static Properties _configValues = null;
        /** Colour scheme object is also part of config */
        private static ColourScheme _colourScheme = new ColourScheme();
+       /** Point colourer object, if any */
+       private static PointColourer _pointColourer = null;
        /** Recently-used file list */
        private static RecentFileList _recentFiles = new RecentFileList();
        /** Current unit set */
@@ -44,6 +49,8 @@ public abstract class Config
        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 GPSBabel import file format */
+       public static final String KEY_IMPORT_FILE_FORMAT = "prune.lastimportfileformat";
        /** Key for Povray font */
        public static final String KEY_POVRAY_FONT = "prune.povrayfont";
        /** Key for the selected unit set */
@@ -56,6 +63,8 @@ public abstract class Config
        public static final String KEY_MAPSOURCE_LIST = "prune.mapsourcelist";
        /** Key for show map flag */
        public static final String KEY_SHOW_MAP = "prune.showmap";
+       /** Key for window position */
+       public static final String KEY_WINDOW_BOUNDS = "prune.windowbounds";
        /** Key for path to disk cache */
        public static final String KEY_DISK_CACHE = "prune.diskcache";
        /** Key for working online flag */
@@ -70,8 +79,12 @@ public abstract class Config
        public static final String KEY_EXIFTOOL_PATH = "prune.exiftoolpath";
        /** Key for colour scheme */
        public static final String KEY_COLOUR_SCHEME = "prune.colourscheme";
+       /** Key for point colourer */
+       public static final String KEY_POINT_COLOURER = "prune.pointcolourer";
        /** Key for line width used for drawing */
        public static final String KEY_LINE_WIDTH = "prune.linewidth";
+       /** Key for whether to use antialiasing or not */
+       public static final String KEY_ANTIALIAS = "prune.antialias";
        /** Key for kml track colour */
        public static final String KEY_KML_TRACK_COLOUR = "prune.kmltrackcolour";
        /** Key for autosaving settings */
@@ -80,6 +93,18 @@ public abstract class Config
        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";
+       /** Key for terrain grid size */
+       public static final String KEY_TERRAIN_GRID_SIZE = "prune.terraingridsize";
+       /** Key for altitude tolerance */
+       public static final String KEY_ALTITUDE_TOLERANCE = "prune.altitudetolerance";
+       /** Key for waypoint icons to use */
+       public static final String KEY_WAYPOINT_ICONS = "prune.waypointicons";
+       /** Size of waypoint icons to use */
+       public static final String KEY_WAYPOINT_ICON_SIZE = "prune.waypointiconsize";
+       /** Id of selected timezone */
+       public static final String KEY_TIMEZONE_ID = "prune.timezoneid";
 
 
        /** Initialise the default properties */
@@ -140,8 +165,11 @@ public abstract class Config
                // Save all properties from file
                _configValues.putAll(props);
                _colourScheme.loadFromHex(_configValues.getProperty(KEY_COLOUR_SCHEME));
+               _pointColourer = ColourerFactory.createColourer(_configValues.getProperty(KEY_POINT_COLOURER));
                _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();
@@ -164,12 +192,38 @@ 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_IMPORT_FILE_FORMAT, "-1"); // no file format selected
                props.put(KEY_KMZ_IMAGE_SIZE, "240");
+               props.put(KEY_ANTIALIAS, "1"); // antialias on by default
                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
+               props.put(KEY_TERRAIN_GRID_SIZE, "50");
+               props.put(KEY_ALTITUDE_TOLERANCE, "0"); // 0, all exact as before
+               props.put(KEY_WAYPOINT_ICON_SIZE, "1"); // medium size
                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
@@ -208,6 +262,14 @@ public abstract class Config
                return _colourScheme;
        }
 
+       /**
+        * @return the current point colourer, if any
+        */
+       public static PointColourer getPointColourer()
+       {
+               return _pointColourer;
+       }
+
        /**
         * @return list of recently used files
         */
@@ -295,9 +357,9 @@ public abstract class Config
         */
        public static boolean isKeyBoolean(String inKey)
        {
-               // Only one boolean key so far (after metric flag was removed)
                return inKey != null && (
-                       inKey.equals(KEY_SHOW_MAP));
+                       inKey.equals(KEY_SHOW_MAP) || inKey.equals(KEY_AUTOSAVE_SETTINGS) || inKey.equals(KEY_ONLINE_MODE)
+                       || inKey.equals(KEY_ANTIALIAS));
        }
 
        /**
@@ -308,6 +370,16 @@ public abstract class Config
                setConfigString(KEY_COLOUR_SCHEME, _colourScheme.toString());
        }
 
+       /**
+        * Update the point colourer from the given colourer
+        * @param inColourer point colourer object, or null
+        */
+       public static void updatePointColourer(PointColourer inColourer)
+       {
+               _pointColourer = inColourer;
+               setConfigString(KEY_POINT_COLOURER, ColourerFactory.PointColourerToString(_pointColourer));
+       }
+
        /**
         * @return the current unit set
         */
@@ -315,6 +387,9 @@ public abstract class Config
                return _unitSet;
        }
 
+       /**
+        * @param inIndex index of unit set to select
+        */
        public static void selectUnitSet(int inIndex)
        {
                _unitSet = UnitSetLibrary.getUnitSet(inIndex);