org.jivesoftware.spark.ui
Class ChatRoom

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.jivesoftware.spark.component.BackgroundPanel
                      extended by org.jivesoftware.spark.ui.ChatRoom
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.DocumentListener, org.jivesoftware.smack.ConnectionListener, org.jivesoftware.smack.PacketListener
Direct Known Subclasses:
ChatRoomImpl, GroupChatRoom

public abstract class ChatRoom
extends BackgroundPanel
implements java.awt.event.ActionListener, org.jivesoftware.smack.PacketListener, javax.swing.event.DocumentListener, org.jivesoftware.smack.ConnectionListener

The base implementation of all ChatRoom conversations. You would implement this class to have most types of Chat.

See Also:
Serialized Form

Nested Class Summary
 class ChatRoom.ChatToolBar
          Used for the top toolbar.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected ChatRoom()
          Initializes the base layout and base background color.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 void addClosingListener(ChatRoomClosingListener listener)
           
 void addFileDropListener(FileDropListener listener)
          Adds a new FileDropListener to allow for Drag and Drop notifications of objects onto the ChatWindow.
 void addMessageListener(MessageListener listener)
          Add a MessageListener to the current ChatRoom.
 void addPacketID(java.lang.String packetID)
          Adds a packetID to the packedIDList.
 void addToTranscript(org.jivesoftware.smack.packet.Message message, boolean updateDate)
          Add a ChatResponse to the current discussion chat area.
 void changedUpdate(javax.swing.event.DocumentEvent docEvent)
          Checks to see if the Send button should be enabled.
protected  void checkForText(javax.swing.event.DocumentEvent e)
          Checks to see if the Send button should be enabled.
 void clearUnreadMessageCount()
          Resets the number of unread messages.
 void closeChatRoom()
          Close the ChatRoom.
 void connectionClosed()
           
 void connectionClosedOnError(java.lang.Exception e)
           
 void disableToolbar()
          Disables the ChatRoom toolbar.
 void enableToolbar()
          Enable the ChatRoom toolbar.
 void fireFileDropListeners(java.util.Collection files)
          Notify all users that a collection of files has been dropped onto the ChatRoom.
protected  void fireMessageSent(org.jivesoftware.smack.packet.Message message)
           
 javax.swing.JPanel getBottomPanel()
          Returns the bottom panel used in the ChatRoom.
 ChatInputEditor getChatInputEditor()
          Returns the SendField component.
 javax.swing.JPanel getChatPanel()
          Returns the ChatPanel that contains the ChatWindow and SendField.
 ChatRoom getChatRoom()
          Returns this instance of the chatroom.
abstract  org.jivesoftware.smack.packet.Message.Type getChatType()
          Returns the Message.Type specific to this chat room.
 javax.swing.JPanel getChatWindowPanel()
          Returns the Container which holds the ChatWindow.
 javax.swing.JPanel getEditorBar()
          Returns the panel which contains the toolbar items, such as spell checker.
abstract  long getLastActivity()
          Implementation of this method should return the last time this chat room sent or recieved a message.
 java.lang.String getNickname()
          Returns the nickname of the current agent as specified in Chat Preferences.
 javax.swing.JLabel getNotificationLabel()
          Returns the notification label.
abstract  java.lang.String getRoomname()
          Get the roomname to use for this ChatRoom.
abstract  java.lang.String getRoomTitle()
          Returns the title of this room to use.
 javax.swing.JScrollPane getScrollPaneForTranscriptWindow()
           
 javax.swing.JButton getSendButton()
          Return the "Send" button.
 javax.swing.JPanel getSendFieldToolbar()
          Returns the button panel.
 javax.swing.JSplitPane getSplitPane()
          Return the splitpane used in this chat room.
abstract  javax.swing.Icon getTabIcon()
          Get the Icon to be used in the tab holding this ChatRoom.
abstract  java.lang.String getTabTitle()
          Get the title to use in the tab holding this ChatRoom.
 ChatRoom.ChatToolBar getToolBar()
          Returns the toolbar used on top of the chat room.
 java.util.List getTranscripts()
          Returns a map of the current Chat Transcript which is a list of all ChatResponses and their order.
 TranscriptWindow getTranscriptWindow()
          Returns the chatWindow components.
 int getUnreadMessageCount()
          Returns the number of unread messages in this ChatRoom.
 javax.swing.JSplitPane getVerticalSlipPane()
           
 void increaseUnreadMessageCount()
          Increases the number of unread messages by 1.
 void insertMessage(org.jivesoftware.smack.packet.Message message)
          The main entry point when receiving any messages.
 void insertUpdate(javax.swing.event.DocumentEvent e)
           
abstract  boolean isActive()
          Returns whether or not this ChatRoom is active.
