Missing preference load/save in AppSettings

  1. AppSetting.load fails when white space exists so trimming for value is needed.
  2. There is load() method for Preferences but the method body is empty so I filled it and implemented save() also

    [patch]

    Index: src/core/com/jme3/system/AppSettings.java

    ===================================================================

    — src/core/com/jme3/system/AppSettings.java (revision 6302)

    +++ src/core/com/jme3/system/AppSettings.java (working copy)

    @@ -39,6 +39,7 @@

    import java.util.HashMap;

    import java.util.Map;

    import java.util.Properties;

    +import java.util.prefs.BackingStoreException;

    import java.util.prefs.Preferences;



    public class AppSettings extends HashMap<String, Object> {

    @@ -91,6 +92,9 @@

    for (Map.Entry<Object, Object> entry : props.entrySet()){

    String key = (String) entry.getKey();

    String val = (String) entry.getValue();
  •        if (val != null) {<br />
    
  •        	val = val.trim();<br />
    
  •        }<br />
    

if (key.endsWith("(int)")){

key = key.substring(0, key.length()-5);

int iVal = Integer.parseInt(val);

@@ -125,8 +129,28 @@

props.store(out, "jME3 AppSettings");

}


  • public void load(String preferencesKey){
  • public void load(String preferencesKey) throws BackingStoreException{

    Preferences prefs = Preferences.userRoot().node(preferencesKey);
  •    String[] keys = prefs.keys();<br />
    
  •    if (keys != null) {<br />
    
  •    	for (String key : keys) {<br />
    
  •   		Object defaultValue = defaults.get(key);<br />
    
  •   		if (defaultValue instanceof Integer) {<br />
    
  •   			put(key, prefs.getInt(key, (Integer)defaultValue));<br />
    
  •   		} else if (defaultValue instanceof String) {<br />
    
  •   			put(key, prefs.get(key, (String)defaultValue));<br />
    
  •   		} else if (defaultValue instanceof Boolean) {<br />
    
  •   			put(key, prefs.getBoolean(key, (Boolean)defaultValue));<br />
    
  •   		}<br />
    
  •   	}<br />
    
  •    }<br />
    
  • }

    +
  • public void save(String preferencesKey) throws BackingStoreException{
  •   Preferences prefs = Preferences.userRoot().node(preferencesKey);<br />
    
  •   for (String key : keySet()) {<br />
    
  •   	prefs.put(key, get(key).toString());<br />
    
  •   }<br />
    

}



public int getInteger(String key){

[/patch]

1 Like

committed thanks :wink: