net.sf.freecol.common.option
Class StringOption

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.option.AbstractOption<java.lang.String>
          extended by net.sf.freecol.common.option.StringOption
All Implemented Interfaces:
java.lang.Cloneable, Option<java.lang.String>

public class StringOption
extends AbstractOption<java.lang.String>

Represents an option that can be an arbitrary string.


Field Summary
private  java.util.List<java.lang.String> choices
          A list of choices to provide to the UI.
private static java.util.logging.Logger logger
           
private  java.lang.String value
          The option value.
 
Fields inherited from class net.sf.freecol.common.option.AbstractOption
isDefined
 
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
StringOption(Specification specification)
          Creates a new StringOption.
StringOption(java.lang.String id)
          Creates a new StringOption.
StringOption(java.lang.String id, Specification specification)
          Creates a new StringOption.
 
Method Summary
 StringOption clone()
           
 java.util.List<java.lang.String> getChoices()
          Get the Choices value.
 java.lang.String getValue()
          Gets the current value of this StringOption.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a single child object.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setChoices(java.util.List<java.lang.String> newChoices)
          Set the Choices value.
 void setValue(java.lang.String value)
          Sets the current value of this StringOption.
protected  void setValue(java.lang.String valueString, java.lang.String defaultValueString)
          Sets the value of this Option from the given string representation.
 java.lang.String toString()
          Returns a textual representation of this object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
protected  void writeChildren(javax.xml.stream.XMLStreamWriter out)
          Write the children of this object to a stream.
 
Methods inherited from class net.sf.freecol.common.option.AbstractOption
generateChoices, getGroup, isNullValueOK, readOption, setGroup, setValues
 
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, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.option.Option
getId, readFromXML, toXML
 

Field Detail

logger

private static java.util.logging.Logger logger

value

private java.lang.String value
The option value.


choices

private java.util.List<java.lang.String> choices
A list of choices to provide to the UI.

Constructor Detail

StringOption

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

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

StringOption

public StringOption(Specification specification)
Creates a new StringOption.

Parameters:
specification - The specification this option belongs to. May be null.

StringOption

public StringOption(java.lang.String id,
                    Specification specification)
Creates a new StringOption.

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

clone

public StringOption clone()
Specified by:
clone in interface Option<java.lang.String>
Specified by:
clone in class AbstractOption<java.lang.String>

getValue

public java.lang.String getValue()
Gets the current value of this StringOption.

Specified by:
getValue in interface Option<java.lang.String>
Specified by:
getValue in class AbstractOption<java.lang.String>
Returns:
The value.

setValue

public void setValue(java.lang.String value)
Sets the current value of this StringOption.

Specified by:
setValue in interface Option<java.lang.String>
Specified by:
setValue in class AbstractOption<java.lang.String>
Parameters:
value - The value.

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.

Overrides:
setValue in class AbstractOption<java.lang.String>
Parameters:
valueString - the string representation of the value of this Option
defaultValueString - the string representation of the default value of this Option

getChoices

public final java.util.List<java.lang.String> getChoices()
Get the Choices value.

Returns:
a List value

setChoices

public final void setChoices(java.util.List<java.lang.String> newChoices)
Set the Choices value.

Parameters:
newChoices - The new Choices value.

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.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream.

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

writeChildren

protected void writeChildren(javax.xml.stream.XMLStreamWriter out)
                      throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream.

Overrides:
writeChildren 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
Description copied from class: AbstractOption
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class AbstractOption<java.lang.String>
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 AbstractOption<java.lang.String>
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

readChild

protected void readChild(javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Reads a single child object. This method does calls readChild with a null specification parameter.

Overrides:
readChild in class FreeColObject
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

getXMLElementTagName

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

Returns:
"StringOption".

toString

public java.lang.String toString()
Description copied from interface: Option
Returns a textual representation of this object.

Specified by:
toString in interface Option<java.lang.String>
Overrides:
toString in class java.lang.Object
Returns:
The name of this Option.