Package net.sf.freecol.common.option
Class OptionGroup
- java.lang.Object
- 
- net.sf.freecol.common.model.FreeColObject
- 
- net.sf.freecol.common.model.FreeColSpecObject
- 
- net.sf.freecol.common.option.AbstractOption<OptionGroup>
- 
- net.sf.freecol.common.option.OptionGroup
 
 
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable,- java.lang.Comparable<FreeColObject>,- ObjectWithId,- Option<OptionGroup>,- OptionContainer
 - Direct Known Subclasses:
- ActionManager,- ClientOptions
 
 public class OptionGroup extends AbstractOption<OptionGroup> implements OptionContainer Used for groupingOptions.
- 
- 
Field SummaryFields Modifier and Type Field Description private booleaneditableIs this option group user editable?private static java.lang.StringEDITABLE_TAGprivate static java.util.logging.Loggerloggerprivate java.util.Map<java.lang.String,Option>optionMapA map of all option ids to its option.private java.util.List<Option>optionsThe options in this group.static java.lang.StringTAGprivate booleanvisibleShould this option group be visible?private static java.lang.StringVISIBLE_TAG- 
Fields inherited from class net.sf.freecol.common.option.AbstractOptionACTION_TAG, DEFAULT_VALUE_TAG, isDefined
 - 
Fields inherited from class net.sf.freecol.common.model.FreeColObjectARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
 
- 
 - 
Constructor SummaryConstructors Constructor Description OptionGroup(java.lang.String id)Creates a newOptionGroup.OptionGroup(java.lang.String id, Specification specification)Creates a newOptionGroup.OptionGroup(FreeColXMLReader xr, Specification specification)Creates a newOptionGroup.OptionGroup(Specification specification)Creates a newOptionGroup.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Option option)Adds the given option to this group.private voidaddOptionGroup(OptionGroup group)Helper function to recursively add option group members to the optionMap.OptionGroupcloneOption()Clone this option.voidgenerateChoices()Generate the choices to provide to the UI.java.lang.StringgetName()Gets the i18n-name of thisOption.OptiongetOption(java.lang.String id)Get an option in this group (or descendents) by object identifier.<T extends Option>
 TgetOption(java.lang.String id, java.lang.Class<T> returnClass)Get an option in this group (or descendents) by object identifier.java.util.List<Option>getOptions()Get the options in this group.java.lang.StringgetShortDescription()Gets the i18n short description of thisOption.OptionGroupgetValue()Gets the value of this option.java.lang.StringgetXMLTagName()Get the serialization tag for this object.<T extends Option>
 booleanhasOption(java.lang.String id, java.lang.Class<T> returnClass)Is an option present in the container.booleanhasOptionGroup()Does this option group contain any subgroups?booleanisEditable()Is this option group editable?booleanisNullValueOK()Is null an acceptable value for this option? Override this in subclasses where necessary.booleanisVisible()Should this option group be visible?booleanload(java.io.File file)Loads the options from the given file.protected booleanload(FreeColXMLReader xr)Loads the options from the given reader.static OptionGrouploadOptionGroup(java.io.File file, java.lang.String optionId, Specification spec)Load a specific option group from a file by identifier.booleanmerge(Option option, LogBuilder lb)Merges the givenOptioninto this group.voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidreadChild(FreeColXMLReader xr)Reads a single child object.voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.Optionremove(java.lang.String id)Remove an option.voidremoveAll()Removes all of theOptions from thisOptionGroup.booleansave(java.io.File file)Writes the object to the given file.voidsetEditable(boolean editable)Set the editable status of this group.voidsetValue(java.lang.String valueString, java.lang.String defaultValueString)Sets the value of this option from the given string representation.voidsetValue(OptionGroup value)Sets the value of this option.java.lang.StringtoString()protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(FreeColXMLWriter xw)Write the children of this object to a stream.- 
Methods inherited from class net.sf.freecol.common.option.AbstractOptiongetEnabledBy, getGroup, readOption, setGroup, setValues
 - 
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObjectcopyIn, getSpecification, setSpecification
 - 
Methods inherited from class net.sf.freecol.common.model.FreeColObjectaddAbility, 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, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXML, toXMLPartial, toXMLPartial
 - 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface net.sf.freecol.common.ObjectWithIdgetId
 - 
Methods inherited from interface net.sf.freecol.common.option.OptionreadFromXML, toXML
 - 
