- Simplifies ChatWindowManager a bit and speeds up some of the code which uses it.

- Removes some duplication in ChatRoom-related code and then does the same for its respective AdHocChatRoom duplicate.
cusax-fix
Lyubomir Marinov 16 years ago
parent 23c8c5b76b
commit 2d9503c0db

@ -555,7 +555,7 @@ public ChatPanel getChat(Contact contact)
MetaContact metaContact
= mainFrame.getContactList().findMetaContactByContact(contact);
return chatWindowManager.getContactChat(metaContact);
return chatWindowManager.getContactChat(metaContact, true);
}
/**

@ -77,7 +77,7 @@ public class ChatPanel
private ChatRoomSubjectPanel subjectPanel;
public int unreadMessageNumber = 0;
int unreadMessageNumber = 0;
/**
* Indicates that a typing notification event is successfully sent.
@ -1968,16 +1968,6 @@ public boolean containsActiveFileTransfers()
return !activeFileTransfers.isEmpty();
}
/**
* Returns the number of messages received but not yet read from the user.
*
* @return the number of messages received but not yet read from the user.
*/
public int getUnreadMessageNumber()
{
return unreadMessageNumber;
}
/**
* Cancels all active file transfers.
*/

@ -105,12 +105,12 @@ public ChatWindow()
public void closeOperation(MouseEvent e)
{
int tabIndex = chatTabbedPane.getOverTabIndex();
ChatPanel chatPanel
= (ChatPanel) chatTabbedPane.getComponentAt(tabIndex);
GuiActivator.getUIService()
.getChatWindowManager().closeChat(chatPanel);
GuiActivator
.getUIService()
.getChatWindowManager().closeChat(chatPanel);
}
});
@ -517,8 +517,7 @@ public void highlightTab(ChatPanel chatPanel)
chatPanel.unreadMessageNumber ++;
this.chatTabbedPane
.highlightTab(tabIndex, chatPanel.getUnreadMessageNumber());
chatTabbedPane.highlightTab(tabIndex, chatPanel.unreadMessageNumber);
}
/**
@ -691,22 +690,14 @@ public void windowDeiconified(WindowEvent e)
*/
protected void close(boolean isEscaped)
{
ChatPanel chatPanel = getCurrentChatPanel();
if(isEscaped)
{
ChatRightButtonMenu chatRightMenu =
chatPanel.getChatConversationPanel().getRightButtonMenu();
ChatPanel chatPanel = getCurrentChatPanel();
ChatRightButtonMenu chatRightMenu
= chatPanel.getChatConversationPanel().getRightButtonMenu();
ChatWritePanel chatWritePanel = chatPanel.getChatWritePanel();
WritePanelRightButtonMenu writePanelRightMenu =
chatWritePanel.getRightButtonMenu();
JMenu selectedMenu = menuBar.getSelectedMenu();
// SIPCommMenu contactMenu = getCurrentChatPanel()
// .getProtoContactSelectorBox().getMenu();
MenuSelectionManager menuSelectionManager =
MenuSelectionManager.defaultManager();
WritePanelRightButtonMenu writePanelRightMenu
= chatWritePanel.getRightButtonMenu();
if (chatRightMenu.isVisible())
{
@ -716,21 +707,22 @@ else if (writePanelRightMenu.isVisible())
{
writePanelRightMenu.setVisible(false);
}
else if (selectedMenu != null
|| chatWritePanel.getEditTextToolBar().hasSelectedMenus())
else if ((menuBar.getSelectedMenu() != null)
|| chatWritePanel
.getEditTextToolBar().hasSelectedMenus())
{
menuSelectionManager.clearSelectedPath();
MenuSelectionManager.defaultManager().clearSelectedPath();
}
else
{
GuiActivator.getUIService().getChatWindowManager().closeChat(
chatPanel);
GuiActivator
.getUIService().getChatWindowManager().closeChat(chatPanel);
}
}
else
{
GuiActivator.getUIService().getChatWindowManager()
.closeWindow(this);
GuiActivator
.getUIService().getChatWindowManager().closeWindow(this);
}
}

@ -44,7 +44,7 @@ public class ChatWindowManager
*/
public void openChat(final ChatPanel chatPanel, final boolean setSelected)
{
if(!SwingUtilities.isEventDispatchThread())
if (!SwingUtilities.isEventDispatchThread())
{
SwingUtilities.invokeLater(new Runnable()
{
@ -119,34 +119,6 @@ public boolean isChatOpenedFor(MetaContact metaContact)
{
return isChatOpenedForDescriptor(metaContact);
}
/**
* Returns <tt>true</tt> if there is an opened <tt>ChatPanel</tt> for the
* given <tt>AdHocChatRoom</tt>.
*
* @param adHocChatRoomWrapper the <tt>AdHocChatRoomWrapper</tt> for which
* the ad-hoc chat is about
* @return <tt>true</tt> if there is an opened <tt>ChatPanel</tt> for the
* given <tt>AdHocChatRoom</tt>
*/
public boolean isChatOpenedFor(AdHocChatRoomWrapper adHocChatRoomWrapper)
{
return isChatOpenedForDescriptor(adHocChatRoomWrapper);
}
/**
* Returns <tt>true</tt> if there is an opened <tt>ChatPanel</tt> for the
* given <tt>ChatRoom</tt>.
*
* @param chatRoomWrapper the <tt>ChatRoomWrapper</tt>, for which the chat
* is about
* @return <tt>true</tt> if there is an opened <tt>ChatPanel</tt> for the
* given <tt>ChatRoom</tt>
*/
public boolean isChatOpenedFor(ChatRoomWrapper chatRoomWrapper)
{
return isChatOpenedForDescriptor(chatRoomWrapper);
}
/**
* Determines whether there is an opened <tt>ChatPanel</tt> for a specific
@ -172,8 +144,20 @@ private boolean isChatOpenedForDescriptor(Object descriptor)
*
* @param chatPanel the chat panel to close
*/
public void closeChat(ChatPanel chatPanel)
public void closeChat(final ChatPanel chatPanel)
{
if (!SwingUtilities.isEventDispatchThread())
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
closeChat(chatPanel);
}
});
return;
}
synchronized (syncChat)
{
if(containsChat(chatPanel))
@ -195,9 +179,7 @@ public void closeChat(ChatPanel chatPanel)
JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION)
{
closeChatPanel(chatPanel);
}
}
else if (System.currentTimeMillis() - chatWindow
.getLastIncomingMsgTimestamp(chatPanel) < 2 * 1000)
@ -262,12 +244,12 @@ else if (chatPanel.getChatSession() instanceof
}
/**
* Closes the chat window. Removes all contained chats and invokes
* <code>setVisible(false)</code> to the window.
* Closes the specified <tt>ChatWindow</tt> and makes it available for
* garbage collection.
*
* @param chatWindow the chat window
* @param chatWindow the <tt>ChatWindow</tt> to close
*/
public void closeWindow(ChatWindow chatWindow)
void closeWindow(ChatWindow chatWindow)
{
synchronized (syncChat)
{
@ -316,9 +298,7 @@ public void closeWindow(ChatWindow chatWindow)
JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION)
{
this.disposeChatWindow(chatWindow);
}
}
else if (System.currentTimeMillis() - chatWindow
.getLastIncomingMsgTimestamp(activePanel) < 2 * 1000)
@ -335,9 +315,7 @@ else if (System.currentTimeMillis() - chatWindow
JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if (answer == JOptionPane.OK_OPTION)
{
this.disposeChatWindow(chatWindow);
}
}
else if (activePanel.containsActiveFileTransfers())
{
@ -357,9 +335,7 @@ else if (activePanel.containsActiveFileTransfers())
if (answer == JOptionPane.OK_OPTION)
{
for (ChatPanel chatPanel : chatPanels)
{
chatPanel.cancelActiveFileTransfers();
}
this.disposeChatWindow(chatWindow);
}
@ -368,19 +344,21 @@ else if (activePanel.containsActiveFileTransfers())
}
/**
* Returns the chat panel corresponding to the given meta contact
* Gets the <tt>ChatPanel</tt> corresponding to the specified
* <tt>MetaContact</tt> and optionally creates it if it does not exist.
*
* @param metaContact the meta contact.
* @return the chat panel corresponding to the given meta contact
* @param metaContact the <tt>MetaContact</tt> to get the corresponding
* <tt>ChatPanel</tt> of
* @param create <tt>true</tt> to create a <tt>ChatPanel</tt> corresponding
* to the specified <tt>MetaContact</tt> if such <tt>ChatPanel</tt> does not
* exist yet
* @return the <tt>ChatPanel</tt> corresponding to the specified
* <tt>MetaContact</tt>; <tt>null</tt> if there is no such
* <tt>ChatPanel</tt> and <tt>create</tt> is <tt>false</tt>
*/
public ChatPanel getContactChat(MetaContact metaContact)
public ChatPanel getContactChat(MetaContact metaContact, boolean create)
{
synchronized (syncChat)
{
ChatPanel chatPanel = findChatPanelForDescriptor(metaContact);
return (chatPanel != null) ? chatPanel : createChat(metaContact);
}
return getContactChat(metaContact, null, create, null);
}
/**
@ -408,18 +386,53 @@ public ChatPanel getContactChat(MetaContact metaContact,
public ChatPanel getContactChat(MetaContact metaContact,
Contact protocolContact,
String escapedMessageID)
{
return
getContactChat(
metaContact,
protocolContact,
true,
escapedMessageID);
}
/**
* Gets the <tt>ChatPanel</tt> corresponding to the specified
* <tt>MetaContact</tt> and optionally creates it if it does not exist.
*
* @param metaContact the <tt>MetaContact</tt> to get the corresponding
* <tt>ChatPanel</tt> of
* @param protocolContact the <tt>Contact</tt> (respectively its
* <tt>ChatTransport</tt>) to be selected in the newly created
* <tt>ChatPanel</tt>; <tt>null</tt> to select the default <tt>Contact</tt>
* of <tt>metaContact</tt> if it is online or one of its <tt>Contact</tt>s
* which supports offline messaging
* @param create <tt>true</tt> to create a <tt>ChatPanel</tt> corresponding
* to the specified <tt>MetaContact</tt> if such <tt>ChatPanel</tt> does not
* exist yet
* @param escapedMessageID the message ID of the message to be excluded from
* the history when the last one is loaded in the newly created
* <tt>ChatPanel</tt>
* @return the <tt>ChatPanel</tt> corresponding to the specified
* <tt>MetaContact</tt>; <tt>null</tt> if there is no such
* <tt>ChatPanel</tt> and <tt>create</tt> is <tt>false</tt>
*/
private ChatPanel getContactChat(
MetaContact metaContact,
Contact protocolContact,
boolean create,
String escapedMessageID)
{
synchronized (syncChat)
{
ChatPanel chatPanel = findChatPanelForDescriptor(metaContact);
return
(chatPanel != null)
? chatPanel
: createChat(
metaContact,
protocolContact,
escapedMessageID);
if ((chatPanel == null) && create)
chatPanel
= createChat(
metaContact,
protocolContact,
escapedMessageID);
return chatPanel;
}
}
@ -462,38 +475,58 @@ public ChatPanel getSelectedChat()
}
/**
* Returns the chat panel corresponding to the given chat room wrapper.
* Gets the <tt>ChatPanel</tt> corresponding to the specified
* <tt>ChatRoomWrapper</tt> and optionally creates it if it does not exist
* yet.
*
* @param chatRoomWrapper the chat room wrapper, corresponding to the chat
* room for which the chat panel is about
* @return the chat panel corresponding to the given chat room
* @param chatRoomWrapper the <tt>ChatRoomWrapper</tt> to get the
* corresponding <tt>ChatPanel</tt> of
* @param create <tt>true</tt> to create a new <tt>ChatPanel</tt> for the
* specified <tt>ChatRoomWrapper</tt> if no such <tt>ChatPanel</tt> exists
* already; otherwise, <tt>false</tt>
* @return the <tt>ChatPanel</tt> corresponding to the specified
* <tt>ChatRoomWrapper</tt> or <tt>null</tt> if no such <tt>ChatPanel</tt>
* exists and <tt>create</tt> is <tt>false</tt>
*/
public ChatPanel getMultiChat(ChatRoomWrapper chatRoomWrapper)
public ChatPanel getMultiChat(
ChatRoomWrapper chatRoomWrapper,
boolean create)
{
synchronized (syncChat)
{
ChatPanel chatPanel = findChatPanelForDescriptor(chatRoomWrapper);
return
(chatPanel != null) ? chatPanel : createChat(chatRoomWrapper);
if ((chatPanel == null) && create)
chatPanel = createChat(chatRoomWrapper);
return chatPanel;
}
}
/**
* Returns the chat panel corresponding to the given chat room wrapper.
* Gets the <tt>ChatPanel</tt> corresponding to the specified
* <tt>AdHocChatRoomWrapper</tt> and optionally creates it if it does not
* exist yet.
*
* @param chatRoomWrapper the ad-hoc chat room wrapper, corresponding to the
* ad-hoc chat room for which the chat panel is about
* @return the chat panel corresponding to the given chat room
* @param chatRoomWrapper the <tt>AdHocChatRoomWrapper</tt> to get the
* corresponding <tt>ChatPanel</tt> of
* @param create <tt>true</tt> to create a new <tt>ChatPanel</tt> for the
* specified <tt>AdHocChatRoomWrapper</tt> if no such <tt>ChatPanel</tt>
* exists already; otherwise, <tt>false</tt>
* @return the <tt>ChatPanel</tt> corresponding to the specified
* <tt>AdHocChatRoomWrapper</tt> or <tt>null</tt> if no such
* <tt>ChatPanel</tt> exists and <tt>create</tt> is <tt>false</tt>
*/
public ChatPanel getMultiChat(AdHocChatRoomWrapper chatRoomWrapper)
public ChatPanel getMultiChat(
AdHocChatRoomWrapper chatRoomWrapper,
boolean create)
{
synchronized (syncChat)
{
ChatPanel chatPanel = findChatPanelForDescriptor(chatRoomWrapper);
return
(chatPanel != null) ? chatPanel : createChat(chatRoomWrapper);
if ((chatPanel == null) && create)
chatPanel = createChat(chatRoomWrapper);
return chatPanel;
}
}
@ -678,22 +711,24 @@ private void closeChatPanel(ChatPanel chatPanel)
}
/**
* Creates a chat for the given meta contact. If the most connected proto
* contact of the meta contact is offline choose the proto contact that
* Gets the default <tt>Contact</tt> of the specified <tt>MetaContact</tt>
* if it is online; otherwise, gets one of its <tt>Contact</tt>s which
* supports offline messaging.
*
* @param metaContact the meta contact for the chat
* @return the newly created ChatPanel
* @param metaContact the <tt>MetaContact</tt> to get the default
* <tt>Contact</tt> of
* @return the default <tt>Contact</tt> of the specified
* <tt>MetaContact</tt> if it is online; otherwise, gets one of its
* <tt>Contact</tt>s which supports offline messaging
*/
private ChatPanel createChat(MetaContact metaContact)
private Contact getDefaultContact(MetaContact metaContact)
{
Contact defaultContact = metaContact.getDefaultContact();
ProtocolProviderService defaultProvider
= defaultContact.getProtocolProvider();
OperationSetBasicInstantMessaging defaultIM
= (OperationSetBasicInstantMessaging)
defaultProvider
.getOperationSet(OperationSetBasicInstantMessaging.class);
= defaultProvider
.getOperationSet(OperationSetBasicInstantMessaging.class);
if (defaultContact.getPresenceStatus().getStatus() < 1
&& (!defaultIM.isOfflineMessagingSupported()
@ -707,10 +742,9 @@ private ChatPanel createChat(MetaContact metaContact)
ProtocolProviderService protoContactProvider
= contact.getProtocolProvider();
OperationSetBasicInstantMessaging protoContactIM
= (OperationSetBasicInstantMessaging)
protoContactProvider
.getOperationSet(
OperationSetBasicInstantMessaging.class);
= protoContactProvider
.getOperationSet(
OperationSetBasicInstantMessaging.class);
if(protoContactIM.isOfflineMessagingSupported()
&& protoContactProvider.isRegistered())
@ -719,16 +753,20 @@ private ChatPanel createChat(MetaContact metaContact)
}
}
}
return createChat(metaContact, defaultContact, null);
return defaultContact;
}
/**
* Creates a <tt>ChatPanel</tt> for the given contact and saves it in the
* list of created <tt>ChatPanel</tt>s.
*
* @param metaContact The MetaContact for this chat.
* @param protocolContact The protocol contact.
* @param metaContact the <tt>MetaContact</tt> to create a
* <tt>ChatPanel</tt> for
* @param protocolContact the <tt>Contact</tt> (respectively its
* <tt>ChatTransport</tt>) to be selected in the newly created
* <tt>ChatPanel</tt>; <tt>null</tt> to select the default <tt>Contact</tt>
* of <tt>metaContact</tt> if it is online or one of its <tt>Contact</tt>s
* which supports offline messaging
* @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 <code>ChatPanel</code> newly created.
@ -737,6 +775,9 @@ private ChatPanel createChat( MetaContact metaContact,
Contact protocolContact,
String escapedMessageID)
{
if (protocolContact == null)
protocolContact = getDefaultContact(metaContact);
ChatWindow chatWindow = getChatWindow();
ChatPanel chatPanel = new ChatPanel(chatWindow);

@ -9,8 +9,6 @@
import java.util.*;
import java.util.concurrent.*;
import javax.swing.*;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.customcontrols.*;
import net.java.sip.communicator.impl.gui.main.chat.*;
@ -109,11 +107,11 @@ public AdHocChatRoomList getAdHocChatRoomList()
*/
public void invitationReceived(ChatRoomInvitationReceivedEvent evt)
{
OperationSetMultiUserChat multiUserChatOpSet
= evt.getSourceOperationSet();
InvitationReceivedDialog dialog = new InvitationReceivedDialog(
this, multiUserChatOpSet, evt.getInvitation());
InvitationReceivedDialog dialog
= new InvitationReceivedDialog(
this,
evt.getSourceOperationSet(),
evt.getInvitation());
dialog.setVisible(true);
}
@ -197,10 +195,12 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt)
break;
}
logger.info("MESSAGE RECEIVED from "+sourceMember.getContactAddress());
logger.trace("MESSAGE RECEIVED from contact: "
+ sourceMember.getContactAddress());
logger
.info("MESSAGE RECEIVED from " + sourceMember.getContactAddress());
logger
.trace(
"MESSAGE RECEIVED from contact: "
+ sourceMember.getContactAddress());
Message message = evt.getMessage();
@ -216,13 +216,19 @@ public void messageReceived(ChatRoomMessageReceivedEvent evt)
sourceChatRoom.getParentProvider());
chatPanel
= chatWindowManager.getMultiChat(
serverWrapper.getSystemRoomWrapper());
= chatWindowManager
.getMultiChat(
serverWrapper.getSystemRoomWrapper(),
true);
}
else
{
chatPanel = chatWindowManager
.getMultiChat(sourceChatRoom, true, message.getMessageUID());
chatPanel
= chatWindowManager
.getMultiChat(
sourceChatRoom,
true,
message.getMessageUID());
}
String messageContent = message.getContent();
@ -389,13 +395,14 @@ public void localUserAdHocPresenceChanged(
LocalUserAdHocChatRoomPresenceChangeEvent evt)
{
AdHocChatRoom sourceAdHocChatRoom = evt.getAdHocChatRoom();
AdHocChatRoomWrapper adHocChatRoomWrapper
= adHocChatRoomList
.findChatRoomWrapperFromAdHocChatRoom(sourceAdHocChatRoom);
AdHocChatRoomWrapper adHocChatRoomWrapper =
adHocChatRoomList.findChatRoomWrapperFromAdHocChatRoom(
sourceAdHocChatRoom);
String eventType = evt.getEventType();
if (evt.getEventType().equals(
LocalUserAdHocChatRoomPresenceChangeEvent.LOCAL_USER_JOINED))
if (LocalUserAdHocChatRoomPresenceChangeEvent
.LOCAL_USER_JOINED.equals(eventType))
{
if(adHocChatRoomWrapper != null)
{
@ -405,22 +412,18 @@ public void localUserAdHocPresenceChanged(
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
ChatPanel chatPanel
= chatWindowManager.getMultiChat(adHocChatRoomWrapper);
= chatWindowManager
.getMultiChat(adHocChatRoomWrapper, true);
// Check if we have already opened a chat window for this chat
// wrapper and load the real chat room corresponding to the
// wrapper.
if(chatWindowManager.isChatOpenedFor(adHocChatRoomWrapper))
{
if(chatPanel.isShown())
((AdHocConferenceChatSession) chatPanel.getChatSession())
.loadChatRoom(sourceAdHocChatRoom);
}
else
{
chatWindowManager.openChat(chatPanel, true);
}
}
sourceAdHocChatRoom.addMessageListener(this);
@ -437,8 +440,10 @@ else if (evt.getEventType().equals(
+ evt.getReason())
.showDialog();
}
else if (evt.getEventType().equals(
LocalUserAdHocChatRoomPresenceChangeEvent.LOCAL_USER_LEFT))
else if (LocalUserAdHocChatRoomPresenceChangeEvent
.LOCAL_USER_LEFT.equals(eventType)
|| LocalUserAdHocChatRoomPresenceChangeEvent
.LOCAL_USER_DROPPED.equals(eventType))
{
this.closeAdHocChatRoom(adHocChatRoomWrapper);
@ -450,21 +455,8 @@ else if (evt.getEventType().equals(
sourceAdHocChatRoom.removeMessageListener(this);
}
else if (evt.getEventType().equals(
LocalUserAdHocChatRoomPresenceChangeEvent.LOCAL_USER_DROPPED))
{
this.closeAdHocChatRoom(adHocChatRoomWrapper);
// Need to refresh the ad-hoc chat room's list in order to change
// the state of the ad-hoc chat room to offline.
fireAdHocChatRoomListChangedEvent(
adHocChatRoomWrapper,
AdHocChatRoomListChangeEvent.AD_HOC_CHAT_ROOM_CHANGED);
sourceAdHocChatRoom.removeMessageListener(this);
}
}
/**
* Implements the
* <tt>LocalUserChatRoomPresenceListener.localUserPresenceChanged</tt>
@ -474,12 +466,13 @@ public void localUserPresenceChanged(
LocalUserChatRoomPresenceChangeEvent evt)
{
ChatRoom sourceChatRoom = evt.getChatRoom();
ChatRoomWrapper chatRoomWrapper
= chatRoomList.findChatRoomWrapperFromChatRoom(sourceChatRoom);
ChatRoomWrapper chatRoomWrapper = chatRoomList
.findChatRoomWrapperFromChatRoom(sourceChatRoom);
String eventType = evt.getEventType();
if (evt.getEventType().equals(
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOINED))
if (LocalUserChatRoomPresenceChangeEvent
.LOCAL_USER_JOINED.equals(eventType))
{
if(chatRoomWrapper != null)
{
@ -490,20 +483,16 @@ public void localUserPresenceChanged(
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper);
= chatWindowManager.getMultiChat(chatRoomWrapper, true);
// Check if we have already opened a chat window for this chat
// wrapper and load the real chat room corresponding to the
// wrapper.
if(chatWindowManager.isChatOpenedFor(chatRoomWrapper))
{
if(chatPanel.isShown())
((ConferenceChatSession) chatPanel.getChatSession())
.loadChatRoom(sourceChatRoom);
}
else
{
chatWindowManager.openChat(chatPanel, true);
}
}
if (sourceChatRoom.isSystem())
@ -517,8 +506,8 @@ public void localUserPresenceChanged(
sourceChatRoom.addMessageListener(this);
}
else if (evt.getEventType().equals(
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_JOIN_FAILED))
else if (LocalUserChatRoomPresenceChangeEvent
.LOCAL_USER_JOIN_FAILED.equals(eventType))
{
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
@ -528,34 +517,12 @@ else if (evt.getEventType().equals(
new String[]{sourceChatRoom.getName()}) + evt.getReason())
.showDialog();
}
else if (evt.getEventType().equals(
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_LEFT))
{
this.closeChatRoom(chatRoomWrapper);
// Need to refresh the chat room's list in order to change
// the state of the chat room to offline.
fireChatRoomListChangedEvent(
chatRoomWrapper,
ChatRoomListChangeEvent.CHAT_ROOM_CHANGED);
sourceChatRoom.removeMessageListener(this);
}
else if (evt.getEventType().equals(
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_KICKED))
{
this.closeChatRoom(chatRoomWrapper);
// Need to refresh the chat room's list in order to change
// the state of the chat room to offline.
fireChatRoomListChangedEvent(
chatRoomWrapper,
ChatRoomListChangeEvent.CHAT_ROOM_CHANGED);
sourceChatRoom.removeMessageListener(this);
}
else if (evt.getEventType().equals(
LocalUserChatRoomPresenceChangeEvent.LOCAL_USER_DROPPED))
else if (LocalUserChatRoomPresenceChangeEvent
.LOCAL_USER_LEFT.equals(eventType)
|| LocalUserChatRoomPresenceChangeEvent
.LOCAL_USER_KICKED.equals(eventType)
|| LocalUserChatRoomPresenceChangeEvent
.LOCAL_USER_DROPPED.equals(eventType))
{
this.closeChatRoom(chatRoomWrapper);
@ -913,8 +880,9 @@ public void joinChatRoom(ChatRoom chatRoom)
if(chatRoomWrapper == null)
{
ChatRoomProviderWrapper parentProvider
= chatRoomList.findServerWrapperFromProvider(
chatRoom.getParentProvider());
= chatRoomList
.findServerWrapperFromProvider(
chatRoom.getParentProvider());
chatRoomWrapper = new ChatRoomWrapper(parentProvider, chatRoom);
@ -926,10 +894,14 @@ public void joinChatRoom(ChatRoom chatRoom)
}
this.joinChatRoom(chatRoomWrapper);
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
chatWindowManager.openChat(
chatWindowManager.getMultiChat(chatRoomWrapper), true);
chatWindowManager
.openChat(
chatWindowManager.getMultiChat(chatRoomWrapper, true),
true);
}
/**
@ -960,10 +932,14 @@ public void joinChatRoom(AdHocChatRoom chatRoom)
}
this.joinChatRoom(chatRoomWrapper);
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
chatWindowManager
.openChat(chatWindowManager.getMultiChat(chatRoomWrapper), true);
.openChat(
chatWindowManager.getMultiChat(chatRoomWrapper, true),
true);
}
/**
@ -1273,23 +1249,13 @@ private void fireAdHocChatRoomListChangedEvent(
*/
private void closeChatRoom(ChatRoomWrapper chatRoomWrapper)
{
final ChatWindowManager chatWindowManager
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper, false);
if(chatWindowManager.isChatOpenedFor(chatRoomWrapper))
{
final ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper);
// We have to be sure that we close the chat in the swing thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
chatWindowManager.closeChat(chatPanel);
}
});
}
if (chatPanel != null)
chatWindowManager.closeChat(chatPanel);
}
/**
@ -1301,23 +1267,13 @@ public void run()
*/
private void closeAdHocChatRoom(AdHocChatRoomWrapper chatRoomWrapper)
{
final ChatWindowManager chatWindowManager
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper, false);
if(chatWindowManager.isChatOpenedFor(chatRoomWrapper))
{
final ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper);
// We have to be sure that we close the chat in the swing thread
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
chatWindowManager.closeChat(chatPanel);
}
});
}
if (chatPanel != null)
chatWindowManager.closeChat(chatPanel);
}
/**

@ -21,6 +21,7 @@
* <tt>ChatRoomsList</tt>.
*
* @author Yana Stamcheva
* @author Lubomir Marinov
*/
public class ChatRoomListUI
extends SCScrollPane
@ -85,74 +86,45 @@ private void initChatRoomList()
}
private void openChatForSelection()
{
Object selectedValue = chatRoomList.getSelectedValue();
ChatRoomWrapper chatRoomWrapper;
if (selectedValue instanceof ChatRoomProviderWrapper)
chatRoomWrapper
= ((ChatRoomProviderWrapper) selectedValue)
.getSystemRoomWrapper();
else if (selectedValue instanceof ChatRoomWrapper)
chatRoomWrapper = (ChatRoomWrapper) selectedValue;
else
return;
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper, true);
chatWindowManager.openChat(chatPanel, true);
}
/**
* Opens chat window when the selected value is a MetaContact and opens a
* group when the selected value is a MetaContactGroup.
*/
private class ChatRoomsListPanelEnterAction extends AbstractAction
private class ChatRoomsListPanelEnterAction
extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
Object selectedValue = chatRoomList.getSelectedValue();
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
if(selectedValue instanceof ChatRoomProviderWrapper)
{
ChatRoomProviderWrapper serverWrapper
= (ChatRoomProviderWrapper) selectedValue;
ChatPanel chatPanel
= chatWindowManager.getMultiChat(
serverWrapper.getSystemRoomWrapper());
chatWindowManager.openChat(chatPanel, true);
}
else if(selectedValue instanceof ChatRoomWrapper)
{
ChatRoomWrapper chatRoomWrapper
= (ChatRoomWrapper) selectedValue;
ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper);
chatWindowManager.openChat(chatPanel, true);
}
openChatForSelection();
}
}
public void mouseClicked(MouseEvent e)
{
if ((e.getModifiers() & InputEvent.BUTTON1_MASK) == 0
|| e.getClickCount() < 2)
return;
Object o = this.chatRoomList.getSelectedValue();
ChatWindowManager chatWindowManager
= GuiActivator.getUIService().getChatWindowManager();
if(o instanceof ChatRoomProviderWrapper)
{
ChatRoomProviderWrapper serverWrapper
= (ChatRoomProviderWrapper) o;
ChatPanel chatPanel
= chatWindowManager.getMultiChat(
serverWrapper.getSystemRoomWrapper());
chatWindowManager.openChat(chatPanel, true);
}
else if(o instanceof ChatRoomWrapper)
{
ChatRoomWrapper chatRoomWrapper = (ChatRoomWrapper) o;
ChatPanel chatPanel
= chatWindowManager.getMultiChat(chatRoomWrapper);
chatWindowManager.openChat(chatPanel, true);
}
if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
&& (e.getClickCount() > 1))
openChatForSelection();
}
public void mouseEntered(MouseEvent e)

