Class ModelMessage

    • Field Detail

      • 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
      • displayed

        private boolean displayed
      • 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
    • 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 new ModelMessage.
        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 - The FreeColObject to display.
      • 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 object identifier.
        source - The source of the message. This is what the message should be associated with.
        display - The FreeColObject 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 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 - The FreeColXMLReader to 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 - The Player who 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 - The Game to 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:
        copyIn in class StringTemplate
        Type Parameters:
        T - The FreeColObject subclass 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:
        writeAttributes in class StringTemplate
        Parameters:
        xw - The FreeColXMLWriter to 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:
        readAttributes in class StringTemplate
        Parameters:
        xr - The FreeColXMLReader to 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:
        getXMLTagName in class StringTemplate
        Returns:
        The tag.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class StringTemplate