Package net.sf.freecol.common.option
Class AbstractOption<T>
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.option.AbstractOption<T>
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.lang.Comparable<FreeColObject>
,ObjectWithId
,Option<T>
- Direct Known Subclasses:
AbstractUnitOption
,AudioMixerOption
,BooleanOption
,FileOption
,IntegerOption
,LanguageOption
,ListOption
,ModOption
,OptionGroup
,StringOption
,TextOption
,UnitTypeOption
public abstract class AbstractOption<T> extends FreeColSpecObject implements Option<T>
The super class of all options. GUI components making use of this class can refer to its name and shortDescription properties. The complete keys of these properties consist of the identifier of the option group (if any), followed by a "." unless the option group is null, followed by the identifier of the option object, followed by a ".", followed by "name" or "shortDescription".
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
ACTION_TAG
protected static java.lang.String
DEFAULT_VALUE_TAG
private static java.lang.String
ENABLED_BY_TAG
private java.lang.String
enabledBy
protected boolean
isDefined
Determine if the option has been defined.private static java.util.logging.Logger
logger
private java.lang.String
optionGroupId
The option group prefix.-
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 Modifier Constructor Description protected
AbstractOption(java.lang.String id)
Creates a newAbstractOption
.protected
AbstractOption(java.lang.String id, Specification specification)
Creates a newAbstractOption
.AbstractOption(Specification specification)
Creates a newAbstractOption
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract AbstractOption<T>
cloneOption()
Clone this option.void
generateChoices()
Generate the choices to provide to the UI.java.lang.String
getEnabledBy()
Gets the key of anBooleanOption
that must be true for this option to be enabled.java.lang.String
getGroup()
Gets the option group identifier for this option.abstract T
getValue()
Gets the value of this option.boolean
isNullValueOK()
Is null an acceptable value for this option? Override this in subclasses where necessary.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected AbstractOption
readOption(FreeColXMLReader xr)
General option reader routine.void
setGroup(java.lang.String group)
Set the option group for this option.protected void
setValue(java.lang.String valueString, java.lang.String defaultValueString)
Sets the value of this option from the given string representation.abstract void
setValue(T value)
Sets the value of this option.protected void
setValues(AbstractOption<T> source)
Sets the values from another option.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
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, getXMLTagName, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
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, toString, toXML
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
ENABLED_BY_TAG
private static final java.lang.String ENABLED_BY_TAG
- See Also:
- Constant Field Values
-
optionGroupId
private java.lang.String optionGroupId
The option group prefix.
-
isDefined
protected boolean isDefined
Determine if the option has been defined. When defined an option won't change when a default value is read from an XML file.
-
enabledBy
private java.lang.String enabledBy
-
ACTION_TAG
protected static final java.lang.String ACTION_TAG
- See Also:
- Constant Field Values
-
DEFAULT_VALUE_TAG
protected static final java.lang.String DEFAULT_VALUE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractOption
protected AbstractOption(java.lang.String id, Specification specification)
Creates a newAbstractOption
.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
AbstractOption
protected AbstractOption(java.lang.String id)
Creates a newAbstractOption
.- Parameters:
id
- The object identifier.
-
AbstractOption
public AbstractOption(Specification specification)
Creates a newAbstractOption
.- Parameters:
specification
- TheSpecification
to refer to.
-
-
Method Detail
-
setValues
protected void setValues(AbstractOption<T> source)
Sets the values from another option.- Parameters:
source
- The otherAbstractOption
.
-
setValue
protected void setValue(java.lang.String valueString, java.lang.String defaultValueString) throws javax.xml.stream.XMLStreamException
Sets the value of this option from the given string representation. Both parameters must not be null at the same time. This method does nothing. Override it if the option has a suitable string representation.- Parameters:
valueString
- The string representation of the value of thisOption
.defaultValueString
- The string representation of the default value of thisOption
.- Throws:
javax.xml.stream.XMLStreamException
- if the value is invalid.
-
generateChoices
public void generateChoices()
Generate the choices to provide to the UI. Override if the subclass needs to determine its choices dynamically.
-
isNullValueOK
public boolean isNullValueOK()
Is null an acceptable value for this option? Override this in subclasses where necessary.- Returns:
- False.
-
cloneOption
public abstract AbstractOption<T> cloneOption() throws java.lang.CloneNotSupportedException
Clone this option.- Specified by:
cloneOption
in interfaceOption<T>
- Returns:
- A clone of this option.
- Throws:
java.lang.CloneNotSupportedException
- if we can not clone.
-
getGroup
public java.lang.String getGroup()
Gets the option group identifier for this option.
-
setGroup
public void setGroup(java.lang.String group)
Set the option group for this option.
-
getValue
public abstract T getValue()
Gets the value of this option.
-
setValue
public abstract void setValue(T value)
Sets the value of this option.
-
getEnabledBy
public java.lang.String getEnabledBy()
Gets the key of anBooleanOption
that must be true for this option to be enabled.- Specified by:
getEnabledBy
in interfaceOption<T>
- Returns:
- The key of the
BooleanOption
that needs to be enabled.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readOption
protected AbstractOption readOption(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
General option reader routine.- Parameters:
xr
- TheFreeColXMLReader
to read from.- Returns:
- An option.
- Throws:
javax.xml.stream.XMLStreamException
- on stream errors.
-
-