From 5c1c9ac641ccbe25d24b9042b50153fbcf72bb58 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Mon, 22 Mar 2010 21:59:34 +0000 Subject: [PATCH] - Fixes the message upon joining a chat room stating that the chat room has had its subject changed to null. The fix rather stops the message unless the subject value has really changed. - Fixes the sorting of the chat room members (which first sorts by role and then by name). --- .../impl/gui/main/chat/ChatPanel.java | 12 +- .../chat/conference/ChatContactListModel.java | 4 +- .../conference/ChatRoomMemberListPanel.java | 15 ++- .../chat/conference/ChatRoomSubjectPanel.java | 122 ++++++++++-------- .../impl/protocol/irc/ChatRoomIrcImpl.java | 6 +- .../protocol/irc/ChatRoomMemberIrcImpl.java | 13 +- .../impl/protocol/irc/IrcStack.java | 10 +- 7 files changed, 104 insertions(+), 78 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java index e897b7917..6e9461799 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java @@ -279,7 +279,6 @@ else if (chatSession instanceof ConferenceChatSession) if (chatContactListPanel != null) { - // Initialize chat participants' panel. Iterator chatParticipants = chatSession.getParticipants(); @@ -1774,6 +1773,17 @@ public void setChatSubject(String subject) { if (subjectPanel != null) { + // Don't do anything if the subject doesn't really change. + String oldSubject = subjectPanel.getSubject(); + + if ((subject == null ) || (subject.length() == 0)) + { + if ((oldSubject == null) || (oldSubject.length() == 0)) + return; + } + else if (subject.equals(oldSubject)) + return; + subjectPanel.setSubject(subject); this.addMessage( diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatContactListModel.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatContactListModel.java index bc212a539..5883cc44c 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatContactListModel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatContactListModel.java @@ -86,8 +86,8 @@ public void addElement(ChatContact chatContact) if (chatContact == null) throw new IllegalArgumentException("chatContact"); - int index = -1; int chatContactCount = chatContacts.size(); + int index = -1; for (int i = 0; i < chatContactCount; i++) { @@ -104,7 +104,7 @@ public void addElement(ChatContact chatContact) } } if (index == -1) - index = 0; + index = chatContactCount; chatContacts.add(index, chatContact); fireIntervalAdded(this, index, index); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomMemberListPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomMemberListPanel.java index c0ed8b8b0..1d3fde48c 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomMemberListPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomMemberListPanel.java @@ -43,17 +43,20 @@ public class ChatRoomMemberListPanel private final ChatContactListModel memberListModel = new ChatContactListModel(); - private final ChatPanel chatPanel; + private final ChatPanel chatPanel; /** - * Creates an instance of ChatContactListPanel. - * @param chat Currently not used + * Initializes a new ChatRoomMemberListPanel instance which is to + * depict the members of a chat specified by its ChatPanel. + * + * @param chatPanel the ChatPanel which specifies the chat the new + * instance is to depict the members of */ - public ChatRoomMemberListPanel(final ChatPanel chat) + public ChatRoomMemberListPanel(ChatPanel chatPanel) { super(new BorderLayout()); - this.chatPanel = chat; + this.chatPanel = chatPanel; this.memberList.setModel(memberListModel); this.memberList.addKeyListener(new CListKeySearchListener(memberList)); @@ -77,7 +80,7 @@ public void mouseClicked(MouseEvent e) if (chatContact != null) new ChatContactRightButtonMenu( - chat, + ChatRoomMemberListPanel.this.chatPanel, chatContact) .show(memberList, e.getX(), e.getY()); } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomSubjectPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomSubjectPanel.java index 86656548e..30a3041fb 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomSubjectPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomSubjectPanel.java @@ -16,6 +16,7 @@ import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.swing.*; @@ -24,41 +25,32 @@ * button. * * @author Yana Stamcheva + * @author Lubomir Marinov */ public class ChatRoomSubjectPanel extends TransparentPanel { /** - * The object used for logging. + * The Logger used by the ChatRoomSubjectPanel class and + * its instances for logging output. */ - private Logger logger = Logger.getLogger(ChatRoomSubjectPanel.class); + private static final Logger logger + = Logger.getLogger(ChatRoomSubjectPanel.class); /** - * The panel containing the subject of the chat room. - */ - private JLabel subjectLabel = new JLabel( - GuiActivator.getResources().getI18NString("service.gui.SUBJECT") + ": "); - - /** - * The field containing the subject of the chat room. - */ - private JTextField subjectField = new JTextField(); - - /** - * The button that opens the configuration form of the chat room. + * The corresponding chat session. */ - private JButton configButton = new JButton(new ImageIcon( - ImageLoader.getImage(ImageLoader.CHAT_ROOM_CONFIG))); + private final ConferenceChatSession chatSession; /** - * The corresponding chat session. + * The parent window. */ - private ConferenceChatSession chatSession; + private final ChatWindow chatWindow; /** - * The parent window. + * The field containing the subject of the chat room. */ - private ChatWindow chatWindow; + private final JTextField subjectField = new JTextField(); /** * Creates the panel containing the chat room subject. @@ -72,34 +64,54 @@ public ChatRoomSubjectPanel(ChatWindow chatWindow, { super(new BorderLayout(5, 5)); - this.chatSession = chatSession; this.chatWindow = chatWindow; + this.chatSession = chatSession; - this.add(subjectLabel, BorderLayout.WEST); - this.add(subjectField, BorderLayout.CENTER); - this.add(configButton, BorderLayout.EAST); - - this.configButton.setPreferredSize(new Dimension(26, 26)); - - this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - this.configButton.addActionListener(new ConfigButtonActionListener()); - - this.subjectField.setText(chatSession.getChatSubject()); + JLabel subjectLabel + = new JLabel( + GuiActivator.getResources().getI18NString( + "service.gui.SUBJECT") + ": "); + + subjectField.setText(chatSession.getChatSubject()); + // TODO Implement the editing of the chat room subject. + subjectField.setEditable(false); + + JButton configButton + = new JButton( + new ImageIcon( + ImageLoader.getImage( + ImageLoader.CHAT_ROOM_CONFIG))); + configButton.setPreferredSize(new Dimension(26, 26)); + configButton.addActionListener(new ConfigButtonActionListener()); + + setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + add(subjectLabel, BorderLayout.WEST); + add(subjectField, BorderLayout.CENTER); + add(configButton, BorderLayout.EAST); + } - // The subject is set not editable until we implement this functionality. - // TODO: Implement the editing of the chat room subject - this.subjectField.setEditable(false); + /** + * Gets the (chat room) subject displayed in this + * ChatRoomSubjectPanel. + * + * @return the (chat room) subject displayed in this + * ChatRoomSubjectPanel + */ + public String getSubject() + { + return subjectField.getText(); } /** - * Sets the subject in the corresponding field. + * Sets the (chat room) subject to be displayed in this + * ChatRoomSubjectPanel. * - * @param subject the subject of the chat room + * @param subject the (chat room) subject to be displayed in this + * ChatRoomSubjectPanel */ public void setSubject(String subject) { - this.subjectField.setText(subject); + subjectField.setText(subject); } /** @@ -119,7 +131,6 @@ public void actionPerformed(ActionEvent evt) { ChatRoomConfigurationForm configForm = chatSession.getChatConfigurationForm(); - ChatRoomConfigurationWindow configWindow = new ChatRoomConfigurationWindow( chatSession.getChatName(), configForm); @@ -132,30 +143,31 @@ public void actionPerformed(ActionEvent evt) logger.error( "Failed to obtain the chat room configuration form.", e); + ResourceManagementService resources + = GuiActivator.getResources(); + if(e.getErrorCode() == OperationFailedException.NOT_ENOUGH_PRIVILEGES) { new ErrorDialog( - chatWindow, - GuiActivator.getResources() - .getI18NString("service.gui.WARNING"), - GuiActivator.getResources().getI18NString( - "service.gui.CHAT_ROOM_CONFIGURATION_FORBIDDEN", - new String[]{chatSession.getChatName()}), - ErrorDialog.WARNING) - .showDialog(); + chatWindow, + resources.getI18NString("service.gui.WARNING"), + resources.getI18NString( + "service.gui.CHAT_ROOM_CONFIGURATION_FORBIDDEN", + new String[]{chatSession.getChatName()}), + ErrorDialog.WARNING) + .showDialog(); } else { new ErrorDialog( - chatWindow, - GuiActivator.getResources() - .getI18NString("service.gui.ERROR"), - GuiActivator.getResources().getI18NString( - "service.gui.CHAT_ROOM_CONFIGURATION_FAILED", - new String[]{ - chatSession.getChatName()}), - e).showDialog(); + chatWindow, + resources.getI18NString("service.gui.ERROR"), + resources.getI18NString( + "service.gui.CHAT_ROOM_CONFIGURATION_FAILED", + new String[]{chatSession.getChatName()}), + e) + .showDialog(); } } } diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java index 1d49cf473..b554e0500 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomIrcImpl.java @@ -22,7 +22,7 @@ * @author Yana Stamcheva */ public class ChatRoomIrcImpl - implements ChatRoom + implements ChatRoom { /** * The object used for logging. @@ -49,7 +49,7 @@ public class ChatRoomIrcImpl /** * The parent protocol service provider */ - private ProtocolProviderServiceIrcImpl parentProvider; + private final ProtocolProviderServiceIrcImpl parentProvider; /** * Listeners that will be notified of changes in member status in the @@ -106,7 +106,7 @@ public class ChatRoomIrcImpl * Indicates if this chat room is a private one (i.e. created with the * query command ). */ - private boolean isPrivate = false; + private final boolean isPrivate; /** * Indicates if this chat room is a system one (i.e. corresponding to the diff --git a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomMemberIrcImpl.java b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomMemberIrcImpl.java index 9a0547eff..45ffe2c27 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomMemberIrcImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/ChatRoomMemberIrcImpl.java @@ -12,6 +12,7 @@ * Represents a chat room member. * * @author Stephane Remy + * @author Lubomir Marinov */ public class ChatRoomMemberIrcImpl implements ChatRoomMember @@ -29,12 +30,12 @@ public class ChatRoomMemberIrcImpl /** * The provider that created us. */ - private ProtocolProviderServiceIrcImpl parentProvider = null; + private final ProtocolProviderServiceIrcImpl parentProvider; /** * The role of this member. */ - private ChatRoomMemberRole chatRoomMemberRole = null; + private ChatRoomMemberRole chatRoomMemberRole; /** * Creates an instance of ChatRoomMemberIrcImpl, by specifying the @@ -50,9 +51,9 @@ public class ChatRoomMemberIrcImpl * corresponding chat room */ public ChatRoomMemberIrcImpl(ProtocolProviderServiceIrcImpl parentProvider, - ChatRoom chatRoom, - String contactID, - ChatRoomMemberRole chatRoomMemberRole) + ChatRoom chatRoom, + String contactID, + ChatRoomMemberRole chatRoomMemberRole) { this.parentProvider = parentProvider; this.chatRoom = chatRoom; @@ -150,4 +151,4 @@ public Contact getContact() { return null; } -} \ No newline at end of file +} diff --git a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java index abb724475..ce524e10b 100644 --- a/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java +++ b/src/net/java/sip/communicator/impl/protocol/irc/IrcStack.java @@ -373,11 +373,11 @@ protected void onChannelInfo(String channel, int userCount, String topic) * change. * @param recipient The nick of the user that got 'de-opp-ed'. */ - protected void onDeop( String channel, - String sourceNick, - String sourceLogin, - String sourceHostname, - String recipient) + protected void onDeop(String channel, + String sourceNick, + String sourceLogin, + String sourceHostname, + String recipient) { logger.trace("DEOP on " + channel + ": Received from " + sourceNick + " " + sourceLogin + "@" + sourceHostname + "on " + recipient);