net.sf.freecol.common.model
Class ModelMessage

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.StringTemplate
          extended by net.sf.freecol.common.model.ModelMessage

public class ModelMessage
extends StringTemplate

Contains a message about a change in the model.


Nested Class Summary
static class ModelMessage.MessageType
          Constants describing the type of message.
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.StringTemplate
StringTemplate.TemplateType
 
Field Summary
private  boolean beenDisplayed
           
private  java.lang.String displayId
           
private  ModelMessage.MessageType messageType
           
private  java.lang.String ownerId
           
private  java.lang.String sourceId
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, logger, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
ModelMessage()
           
ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, FreeColGameObject source)
          Creates a new ModelMessage.
ModelMessage(ModelMessage.MessageType messageType, java.lang.String id, FreeColGameObject source, FreeColObject display)
          Creates a new ModelMessage.
ModelMessage(java.lang.String id, FreeColGameObject source)
          Creates a new ModelMessage.
ModelMessage(java.lang.String id, FreeColGameObject source, FreeColObject display)
          Creates a new ModelMessage.
 
Method Summary
 ModelMessage add(java.lang.String value)
          Add a replacement value without a key to the ModelMessage.
 ModelMessage add(java.lang.String key, java.lang.String value)
          Add a new key and replacement to the ModelMessage.
 ModelMessage addAmount(java.lang.String key, int amount)
          Add a key and an integer value to replace it to this StringTemplate.
 ModelMessage addName(java.lang.String value)
          Add a replacement value without a key to the ModelMessage.
 ModelMessage addName(java.lang.String key, java.lang.String value)
          Add a new key and replacement to the ModelMessage.
 ModelMessage addStringTemplate(java.lang.String key, StringTemplate template)
          Add a key and a StringTemplate to replace it to this StringTemplate.
 ModelMessage addStringTemplate(StringTemplate template)
          Add a StringTemplate to this LABEL StringTemplate.
 void divert(FreeColGameObject newSource)
          Switch the source (and display if it is the same) to a new object.
 boolean equals(java.lang.Object o)
          Checks if this ModelMessage is equal to another ModelMessage.
private static FreeColObject getDefaultDisplay(ModelMessage.MessageType messageType, FreeColGameObject source)
          Returns the default display object for the given type.
 java.lang.String getDisplayId()
          Gets the ID of the object to display.
 ModelMessage.MessageType getMessageType()
          Gets the messageType of the message to display.
 java.lang.String getMessageTypeName()
           
 java.lang.String getOwnerId()
          Compatibility hack.
 java.lang.String getSourceId()
          Gets the ID of the source of the message.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasBeenDisplayed()
          Checks if this ModelMessage has been displayed.
 int hashCode()
           
 void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setBeenDisplayed(boolean beenDisplayed)
          Sets the beenDisplayed value of this ModelMessage.
 ModelMessage setDefaultId(java.lang.String newDefaultId)
          Set the DefaultId value.
 void setDisplayId(java.lang.String displayId)
          Sets the ID of the object to display.
 void setMessageType(ModelMessage.MessageType messageType)
          Sets the type of the message.
 void setOwnerId(java.lang.String ownerId)
          Compatibility hack.
 void setSourceId(java.lang.String sourceId)
          Sets the ID of the source object.
 java.lang.String toString()
          Debug helper.
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.
 
Methods inherited from class net.sf.freecol.common.model.StringTemplate
addAmount, addName, getDefaultId, getKeys, getReplacement, getReplacements, getTemplateType, key, label, name, readAttributes, readChildren, template, writeChildren
 
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, readChild, 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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ownerId

private java.lang.String ownerId

sourceId

private java.lang.String sourceId

displayId

private java.lang.String displayId

messageType

private ModelMessage.MessageType messageType

beenDisplayed

private boolean beenDisplayed
Constructor Detail

ModelMessage

public ModelMessage()

ModelMessage

public ModelMessage(java.lang.String id,
                    FreeColGameObject source,
                    FreeColObject display)
Creates a new ModelMessage.

Parameters:
id - The ID of the message to display.
source - The source of the message. This is what the message should be associated with.
display - The Object to display.

ModelMessage

public ModelMessage(ModelMessage.MessageType messageType,
                    java.lang.String id,
                    FreeColGameObject source)
Creates a new ModelMessage.

Parameters:
messageType - The type of this model message.
id - The ID of the message to display.
source - The source of the message. This is what the message should be associated with.

ModelMessage

public ModelMessage(java.lang.String id,
                    FreeColGameObject source)
Creates a new ModelMessage.

Parameters:
id - The ID of the message to display.
source - The source of the message. This is what the message should be associated with.

ModelMessage

public ModelMessage(ModelMessage.MessageType messageType,
                    java.lang.String id,
                    FreeColGameObject source,
                    FreeColObject display)
