net.sf.freecol.common.option
Class SelectOption

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption
          extended by net.sf.freecol.common.option.SelectOption
All Implemented Interfaces:
Option
Direct Known Subclasses:
RangeOption

public class SelectOption
extends AbstractOption

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 id 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 Summary
private  java.util.Map<java.lang.Integer,java.lang.String> itemValues
           
protected  boolean localizedLabels
           
private static java.util.logging.Logger logger
           
private  int value
           
 
Fields inherited from class net.sf.freecol.common.option.AbstractOption
isDefined, NO_ID, previewEnabled
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE
 
Constructor Summary
SelectOption(javax.xml.stream.XMLStreamReader in)
          Creates a new SelectOption.
 
Method Summary
 java.util.Map<java.lang.Integer,java.lang.String> getItemValues()
          Gets the range values of this RangeOption.
protected  java.lang.String getStringValue()
          Gets a String representation of the current value.
 int getValue()
          Gets the current value of this SelectOption.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 java.lang.String getXMLItemElementTagName()
          Gets the tag name of the item element This method is not static to ensure proper overriding in readFromXMLImpl.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setValue(int value)
          Sets the value of this SelectOption.
protected  void setValue(java.lang.String value)
          Converts the given String to an Integer and calls setValue(int).
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
 
Methods inherited from class net.sf.freecol.common.option.AbstractOption
getGroup, getName, getShortDescription, isPreviewEnabled, setGroup, setPreviewEnabled, toString
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readChildren, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, setId, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
addPropertyChangeListener, getId, readFromXML, readFromXMLElement, removePropertyChangeListener, toXML, toXMLElement
 

Field Detail

logger

private static java.util.logging.Logger logger

value

private int value

localizedLabels

protected boolean localizedLabels

itemValues

private java.util.Map<java.lang.Integer,java.lang.String> itemValues
Constructor Detail

SelectOption

public SelectOption(javax.xml.stream.XMLStreamReader in)
             throws javax.xml.stream.XMLStreamException
Creates a new SelectOption.

Parameters:
in - The XMSStreamReader to read the data from
Throws:
javax.xml.stream.XMLStreamException
Method Detail

getValue

public int getValue()
Gets the current value of this SelectOption.

Returns:
The value.

setValue

public void setValue(int value)
Sets the value of this SelectOption.

Parameters:
value - The value to be set.

getItemValues

public java.util.Map<java.lang.Integer,java.lang.String> getItemValues()
Gets the range values of this RangeOption.

Returns:
The value.

getStringValue

protected java.lang.String getStringValue()
Gets a String representation of the current value. This method can be overwritten by subclasses to allow a custom save value, since this method is used by FreeColObject.toXML(XMLStreamWriter).

Returns:
The String value of the Integer.
See Also:
setValue(String)

setValue

protected void setValue(java.lang.String value)
Converts the given String to an Integer and calls setValue(int).

This method can be overwritten by subclasses to allow a custom save value, since this method is used by FreeColObject.readFromXML(XMLStreamReader).

Parameters:
value - The String value of the Integer.
See Also:
getStringValue()

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"selectOption".

getXMLItemElementTagName

public java.lang.String getXMLItemElementTagName()
Gets the tag name of the item element This method is not static to ensure proper overriding in readFromXMLImpl.

Returns:
"selectValue".