Methods inherited from interface net.sf.freecol.common.option.OptionContainergetBoolean, getFile, getInteger, getIntegerMinimum, getModList, getOptionGroup, getPercentage, getPercentageMultiplier, getRange, getSelection, getSelectionName, getString, getText, getUnitList, setBoolean, setFile, setInteger, setIntegerMinimum, setString, setText
 
- 
 
- 
- 
- 
Field Detail- 
loggerprivate static final java.util.logging.Logger logger 
 - 
TAGpublic static final java.lang.String TAG - See Also:
- Constant Field Values
 
 - 
optionsprivate final java.util.List<Option> options The options in this group.
 - 
optionMapprivate final java.util.Map<java.lang.String,Option> optionMap A map of all option ids to its option. Unlike the options array, this contains all child options of options that are themselves groups.
 - 
editableprivate boolean editable Is this option group user editable?
 - 
visibleprivate boolean visible Should this option group be visible?
 - 
EDITABLE_TAGprivate static final java.lang.String EDITABLE_TAG - See Also:
- Constant Field Values
 
 - 
VISIBLE_TAGprivate static final java.lang.String VISIBLE_TAG - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
OptionGrouppublic OptionGroup(java.lang.String id) Creates a newOptionGroup.- Parameters:
- id- The object identifier.
 
 - 
OptionGrouppublic OptionGroup(Specification specification) Creates a newOptionGroup.- Parameters:
- specification- The- Specificationto refer to.
 
 - 
OptionGrouppublic OptionGroup(java.lang.String id, Specification specification)Creates a newOptionGroup.- Parameters:
- id- The object identifier.
- specification- The- Specificationto refer to.
 
 - 
OptionGrouppublic OptionGroup(FreeColXMLReader xr, Specification specification) throws javax.xml.stream.XMLStreamException Creates a newOptionGroup.- Parameters:
- xr- The- FreeColXMLReaderto read from.
- specification- The- Specificationto refer to.
- Throws:
- javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
 
 
- 
 - 
Method Detail- 
isEditablepublic boolean isEditable() Is this option group editable?- Returns:
- True if the option group is editable.
 
 - 
setEditablepublic void setEditable(boolean editable) Set the editable status of this group.- Parameters:
- editable- The new editable status.
 
 - 
isVisiblepublic boolean isVisible() Should this option group be visible?- Returns:
- True if the option group should be visible.
 
 - 
getNamepublic java.lang.String getName() Gets the i18n-name of thisOption.- Returns:
- The name as provided in the constructor.
 
 - 
getShortDescriptionpublic java.lang.String getShortDescription() Gets the i18n short description of thisOption. Should be suitable for use as a tooltip text.- Returns:
- A short description of this Option.
 
 - 
getOptionspublic java.util.List<Option> getOptions() Get the options in this group.- Returns:
- The list of Options.
 
 - 
getOptionpublic Option getOption(java.lang.String id) Get an option in this group (or descendents) by object identifier.- Parameters:
- id- The object identifier.
- Returns:
- The option, or null if not found.
 
 - 
hasOptionGrouppublic boolean hasOptionGroup() Does this option group contain any subgroups?- Returns:
- True if there are any child OptionGroups present.
 
 - 
addpublic void add(Option option) Adds the given option to this group. The option is assumed to be correct.- Parameters:
- option- The- Optionto add.
 
 - 
mergepublic boolean merge(Option option, LogBuilder lb) Merges the givenOptioninto this group. - Option groups are *not* merged, but their leaf options are. - If an option is not already present it is ignored. - If an option is present, it is merged but in the option group where it is already placed. The intent is that the option group structure is never subject to merging.- Parameters:
- option- The- Optionto merge.
- lb- A- LogBuilderto log to.
- Returns:
- True if the merge was accepted.
 
 - 
addOptionGroupprivate void addOptionGroup(OptionGroup group) Helper function to recursively add option group members to the optionMap.- Parameters:
- group- The initial- OptionGroupto add.
 
 - 
removepublic Option remove(java.lang.String id) Remove an option.- Parameters:
- id- The identifier of the option to remove.
- Returns:
- The Optionremoved if any.
 
 - 
removeAllpublic void removeAll() Removes all of theOptions from thisOptionGroup.
 - 
