Class SelectOption

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<FreeColObject>, ObjectWithId, Option<java.lang.Integer>
    Direct Known Subclasses:
    RangeOption

    public class SelectOption
    extends IntegerOption
    Represents an option where the valid choice is an integer and the choices are represented by strings. In general, these strings are localized by looking up the key of the choice, which consists of the identifier of the AbstractObject followed by a "." followed by the value of the option string. The automatic localization can be suppressed with the doNotLocalize parameter, however. There are two reasons to do this: either the option strings should not be localized at all (because they are language names, for example), or the option strings have already been localized (because they do not use the default keys, for example).
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • localizedLabels

        protected boolean localizedLabels
        Use localized labels?
      • itemValues

        private final java.util.Map<java.lang.Integer,​java.lang.String> itemValues
        A map of the valid values.
      • LOCALIZED_LABELS_TAG

        private static final java.lang.String LOCALIZED_LABELS_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • SelectOption

        public SelectOption​(Specification specification)
        Creates a new SelectOption.
        Parameters:
        specification - The Specification to refer to.
      • SelectOption

        public SelectOption​(java.lang.String id,
                            Specification specification)
        Creates a new SelectOption.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • getName

        public java.lang.String getName()
        Get the name associated with the current value.
        Returns:
        The name.
      • getItemValues

        public java.util.Map<java.lang.Integer,​java.lang.String> getItemValues()
        Gets the range values of this RangeOption.
        Returns:
        The value.
      • addItemValue

        public void addItemValue​(java.lang.Integer key,
                                 java.lang.String value)
        Add a new key,value pair to this option.
        Parameters:
        key - The key to add.
        value - The value to add.
      • clearItemValues

        public void clearItemValues()
        Clear the item values for this option. Required by ClientOptions.fixClientOptions.
      • localizeLabels

        public boolean localizeLabels()
        Whether the labels of this option need to be localized. This is not the case when the labels are just numeric values.
        Returns:
        True if localization is required.
      • getXMLItemElementTagName

        public java.lang.String getXMLItemElementTagName()
        Gets the tag name of the contained object. Should be overridden by subclasses to ensure read/writeChildren work.
        Returns:
        "selectValue".
      • setValue

        public void setValue​(java.lang.Integer value)
        Sets the value of this option.
        Specified by:
        setValue in interface Option<java.lang.Integer>
        Overrides:
        setValue in class IntegerOption
        Parameters:
        value - The new value of this Option.
      • writeAttributes

        protected void writeAttributes​(FreeColXMLWriter xw)
                                throws javax.xml.stream.XMLStreamException
        Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeAttributes in class IntegerOption
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • writeChildren

        protected void writeChildren​(FreeColXMLWriter xw)
                              throws javax.xml.stream.XMLStreamException
        Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeChildren in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • readAttributes

        protected void readAttributes​(FreeColXMLReader xr)
                               throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class IntegerOption
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChildren

        protected void readChildren​(FreeColXMLReader xr)
                             throws javax.xml.stream.XMLStreamException
        Reads the children of this object from an XML stream.
        Overrides:
        readChildren in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChild

        protected void readChild​(FreeColXMLReader xr)
                          throws javax.xml.stream.XMLStreamException
        Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.
        Overrides:
        readChild in class FreeColObject
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • getXMLTagName

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Overrides:
        getXMLTagName in class IntegerOption
        Returns:
        The tag.