Class DoubleConfigKey
java.lang.Object
uk.ac.starlink.ttools.plot2.config.ConfigKey<Double>
uk.ac.starlink.ttools.plot2.config.DoubleConfigKey
Config key for double precision values.
NaN and null are not distinguished.
Static methods are provided to produce config keys with a variety of GUI options for specifying values.
- Since:
- 22 Feb 2013
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
DoubleConfigKey
(ConfigMeta meta, double dflt) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic DoubleConfigKey
createSliderKey
(ConfigMeta meta, double dflt, double lo, double hi, boolean log) Returns a key with a linear or logarithmic slider for a specifier.static DoubleConfigKey
createSliderKey
(ConfigMeta meta, double dflt, double lo, double hi, boolean log, boolean flip, SliderSpecifier.TextOption txtOpt) Returns a key with a linear or logarithmic slider for a specifier, more options available.static DoubleConfigKey
createTextKey
(ConfigMeta meta) Constructs a key with a text field specifier and default NaN.static DoubleConfigKey
createTextKey
(ConfigMeta meta, double dflt) Constructs a key with a text field specifier and an explicit default.static DoubleConfigKey
createToggleKey
(ConfigMeta meta, double fval, double tval) Returns a key with a specifier that only provides a toggle between two values.static String
doubleToString
(double dval) Returns a string representation of a double value.static double
stringToDouble
(String txt, ConfigKey<?> key) Interprets the value of a string as a double precision number.stringToValue
(String txt) Decodes a string value to the value type of this key.valueToString
(Double value) Reports a value as a string.Methods inherited from class uk.ac.starlink.ttools.plot2.config.ConfigKey
cast, createSpecifier, getDefaultValue, getMeta, getValueClass, toString
-
Constructor Details
-
DoubleConfigKey
Constructor.- Parameters:
meta
- metadatadflt
- default value
-
-
Method Details
-
valueToString
Description copied from class:ConfigKey
Reports a value as a string. If at all possible the roundtripping should be possible, sostringToValue(valueToString(v)).equals(v)
. A null value, if permitted, should be represented as an empty string.- Specified by:
valueToString
in classConfigKey<Double>
- Parameters:
value
- possible value associated with this key- Returns:
- string representation
-
stringToValue
Description copied from class:ConfigKey
Decodes a string value to the value type of this key. An empty string should be interpreted as a null value, but this may cause an exception if null is not a permissible value for this key.- Specified by:
stringToValue
in classConfigKey<Double>
- Parameters:
txt
- string representation of value- Returns:
- value
- Throws:
ConfigException
-
createTextKey
Constructs a key with a text field specifier and default NaN.- Parameters:
meta
- metadata- Returns:
- key
-
createTextKey
Constructs a key with a text field specifier and an explicit default.- Parameters:
meta
- metadatadflt
- default value- Returns:
- key
-
createToggleKey
Returns a key with a specifier that only provides a toggle between two values.- Parameters:
meta
- metadatafval
- value for toggle false (default)tval
- value for toggle true- Returns:
- key
-
createSliderKey
public static DoubleConfigKey createSliderKey(ConfigMeta meta, double dflt, double lo, double hi, boolean log) Returns a key with a linear or logarithmic slider for a specifier. Note the lower and upper bounds configure only the slider range, they do not enforce a range when the value is set from a string value.- Parameters:
meta
- metadatadflt
- default valuelo
- slider lower boundhi
- slider upper boundlog
- true for logarithmic slider scale, false for linear- Returns:
- key
-
createSliderKey
public static DoubleConfigKey createSliderKey(ConfigMeta meta, double dflt, double lo, double hi, boolean log, boolean flip, SliderSpecifier.TextOption txtOpt) Returns a key with a linear or logarithmic slider for a specifier, more options available. Note the lower and upper bounds configure only the slider range, they do not enforce a range when the value is set from a string value.- Parameters:
meta
- metadatadflt
- default valuelo
- slider lower boundhi
- slider upper boundlog
- true for logarithmic slider scale, false for linearflip
- true to make slider values increase right to lefttxtOpt
- configures whether a text field should appear; null means NONE- Returns:
- key
-
doubleToString
Returns a string representation of a double value.- Parameters:
dval
- double value, may be NaN- Returns:
- stringified value, may be the empty string but not null
-
stringToDouble
Interprets the value of a string as a double precision number.- Parameters:
txt
- string, may be nullkey
- reference key, used for error reporting- Returns:
- numeric value where possible, NaN for empty string
- Throws:
ConfigException
- for non-numeric strings
-