diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java
index 61250883a..380725bf8 100644
--- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java
@@ -376,16 +376,9 @@ public ApplicationWindow getChatWindow(Contact contact)
ChatWindowManager chatWindowManager = mainFrame.getChatWindowManager();
- if (chatWindowManager.containsContactChat(metaContact))
- {
- ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact);
+ ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact);
- return (ApplicationWindow) chatPanel;
- }
- else {
- return (ApplicationWindow) chatWindowManager.createChat(
- metaContact, contact);
- }
+ return (ApplicationWindow) chatPanel;
}
/**
diff --git a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java
index f486cb4b3..385e3b6d4 100755
--- a/src/net/java/sip/communicator/impl/gui/main/MainFrame.java
+++ b/src/net/java/sip/communicator/impl/gui/main/MainFrame.java
@@ -567,7 +567,7 @@ public void contactPresenceStatusChanged(
if (metaContact != null) {
if(evt.getOldStatus() != evt.getNewStatus()) {
clistPanel.getContactList().modifyContact(metaContact);
- clistPanel.updateChatContactStatus(
+ chatWindowManager.updateChatContactStatus(
metaContact, sourceContact);
}
}
diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java
index ccf3c0323..a1f24ca0e 100755
--- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java
+++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPanel.java
@@ -184,18 +184,11 @@ public void run()
{
ChatPanel chatPanel;
- if(chatWindowManager.containsContactChat(metaContact))
- {
- chatPanel = chatWindowManager.getContactChat(metaContact);
- }
+ if(protocolContact != null)
+ chatPanel = chatWindowManager
+ .getContactChat(metaContact, protocolContact);
else
- {
- if(protocolContact != null)
- chatPanel = chatWindowManager
- .createChat(metaContact, protocolContact);
- else
- chatPanel = chatWindowManager.createChat(metaContact);
- }
+ chatPanel = chatWindowManager.getContactChat(metaContact);
chatWindowManager.openChat(chatPanel, true);
}
@@ -226,57 +219,28 @@ public void messageReceived(MessageReceivedEvent evt)
if (!Constants.TABBED_CHAT_WINDOW) {
// If in mode "open all messages in new window"
- if (chatWindowManager.containsContactChat(metaContact))
- {
- /*
- * If a chat window for this contact is already opened show it.
- */
- chatPanel = chatWindowManager.getContactChat(metaContact);
+
+ chatPanel = chatWindowManager.getContactChat(
+ metaContact, protocolContact, message.getMessageUID());
- chatPanel.processMessage(
+ chatPanel.processMessage(
protocolContact.getDisplayName(), date,
- Constants.INCOMING_MESSAGE, message.getContent());
- }
- else
- {
- chatPanel = chatWindowManager
- .createChat(metaContact, protocolContact,
- message.getMessageUID());
-
- chatPanel.processMessage(protocolContact.getDisplayName(),
- date, Constants.INCOMING_MESSAGE, message.getContent());
- }
+ Constants.INCOMING_MESSAGE, message.getContent());
}
- else {
-
- // If there's no open tab for the given contact.
- if (!chatWindowManager.containsContactChat(metaContact)) {
-
- logger.trace("MESSAGE RECEIVED: create new chat for contact: "
- + evt.getSourceContact().getAddress());
-
- chatPanel = chatWindowManager
- .createChat(metaContact, protocolContact,
- message.getMessageUID());
-
- logger.trace("MESSAGE RECEIVED: process message in chat for contact: "
- + evt.getSourceContact().getAddress());
-
- chatPanel.processMessage(protocolContact.getDisplayName(),
- date, Constants.INCOMING_MESSAGE, message.getContent());
- }
- else {
- logger.trace("MESSAGE RECEIVED: get existing chat for contact: "
- + evt.getSourceContact().getAddress());
-
- chatPanel = chatWindowManager.getContactChat(metaContact);
-
- logger.trace("MESSAGE RECEIVED: process message in chat for contact: "
- + evt.getSourceContact().getAddress());
-
- chatPanel.processMessage(protocolContact.getDisplayName(),
- date, Constants.INCOMING_MESSAGE, message.getContent());
- }
+ else
+ {
+ logger.trace("MESSAGE RECEIVED: create new chat for contact: "
+ + evt.getSourceContact().getAddress());
+
+ chatPanel = chatWindowManager
+ .getContactChat(metaContact, protocolContact,
+ message.getMessageUID());
+
+ logger.trace("MESSAGE RECEIVED: process message in chat for contact: "
+ + evt.getSourceContact().getAddress());
+
+ chatPanel.processMessage(protocolContact.getDisplayName(),
+ date, Constants.INCOMING_MESSAGE, message.getContent());
}
chatWindowManager.openChat(chatPanel, false);
@@ -372,83 +336,46 @@ else if (evt.getErrorCode()
ChatPanel chatPanel;
ChatWindow chatWindow;
- if (!Constants.TABBED_CHAT_WINDOW) {
- // If in mode "open all messages in new window"
- if (chatWindowManager.containsContactChat(metaContact))
- {
- chatPanel = chatWindowManager.getContactChat(metaContact);
-
- chatWindow = chatPanel.getChatWindow();
-
- chatPanel.refreshWriteArea();
-
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.OUTGOING_MESSAGE,
- sourceMessage.getContent());
-
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.ERROR_MESSAGE,
- errorMsg);
- }
- else
- {
- chatPanel = chatWindowManager.createChat(
- metaContact, sourceContact);
-
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.OUTGOING_MESSAGE,
- sourceMessage.getContent());
-
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.ERROR_MESSAGE,
- errorMsg);
- }
+ if (!Constants.TABBED_CHAT_WINDOW)
+ {
+ // If in mode "open all messages in new window"
+ chatPanel = chatWindowManager
+ .getContactChat(metaContact, sourceContact);
+
+ chatWindow = chatPanel.getChatWindow();
+
+ chatPanel.refreshWriteArea();
+
+ chatPanel.processMessage(
+ metaContact.getDisplayName(),
+ new Date(System.currentTimeMillis()),
+ Constants.OUTGOING_MESSAGE,
+ sourceMessage.getContent());
+
+ chatPanel.processMessage(
+ metaContact.getDisplayName(),
+ new Date(System.currentTimeMillis()),
+ Constants.ERROR_MESSAGE,
+ errorMsg);
}
else
{
- if (chatWindowManager.containsContactChat(metaContact))
- {
- chatPanel = chatWindowManager.getContactChat(metaContact);
-
- chatWindow = chatPanel.getChatWindow();
-
- chatPanel.refreshWriteArea();
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.OUTGOING_MESSAGE,
- sourceMessage.getContent());
+ chatPanel = chatWindowManager.getContactChat(metaContact, sourceContact);
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.ERROR_MESSAGE,
- errorMsg);
- }
- else {
- chatPanel = chatWindowManager.createChat(
- metaContact, sourceContact);
-
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.OUTGOING_MESSAGE,
- sourceMessage.getContent());
-
- chatPanel.processMessage(
- metaContact.getDisplayName(),
- new Date(System.currentTimeMillis()),
- Constants.ERROR_MESSAGE,
- errorMsg);
- }
+ chatWindow = chatPanel.getChatWindow();
+
+ chatPanel.refreshWriteArea();
+ chatPanel.processMessage(
+ metaContact.getDisplayName(),
+ new Date(System.currentTimeMillis()),
+ Constants.OUTGOING_MESSAGE,
+ sourceMessage.getContent());
+
+ chatPanel.processMessage(
+ metaContact.getDisplayName(),
+ new Date(System.currentTimeMillis()),
+ Constants.ERROR_MESSAGE,
+ errorMsg);
}
chatWindowManager.openChat(chatPanel, false);
@@ -520,42 +447,9 @@ else if (typingState == OperationSetTypingNotifications.STATE_UNKNOWN)
public void setChatNotificationMsg(MetaContact metaContact,
String notificationMsg)
{
- if (chatWindowManager.containsContactChat(metaContact))
- {
+ if(chatWindowManager.isChatOpenedForContact(metaContact))
chatWindowManager.getContactChat(metaContact)
- .setStatusMessage(notificationMsg);
- }
- }
-
- /**
- * Updates the status of the given metacontact in all opened chats
- * containing this contact.
- *
- * @param metaContact the contact whose status we will be updating
- */
- public void updateChatContactStatus(MetaContact metaContact,
- Contact protoContact)
- {
-
- ContactListModel listModel = (ContactListModel) this.getContactList()
- .getModel();
-
- if (chatWindowManager.containsContactChat(metaContact))
- {
- ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact);
-
- chatPanel.updateContactStatus(metaContact, protoContact);
-
- if(Constants.TABBED_CHAT_WINDOW)
- {
- ChatWindow chatWindow = chatPanel.getChatWindow();
-
- if (chatWindow.getTabCount() > 0) {
- chatWindow.setTabIcon(chatPanel, listModel
- .getMetaContactStatusIcon(metaContact));
- }
- }
- }
+ .setStatusMessage(notificationMsg);
}
/**
diff --git a/src/net/java/sip/communicator/impl/gui/main/message/ChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/message/ChatPanel.java
index be46870d0..38f62df52 100644
--- a/src/net/java/sip/communicator/impl/gui/main/message/ChatPanel.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/ChatPanel.java
@@ -117,7 +117,7 @@ public ChatPanel( ChatWindow chatWindow,
this.init();
- addComponentListener(new TabSelectionFocusGainListener());
+ addComponentListener(new TabSelectionComponentListener());
new Thread(){
public void run(){
@@ -145,7 +145,8 @@ private void init() {
/**
* Loads history in another thread.
*/
- public void loadHistory() {
+ public void loadHistory()
+ {
new Thread() {
public void run() {
Collection historyList = msgHistory.findLast(
@@ -174,7 +175,8 @@ public void run()
* escapedMessageID.
* @param escapedMessageID The id of the message that should be ignored.
*/
- public void loadHistory(String escapedMessageID) {
+ public void loadHistory(String escapedMessageID)
+ {
Collection historyList = msgHistory.findLast(
metaContact, Constants.CHAT_HISTORY_SIZE);
@@ -234,7 +236,7 @@ else if(o instanceof MessageReceivedEvent) {
public void updateContactStatus(MetaContact metaContact, Contact protoContact)
{
PresenceStatus status = sendPanel.getProtoContactSelectorBox()
- .getProtocolContact().getPresenceStatus();
+ .getSelectedProtocolContact().getPresenceStatus();
this.chatConferencePanel.updateContactStatus(
metaContact.getDefaultContact().getPresenceStatus());
@@ -326,18 +328,14 @@ public void setTnOperationSet(
}
/**
- * Returns the chat send panel.
- * @return ChatSendPanel The chat send panel.
+ * When user select a chat tab clicking with the mouse we change the
+ * currently selected chat panel, thus changing the title of the window,
+ * history buttons states, etc.
*/
- /*
- public ChatSendPanel getSendPanel() {
- return sendPanel;
- }
- */
- private class TabSelectionFocusGainListener
+ private class TabSelectionComponentListener
implements ComponentListener {
- public TabSelectionFocusGainListener() {
+ public TabSelectionComponentListener() {
super();
}
@@ -347,19 +345,31 @@ public void componentResized(ComponentEvent e) {
public void componentMoved(ComponentEvent e) {
}
- public void componentShown(ComponentEvent e) {
+ public void componentShown(ComponentEvent e)
+ {
Component component = e.getComponent();
Container parent = component.getParent();
- if (parent instanceof JTabbedPane) {
+ if (parent instanceof JTabbedPane)
+ {
JTabbedPane tabbedPane = (JTabbedPane) parent;
- if (tabbedPane.getSelectedComponent() == component) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
-
- chatWindow.setCurrentChatPanel(ChatPanel.this);
-
- writeMessagePanel.getEditorPane()
- .requestFocus();
+ if (tabbedPane.getSelectedComponent() == component)
+ {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ String metaContactName
+ = getMetaContact().getDisplayName();
+
+ if(!chatWindow.getTitle().equals(metaContactName))
+ {
+ chatWindow.setTitle(metaContactName);
+
+ chatWindow.getMainToolBar()
+ .changeHistoryButtonsState(ChatPanel.this);
+
+ ChatPanel.this.requestFocusInWriteArea();
+ }
}
});
}
@@ -376,7 +386,7 @@ public void componentHidden(ComponentEvent e) {
*/
public Contact getProtocolContact() {
return sendPanel.getProtoContactSelectorBox()
- .getProtocolContact();
+ .getSelectedProtocolContact();
}
/**
@@ -437,10 +447,9 @@ public void refreshWriteArea(){
/**
* Requests the focus in the write message area.
*/
- public void requestFocusInWriteArea(){
- JEditorPane writeMsgPane = this.writeMessagePanel.getEditorPane();
-
- writeMsgPane.requestFocus();
+ public void requestFocusInWriteArea()
+ {
+ this.writeMessagePanel.getEditorPane().requestFocus();
}
/**
diff --git a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java
index beb84b2d0..b4cff12c9 100755
--- a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindow.java
@@ -68,6 +68,25 @@ public ChatWindow(MainFrame mainFrame)
menusPanel = new MenusPanel(this);
+ //If in mode TABBED_CHAT_WINDOW initialize the tabbed pane
+ if(Constants.TABBED_CHAT_WINDOW)
+ {
+ chatTabbedPane = new SIPCommTabbedPane(true, false);
+
+ chatTabbedPane.addCloseListener(new CloseListener() {
+ public void closeOperation(MouseEvent e)
+ {
+ int tabIndex = chatTabbedPane.getOverTabIndex();
+
+ ChatPanel chatPanel
+ = (ChatPanel) chatTabbedPane.getComponentAt(tabIndex);
+
+ ChatWindow.this.mainFrame
+ .getChatWindowManager().closeChat(chatPanel);
+ }
+ });
+ }
+
this.setSizeAndLocation();
this.init();
@@ -156,7 +175,6 @@ public MainToolBar getMainToolBar()
return menusPanel.getMainToolBar();
}
-
/**
* Adds a given ChatPanel to this chat window.
*
@@ -165,15 +183,9 @@ public MainToolBar getMainToolBar()
public void addChat(ChatPanel chatPanel)
{
if(Constants.TABBED_CHAT_WINDOW)
- {
- this.addChatTab(chatPanel);
- this.chatTabbedPane.revalidate();
- this.chatTabbedPane.repaint();
- }
+ addChatTab(chatPanel);
else
- {
addSimpleChat(chatPanel);
- }
chatPanel.setChatVisible(true);
}
@@ -187,13 +199,7 @@ private void addSimpleChat(ChatPanel chatPanel)
{
chatPanel.setChatVisible(true);
- this.setCurrentChatPanel(chatPanel);
-
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
-
- this.windowTitle += chatPanel.getMetaContact().getDisplayName() + " ";
-
- this.setTitle(this.windowTitle);
}
/**
@@ -206,44 +212,20 @@ private void addChatTab(ChatPanel chatPanel)
{
String contactName = chatPanel.getMetaContact().getDisplayName();
PresenceStatus status = chatPanel.getDefaultContactStatus();
-
- if (chatTabbedPane == null) {
- // Initialize the tabbed pane for the first time
-
- chatTabbedPane = new SIPCommTabbedPane(true, false);
-
- chatTabbedPane.addCloseListener(new CloseListener() {
- public void closeOperation(MouseEvent e)
- {
- int tabIndex = chatTabbedPane.getOverTabIndex();
-
- ChatPanel chatPanel
- = (ChatPanel) chatTabbedPane.getComponentAt(tabIndex);
-
- mainFrame.getChatWindowManager().closeChat(chatPanel);
- }
- });
-
+
+ if (getCurrentChatPanel() == null)
+ {
this.getContentPane().add(chatPanel, BorderLayout.CENTER);
-
- this.setTitle(contactName);
-
- this.setCurrentChatPanel(chatPanel);
}
- else {
- if (chatTabbedPane.getTabCount() > 0) {
- // The tabbed pane contains already tabs.
-
- chatTabbedPane.addTab(contactName, new ImageIcon(Constants
- .getStatusIcon(status)), chatPanel);
-
- chatTabbedPane.getParent().validate();
- }
- else {
+ else
+ {
+ if (getChatTabCount() == 0)
+ {
ChatPanel firstChatPanel = getCurrentChatPanel();
-
+
PresenceStatus currentContactStatus = firstChatPanel
.getDefaultContactStatus();
+
// Add first two tabs to the tabbed pane.
chatTabbedPane.addTab(firstChatPanel.getMetaContact()
.getDisplayName(), new ImageIcon(Constants
@@ -260,139 +242,169 @@ public void closeOperation(MouseEvent e)
// conversation area is slightly resized and is made smaller,
// which moves the scrollbar up.
firstChatPanel.setCaretToEnd();
+
+ //add the chatTabbedPane to the window
+ this.getContentPane().add(chatTabbedPane, BorderLayout.CENTER);
+ this.getContentPane().validate();
}
+ else
+ {
+ // The tabbed pane contains already tabs.
- this.getContentPane().add(chatTabbedPane, BorderLayout.CENTER);
- this.getContentPane().validate();
+ chatTabbedPane.addTab(contactName, new ImageIcon(Constants
+ .getStatusIcon(status)), chatPanel);
- int chatIndex = chatTabbedPane.getTabCount() - 1;
- if (chatTabbedPane.getSelectedIndex() == chatIndex)
- this.setCurrentChatPanel(chatPanel);
+ chatTabbedPane.getParent().validate();
+ }
}
}
-
- /**
- * Selects the chat tab which corresponds to the given MetaContact.
- *
- * @param contact The MetaContact to select.
- */
- public void setSelectedChatTab(ChatPanel chatPanel)
- {
- this.chatTabbedPane.setSelectedComponent(chatPanel);
- this.setCurrentChatPanel(chatPanel);
- chatPanel.requestFocusInWriteArea();
- }
-
- /**
- * Selects the contact tab given by index.
- *
- * @param index The index of the tab to select.
- */
- public void setSelectedChatTab(int index)
- {
- ChatPanel chatPanel = (ChatPanel) this.chatTabbedPane
- .getComponentAt(index);
-
- this.setCurrentChatPanel(chatPanel);
- this.chatTabbedPane.setSelectedIndex(index);
- chatPanel.requestFocusInWriteArea();
- }
-
+
/**
- * Removes a given ChatPanel from the tabbed pane.
+ * Removes a given ChatPanel from this chat window.
*
* @param chatPanel The ChatPanel to remove.
*/
- public void removeChatTab(ChatPanel chatPanel)
+ public void removeChat(ChatPanel chatPanel)
{
+ logger.debug("Removes chat for contact: "
+ + chatPanel.getMetaContact().getDisplayName());
+
+ //if there's no tabs remove the chat panel directly from the content
+ //pane and hide the window.
+ if(getChatTabCount() == 0)
+ {
+ this.getContentPane().remove(chatPanel);
+
+ this.setVisible(false);
+
+ return;
+ }
+
+ //in the case of a tabbed chat window
int index = chatTabbedPane.indexOfComponent(chatPanel);
-
- String title = chatTabbedPane.getTitleAt(index);
- if (title != null)
+ if (index != -1)
{
if (chatTabbedPane.getTabCount() > 1)
chatTabbedPane.removeTabAt(index);
- if (chatTabbedPane.getTabCount() == 1) {
-
- String onlyTabtitle = chatTabbedPane.getTitleAt(0);
-
+ if (chatTabbedPane.getTabCount() == 1)
+ {
ChatPanel currentChatPanel = (ChatPanel) this.chatTabbedPane
.getComponentAt(0);
- this.getContentPane().remove(chatTabbedPane);
-
this.chatTabbedPane.removeAll();
+
+ this.getContentPane().remove(chatTabbedPane);
this.getContentPane().add(currentChatPanel, BorderLayout.CENTER);
this.setCurrentChatPanel(currentChatPanel);
-
- this.setTitle(onlyTabtitle);
}
}
}
- public void removeChatTab(int index)
+ /**
+ * Removes the chat at the given index. If there's no tabbed pane
+ * does nothing.
+ *
+ * @param index the index indicating, which tab to remove
+ */
+ public void removeChat(int index)
{
- this.removeChatTab((ChatPanel)chatTabbedPane.getComponentAt(index));
+ if(getChatTabCount() > 0)
+ this.removeChat((ChatPanel)chatTabbedPane.getComponentAt(index));
}
- public void removeAllTabs()
- {
- this.getContentPane().remove(chatTabbedPane);
-
- this.chatTabbedPane.removeAll();
- }
-
/**
- * Returns the currently selected chat panel.
- *
- * @return the currently selected chat panel.
+ * Removes all tabs in the chat tabbed pane. If not in mode
+ * TABBED_CHAT_WINDOW doesn nothing.
*/
- public ChatPanel getCurrentChatPanel()
+ public void removeAllChats()
{
- if(Constants.TABBED_CHAT_WINDOW && getTabCount() > 1)
- return (ChatPanel)chatTabbedPane.getSelectedComponent();
+ logger.debug("Remove all tabs from the chat window.");
+
+ if(getChatTabCount() > 0)
+ {
+ this.chatTabbedPane.removeAll();
+
+ this.getContentPane().remove(chatTabbedPane);
+ }
else
- return (ChatPanel) getContentPane().getComponent(1);
+ {
+ this.removeChat(getCurrentChatPanel());
+ }
}
/**
- * Sets the currently selected chat panel.
+ * Selects the chat tab which corresponds to the given MetaContact.
*
- * @param chatPanel The chat panel which is currently selected.
+ * @param contact The MetaContact to select.
*/
public void setCurrentChatPanel(ChatPanel chatPanel)
{
+ logger.debug("Set current chat panel to: "
+ + chatPanel.getMetaContact().getDisplayName());
+
+ if(getChatTabCount() > 0)
+ this.chatTabbedPane.setSelectedComponent(chatPanel);
+
this.setTitle(chatPanel.getMetaContact().getDisplayName());
this.getMainToolBar().changeHistoryButtonsState(chatPanel);
chatPanel.requestFocusInWriteArea();
}
+
+ /**
+ * Selects the tab given by the index. If there's no tabbed pane does nothing.
+ * @param index the index to select
+ */
+ public void setCurrentChatTab(int index)
+ {
+ ChatPanel chatPanel = null;
+ if(getChatTabCount() > 0)
+ {
+ chatPanel = (ChatPanel) this.chatTabbedPane
+ .getComponentAt(index);
+
+ setCurrentChatPanel(chatPanel);
+ }
+ }
/**
- * Returns the tab count of the chat tabbed pane. Meant to be used when in
- * "Group chat windows" mode.
+ * Returns the currently selected chat panel.
*
- * @return int The number of opened tabs.
+ * @return the currently selected chat panel.
*/
- public int getTabCount()
- {
- return (chatTabbedPane == null) ? 0 : chatTabbedPane.getTabCount();
+ public ChatPanel getCurrentChatPanel()
+ {
+ if(getChatTabCount() > 0)
+ return (ChatPanel)chatTabbedPane.getSelectedComponent();
+ else
+ {
+ int componentCount = getContentPane().getComponentCount();
+
+ for (int i = 0; i < componentCount; i ++)
+ {
+ Component c = getContentPane().getComponent(i);
+
+ if(c instanceof ChatPanel)
+ return (ChatPanel)c;
+ }
+ }
+ return null;
}
/**
- * Returns the chat tab index for the given MetaContact.
+ * Returns the tab count of the chat tabbed pane. Meant to be used when in
+ * "Group chat windows" mode.
*
- * @param contact The MetaContact we are searching for.
- * @return int The chat tab index for the given MetaContact.
+ * @return int The number of opened tabs.
*/
- public int getTabInex(ChatPanel chatPanel)
+ public int getChatTabCount()
{
- return this.chatTabbedPane.indexOfComponent(chatPanel);
+ return (chatTabbedPane == null) ? 0 : chatTabbedPane.getTabCount();
}
/**
@@ -442,13 +454,13 @@ private class ForwordTabAction
{
public void actionPerformed(ActionEvent e)
{
- if (chatTabbedPane != null) {
+ if (getChatTabCount() > 0) {
int selectedIndex = chatTabbedPane.getSelectedIndex();
if (selectedIndex < chatTabbedPane.getTabCount() - 1) {
- setSelectedChatTab(selectedIndex + 1);
+ setCurrentChatTab(selectedIndex + 1);
}
else {
- setSelectedChatTab(0);
+ setCurrentChatTab(0);
}
}
}
@@ -464,13 +476,13 @@ private class BackwordTabAction
{
public void actionPerformed(ActionEvent e)
{
- if (chatTabbedPane != null) {
+ if (getChatTabCount() > 0) {
int selectedIndex = chatTabbedPane.getSelectedIndex();
if (selectedIndex != 0) {
- setSelectedChatTab(selectedIndex - 1);
+ setCurrentChatTab(selectedIndex - 1);
}
else {
- setSelectedChatTab(chatTabbedPane.getTabCount() - 1);
+ setCurrentChatTab(chatTabbedPane.getTabCount() - 1);
}
}
}
@@ -608,7 +620,6 @@ public void windowDeiconified(WindowEvent e)
}
}
-
/**
* 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.
@@ -650,7 +661,7 @@ else if (selectedMenu != null
}
}
else {
- mainFrame.getChatWindowManager().closeTabbedWindow();
+ mainFrame.getChatWindowManager().closeWindow();
}
}
}
diff --git a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindowManager.java b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindowManager.java
index f69ff87e0..ffe7dc2a4 100644
--- a/src/net/java/sip/communicator/impl/gui/main/message/ChatWindowManager.java
+++ b/src/net/java/sip/communicator/impl/gui/main/message/ChatWindowManager.java
@@ -13,6 +13,7 @@
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.*;
+import net.java.sip.communicator.impl.gui.main.contactlist.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.protocol.*;
@@ -38,6 +39,8 @@ public class ChatWindowManager
public ChatWindowManager(MainFrame mainFrame)
{
this.mainFrame = mainFrame;
+
+ this.chatWindow = new ChatWindow(mainFrame);
}
/**
@@ -52,47 +55,58 @@ public void openChat(ChatPanel chatPanel, boolean setSelected)
{
synchronized (syncChat)
{
- ChatWindow chatWindow;
-
- chatWindow = chatPanel.getChatWindow();
+ ChatWindow chatWindow = chatPanel.getChatWindow();
if(!chatPanel.isWindowVisible())
chatWindow.addChat(chatPanel);
- if (chatWindow.getState() == JFrame.ICONIFIED
- && !chatWindow.getTitle().startsWith("*"))
- {
- chatWindow.setTitle(
- "*" + chatWindow.getTitle());
- }
-
if(chatWindow.isVisible())
- {
- if (ConfigurationManager.isAutoPopupNewMessage())
- {
- if(chatWindow.getState() == JFrame.ICONIFIED && setSelected)
+ {
+ if (ConfigurationManager.isAutoPopupNewMessage() || setSelected)
+ {
+ if(chatWindow.getState() == JFrame.ICONIFIED)
chatWindow.setState(JFrame.NORMAL);
chatWindow.toFront();
}
+ else
+ {
+ if (chatWindow.getState() == JFrame.ICONIFIED
+ && !chatWindow.getTitle().startsWith("*"))
+ {
+ chatWindow.setTitle(
+ "*" + chatWindow.getTitle());
+ }
+ }
}
else
+ {
+ if(!setSelected)
+ chatWindow.setCurrentChatPanel(chatPanel);
+
chatWindow.setVisible(true);
+ }
- if(Constants.TABBED_CHAT_WINDOW
- && chatWindow.getTabCount() > 1)
+ chatPanel.setCaretToEnd();
+
+ if(setSelected)
+ chatWindow.setCurrentChatPanel(chatPanel);
+ else
{
- if(setSelected)
- chatWindow.setSelectedChatTab(chatPanel);
- else
+ if(chatWindow.getChatTabCount() > 0)
chatPanel.getChatWindow().highlightTab(chatPanel);
}
-
- chatPanel.setCaretToEnd();
-
- chatWindow.getCurrentChatPanel().requestFocusInWriteArea();
}
}
+
+ public boolean isChatOpenedForContact(MetaContact metaContact)
+ {
+ if(containsContactChat(metaContact)
+ && getContactChat(metaContact).isVisible())
+ return true;
+
+ return false;
+ }
/**
* Closes the chat corresponding to the given meta contact.
@@ -150,7 +164,7 @@ else if (System.currentTimeMillis() - chatPanel
}
}
- public void closeTabbedWindow()
+ public void closeWindow()
{
synchronized (syncChat)
{
@@ -162,9 +176,10 @@ public void closeTabbedWindow()
msgText, Messages.getI18NString("warning").getText(),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
- if (answer == JOptionPane.OK_OPTION) {
- chatWindow.dispose();
- chatWindow = null;
+ if (answer == JOptionPane.OK_OPTION)
+ {
+ chatWindow.removeAllChats();
+ chatWindow.setVisible(false);
synchronized (chats)
{
@@ -173,7 +188,8 @@ public void closeTabbedWindow()
}
}
else if (System.currentTimeMillis() - chatWindow.getCurrentChatPanel()
- .getLastIncomingMsgTimestamp().getTime() < 2 * 1000) {
+ .getLastIncomingMsgTimestamp().getTime() < 2 * 1000)
+ {
SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages
.getI18NString("closeChatAfterNewMsg").getText());
@@ -181,9 +197,10 @@ else if (System.currentTimeMillis() - chatWindow.getCurrentChatPanel()
msgText, Messages.getI18NString("warning").getText(),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
- if (answer == JOptionPane.OK_OPTION) {
- chatWindow.dispose();
- chatWindow = null;
+ if (answer == JOptionPane.OK_OPTION)
+ {
+ chatWindow.removeAllChats();
+ chatWindow.setVisible(false);
synchronized (chats)
{
@@ -191,9 +208,10 @@ else if (System.currentTimeMillis() - chatWindow.getCurrentChatPanel()
}
}
}
- else {
- chatWindow.dispose();
- chatWindow = null;
+ else
+ {
+ chatWindow.removeAllChats();
+ chatWindow.setVisible(false);
synchronized (chats)
{
@@ -209,22 +227,9 @@ else if (System.currentTimeMillis() - chatWindow.getCurrentChatPanel()
* @param chatPanel the chat panel to close.
*/
private void closeChatPanel(ChatPanel chatPanel)
- {
- if (Constants.TABBED_CHAT_WINDOW)
- {
- if (chatWindow.getTabCount() > 0)
- this.chatWindow.removeChatTab(chatPanel);
- else
- {
- chatWindow.dispose();
- chatWindow = null;
- }
- }
- else
- {
- chatPanel.getChatWindow().setVisible(false);
- }
-
+ {
+ this.chatWindow.removeChat(chatPanel);
+
synchronized (chats)
{
chats.remove(chatPanel.getMetaContact());
@@ -240,7 +245,7 @@ private void closeChatPanel(ChatPanel chatPanel)
*
* @return the newly created ChatPanel
*/
- public ChatPanel createChat(MetaContact metaContact)
+ private ChatPanel createChat(MetaContact metaContact)
{
Contact defaultContact = metaContact.getDefaultContact();
@@ -291,7 +296,7 @@ public ChatPanel createChat(MetaContact metaContact)
* @param protocolContact The protocol contact.
* @return The ChatPanel newly created.
*/
- public ChatPanel createChat(MetaContact contact, Contact protocolContact)
+ private ChatPanel createChat(MetaContact contact, Contact protocolContact)
{
return createChat(contact, protocolContact, null);
}
@@ -306,14 +311,14 @@ public ChatPanel createChat(MetaContact contact, Contact protocolContact)
* excluded from the history when the last one is loaded in the chat.
* @return The ChatPanel newly created.
*/
- public ChatPanel createChat(MetaContact contact,
+ private ChatPanel createChat(MetaContact contact,
Contact protocolContact, String escapedMessageID)
{
synchronized (syncChat)
{
ChatWindow chatWindow;
- if(Constants.TABBED_CHAT_WINDOW && this.chatWindow != null)
+ if(Constants.TABBED_CHAT_WINDOW)
chatWindow = this.chatWindow;
else
{
@@ -329,7 +334,6 @@ public ChatPanel createChat(MetaContact contact,
{
this.chats.put(contact, chatPanel);
}
- chatPanel.loadHistory(escapedMessageID);
if(escapedMessageID != null)
chatPanel.loadHistory(escapedMessageID);
@@ -349,7 +353,7 @@ public ChatPanel createChat(MetaContact contact,
* @return TRUE if this chat window contains a chat for the given contact,
* FALSE otherwise
*/
- public boolean containsContactChat(MetaContact metaContact)
+ private boolean containsContactChat(MetaContact metaContact)
{
synchronized (chats)
{
@@ -366,7 +370,7 @@ public boolean containsContactChat(MetaContact metaContact)
* @return TRUE if this chat window contains the given chatPanel,
* FALSE otherwise
*/
- public boolean containsContactChat(ChatPanel chatPanel)
+ private boolean containsContactChat(ChatPanel chatPanel)
{
synchronized (chats)
{
@@ -382,10 +386,95 @@ public boolean containsContactChat(ChatPanel chatPanel)
*/
public ChatPanel getContactChat(MetaContact metaContact)
{
- synchronized (chats)
+ if(containsContactChat(metaContact))
{
- return (ChatPanel) chats.get(metaContact);
+ synchronized (chats)
+ {
+ return (ChatPanel) chats.get(metaContact);
+ }
+ }
+ else
+ return createChat(metaContact);
+ }
+
+ /**
+ * Returns the chat panel corresponding to the given meta contact
+ *
+ * @param metaContact the meta contact.
+ * @param protocolContact the protocol specific contact
+ * @return the chat panel corresponding to the given meta contact
+ */
+ public ChatPanel getContactChat(MetaContact metaContact,
+ Contact protocolContact)
+ {
+ if(containsContactChat(metaContact))
+ {
+ synchronized (chats)
+ {
+ return (ChatPanel) chats.get(metaContact);
+ }
+ }
+ else
+ return createChat(metaContact, protocolContact);
+ }
+
+ /**
+ * Returns the chat panel corresponding to the given meta contact
+ *
+ * @param metaContact the meta contact.
+ * @param protocolContact the protocol specific contact
+ * @param escapedMessageID the message ID of the message that should be
+ * excluded from the history when the last one is loaded in the chat
+ * @return the chat panel corresponding to the given meta contact
+ */
+ public ChatPanel getContactChat(MetaContact metaContact,
+ Contact protocolContact, String escapedMessageID)
+ {
+ if(containsContactChat(metaContact))
+ {
+ synchronized (chats)
+ {
+ return (ChatPanel) chats.get(metaContact);
+ }
+ }
+ else
+ return createChat(metaContact, protocolContact, escapedMessageID);
+ }
+
+ /**
+ * Updates the status of the given metacontact in all opened chats
+ * containing this contact.
+ *
+ * @param metaContact the contact whose status we will be updating
+ * @param protoContact the protocol specific contact
+ */
+ public void updateChatContactStatus(MetaContact metaContact,
+ Contact protoContact)
+ {
+ if(containsContactChat(metaContact))
+ {
+ ContactListModel listModel
+ = (ContactListModel) mainFrame.getContactListPanel()
+ .getContactList().getModel();
+
+ ChatPanel chatPanel;
+
+ synchronized (chats)
+ {
+ chatPanel = (ChatPanel) chats.get(metaContact);
+ }
+
+ chatPanel.updateContactStatus(metaContact, protoContact);
+
+ if(Constants.TABBED_CHAT_WINDOW)
+ {
+ ChatWindow chatWindow = chatPanel.getChatWindow();
+
+ if (chatWindow.getChatTabCount() > 0) {
+ chatWindow.setTabIcon(chatPanel, listModel
+ .getMetaContactStatusIcon(metaContact));
+ }
+ }
}
}
-
}