Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.gui.main.chat
Class ChatWindow

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by net.java.sip.communicator.util.swing.SIPCommFrame
                          extended by net.java.sip.communicator.impl.gui.main.chat.ChatWindow
All Implemented Interfaces:
WindowFocusListener, ImageObserver, MenuContainer, Serializable, EventListener, Observer, Accessible, RootPaneContainer, WindowConstants, PluginComponentListener, ChatContainer, ExportedWindow

public class ChatWindow
extends SIPCommFrame
implements ChatContainer, ExportedWindow, PluginComponentListener, WindowFocusListener

The chat window is the place, where users can write and send messages, view received messages. The ChatWindow supports two modes of use: "Group all messages in one window" and "Open messages in new window". In the first case a JTabbedPane is added in the window, where each tab contains a ChatPanel. In the second case the ChatPanel is added like a "write message area", "send" button, etc. It corresponds to a MetaContact or to a conference.

Note that the conference case is not yet implemented.

Author:
Yana Stamcheva, Lubomir Marinov, Adam Netocny
See Also:
Serialized Form

Nested Class Summary
 class ChatWindow.ChatWindowAdapter
          Before closing the chat window saves the current size and position through the ConfigurationService.
 
Nested classes/interfaces inherited from class net.java.sip.communicator.util.swing.SIPCommFrame
SIPCommFrame.MainContentPane
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface net.java.sip.communicator.service.gui.ExportedWindow
ABOUT_WINDOW, ADD_CONTACT_WINDOW, CHAT_WINDOW, MAIN_WINDOW
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ChatWindow()
          Creates an instance of ChatWindow by passing to it an instance of the main application window.
 
Method Summary
 void addChat(ChatPanel chatPanel)
          Adds a given ChatPanel to this chat window.
 void addChatChangeListener(ChatChangeListener listener)
          Adds the given ChatChangeListener.
 void bringToFront()
          Implements the ExportedWindow.bringToFront() method.
protected  void close(boolean isEscaped)
          Implements the SIPCommFrame close method.
 void directoryDropped(File dir, Point point)
          Sends all files from the given directory when it's dropped in the chat window.
 void dispose()
          Overwrites the dispose method in order to save the size and the position of this window before closing it.
 void fileDropped(File file, Point point)
          Sends the given file when dropped to the chat window.
 int getChatCount()
          Returns the number of all open chats.
 List<ChatPanel> getChats()
          Returns the currently available chat panels.
 ChatPanel getCurrentChat()
          Returns the currently selected chat panel.
 Frame getFrame()
          Returns the frame to which this container belongs.
 WindowID getIdentifier()
          Implements the ExportedWindow.getIdentifier() method.
 MainToolBar getMainToolBar()
          Returns the main toolbar in this chat window.
 Object getSource()
          The source of the window
 boolean isFrameActive()
          Indicates if the parent frame is currently the active window.
 void maximize()
          Implements the ExportedWindow.maximize() method.
 void minimize()
          Implements the ExportedWindow.minimize() method.
 void openChat(ChatPanel chatPanel, boolean setSelected)
          Opens the specified ChatPanel and optinally brings it to the front.
 void pluginComponentAdded(PluginComponentEvent event)
          Adds a plugin component to this container.
 void pluginComponentRemoved(PluginComponentEvent event)
          Removes a plugin component from this container.
 void removeAllChats()
          Removes all tabs in the chat tabbed pane.
 void removeChat(ChatPanel chatPanel)
          Removes a given ChatPanel from this chat window.
 void removeChatChangeListener(ChatChangeListener listener)
          Removes the given ChatChangeListener.
 void setChatIcon(ChatPanel chatPanel, Icon icon)
          Sets the icon for the given chat.
 void setChatTitle(ChatPanel chatPanel, String title)
          Sets the title of this chat container.
 void setCurrentChat(ChatPanel chatPanel)
          Selects the chat tab which corresponds to the given MetaContact.
 void setCurrentChatTab(int index)
          Selects the tab given by the index.
 void setParams(Object[] windowParams)
          Implementation of ExportedWindow.setParams(Object[]).
 void setTabIcon(ChatPanel chatPanel, Icon icon)
          Sets the given icon to the tab opened for the given chat panel.
 void setTabTitle(ChatPanel chatPanel, String title)
          Sets the given title to the tab opened for the given chat panel.
 void setToolbarVisible(boolean b)
          Shows or hides the Toolbar depending on the value of parameter b.
 void updateHistoryButtonState(ChatPanel chatPanel)
          Updates history buttons state.
 void windowGainedFocus(WindowEvent evt)
          Handles WindowEvents triggered when the window has gained focus.
 void windowLostFocus(WindowEvent arg0)
           
 
