Class MessageStore_<M extends Message>
- Type Parameters:
M- the type of the messages
- All Implemented Interfaces:
MessageReceiver<M>
- Direct Known Subclasses:
MessageStore,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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassStandard specialisation ofAbstractListModel.classStandard specialisation ofAbstractTableModel. -
Field Summary
FieldsModifier and TypeFieldDescriptionLocal store of the indentation levels.protected MessageStore_<M>.ListModelThe Swing list model, either user defined or default.All stored messages.protected MessageStore_<M>.TableModelThe Swing table model, either user defined or default. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the internal storage, thus deletes all messages, and notifies the GUIs.voiddrainAndClear(MessageReceiver<? super M> receiver) Send all currently contained messages to the receiver and clear the storage.voiddrainTo(MessageReceiver<? super M> receiver) Send all currently contained messages (in their stored order) to the receiver.get(int i) Return the message stored at the given poisition.Returns the user-defined list model, if set, or a lazy constructed instance of the default.Returns an unmodifiable copy of the current content.intgetSize()Returns the number of currently contained messages.Returns the user-defined table model, if set, or a lazy constructed instance of the default.booleanisEmpty()Returns whether the store is empty.protected voidnotifyGuiAdd(int i) An item has been inserted at a particular position.protected voidCalled in case of sort order change byMessageStoreSorted.setOrder(Comparator)andclear().abstract voidAdds the received message to the internal store and notifies all subscribing GUI objects.voidProcide a user-defined list model.voidProvide a user-defined table model.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Field Details
-
messages
All stored messages. Either ordered by applyingMessageStoreSorted.orderor by arrival. The second item in the stored pair is the nesting level, which can be represented by GUIs. -
tableModel
The Swing table model, either user defined or default. -
listModel
The Swing list model, either user defined or default. -
indents
Local store of the indentation levels. Runs in parallel with the list of messages. May be read byMessageStore_<M extends Message>.TableModel. Is set to null if no indentation shall be applied,
-
-
Constructor Details
-
MessageStore_
Only constructor. Not to be called by the user, but only by subclass constructor.- Parameters:
indents- an empty list to store the indentation levels. Can be null if indentation shall not be shown graphically.
-
-
Method Details
-
drainTo
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
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
Returns an unmodifiable copy of the current content. The result is backed by the muessage store and wil reflect all its future changes.- Returns:
- the list of all currently contained messages.
-
get
Return the message stored at the given poisition.- Parameters:
i- the position of the returned message, >= 0.- Returns:
- the message stored at the given poisition.
- Throws:
IndexOutOfBoundsException- - if the index is out of range (index < 0 || index >= getSize())
-
getSize
public int getSize()Returns the number of currently contained messages.- Returns:
- the number of currently contained messages.
-
isEmpty
public boolean isEmpty()Returns whether the store is empty.- Returns:
- whether the store is empty.
-
setTableModel
Provide a user-defined table model.- Parameters:
tm- the table model to be used.- See Also:
-
setListModel
Procide a user-defined list model.- Parameters:
lm- the list model to be used.- See Also:
-
getTableModel
Returns the user-defined table model, if set, or a lazy constructed instance of the default.- Returns:
- the currently used table model.
- See Also:
-
getListModel
Returns the user-defined list model, if set, or a lazy constructed instance of 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 a particular position.- Parameters:
i- the position of the insertion.
-
notifyGuiChanged_ALL
protected void notifyGuiChanged_ALL()Called in case of sort order change byMessageStoreSorted.setOrder(Comparator)andclear(). -
receive
Adds the received message to the internal store and notifies all subscribing GUI objects.- Specified by:
receivein interfaceMessageReceiver<M extends Message>- Parameters:
message- the received message.
-