abstract  void leaveChatRoom()
          Disable the chat room.
 boolean packetIDExists(java.lang.String packetID)
          Checks if the packetID has already been used.
 void positionCursor()
          Requests valid focus to the SendField.
 void processPacket(org.jivesoftware.smack.packet.Packet packet)
          Process incoming packets.
 void reconnectingIn(int seconds)
           
 void reconnectionFailed(java.lang.Exception e)
           
 void reconnectionSuccessful()
           
 void removeClosingListener(ChatRoomClosingListener listener)
           
 void removeFileDropListener(FileDropListener listener)
          Remove the FileDropListener from ChatRoom.
 void removeMessageListener(MessageListener listener)
          Remove the specified MessageListener from the current ChatRoom.
 void removeUpdate(javax.swing.event.DocumentEvent event)
          Checks to see if the Send Button should be enabled depending on the current update in SendField.
 void saveTranscript()
          Override to save transcript in preferred room style.
 void scrollToBottom()
          Scrolls the chat window to the bottom.
protected abstract  void sendMessage()
          Creates and sends a message object from the text in the Send Field, using the default nickname specified in your Chat Preferences.
abstract  void sendMessage(org.jivesoftware.smack.packet.Message message)
          Sends the current message.
protected abstract  void sendMessage(java.lang.String text)
          Creates a Message object from the given text and delegates to the room for sending.
 
Methods inherited from class org.jivesoftware.spark.component.BackgroundPanel
paintComponent
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChatRoom

protected ChatRoom()
Initializes the base layout and base background color.

Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

sendMessage

protected abstract void sendMessage()
Creates and sends a message object from the text in the Send Field, using the default nickname specified in your Chat Preferences.


sendMessage

protected abstract void sendMessage(java.lang.String text)
Creates a Message object from the given text and delegates to the room for sending.

Parameters:
text - the text to send.

sendMessage

public abstract void sendMessage(org.jivesoftware.smack.packet.Message message)
Sends the current message.

Parameters:
message - - the message to send.

getNickname

public java.lang.String getNickname()
Returns the nickname of the current agent as specified in Chat Preferences.

Returns:
the nickname of the agent.

insertMessage

public void insertMessage(org.jivesoftware.smack.packet.Message message)
The main entry point when receiving any messages. This will either handle a message from a customer or delegate itself as an agent handler.

Parameters:
message - - the message receieved.

addToTranscript

public void addToTranscript(org.jivesoftware.smack.packet.Message message,
                            boolean updateDate)
Add a ChatResponse to the current discussion chat area.

Parameters:
message - the message to add to the transcript list
updateDate - true if you wish the date label to be updated with the date and time the message was received.

scrollToBottom

public void scrollToBottom()
Scrolls the chat window to the bottom.


checkForText

protected void checkForText(javax.swing.event.DocumentEvent e)
Checks to see if the Send button should be enabled.

Parameters:
e - - the documentevent to react to.

positionCursor

public void positionCursor()
Requests valid focus to the SendField.


leaveChatRoom

public abstract void leaveChatRoom()
Disable the chat room. This is called when a chat has been either transfered over or the customer has left the chat room.


processPacket

public void processPacket(org.jivesoftware.smack.packet.Packet packet)
Process incoming packets.

Specified by:
processPacket in interface org.jivesoftware.smack.PacketListener
Parameters:
packet - - the packet to process

getChatInputEditor

public ChatInputEditor getChatInputEditor()
Returns the SendField component.

Returns:
the SendField ChatSendField.

getTranscriptWindow

public TranscriptWindow getTranscriptWindow()
Returns the chatWindow components.

Returns:
the ChatWindow component.

addMessageListener

public void addMessageListener(MessageListener listener)
Add a MessageListener to the current ChatRoom.

Parameters:
listener - - the MessageListener to add to the current ChatRoom.

removeMessageListener

public void removeMessageListener(MessageListener listener)
Remove the specified MessageListener from the current ChatRoom.

Parameters:
listener - - the MessageListener to remove from the current ChatRoom.

fireMessageSent

protected void fireMessageSent(org.jivesoftware.smack.packet.Message message)

getTranscripts

public java.util.List getTranscripts()
Returns a map of the current Chat Transcript which is a list of all ChatResponses and their order. You should retrieve this map to get any current chat transcript state.

Returns:
- the map of current chat responses.

disableToolbar

public void disableToolbar()
Disables the ChatRoom toolbar.


enableToolbar

public void enableToolbar()
Enable the ChatRoom toolbar.


removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent event)
Checks to see if the Send Button should be enabled depending on the current update in SendField.

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener
Parameters:
event - the DocumentEvent from the sendField.

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent docEvent)
Checks to see if the Send button should be enabled.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener
Parameters:
docEvent - the document event.

getSplitPane

public javax.swing.JSplitPane getSplitPane()
Return the splitpane used in this chat room.

Returns:
the splitpane used in this chat room.

getChatPanel

public javax.swing.JPanel getChatPanel()
Returns the ChatPanel that contains the ChatWindow and SendField.

Returns:
the ChatPanel.

closeChatRoom

public void closeChatRoom()
Close the ChatRoom.


getTabIcon

public abstract javax.swing.Icon getTabIcon()
Get the Icon to be used in the tab holding this ChatRoom.

Returns:
- Icon to use

getRoomname