Methods inherited from class net.java.sip.communicator.util.swing.SIPCommFrame
addKeybindingAction, setKeybindingInput, setSizeAndLocation, setVisible, setVisible, update, validate, windowClosing
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.java.sip.communicator.impl.gui.main.chat.ChatContainer
setTitle
 
Methods inherited from interface net.java.sip.communicator.service.gui.ExportedWindow
isFocused, isVisible, setLocation, setSize, setVisible
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

ChatWindow

public ChatWindow()
Creates an instance of ChatWindow by passing to it an instance of the main application window.

Method Detail

setToolbarVisible

public void setToolbarVisible(boolean b)
Shows or hides the Toolbar depending on the value of parameter b.

Specified by:
setToolbarVisible in interface ChatContainer
Parameters:
b - if true, makes the Toolbar visible, otherwise hides the Toolbar

dispose

public void dispose()
Description copied from class: SIPCommFrame
Overwrites the dispose method in order to save the size and the position of this window before closing it.

Overrides:
dispose in class SIPCommFrame
See Also:
SIPCommFrame.dispose()

getMainToolBar

public MainToolBar getMainToolBar()
Returns the main toolbar in this chat window.

Returns:
the main toolbar in this chat window

addChat

public void addChat(ChatPanel chatPanel)
Adds a given ChatPanel to this chat window.

Specified by:
addChat in interface ChatContainer
Parameters:
chatPanel - The ChatPanel to add.

removeChat

public void removeChat(ChatPanel chatPanel)
Removes a given ChatPanel from this chat window.

Specified by:
removeChat in interface ChatContainer
Parameters:
chatPanel - The ChatPanel to remove.

removeAllChats

public void removeAllChats()
Removes all tabs in the chat tabbed pane. If not in mode TABBED_CHAT_WINDOW does nothing.

Specified by:
removeAllChats in interface ChatContainer

setCurrentChat

public void setCurrentChat(ChatPanel chatPanel)
Selects the chat tab which corresponds to the given MetaContact.

Specified by:
setCurrentChat in interface ChatContainer
Parameters:
chatPanel - The ChatPanel to select.

setCurrentChatTab

public void setCurrentChatTab(int index)
Selects the tab given by the index. If there's no tabbed pane, does nothing.

Parameters:
index - the index to select

getCurrentChat

public ChatPanel getCurrentChat()
Returns the currently selected chat panel.

Specified by:
getCurrentChat in interface ChatContainer
Returns:
the currently selected chat panel.

getChats

public List<ChatPanel> getChats()
Returns the currently available chat panels.

Specified by:
getChats in interface ChatContainer
Returns:
the currently available chat panels.

setTabIcon

public void setTabIcon(ChatPanel chatPanel,
                       Icon icon)
Sets the given icon to the tab opened for the given chat panel.

Parameters:
chatPanel - the chat panel, which corresponds the tab
icon - the icon to be set

setTabTitle

public void setTabTitle(ChatPanel chatPanel,
                        String title)
Sets the given title to the tab opened for the given chat panel.

Parameters:
chatPanel - the chat panel
title - the new title of the tab

close

protected void close(boolean isEscaped)
Implements the SIPCommFrame close method. We check for an open menu and if there's one we close it, otherwise we close the current chat.

Overrides:
close in class SIPCommFrame
Parameters:
isEscaped - indicates if this window was closed by pressing the esc button

getIdentifier

public WindowID getIdentifier()
Implements the ExportedWindow.getIdentifier() method.

Specified by:
getIdentifier in interface ExportedWindow
Returns:
the identifier of this window, used as plugin container identifier.

