Class DoubleConfigKey
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.config.ConfigKey<java.lang.Double>
-
- uk.ac.starlink.ttools.plot2.config.DoubleConfigKey
-
public abstract class DoubleConfigKey extends ConfigKey<java.lang.Double>
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
Constructors Modifier Constructor Description protected
DoubleConfigKey(ConfigMeta meta, double dflt)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.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 java.lang.String
doubleToString(double dval)
Returns a string representation of a double value.static double
stringToDouble(java.lang.String txt, ConfigKey<?> key)
Interprets the value of a string as a double precision number.java.lang.Double
stringToValue(java.lang.String txt)
Decodes a string value to the value type of this key.java.lang.String
valueToString(java.lang.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 Detail
-
DoubleConfigKey
protected DoubleConfigKey(ConfigMeta meta, double dflt)
Constructor.- Parameters:
meta
- metadatadflt
- default value
-
-
Method Detail
-
valueToString
public java.lang.String valueToString(java.lang.Double value)
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<java.lang.Double>
- Parameters:
value
- possible value associated with this key- Returns:
- string representation
-
stringToValue
public java.lang.Double stringToValue(java.lang.String txt) throws ConfigException
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<java.lang.Double>
- Parameters:
txt
- string representation of value- Returns:
- value
- Throws:
ConfigException
-
createTextKey
public static DoubleConfigKey createTextKey(ConfigMeta meta)
Constructs a key with a text field specifier and default NaN.- Parameters:
meta
- metadata- Returns:
- key
-
createTextKey
public static DoubleConfigKey createTextKey(ConfigMeta meta, double dflt)
Constructs a key with a text field specifier and an explicit default.- Parameters:
meta
- metadatadflt
- default value- Returns:
- key
-
createToggleKey
public static DoubleConfigKey createToggleKey(ConfigMeta meta, double fval, double tval)
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
public static java.lang.String doubleToString(double dval)
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
public static double stringToDouble(java.lang.String txt, ConfigKey<?> key) throws ConfigException
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
-
-