This package provides support for building up chat applications.

Each chat application has
  1. an IChatModel: a model that has on the one hand a list model representation of the chat history and on the other hand a method to send a new message
  2. a chat view: some component rendering the IChatMessages stored in the list model returned by the IChatModel
  3. a local message model: a model representing the properties of a message the user currently creates. Each message model is accompanied by a MessageFlowModel controlling the editability of the properties stored in the message model. This allows you to define the steps the user has to go when creating a message (for instance first selecting a type, than creating the reference and than writing the message text
  4. a message editor: at least a message editor which allows the input of the message text. For other properties (like the outgoing references, the type, or the style) you need appropriate editors.

Framework dependend classes

The following classes must be implemented for a given framework.
  1. IChatMessage: A chat message.
  2. IReferencingMessage: A chat message with references.
  3. HTMLPage: An object describing an URL. Could be a serializable object.
  4. IPresenceMessage: A message describing the entering or leaving of a user (with respect to a chatroom).
  5. ChatRoomFactory: A factory for chat rooms.
  6. ChatRoomFactory: A factory for chat rooms.
  7. IPublicRoom: A public chat room.
  8. IMaterialRoom: A room with some material (url).
  9. IPublicRoom: A public chat room.
  10. ChatRoomFactory: A factory for chat rooms.

Creating a simple chat

For a simple chat (without referencing) you need something like:
public class SimpleChatPanel extends JPanel
{
  /** creates a new simple chat panel for the given chatModel
   */
  public SimpleChatPanel(IChatModel chatModel)                // the chat model
  {
     super(new BorderLayout());
     MessageList messageList = new MessageList(false);       // the message view
     messageList.setModel(chatModel.getChatListModel());
     MessageModel messageModel = new MessageModel(chatModel);// the local message model
     DefaultMessageEditor editor =                           // the message editor
          new DefaultMessageEditor(messageModel);
     this.add(new JScrollPane(messageList), BorderLayout.CENTER);
     this.add(editor, BorderLayout.SOUTH);
     messageModel.startEditing();
  }
}

Creating a referenced chat

In a referenced chat the user can usually select messages or part of them in a chat view and can create references to these selections.

The references are rendered by a ReferencePanel. The reference panel must be the root component of all IReferencingDocViewers (eg. the message editor and the chat views) and all IReferencedDocViewers (eg. the chat views and the material components). The reference panel delegates the actual computations of the reference shapes to registered reference renderers. There exists some base implementations for showing references between messages in the list view, the tree view and between the message editor and a chat view.

The ChatPanel is a base container for multiple chat views as well as multiple editors (if you need different message editors in your application). The chat panel can show the references either on the left or the right side.

The base implementation of the local message model with outgoing references is the ReferencingMessageModel. A "reference property" editor is the reference creator, which allows the creation of references by pressing the right mouse button.

public class ReferencingChatPanel extends ReferencePanel           // we extend the reference panel to have it as root
{
  public ReferencingChatPanel(IChatModel chatModel)                // the chat model
  {
     super(new BorderLayout());

		// create the chat panel containing one Filler
		chatPanel = new ChatPanel(true, referenceDirection);
		chatPanel.setChatModel(messageFilter);

		// create and register the reference renderer using the chat panels filler
		referencePanel.registerRenderer(new DefaultVerticalReferenceRenderer(chatPanel.getFillPanel()));

		// create and add the chat views
		if (listView)
		{
			MessageList messageList = new MessageList();
			chatPanel.addChatView(messageList);
		}
		if (treeView)
		{
			MessageTree messageTree = new MessageTree();
			chatPanel.addChatView(messageTree);
		}

		chatPanel.getMultipleChatView().getToolbar().setVisible(treeView && listView);
		// create the message model containing the local message properties
//		final MessageModel messageModel = new MessageModel(chatModel, true);
		messageModel = new MessageModel(null, true);

		if (messageFactory != null)
		{
			messageModel.setMessageFactory(messageFactory);
		}

		// create the message editor and add it to the chat panel
		DefaultMessageEditor editor = new DefaultMessageEditor(messageModel);
		chatPanel.addMessageEditor(editor);

		materialListModel = new MaterialListModel();
		targetSelectionListModel = new TargetSelectionListModel();

		targetSelectionListModel.addReverseListModel(chatPanel.getMultipleChatView().getMessageListModel());
		targetSelectionListModel.addListModel(materialListModel);

		PopupReferenceEditor.bindPopupTo(editor.getMessageArea(),targetSelectionListModel,messageModel);

		// add a listener to the message model updating the shown references for the message editor
		messageModel.addMessageChangeListener(
		        new MessageReferenceChangeListener(
		                referencePanel.getMultiSelectionModel(),
		                referencePanel.getReferenceModel()));

		// create a reference editor using the mouse and the currently selected things and
		// add it to all chat views
		mouseReferenceEditor =
		        new MouseReferenceEditor(messageModel, referencePanel.getReferenceModel());
		chatPanel.getMultipleChatView().addMouseListenerToChatViews(mouseReferenceEditor);

		// create a type model and mouse editor using the mouse and a popup and
		// add it to all chat views
		typeModel = new TypeModel();
		mouseTypeEditor = new MouseTypeEditor(messageModel, typeModel);
		PopupTypeEditor.bindPopupTo(editor.getMessageArea(), typeModel, messageModel);
		chatPanel.getMultipleChatView().addMouseListenerToChatViews(mouseTypeEditor);

		// add the chat panel to the reference panel
		this.add(chatPanel, BorderLayout.CENTER);

		// let the message model start the message creation process
		messageModel.startEditing();
  }
}