@ -281,14 +281,9 @@ public RunMessageWindow(MetaContact metaContact,
*/
public void run()
{
ChatPanel chatPanel;
if(protocolContact != null)
chatPanel
= chatWindowManager
.getContactChat(metaContact, protocolContact);
else
chatPanel = chatWindowManager.getContactChat(metaContact);
ChatPanel chatPanel
= chatWindowManager
.getContactChat(metaContact, protocolContact);
chatPanel.setSmsSelected(isSmsSelected);
@ -401,28 +396,23 @@ public void run()
public void messageDelivered(MessageDeliveredEvent evt)
{
Contact contact = evt.getDestinationContact();
MetaContact metaContact
= mainFrame.getContactList().findMetaContactByContact(contact);
MetaContact metaContact = mainFrame.getContactList()
.findMetaContactByContact(contact);
logger.trace("MESSAGE DELIVERED to contact: "
+ evt.getDestinationContact().getAddress());
Message msg = evt.getSourceMessage();
ChatPanel chatPanel = null;
logger.trace("MESSAGE DELIVERED to contact: " + contact.getAddress());
if(chatWindowManager.isChatOpenedFor(metaContact))
chatPanel = chatWindowManager.getContactChat(metaContact);
ChatPanel chatPanel
= chatWindowManager.getContactChat(metaContact, false);
if (chatPanel != null)
{
ProtocolProviderService protocolProvider = evt
.getDestinationContact().getProtocolProvider();
Message msg = evt.getSourceMessage();
ProtocolProviderService protocolProvider
= contact.getProtocolProvider();
logger.trace(
"MESSAGE DELIVERED: process message to chat for contact: "
+ evt.getDestinationContact().getAddress()
+ contact.getAddress()
+ " MESSAGE: " + msg.getContent());
chatPanel.addMessage(
@ -485,8 +475,8 @@ else if (evt.getErrorCode()
new String[]{evt.getReason()});
}
ChatPanel chatPanel = chatWindowManager
.getContactChat(metaContact, sourceContact);
ChatPanel chatPanel
= chatWindowManager.getContactChat(metaContact, sourceContact);
chatPanel.addMessage(
metaContact.getDisplayName(),
@ -604,11 +594,12 @@ public void fileTransferRequestReceived(FileTransferRequestEvent event)
"service.gui.FILE_RECEIVING_FROM",
new String[]{sourceContact.getDisplayName()});
NotificationManager.fireChatNotification(
sourceContact,
NotificationManager.INCOMING_FILE,
title,
request.getFileName());
NotificationManager
.fireChatNotification(
sourceContact,
NotificationManager.INCOMING_FILE,
title,
request.getFileName());
}
/**
@ -695,9 +686,11 @@ private void fireProactiveNotification(Contact contact)
public void setChatNotificationMsg(MetaContact metaContact,
String notificationMsg)
{
if(chatWindowManager.isChatOpenedFor(metaContact))
chatWindowManager.getContactChat(metaContact)
.setStatusMessage(notificationMsg);
ChatPanel chatPanel
= chatWindowManager.getContactChat(metaContact, false);
if (chatPanel != null)
chatPanel.setStatusMessage(notificationMsg);
}
/**

@ -110,8 +110,10 @@ private ChatPanel getChatPanel()
// Obtain the corresponding chat panel.
chatPanel
= GuiActivator.getUIService().getChatWindowManager()
.getContactChat(metaContact);
= GuiActivator
.getUIService()
.getChatWindowManager()
.getContactChat(metaContact, true);
}
return chatPanel;

@ -477,17 +477,15 @@ public void actionPerformed(ActionEvent e)
if(pps != null)
{
AddContactDialog dialog = new AddContactDialog(
mainFrame,
contactItem, pps);
dialog.setLocation(
Toolkit.getDefaultToolkit().getScreenSize().width/2
- 250,
Toolkit.getDefaultToolkit().getScreenSize().height/2
- 100
);
AddContactDialog dialog
= new AddContactDialog(mainFrame, contactItem, pps);
Dimension screenSize
= Toolkit.getDefaultToolkit().getScreenSize();
dialog
.setLocation(
screenSize.width/2 - 250,
screenSize.height/2 - 100);
dialog.showDialog();
}
}
@ -517,8 +515,7 @@ else if (itemName.equalsIgnoreCase("sendFile"))
{
ContactListPane clistPanel = mainFrame.getContactListPanel();
SwingUtilities.invokeLater(
clistPanel.new RunMessageWindow(
contactItem)
clistPanel.new RunMessageWindow(contactItem)
{
public void run()
{
@ -543,7 +540,8 @@ public void run()
getChatWindowManager().getSelectedChat().
sendFile(selectedFile);
}
} });
}
});
}
else if (itemName.equalsIgnoreCase("renameContact"))
{

Loading…
Cancel
Save