loadprotected boolean load(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException Loads the options from the given reader.- Parameters:
- xr- The- FreeColXMLReaderto read from.
- Returns:
- True if the options were loaded without error.
- Throws:
- javax.xml.stream.XMLStreamException- if there is an error reading the stream.
 
 - 
loadpublic boolean load(java.io.File file) Loads the options from the given file.- Parameters:
- file- The- Fileto read the options from.
- Returns:
- True if the options were loaded without error.
 
 - 
loadOptionGrouppublic static OptionGroup loadOptionGroup(java.io.File file, java.lang.String optionId, Specification spec) Load a specific option group from a file by identifier.- Parameters:
- file- The- Fileto load from.
- optionId- The option identifier to look for.
- spec- A base- Specification.
- Returns:
- The OptionGroupfound, or null on error or not found.
 
 - 
hasOptionpublic <T extends Option> boolean hasOption(java.lang.String id, java.lang.Class<T> returnClass) Is an option present in the container.- Specified by:
- hasOptionin interface- OptionContainer
- Type Parameters:
- T- The actual return type.
- Parameters:
- id- The object identifier.
- returnClass- The expected option class.
- Returns:
- True if the option is present.
 
 - 
getOptionpublic <T extends Option> T getOption(java.lang.String id, java.lang.Class<T> returnClass) Get an option in this group (or descendents) by object identifier.- Specified by:
- getOptionin interface- OptionContainer
- Type Parameters:
- T- The actual return type.
- Parameters:
- id- The object identifier.
- returnClass- The expected option class.
- Returns:
- The option, or a run time exception if the option does not exist or is of the wrong class.
 
 - 
cloneOptionpublic OptionGroup cloneOption() Clone this option.- Specified by:
- cloneOptionin interface- Option<OptionGroup>
- Specified by:
- cloneOptionin class- AbstractOption<OptionGroup>
- Returns:
- A clone of this option.
 
 - 
getValuepublic OptionGroup getValue() Gets the value of this option.- Specified by:
- getValuein interface- Option<OptionGroup>
- Specified by:
- getValuein class- AbstractOption<OptionGroup>
- Returns:
- The value of this Option.
 
 - 
setValuepublic void setValue(OptionGroup value) Sets the value of this option.- Specified by:
- setValuein interface- Option<OptionGroup>
- Specified by:
- setValuein class- AbstractOption<OptionGroup>
- Parameters:
- value- The new value of this- Option.
 
 - 
setValuepublic 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.- Overrides:
- setValuein class- AbstractOption<OptionGroup>
- Parameters:
- valueString- The string representation of the value of this- Option.
- defaultValueString- The string representation of the default value of this- Option.
 
 - 
generateChoicespublic void generateChoices() Generate the choices to provide to the UI. Override if the subclass needs to determine its choices dynamically.- Overrides:
- generateChoicesin class- AbstractOption<OptionGroup>
 
 - 
isNullValueOKpublic boolean isNullValueOK() Is null an acceptable value for this option? Override this in subclasses where necessary.- Overrides:
- isNullValueOKin class- AbstractOption<OptionGroup>
- Returns:
- False.
 
 - 
savepublic boolean save(java.io.File file) Writes the object to the given file.- Overrides:
- savein class- FreeColObject
- Parameters:
- file- The- Fileto write to.
- Returns:
- True if the save proceeded without error.
 
 - 
writeAttributesprotected 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:
- writeAttributesin class- AbstractOption<OptionGroup>
- Parameters:
- xw- The- FreeColXMLWriterto write to.
- Throws:
- javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
 
 - 
writeChildrenprotected 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:
- writeChildrenin class- FreeColObject
- Parameters:
- xw- The- FreeColXMLWriterto write to.
- Throws:
- javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
 
 - 
readAttributespublic void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException Reads the attributes of this object from an XML stream.- Overrides:
- readAttributesin class- AbstractOption<OptionGroup>
- Parameters:
- xr- The- FreeColXMLReaderto read from.
- Throws:
- javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
 
 - 
readChildrenpublic void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException Reads the children of this object from an XML stream.- Overrides:
- readChildrenin class- FreeColObject
- Parameters:
- xr- The- FreeColXMLReaderto read from.
- Throws:
- javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
 
 - 
readChildpublic 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:
- readChildin class- FreeColObject
- Parameters:
- xr- The- FreeColXMLReaderto read from.
- Throws:
- javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
 
 - 
getXMLTagNamepublic java.lang.String getXMLTagName() Get the serialization tag for this object.- Specified by:
- getXMLTagNamein class- FreeColObject
- Returns:
- The tag.
 
 - 
toStringpublic java.lang.String toString() - Specified by:
- toStringin interface- Option<OptionGroup>
- Overrides:
- toStringin class- FreeColObject
 
 
- 
 
-