Example #1
0
 /**
  * Return a integer parsed from the value associated with the given key, or "def" in key wasn't
  * found.
  */
 public static int parseProperty(Properties preferences, String key, int def) {
   String val = preferences.getProperty(key);
   if (val == null) return def;
   try {
     return Integer.parseInt(val);
   } catch (NumberFormatException nfe) {
     nfe.printStackTrace();
     return def;
   }
 }
Example #2
0
 /**
  * @return a double parsed from the value associated with the given key in the given Properties.
  *     returns "def" in key wasn't found, or if a parsing error occured. If "value" contains a "%"
  *     sign, we use a <code>NumberFormat.getPercentInstance</code> to convert it to a double.
  */
 public static double parseProperty(Properties preferences, String key, double def) {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   String val = preferences.getProperty(key);
   if (val == null) return def;
   if (val.indexOf("%") == -1) { // not in percent format !
     try {
       return Double.parseDouble(val);
     } catch (NumberFormatException nfe) {
       nfe.printStackTrace();
       return def;
     }
   }
   // else it's a percent format -> parse it
   try {
     Number n = formatPercent.parse(val);
     return n.doubleValue();
   } catch (ParseException ex) {
     ex.printStackTrace();
     return def;
   }
 }