Class MessageStore_<M extends Message>

java.lang.Object
eu.bandm.tools.message.MessageStore_<M>
All Implemented Interfaces:
MessageReceiver<M>
Direct Known Subclasses:
MessageStore, MessageStoreSorted

public abstract class MessageStore_<M extends Message> extends Object implements MessageReceiver<M>
Common superclass for the two kinds of message storage, MessageStore and MessageStoreSorted.
All messages received are added to an internal sequential storage.
There are two kinds of graphic representations, both in the context of javax.swing, namely MessageStore_<M extends Message>.TableModel and MessageStore_<M extends Message>.ListModel. The user can derive from these classes and provide its own instance by setTableModel(TableModel) and setListModel(ListModel). If not, a standard implementation will be provided by getTableModel() and getListModel(). A standard GUI implementation using the table model is SwingMessageTable.
This class can also be used for collecting, sorting and further processing: all messages currently stored can be propagated explicitly to some MessageReceiver by calling drainTo(MessageReceiver).
  • Field Details

    • messages

      protected final List<M extends Message> messages
      All stored messages. Either ordered by applying MessageStoreSorted.order or by arrival. The second item in the stored pair is the nesting level, which can be represented by GUIs.
    • tableModel

      protected MessageStore_<M extends Message>.TableModel tableModel
      The Swing table model, either user defined or default.
    • listModel

      protected MessageStore_<M extends Message>.ListModel listModel
      The Swing list model, either user defined or default.
    • indents

      @Opt protected final @Opt List<Integer> indents
      Local store of the indentation levels. Runs in parallel with the list of messages. Is set to null if no indentation shall be applied, and read by MessageStore_<M extends Message>.TableModel.
  • Constructor Details

  • Method Details

    • drainTo

      public void drainTo(MessageReceiver<? super M> receiver)
      Send all currently contained messages (in their stored order) to the receiver. The contents of the store is not altered.
      This method is synchronized, so that a further sending to this store cannot interfer.
      Parameters:
      receiver - to which the messages shall be sent.
    • drainAndClear

      public void drainAndClear(MessageReceiver<? super M> receiver)
      Send all currently contained messages to the receiver and clear the storage. This method is synchronized, so that a further sending to this store cannot interfer.
      Parameters:
      receiver - to which the messages shall be sent.
    • getMessages

      public List<M> getMessages()
      Returns an unmodifiable copy of the current content. This is a "live image", i.e. will reflect also all future changes.
      Returns:
      the list of all currently contained messages.
    • getSize

      public int getSize()
      Returns the number of currently contained messages.
      Returns:
      the number of currently contained messages.
    • isEmpty

      public boolean isEmpty()
    • setTableModel

      public void setTableModel(MessageStore_<M>.TableModel tm)
      Only needed for inserting a user-defined table model.
      Parameters:
      tm - the table model to be used.
      See Also:
    • setListModel

      public void setListModel(MessageStore_<M>.ListModel lm)
      Only needed for inserting user-defined list model.
      Parameters:
      lm - the list model to be used.
      See Also:
    • getTableModel

      public MessageStore_<M>.TableModel getTableModel()
      Returns the user-defined table model, if set, or the default.
      Returns:
      the currently used table model.
      See Also:
    • getListModel

      public MessageStore_<M>.ListModel getListModel()
      Returns the user-defined list model, if set, or the default.
      Returns:
      the currently used list model.
      See Also:
    • clear

      public void clear()
      Clears the internal storage, thus deletes all messages, and notifies the GUIs.
    • notifyGuiAdd

      protected void notifyGuiAdd(int i)
      An item has been inserted at position "i".
      Parameters:
      i - the position of the insertion.
    • notifyGuiChanged_ALL

      protected void notifyGuiChanged_ALL()
      Called in case of sort order change by MessageStoreSorted.setOrder(Comparator) and clear().
    • receive

      public abstract void receive(M message)
      Adds the received message to the internal store and notifies all subscribing GUI objects.
      Specified by:
      receive in interface MessageReceiver<M extends Message>
      Parameters:
      message - the received message.