Creates a new ModelMessage.

Parameters:
messageType - The type of this model message.
id - The ID of the message to display.
source - The source of the message. This is what the message should be associated with.
display - The object to display.
Method Detail

setDefaultId

public final ModelMessage setDefaultId(java.lang.String newDefaultId)
Set the DefaultId value.

Overrides:
setDefaultId in class StringTemplate
Parameters:
newDefaultId - The new DefaultId value.
Returns:
a ModelMessage value

getDefaultDisplay

private static FreeColObject getDefaultDisplay(ModelMessage.MessageType messageType,
                                               FreeColGameObject source)
Returns 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.

hasBeenDisplayed

public boolean hasBeenDisplayed()
Checks if this ModelMessage has been displayed.

Returns:
true if this ModelMessage has been displayed.
See Also:
setBeenDisplayed(boolean)

setBeenDisplayed

public void setBeenDisplayed(boolean beenDisplayed)
Sets the beenDisplayed value of this ModelMessage. This is used to avoid showing the same message twice.

Parameters:
beenDisplayed - Should be set to true after the message has been displayed.

getSourceId

public java.lang.String getSourceId()
Gets the ID of the source of the message.

Returns:
The source of the message.

setSourceId

public void setSourceId(java.lang.String sourceId)
Sets the ID of the source object.

Parameters:
sourceId - A new source ID.

getDisplayId

public java.lang.String getDisplayId()
Gets the ID of the object to display.

Returns:
The ID of the object to display.

setDisplayId

public void setDisplayId(java.lang.String displayId)
Sets the ID of the object to display.

Parameters:
displayId - A new display ID.

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.

getMessageTypeName

public java.lang.String getMessageTypeName()

divert

public void divert(FreeColGameObject newSource)
Switch the source (and display if it is the same) to a new object. Called when an object becomes invalid.

Parameters:
newSource - A new source.

getOwnerId

public java.lang.String getOwnerId()
Compatibility hack. Do not use.


setOwnerId

public void setOwnerId(java.lang.String ownerId)
Compatibility hack. Do not use.


add

public ModelMessage add(java.lang.String key,
                        java.lang.String value)
Add a new key and replacement to the ModelMessage. This is only possible if the ModelMessage is of type TEMPLATE.

Overrides:
add in class StringTemplate
Parameters:
key - a String value
value - a String value
Returns:
a ModelMessage value

add

public ModelMessage add(java.lang.String value)
Add a replacement value without a key to the ModelMessage. This is only possible if the ModelMessage is of type LABEL.

Overrides:
add in class StringTemplate
Parameters:
value - a String value
Returns:
a ModelMessage value

addName

public ModelMessage addName(java.lang.String key,
                            java.lang.String value)
Add a new key and replacement to the ModelMessage. The replacement must be a proper name. This is only possible if the ModelMessage is of type TEMPLATE.

Overrides:
addName in class StringTemplate
Parameters:
key - a String value
value - a String value
Returns:
a ModelMessage value

addName

public ModelMessage addName(java.lang.String value)
Add a replacement value without a key to the ModelMessage. The replacement must be a proper name. This is only possible if the ModelMessage is of type LABEL.

Overrides:
addName in class StringTemplate
Parameters:
value - a String value
Returns:
a ModelMessage value

addAmount

public ModelMessage addAmount(java.lang.String key,
                              int amount)
Add a key and an integer value to replace it to this StringTemplate.

Parameters:
key - a String value
amount - an int value
Returns:
a ModelMessage value

addStringTemplate

public ModelMessage addStringTemplate(java.lang.String key,
                                      StringTemplate template)
Add a key and a StringTemplate to replace it to this StringTemplate.

Overrides:
addStringTemplate in class StringTemplate
Parameters:
key - a String value
template - a StringTemplate value
Returns:
a ModelMessage value

addStringTemplate

public ModelMessage addStringTemplate(StringTemplate template)
Add a StringTemplate to this LABEL StringTemplate.

Overrides:
addStringTemplate in class StringTemplate
Parameters:
template - a StringTemplate value
Returns:
a ModelMessage value

equals

public boolean equals(java.lang.Object o)
Checks if this ModelMessage is equal to another ModelMessage.

Overrides:
equals in class StringTemplate
Parameters:
o - The Object to compare.
Returns:
true if the sources, message IDs and data are equal.

hashCode

public int hashCode()
Overrides:
hashCode in class StringTemplate

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.

Overrides:
toXMLImpl in class StringTemplate
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 StringTemplate
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

public 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.

toString

public java.lang.String toString()
Debug helper.

Overrides:
toString in class StringTemplate

getXMLElementTagName

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

Returns:
"modelMessage"