# Class DoubleConfigKey

java.lang.Object
uk.ac.starlink.ttools.plot2.config.ConfigKey<Double>
uk.ac.starlink.ttools.plot2.config.DoubleConfigKey

public abstract class DoubleConfigKey extends ConfigKey<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

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 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.
`Double`
`stringToValue(String txt)`
Decodes a string value to the value type of this key.
`String`
`valueToString(Double value)`
Reports a value as a string.

### Methods inherited from class ConfigKey

`cast, createSpecifier, getDefaultValue, getMeta, getValueClass, toString`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### DoubleConfigKey

protected DoubleConfigKey(ConfigMeta meta, double dflt)
Constructor.

Parameters:
  `meta` - metadata
  `dflt` - default value

## Method Details

### valueToString

public String valueToString(Double value)
Description copied from class: `ConfigKey`
Reports a value as a string. If at all possible the roundtripping should be possible, so `stringToValue(valueToString(v)).equals(v)`. A null value, if permitted, should be represented as an empty string.

Specified by:
  `valueToString` in class `ConfigKey<Double>`
Parameters:
  `value` - possible value associated with this key
Returns:
  string representation

### stringToValue

public Double stringToValue(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 class `ConfigKey<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` - metadata
  `dflt` - 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` - metadata
  `fval` - 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` - metadata
  `dflt` - default value
  `lo` - slider lower bound
  `hi` - slider upper bound
  `log` - 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` - metadata
  `dflt` - default value
  `lo` - slider lower bound
  `hi` - slider upper bound
  `log` - true for logarithmic slider scale, false for linear
  `flip` - true to make slider values increase right to left
  `txtOpt` - configures whether a text field should appear; null means NONE
Returns:
  key

### doubleToString

public static 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(String txt, ConfigKey<?> key) throws ConfigException
Interprets the value of a string as a double precision number.

Parameters:
  `txt` - string, may be null
  `key` - reference key, used for error reporting
Returns:
  numeric value where possible, NaN for empty string
Throws:
  `ConfigException` - for non-numeric strings