Class OptionConfigKey<T>

  • Direct Known Subclasses:
    MultiPointConfigKey, PerUnitConfigKey, SkySysConfigKey

    public abstract class OptionConfigKey<T>
    extends ConfigKey<T>
    Config key for use with items that can be chosen from a list of options. The list is basically closed, though it may be possible programmatically to supply an object of the required type. For open lists of options see ChoiceConfigKey.
    Since:
    23 Feb 2013
    Author:
    Mark Taylor
    • Constructor Detail

      • OptionConfigKey

        public OptionConfigKey​(ConfigMeta meta,
                               java.lang.Class<T> clazz,
                               T[] options,
                               T dflt,
                               boolean useRadio)
        Constructor that specifies an explicit default and specifier type.
        Parameters:
        meta - metadata
        clazz - class to which all the possible options belong
        options - array of possible values for this key
        dflt - default option, should be one of options
        useRadio - true to use radio buttons, false for a combo box
      • OptionConfigKey

        public OptionConfigKey​(ConfigMeta meta,
                               java.lang.Class<T> clazz,
                               T[] options,
                               T dflt)
        Constructor that specifies an explicit default and uses the default specifier type.
        Parameters:
        meta - metadata
        clazz - class to which all the possible options belong
        options - array of possible values for this key
        dflt - default option, should be one of options
      • OptionConfigKey

        public OptionConfigKey​(ConfigMeta meta,
                               java.lang.Class<T> clazz,
                               T[] options)
        Constructor that uses the first of the supplied options as a default.
        Parameters:
        meta - metadata
        clazz - class to which all the possible options belong
        options - array of possible values for this key, first element is used as the default value
    • Method Detail

      • valueToString

        public java.lang.String valueToString​(T value)
        Invokes the toString method of the supplied option. May be overridden.
        Specified by:
        valueToString in class ConfigKey<T>
        Parameters:
        value - possible value associated with this key
        Returns:
        string representation
      • getXmlDescription

        public abstract java.lang.String getXmlDescription​(T value)
        Returns a description in XML of the given option value. This, along with valueToString(T), is used by the getOptionsXml() method to assemble a described list of the options.
        Parameters:
        value - possible value of this key
        Returns:
        short snippet of XML (not wrapped in any outer element) describing the value; may be null if no description required or available
      • stringToValue

        public T stringToValue​(java.lang.String txt)
                        throws ConfigException
        Calls valueToString repeatedly looking for a match. This means that if valueToString is overridden it is usually not necessary to override this method.
        Specified by:
        stringToValue in class ConfigKey<T>
        Parameters:
        txt - string representation of value
        Returns:
        value
        Throws:
        ConfigException
      • getOptions

        public T[] getOptions()
        Returns the available options for this key.
        Returns:
        choosable values
      • 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
      • setOptionUsage

        public OptionConfigKey<T> setOptionUsage()
        Sets the usage string based on the currently configured options. This method calls setStringUsage.
        Returns:
        this object, as a convenience
      • addOptionsXml

        public OptionConfigKey<T> addOptionsXml()
        Convenience method to add the result of getOptionsXml() to the XML documentation of this key.
        Returns:
        this object, as a convenience
      • getOptionsXml

        public java.lang.String getOptionsXml()
        Returns an XML list of the available options for this config key. Descriptions are not included.
        Returns:
        p element