minimize

public void minimize()
Implements the ExportedWindow.minimize() method. Minimizes this window.

Specified by:
minimize in interface ExportedWindow

maximize

public void maximize()
Implements the ExportedWindow.maximize() method. Maximizes this window.

Specified by:
maximize in interface ExportedWindow

bringToFront

public void bringToFront()
Implements the ExportedWindow.bringToFront() method. Brings this window to front.

Specified by:
bringToFront in interface ExportedWindow

pluginComponentAdded

public void pluginComponentAdded(PluginComponentEvent event)
Adds a plugin component to this container.

Specified by:
pluginComponentAdded in interface PluginComponentListener
Parameters:
event - the PluginComponentEvent that notified us of the add

pluginComponentRemoved

public void pluginComponentRemoved(PluginComponentEvent event)
Removes a plugin component from this container.

Specified by:
pluginComponentRemoved in interface PluginComponentListener
Parameters:
event - the PluginComponentEvent that notified us of the remove

getSource

public Object getSource()
The source of the window

Specified by:
getSource in interface ExportedWindow
Returns:
the source of the window

getChatCount

public int getChatCount()
Returns the number of all open chats.

Specified by:
getChatCount in interface ChatContainer
Returns:
the number of all open chats

addChatChangeListener

public void addChatChangeListener(ChatChangeListener listener)
Adds the given ChatChangeListener.

Specified by:
addChatChangeListener in interface ChatContainer
Parameters:
listener - the listener to add

removeChatChangeListener

public void removeChatChangeListener(ChatChangeListener listener)
Removes the given ChatChangeListener.

Specified by:
removeChatChangeListener in interface ChatContainer
Parameters:
listener - the listener to remove

setParams

public void setParams(Object[] windowParams)
Implementation of ExportedWindow.setParams(Object[]).

Specified by:
setParams in interface ExportedWindow
Parameters:
windowParams - the parameters to pass.

windowGainedFocus

public void windowGainedFocus(WindowEvent evt)
Handles WindowEvents triggered when the window has gained focus.

Specified by:
windowGainedFocus in interface WindowFocusListener
Parameters:
evt - the WindowEvent

windowLostFocus

public void windowLostFocus(WindowEvent arg0)
Specified by:
windowLostFocus in interface WindowFocusListener

directoryDropped

public void directoryDropped(File dir,
                             Point point)
Sends all files from the given directory when it's dropped in the chat window.

Parameters:
dir - the directory to send
point - the point, where the directory was dropped

fileDropped

public void fileDropped(File file,
                        Point point)
Sends the given file when dropped to the chat window.

Parameters:
file - the file to send
point - the point, where the file was dropped

openChat

public void openChat(ChatPanel chatPanel,
                     boolean setSelected)
Opens the specified ChatPanel and optinally brings it to the front.

Specified by:
openChat in interface ChatContainer
Parameters:
chatPanel - the ChatPanel to be opened
setSelected - true if chatPanel (and respectively this ChatContainer) should be brought to the front; otherwise, false

getFrame

public Frame getFrame()
Returns the frame to which this container belongs.

Specified by:
getFrame in interface ChatContainer
Returns:
the frame to which this container belongs

setChatTitle

public void setChatTitle(ChatPanel chatPanel,
                         String title)
Sets the title of this chat container.

Specified by:
setChatTitle in interface ChatContainer
Parameters:
chatPanel - the chat, for which we set the title
title - the title to set

setChatIcon

public void setChatIcon(ChatPanel chatPanel,
                        Icon icon)
Description copied from interface: ChatContainer
Sets the icon for the given chat.

Specified by:
setChatIcon in interface ChatContainer
Parameters:
chatPanel - the chat, for which we want to set an icon
icon - the icon to set

isFrameActive

public boolean isFrameActive()
Indicates if the parent frame is currently the active window.

Returns:
true if the parent window is currently the active window, false otherwise

updateHistoryButtonState

public void updateHistoryButtonState(ChatPanel chatPanel)
Updates history buttons state.

Specified by:
updateHistoryButtonState in interface ChatContainer
Parameters:
chatPanel - the chat panel for which we should update button states

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.