Package net.sf.freecol.common.model
Class ModelMessage
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.StringTemplate
-
- net.sf.freecol.common.model.ModelMessage
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
public class ModelMessage extends StringTemplate
Contains a message about a change in the model.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classModelMessage.MessageTypeConstants categorizing the type of message.-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.StringTemplate
StringTemplate.TemplateType
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringDISPLAY_TAGprivate booleandisplayedprivate java.lang.StringdisplayIdprivate static java.lang.StringHAS_BEEN_DISPLAYED_TAGprivate static java.lang.StringMESSAGE_TYPE_TAGprivate ModelMessage.MessageTypemessageTypestatic java.util.Comparator<ModelMessage>messageTypeComparatorCompare messages by type.private static java.lang.StringSOURCE_TAGprivate java.lang.StringsourceIdstatic java.lang.StringTAG-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description ModelMessage()Trivial constructor to allow creation with Game.newInstance.ModelMessage(FreeColXMLReader xr)Creates a new model message by reading a stream.ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, java.lang.String defaultId, FreeColGameObject source, FreeColObject display)Creates a newModelMessage.ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, FreeColGameObject source)Creates a newModelMessage.ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, FreeColGameObject source, FreeColObject display)Creates a newModelMessage.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ModelMessageaddDefaultId(java.lang.String id)Set a default identifier.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.voiddivert(FreeColGameObject newSource)Switch the source (and display if it is the same) to a new object.booleanequals(java.lang.Object o)private static FreeColObjectgetDefaultDisplay(ModelMessage.MessageType messageType, FreeColGameObject source)Gets the default display object for the given type.booleangetDisplayed()Has this message been displayed?java.lang.StringgetDisplayId()Gets the object to display.java.lang.StringgetIgnoredMessageKey()Get a key for a message that might be ignored.ModelMessage.MessageTypegetMessageType()Gets the messageType of the message to display.java.lang.StringgetOptionName()Get the option name for this message.static java.util.Comparator<ModelMessage>getSourceComparator(Game game, java.util.Map<java.lang.String,java.util.Comparator<?>> specialized)Get a comparator that sorts on the message source object.java.lang.StringgetSourceId()Gets the source of the message.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.voidsetDisplayed(boolean displayed)Sets whether this message has been displayed.voidsetDisplayId(java.lang.String displayId)Sets the object to display.voidsetMessageType(ModelMessage.MessageType messageType)Sets the type of the message.voidsetSourceId(java.lang.String sourceId)Sets the source object.java.util.List<java.lang.Object>splitLinks(Player player)Split a message into a list of text and link objects.java.lang.StringtoString()protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.StringTemplate
add, add, addAmount, addName, addName, addName, addNamed, addNamed, addStringTemplate, addStringTemplate, addTagged, copy, entryList, getDefaultId, getReplacement, getTemplateType, isEmpty, key, key, label, name, readChild, readChildren, setDefaultId, setDefaultId, template, template, writeChildren
-
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, 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, getSpecification, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, 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, setSpecification, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
messageTypeComparator
public static final java.util.Comparator<ModelMessage> messageTypeComparator
Compare messages by type.
-
sourceId
private java.lang.String sourceId
-
displayId
private java.lang.String displayId
-
messageType
private ModelMessage.MessageType messageType
-
displayed
private boolean displayed
-
DISPLAY_TAG
private static final java.lang.String DISPLAY_TAG
- See Also:
- Constant Field Values
-
HAS_BEEN_DISPLAYED_TAG
private static final java.lang.String HAS_BEEN_DISPLAYED_TAG
- See Also:
- Constant Field Values
-
MESSAGE_TYPE_TAG
private static final java.lang.String MESSAGE_TYPE_TAG
- See Also:
- Constant Field Values
-
SOURCE_TAG
private static final java.lang.String SOURCE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ModelMessage
public ModelMessage()
Trivial constructor to allow creation with Game.newInstance.
-
ModelMessage
public ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, java.lang.String defaultId, FreeColGameObject source, FreeColObject display)
Creates a newModelMessage.- Parameters:
messageType- The type of this model message.id- The object identifier.defaultId- The default identifier.source- The source of the message. This is what the message should be associated with.display- TheFreeColObjectto display.
-
ModelMessage
public ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, FreeColGameObject source, FreeColObject display)
Creates a newModelMessage.- Parameters:
messageType- The type of this model message.id- The object identifier.source- The source of the message. This is what the message should be associated with.display- TheFreeColObjectto display.
-
ModelMessage
public ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, FreeColGameObject source)
Creates a newModelMessage.- Parameters:
messageType- The type of this model message.id- The object identifier.source- The source of the message. This is what the message should be associated with.
-
ModelMessage
public ModelMessage(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a new model message by reading a stream.- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
-
Method Detail
-
getSourceId
public java.lang.String getSourceId()
Gets the source of the message.- Returns:
- The identifier for the source of the message.
-
setSourceId
public void setSourceId(java.lang.String sourceId)
Sets the source object.- Parameters:
sourceId- A new source object identifier.
-
getDisplayId
public java.lang.String getDisplayId()
Gets the object to display.- Returns:
- The identifier of the object to display.
-
setDisplayId
public void setDisplayId(java.lang.String displayId)
Sets the object to display.- Parameters:
displayId- A new display object identifier.
-
divert
public void divert(FreeColGameObject newSource)
Switch the source (and display if it is the same) to a new object. Called when the source object becomes invalid.- Parameters:
newSource- A new source.
-
getMessageType
public ModelMessage.MessageType getMessageType()
Gets the messageType of the message to display.- Returns:
- The messageType.
-
setMessageType
public void setMessageType(ModelMessage.MessageType messageType)
Sets the type of the message.- Parameters:
messageType- The new messageType.
-
getOptionName
public java.lang.String getOptionName()
Get the option name for this message.- Returns:
- The option name.
-
getDisplayed
public boolean getDisplayed()
Has this message been displayed?- Returns:
- True if this message has been displayed.
-
setDisplayed
public void setDisplayed(boolean displayed)
Sets whether this message has been displayed.- Parameters:
displayed- The new displayed state.
-
addDefaultId
public ModelMessage addDefaultId(java.lang.String id)
Set a default identifier.- Parameters:
id- The new default identifier.- Returns:
- This
ModelMessage.
-
getDefaultDisplay
private static FreeColObject getDefaultDisplay(ModelMessage.MessageType messageType, FreeColGameObject source)
Gets the default display object for the given type.- Parameters:
messageType- The type to find the default display object for.source- The source object- Returns:
- An object to be displayed for the message.
-
getIgnoredMessageKey
public java.lang.String getIgnoredMessageKey()
Get a key for a message that might be ignored.- Returns:
- A key, or null if the message should not be ignored.
-
splitLinks
public java.util.List<java.lang.Object> splitLinks(Player player)
Split a message into a list of text and link objects.- Parameters:
player- ThePlayerwho will see the result.- Returns:
- A list of strings and buttons.
-
getSourceComparator
public static java.util.Comparator<ModelMessage> getSourceComparator(Game game, java.util.Map<java.lang.String,java.util.Comparator<?>> specialized)
Get a comparator that sorts on the message source object.- Parameters:
game- TheGameto look up source objects in.specialized- A map of specialized comparators keyed by class name.- Returns:
- The
Comparator.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classStringTemplate- Type Parameters:
T- TheFreeColObjectsubclass of the object to copy in.- Parameters:
other- The other object.- Returns:
- True if the copy in is succesful.
-
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:
writeAttributesin classStringTemplate- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributesin classStringTemplate- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classStringTemplate- Returns:
- The tag.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classStringTemplate
-
hashCode
public int hashCode()
- Overrides:
hashCodein classStringTemplate
-
toString
public java.lang.String toString()
- Overrides:
toStringin classStringTemplate
-
-