updates for 0.9.4
[debian/openrocket] / src / net / sf / openrocket / util / Prefs.java
index 0ca273f6539abbaecd99d792f898050d22f618da..f4f26133d81beb2d3fe35b4e291ae04a6746673b 100644 (file)
@@ -18,6 +18,7 @@ import java.util.prefs.Preferences;
 
 import net.sf.openrocket.database.Databases;
 import net.sf.openrocket.document.Simulation;
+import net.sf.openrocket.gui.main.ExceptionHandler;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.rocketcomponent.BodyComponent;
 import net.sf.openrocket.rocketcomponent.FinSet;
@@ -55,13 +56,16 @@ public class Prefs {
        
        private static final String BUILD_VERSION;
        private static final String BUILD_SOURCE;
+       public static final String DEFAULT_BUILD_SOURCE = "default";
+       private static final boolean DEFAULT_CHECK_UPDATES;
        
        static {
                try {
                        InputStream is = ClassLoader.getSystemResourceAsStream("build.properties");
                        if (is == null) {
                                throw new MissingResourceException(
-                                               "build.properties not found, distribution built wrong",
+                                               "build.properties not found, distribution built wrong" + 
+                                               "   path:"+System.getProperty("java.class.path"),
                                                "build.properties", "build.version");
                        }
                        
@@ -78,6 +82,12 @@ public class Prefs {
                        
                        BUILD_SOURCE = props.getProperty("build.source");
                        
+                       String value = props.getProperty("build.checkupdates");
+                       if (value != null)
+                               DEFAULT_CHECK_UPDATES = Boolean.parseBoolean(value);
+                       else
+                               DEFAULT_CHECK_UPDATES = true;
+                       
                } catch (IOException e) {
                        throw new MissingResourceException(
                                        "Error reading build.properties",
@@ -100,6 +110,8 @@ public class Prefs {
        
        public static final String PLOT_SHOW_POINTS = "ShowPlotPoints";
        
+       private static final String CHECK_UPDATES = "CheckUpdates";
+       
        /**
         * Node to this application's preferences.
         * @deprecated  Use the static methods instead.
@@ -149,14 +161,18 @@ public class Prefs {
        }
        
        
-       private static final Material DEFAULT_LINE_MATERIAL = 
-               Databases.findMaterial(Material.Type.LINE, "Elastic cord (round 2mm, 1/16 in)", 
-                               0.0018, false);
-       private static final Material DEFAULT_SURFACE_MATERIAL = 
-               Databases.findMaterial(Material.Type.SURFACE, "Ripstop nylon", 0.067, false);
-       private static final Material DEFAULT_BULK_MATERIAL = 
-               Databases.findMaterial(Material.Type.BULK, "Cardboard", 680, false);
-
+       /*
+        * Within a holder class so they will load only when needed.
+        */
+       private static class DefaultMaterialHolder {
+               private static final Material DEFAULT_LINE_MATERIAL = 
+                       Databases.findMaterial(Material.Type.LINE, "Elastic cord (round 2mm, 1/16 in)", 
+                                       0.0018, false);
+               private static final Material DEFAULT_SURFACE_MATERIAL = 
+                       Databases.findMaterial(Material.Type.SURFACE, "Ripstop nylon", 0.067, false);
+               private static final Material DEFAULT_BULK_MATERIAL = 
+                       Databases.findMaterial(Material.Type.BULK, "Cardboard", 680, false);
+       }
        
        //////////////////////
        
@@ -171,6 +187,16 @@ public class Prefs {
        }
        
        
+       public static String getUniqueID() {
+               String id = PREFNODE.get("id", null);
+               if (id == null) {
+                       id = UniqueID.generateHashedID();
+                       PREFNODE.put("id", id);
+               }
+               return id;
+       }
+       
+       
        
        public static void storeVersion() {
                PREFNODE.put("OpenRocketVersion", getVersion());
@@ -229,6 +255,16 @@ public class Prefs {
 
        
        
+       public static boolean getCheckUpdates() {
+               return PREFNODE.getBoolean(CHECK_UPDATES, DEFAULT_CHECK_UPDATES);
+       }
+       
+       public static void setCheckUpdates(boolean check) {
+               PREFNODE.putBoolean(CHECK_UPDATES, check);
+               storeVersion();
+       }
+       
+       
        //////////////////
        
        public static File getDefaultDirectory() {
@@ -347,11 +383,11 @@ public class Prefs {
                
                switch (type) {
                case LINE:
-                       return DEFAULT_LINE_MATERIAL;
+                       return DefaultMaterialHolder.DEFAULT_LINE_MATERIAL;
                case SURFACE:
-                       return DEFAULT_SURFACE_MATERIAL;
+                       return DefaultMaterialHolder.DEFAULT_SURFACE_MATERIAL;
                case BULK:
-                       return DEFAULT_BULK_MATERIAL;
+                       return DefaultMaterialHolder.DEFAULT_BULK_MATERIAL;
                }
                throw new IllegalArgumentException("Unknown material type: "+type);
        }
@@ -470,8 +506,7 @@ public class Prefs {
                        }
                        
                } catch (BackingStoreException e) {
-                       System.err.println("BackingStoreException:");
-                       e.printStackTrace();
+                       ExceptionHandler.handleErrorCondition(e);
                }
        }