net.sf.freecol.common.option
Class AbstractOption<T>

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption<T>
All Implemented Interfaces:
Option
Direct Known Subclasses:
AbstractUnitOption, AudioMixerOption, BooleanOption, FileOption, IntegerOption, LanguageOption, ListOption, OptionGroup, StringOption, UnitListOption

public abstract class AbstractOption<T>
extends FreeColObject
implements Option

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 id of the option group (if any), followed by a "." unless the option group is null, followed by the id of the option object, followed by a ".", followed by "name" or "shortDescription".


Field Summary
protected  boolean isDefined
           
private static java.util.logging.Logger logger
           
private  java.lang.String optionGroup
           
protected  boolean previewEnabled
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
AbstractOption(java.lang.String id)
          Creates a new AbstractOption.
 
Method Summary
 java.lang.String getGroup()
          Returns the string prefix that identifies the group of this Option.
abstract  T getValue()
          Returns the value of this Option.
 boolean isPreviewEnabled()
          Should this option be updated directly so that changes may be previewed?
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setGroup(java.lang.String group)
          Set the option group
 void setPreviewEnabled(boolean previewEnabled)
          Sets if this option should be updated directly.
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.
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, getXMLElementTagName, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLImpl, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
addPropertyChangeListener, getId, readFromXML, readFromXMLElement, removePropertyChangeListener, toString, toXML, toXMLElement
 

Field Detail

logger

private static java.util.logging.Logger logger

optionGroup

private java.lang.String optionGroup

isDefined

protected boolean isDefined

previewEnabled

protected boolean previewEnabled
Constructor Detail

AbstractOption

public AbstractOption(java.lang.String id)
Creates a new AbstractOption.

Parameters:
id - The identifier for this option. This is used when the object should be found in an OptionGroup.
Method Detail

isPreviewEnabled

public boolean isPreviewEnabled()
Should this option be updated directly so that changes may be previewed?

Specified by:
isPreviewEnabled in interface Option
Returns:
true if changes to this option should be made directly (and reset back later if the changes are not stored).

setPreviewEnabled

public void setPreviewEnabled(boolean previewEnabled)
Sets if this option should be updated directly.

Parameters:
previewEnabled - true if changes to this option should be made directly (and reset back later if the changes are not stored).

getGroup

public java.lang.String getGroup()
Returns the string prefix that identifies the group of this Option.

Returns:
The string prefix provided by the OptionGroup.

setGroup

public void setGroup(java.lang.String group)
Set the option group

Parameters:
group - OptionGroup to set

getValue

public abstract T getValue()
Returns the value of this Option.

Returns:
the value of this Option

setValue

public abstract void setValue(T value)
Sets the value of this Option.

Parameters:
value - the value of this Option

setValue

protected void setValue(java.lang.String valueString,
                        java.lang.String defaultValueString)
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 this Option
defaultValueString - the string representation of the default value of this Option

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.

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

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