package textbender.g.util.prefs; // Copyright 2001-2005, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import java.util.prefs.Preferences; /** A float in a preference node. */ public class FloatPreference extends Preference { /** Constructs a FloatPreference. * * @param preferences per {@linkplain Preference#preferences() preferences}() * @param key per {@linkplain Preference#key() key}() * @param def default per {@linkplain #getDefault() getDefault}() */ public FloatPreference( Preferences preferences, String key, float def ) { super( preferences, key ); this.def = def; } // ------------------------------------------------------------------------------------ /** Retrieves the value of this preference from storage. * Equivalent to preferences.getFloat(key,default) * * @return value if any was stored; else the {@linkplain #getDefault() default} */ public float get() { return preferences.getFloat( key, def ); } /** Returns the default value of this preference. */ public float getDefault() { return def; } private float def; // not 'default', which is a keyword /** Sets the default value, per {@linkplain #getDefault() getDefault}(). */ public void setDefault( float newDefault ) { def = newDefault; } /** Stores a new value for the preference. * Equivalent to preferences.putFloat(key,value). * * @param value new value of the preference */ public void put( float value ) { preferences.putFloat( key, value ); } }