Package net.sf.freecol.common.option
Class SelectOption
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.option.AbstractOption<java.lang.Integer>
-
- net.sf.freecol.common.option.IntegerOption
-
- net.sf.freecol.common.option.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 Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,java.lang.String>
itemValues
A map of the valid values.private static java.lang.String
LABEL_TAG
private static java.lang.String
LOCALIZED_LABELS_TAG
protected boolean
localizedLabels
Use localized labels?private static java.util.logging.Logger
logger
static java.lang.String
TAG
-
Fields inherited from class net.sf.freecol.common.option.AbstractOption
ACTION_TAG, DEFAULT_VALUE_TAG, isDefined
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description SelectOption(java.lang.String id, Specification specification)
Creates a newSelectOption
.SelectOption(Specification specification)
Creates a newSelectOption
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addItemValue(java.lang.Integer key, java.lang.String value)
Add a new key,value pair to this option.void
clearItemValues()
Clear the item values for this option.java.util.Map<java.lang.Integer,java.lang.String>
getItemValues()
Gets the range values of thisRangeOption
.java.lang.String
getName()
Get the name associated with the current value.java.lang.String
getXMLItemElementTagName()
Gets the tag name of the contained object.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
localizeLabels()
Whether the labels of this option need to be localized.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
setValue(java.lang.Integer value)
Sets the value of this option.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.option.IntegerOption
cloneOption, getMaximumValue, getMinimumValue, getStepSize, getValue, limitValue, setMaximumValue, setMinimumValue, setValue
-
Methods inherited from class net.sf.freecol.common.option.AbstractOption
generateChoices, getEnabledBy, getGroup, isNullValueOK, readOption, setGroup, setValues
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
copyIn, getSpecification, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.freecol.common.ObjectWithId
getId
-
Methods inherited from interface net.sf.freecol.common.option.Option
readFromXML, toXML
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
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.
-
LABEL_TAG
private static final java.lang.String LABEL_TAG
- See Also:
- Constant Field 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 newSelectOption
.- Parameters:
specification
- TheSpecification
to refer to.
-
SelectOption
public SelectOption(java.lang.String id, Specification specification)
Creates a newSelectOption
.- Parameters:
id
- The object identifier.specification
- TheSpecification
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 thisRangeOption
.- 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 interfaceOption<java.lang.Integer>
- Overrides:
setValue
in classIntegerOption
- Parameters:
value
- The new value of thisOption
.
-
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 classIntegerOption
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classIntegerOption
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classIntegerOption
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfaceOption<java.lang.Integer>
- Overrides:
toString
in classIntegerOption
-
-