Class ToggleNullConfigKey<T>
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.config.ConfigKey<T>
-
- uk.ac.starlink.ttools.plot2.config.ToggleNullConfigKey<T>
-
public class ToggleNullConfigKey<T> extends ConfigKey<T>
Wraps a supplied ConfigKey to provide one that will also allow selection of the null value. In the GUI, this is represented with a toggle button that when selected indicates null, and when not defers to the usual specifier GUI.This is intended for use with config keys that do not normally accept null values. If used with config keys that do permit null values, confusion may result.
- Since:
- 29 Jun 2016
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description ToggleNullConfigKey(ConfigKey<T> baseKey, java.lang.String toggleLabel, boolean toggleDflt)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Specifier<T>
createSpecifier()
Constructs a graphical control with which the user can specify a suitable value for association with this key.T
stringToValue(java.lang.String txt)
Decodes a string value to the value type of this key.java.lang.String
valueToString(T value)
Reports a value as a string.-
Methods inherited from class uk.ac.starlink.ttools.plot2.config.ConfigKey
cast, getDefaultValue, getMeta, getValueClass, toString
-
-
-
-
Constructor Detail
-
ToggleNullConfigKey
public ToggleNullConfigKey(ConfigKey<T> baseKey, java.lang.String toggleLabel, boolean toggleDflt)
Constructor.- Parameters:
baseKey
- config key providing non-null-valued behaviourtoggleLabel
- GUI label for the toggle button selecting nulltoggleDflt
- true if the default is null, false if the default is that of the base key
-
-
Method Detail
-
valueToString
public java.lang.String valueToString(T 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<T>
- Parameters:
value
- possible value associated with this key- Returns:
- string representation
-
stringToValue
public T 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<T>
- Parameters:
txt
- string representation of value- Returns:
- value
- Throws:
ConfigException
-
-