diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java index 4fbcfa3cb..5c190b5ff 100755 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindow.java @@ -71,7 +71,7 @@ public ChatWindow(MainFrame mainFrame) menusPanel = new MenusPanel(this); //If in mode TABBED_CHAT_WINDOW initialize the tabbed pane - if(Constants.TABBED_CHAT_WINDOW) + if(ConfigurationManager.isMultiChatWindowEnabled()) { chatTabbedPane = new SIPCommTabbedPane(true, false); @@ -151,7 +151,7 @@ public MainToolBar getMainToolBar() */ public void addChat(ChatPanel chatPanel) { - if (Constants.TABBED_CHAT_WINDOW) + if (ConfigurationManager.isMultiChatWindowEnabled()) addChatTab(chatPanel); else addSimpleChat(chatPanel); @@ -348,9 +348,11 @@ public ChatPanel getCurrentChatPanel() for (int i = 0; i < componentCount; i ++) { Component c = getContentPane().getComponent(i); - + if(c instanceof ChatPanel) + { return (ChatPanel)c; + } } } return null; @@ -602,7 +604,7 @@ else if (selectedMenu != null } else { - mainFrame.getChatWindowManager().closeWindow(); + mainFrame.getChatWindowManager().closeWindow(this); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java index c3136a5a6..78e97b4de 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java @@ -30,8 +30,6 @@ public class ChatWindowManager { private Logger logger = Logger.getLogger(ChatWindowManager.class); - private ChatWindow chatWindow; - private Hashtable chats = new Hashtable(); private MainFrame mainFrame; @@ -58,7 +56,7 @@ public void openChat(ChatPanel chatPanel, boolean setSelected) ChatWindow chatWindow = chatPanel.getChatWindow(); boolean isChatVisible = chatPanel.isShown(); - + if(!isChatVisible) chatWindow.addChat(chatPanel); @@ -82,7 +80,7 @@ public void openChat(ChatPanel chatPanel, boolean setSelected) chatWindow.setTitle( "*" + chatWindow.getTitle()); } - + if(setSelected) { chatWindow.setCurrentChatPanel(chatPanel); @@ -96,7 +94,7 @@ else if(!chatWindow.getCurrentChatPanel().equals(chatPanel) } } else - { + { chatWindow.setVisible(true); chatWindow.setCurrentChatPanel(chatPanel); @@ -233,12 +231,12 @@ else if (System.currentTimeMillis() - chatWindow * Closes the chat window. Removes all contained chats and invokes * setVisible(false) to the window. */ - public void closeWindow() + public void closeWindow(ChatWindow chatWindow) { synchronized (syncChat) { ChatPanel chatPanel = chatWindow.getCurrentChatPanel(); - + if (!chatPanel.isWriteAreaEmpty()) { SIPCommMsgTextArea msgText = new SIPCommMsgTextArea(Messages @@ -249,7 +247,7 @@ public void closeWindow() if (answer == JOptionPane.OK_OPTION) { - this.disposeChatWindow(); + this.disposeChatWindow(chatWindow); } } else if (System.currentTimeMillis() - chatWindow @@ -264,12 +262,12 @@ else if (System.currentTimeMillis() - chatWindow if (answer == JOptionPane.OK_OPTION) { - this.disposeChatWindow(); + this.disposeChatWindow(chatWindow); } } else { - this.disposeChatWindow(); + this.disposeChatWindow(chatWindow); } } } @@ -335,7 +333,7 @@ public MetaContactChatPanel getContactChat( MetaContact metaContact, { return (MetaContactChatPanel) getChat(metaContact); } - else + else return createChat( metaContact, protocolContact, escapedMessageID); @@ -348,9 +346,35 @@ public MetaContactChatPanel getContactChat( MetaContact metaContact, */ public ChatPanel getSelectedChat() { + ChatPanel selectedChat = null; + + Enumeration chatPanels = chats.keys(); + synchronized (syncChat) { - return chatWindow.getCurrentChatPanel(); + if (ConfigurationManager.isMultiChatWindowEnabled()) + { + if (chatPanels.hasMoreElements()) + { + ChatPanel firstChatPanel + = (ChatPanel) chatPanels.nextElement(); + + selectedChat + = firstChatPanel.getChatWindow().getCurrentChatPanel(); + } + } + else + { + while (chatPanels.hasMoreElements()) + { + ChatPanel chatPanel = (ChatPanel) chatPanels.nextElement(); + + if (chatPanel.getChatWindow().isFocusOwner()) + selectedChat = chatPanel; + } + } + + return selectedChat; } } @@ -434,10 +458,12 @@ public ConferenceChatPanel getMultiChat(ChatRoom chatRoom, */ private void closeChatPanel(ChatPanel chatPanel) { - this.chatWindow.removeChat(chatPanel); + ChatWindow chatWindow = chatPanel.getChatWindow(); + + chatWindow.removeChat(chatPanel); if (chatWindow.getChatCount() == 0) - disposeChatWindow(); + disposeChatWindow(chatWindow); synchronized (chats) { @@ -527,23 +553,27 @@ private MetaContactChatPanel createChat(MetaContact contact, { ChatWindow chatWindow; - if(Constants.TABBED_CHAT_WINDOW) + if(ConfigurationManager.isMultiChatWindowEnabled()) { - if(this.chatWindow == null) + // If we're in a tabbed window we're looking for the chat window + // through one of the already created chats. + if(chats.keys().hasMoreElements()) + { + chatWindow + = ((ChatPanel) chats.elements().nextElement()) + .getChatWindow(); + } + else { - this.chatWindow = new ChatWindow(mainFrame); + chatWindow = new ChatWindow(mainFrame); GuiActivator.getUIService() - .registerExportedWindow(this.chatWindow); + .registerExportedWindow(chatWindow); } - - chatWindow = this.chatWindow; } else { chatWindow = new ChatWindow(mainFrame); - - this.chatWindow = chatWindow; } MetaContactChatPanel chatPanel @@ -589,24 +619,26 @@ private ConferenceChatPanel createChat( ChatRoomWrapper chatRoomWrapper, ChatWindow chatWindow; - if(Constants.TABBED_CHAT_WINDOW) + if(ConfigurationManager.isMultiChatWindowEnabled()) { - if(this.chatWindow == null) + // If we're in a tabbed window we're looking for the chat window + // through one of the already created chats. + if(chats.keys().hasMoreElements()) { - this.chatWindow = new ChatWindow(mainFrame); + chatWindow + = ((ChatPanel) chats.keys().nextElement()).getChatWindow(); + } + else + { + chatWindow = new ChatWindow(mainFrame); GuiActivator.getUIService() - .registerExportedWindow(this.chatWindow); + .registerExportedWindow(chatWindow); } - - chatWindow = this.chatWindow; } else { chatWindow = new ChatWindow(mainFrame); - GuiActivator.getUIService().registerExportedWindow(chatWindow); - - this.chatWindow = chatWindow; } ConferenceChatPanel chatPanel @@ -678,18 +710,23 @@ private ChatPanel getChat(Object key) /** * Disposes the chat window. */ - private void disposeChatWindow() + private void disposeChatWindow(ChatWindow chatWindow) { + synchronized (chats) + { + // If we're in a tabbed window we clear the list of active chats, as + // they'll be all gone with the window. + if (ConfigurationManager.isMultiChatWindowEnabled()) + chats.clear(); + else + chats.remove( + chatWindow.getCurrentChatPanel().getChatIdentifier()); + } + if (chatWindow.getChatCount() > 0) chatWindow.removeAllChats(); chatWindow.dispose(); - chatWindow = null; - - synchronized (chats) - { - chats.clear(); - } ContactList clist = mainFrame.getContactListPanel().getContactList(); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java index 2a51fd425..d06d469ab 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/MetaContactChatPanel.java @@ -341,7 +341,7 @@ public void updateContactStatus(Contact contact, PresenceStatus newStatus) getChatConversationPanel().appendMessageToEnd(message); - if(Constants.TABBED_CHAT_WINDOW) + if(ConfigurationManager.isMultiChatWindowEnabled()) { if (getChatWindow().getChatTabCount() > 0) { getChatWindow().setTabIcon(this, diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatPanel.java index 66b55dcf1..02e38db83 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatPanel.java @@ -507,7 +507,7 @@ public void chatRoomPropertyChangeFailed( */ public void updateChatRoomStatus(String status) { - if(Constants.TABBED_CHAT_WINDOW) + if(ConfigurationManager.isMultiChatWindowEnabled()) { if (getChatWindow().getChatTabCount() > 0) { getChatWindow().setTabIcon(this, diff --git a/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java index 1820295a6..ab614a13a 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ConfigurationManager.java @@ -24,7 +24,7 @@ public class ConfigurationManager private static boolean autoPopupNewMessage = false; private static String sendMessageCommand; - + private static boolean isCallPanelShown = true; private static boolean isShowOffline = true; @@ -37,6 +37,8 @@ public class ConfigurationManager private static boolean isMoveContactConfirmationRequested = true; + private static boolean isMultiChatWindowEnabled = true; + private static ConfigurationService configService = GuiActivator.getConfigurationService(); @@ -118,6 +120,19 @@ public static void loadGuiConfigurations() = new Boolean(isMoveContactConfirmationRequestedString) .booleanValue(); } + + // Load the "isMultiChatWindowEnabled" property. + String isMultiChatWindowEnabledString + = configService.getString( + "net.java.sip.communicator.impl.gui.isMultiChatWindowEnabled"); + + if(isMultiChatWindowEnabledString != null + && isMultiChatWindowEnabledString != "") + { + isMultiChatWindowEnabled + = new Boolean(isMultiChatWindowEnabledString) + .booleanValue(); + } } /** @@ -205,6 +220,19 @@ public static boolean isMoveContactConfirmationRequested() return isMoveContactConfirmationRequested; } + /** + * Returns true if the "isMultiChatWindowEnabled" property is + * true, otherwise - returns false. Indicates to the user + * interface whether the chat window could contain multiple chats or just + * one chat. + * @return true if the "isMultiChatWindowEnabled" property is + * true, otherwise - returns false. + */ + public static boolean isMultiChatWindowEnabled() + { + return isMultiChatWindowEnabled; + } + /** * Return the "sendMessageCommand" property that was saved previously * through the ConfigurationService. Indicates to the user @@ -349,6 +377,23 @@ public static void setMoveContactConfirmationRequested(boolean isRequested) new Boolean(isMoveContactConfirmationRequested)); } + /** + * Updates the "isMultiChatWindowEnabled" property through the + * ConfigurationService. + * + * @param isMultiChatWindowEnabled indicates if the chat window could + * contain multiple chats or only one chat. + */ + public static void setMultiChatWindowEnabled( + boolean isMultiChatWindowEnabled) + { + isMoveContactConfirmationRequested = isMultiChatWindowEnabled; + + configService.setProperty( + "net.java.sip.communicator.impl.gui.isMultiChatWindowEnabled", + new Boolean(isMultiChatWindowEnabled)); + } + /** * Saves a chat room through the ConfigurationService. * diff --git a/src/net/java/sip/communicator/impl/gui/utils/Constants.java b/src/net/java/sip/communicator/impl/gui/utils/Constants.java index 70f7d5923..72d101271 100755 --- a/src/net/java/sip/communicator/impl/gui/utils/Constants.java +++ b/src/net/java/sip/communicator/impl/gui/utils/Constants.java @@ -260,12 +260,6 @@ public class Constants * ------------------------ OTHER CONSTANTS ------------------------------ * ====================================================================== */ - /** - * Indicates whether the application is in mode "group messages in one - * window". - */ - public static final boolean TABBED_CHAT_WINDOW = true; - /** * The default path, where chat window styles could be found. */