public abstract java.lang.String getRoomname()
Get the roomname to use for this ChatRoom.

Returns:
- the Roomname of this ChatRoom.

getTabTitle

public abstract java.lang.String getTabTitle()
Get the title to use in the tab holding this ChatRoom.

Returns:
- the title to use.

getRoomTitle

public abstract java.lang.String getRoomTitle()
Returns the title of this room to use. The title will be used in the title bar of the ChatRoom.

Returns:
- the title of this ChatRoom.

getChatType

public abstract org.jivesoftware.smack.packet.Message.Type getChatType()
Returns the Message.Type specific to this chat room. GroupChat is Message.Type.GROUP_CHAT Normal Chat is Message.TYPE.NORMAL

Returns:
the ChatRooms Message.TYPE

isActive

public abstract boolean isActive()
Returns whether or not this ChatRoom is active. Note: carrying a conversation rather than being disabled, as it would be transcript mode.

Returns:
true if the chat room is active.

getNotificationLabel

public javax.swing.JLabel getNotificationLabel()
Returns the notification label. The notification label notifies the user of chat room activity, such as the date of the last message and typing notifications.

Returns:
the notification label.

addPacketID

public void addPacketID(java.lang.String packetID)
Adds a packetID to the packedIDList. The packetIDLlist keeps track of all messages coming into the chatroom.

Parameters:
packetID - the packetID to add.

packetIDExists

public boolean packetIDExists(java.lang.String packetID)
Checks if the packetID has already been used.

Parameters:
packetID - the packetID to check for.
Returns:
true if the packetID already exists.

getChatRoom

public ChatRoom getChatRoom()
Returns this instance of the chatroom.

Returns:
the current ChatRoom instance.

getToolBar

public ChatRoom.ChatToolBar getToolBar()
Returns the toolbar used on top of the chat room.

Returns:
the toolbar used on top of this chat room.

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Specified by:
insertUpdate in interface javax.swing.event.DocumentListener

saveTranscript

public void saveTranscript()
Override to save transcript in preferred room style.


getSendFieldToolbar

public javax.swing.JPanel getSendFieldToolbar()
Returns the button panel. The Button Panel contains all tool items above the send field.

Returns:
the chat's button panel.

getUnreadMessageCount

public int getUnreadMessageCount()
Returns the number of unread messages in this ChatRoom.

Returns:
the number of unread messages.

increaseUnreadMessageCount

public void increaseUnreadMessageCount()
Increases the number of unread messages by 1.


clearUnreadMessageCount

public void clearUnreadMessageCount()
Resets the number of unread messages.


getBottomPanel

public javax.swing.JPanel getBottomPanel()
Returns the bottom panel used in the ChatRoom.

Returns:
the bottomPane;

getChatWindowPanel

public javax.swing.JPanel getChatWindowPanel()
Returns the Container which holds the ChatWindow.

Returns:
the Container.

addFileDropListener

public void addFileDropListener(FileDropListener listener)
Adds a new FileDropListener to allow for Drag and Drop notifications of objects onto the ChatWindow.

Parameters:
listener - the listener.

removeFileDropListener

public void removeFileDropListener(FileDropListener listener)
Remove the FileDropListener from ChatRoom.

Parameters:
listener - the listener.

fireFileDropListeners

public void fireFileDropListeners(java.util.Collection files)
Notify all users that a collection of files has been dropped onto the ChatRoom.

Parameters:
files - the files dropped.

getEditorBar

public javax.swing.JPanel getEditorBar()
Returns the panel which contains the toolbar items, such as spell checker.

Returns:
the panel which contains the lower toolbar items.

addClosingListener

public void addClosingListener(ChatRoomClosingListener listener)

removeClosingListener

public void removeClosingListener(ChatRoomClosingListener listener)

getScrollPaneForTranscriptWindow

public javax.swing.JScrollPane getScrollPaneForTranscriptWindow()

getSendButton

public javax.swing.JButton getSendButton()
Return the "Send" button.

Returns:
the send button.

getVerticalSlipPane

public javax.swing.JSplitPane getVerticalSlipPane()

getLastActivity

public abstract long getLastActivity()
Implementation of this method should return the last time this chat room sent or recieved a message.

Returns:
the last time (in system milliseconds) that the room last recieved a message.

connectionClosed

public void connectionClosed()
Specified by:
connectionClosed in interface org.jivesoftware.smack.ConnectionListener

connectionClosedOnError

public void connectionClosedOnError(java.lang.Exception e)
Specified by:
connectionClosedOnError in interface org.jivesoftware.smack.ConnectionListener

reconnectingIn

public void reconnectingIn(int seconds)
Specified by:
reconnectingIn in interface org.jivesoftware.smack.ConnectionListener

reconnectionSuccessful

public void reconnectionSuccessful()
Specified by:
reconnectionSuccessful in interface org.jivesoftware.smack.ConnectionListener

reconnectionFailed

public void reconnectionFailed(java.lang.Exception e)
Specified by:
reconnectionFailed in interface org.jivesoftware.smack.ConnectionListener