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 Details

    • ToggleNullConfigKey

      public ToggleNullConfigKey(ConfigKey<T> baseKey, String toggleLabel, boolean toggleDflt)
      Constructor.
      Parameters:
      baseKey - config key providing non-null-valued behaviour
      toggleLabel - GUI label for the toggle button selecting null
      toggleDflt - true if the default is null, false if the default is that of the base key
  • Method Details

    • valueToString

      public String valueToString(T 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<T>
      Parameters:
      value - possible value associated with this key
      Returns:
      string representation
    • stringToValue

      public T 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<T>
      Parameters:
      txt - string representation of value
      Returns:
      value
      Throws:
      ConfigException
    • createSpecifier

      public Specifier<T> createSpecifier()
      Description copied from class: ConfigKey
      Constructs a graphical control with which the user can specify a suitable value for association with this key.
      Specified by:
      createSpecifier in class ConfigKey<T>
      Returns:
      new specifier