From 5bb698e4560977ece944c23501425f3c04ee6749 Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Thu, 29 Aug 2013 14:01:53 +0300 Subject: [PATCH] Adds "set subject" checkbox and subject text field to the chat room nickname dialog. If the subject checkbox is checked the subject of the room will be changed when the user join the chat room. --- resources/languages/resources.properties | 1 + .../gui/customcontrols/MessageDialog.java | 2 +- .../main/chat/ChatOperationReasonDialog.java | 16 ++- .../main/chat/conference/ChatRoomWrapper.java | 128 ++++++++++++++++-- .../conference/ConferenceChatManager.java | 105 ++++++++++++-- .../ChatRoomRightButtonMenu.java | 28 ++-- .../chatroomslist/ChatRoomTableDialog.java | 24 ++-- .../main/chatroomslist/ChatRoomTableUI.java | 6 +- .../protocol/jabber/ChatRoomJabberImpl.java | 2 +- 9 files changed, 273 insertions(+), 39 deletions(-) diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 20fbea494..e33ae2763 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -466,6 +466,7 @@ service.gui.SEND_VIA=Send via service.gui.SENT=sent service.gui.SET_GLOBAL_STATUS=Set global status service.gui.SET_STATUS_MESSAGE=Set status message +service.gui.SET_SUBJECT=Set Subject service.gui.SETTINGS=&Options service.gui.SHARE_DESKTOP=&Share desktop service.gui.SHARE_DESKTOP_WITH_CONTACT=Share desktop with contact diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java b/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java index d107c0470..ed512be6c 100644 --- a/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java +++ b/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java @@ -218,7 +218,7 @@ private void init() TransparentPanel iconPanel = new TransparentPanel(new BorderLayout()); iconPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 0)); - iconPanel.add(iconLabel, BorderLayout.CENTER); + iconPanel.add(iconLabel, BorderLayout.NORTH); this.getContentPane().add(iconPanel, BorderLayout.WEST); this.getContentPane().add(mainPanel, BorderLayout.CENTER); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatOperationReasonDialog.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatOperationReasonDialog.java index 9905eb20e..6cb22db19 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatOperationReasonDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatOperationReasonDialog.java @@ -25,6 +25,9 @@ public class ChatOperationReasonDialog extends MessageDialog private final JLabel reasonLabel = new JLabel( GuiActivator.getResources() .getI18NString("service.gui.REASON") + ":"); + + + private JPanel reasonFieldPanel = new JPanel(new BorderLayout()); private final JTextField reasonField = new JTextField(); @@ -152,9 +155,9 @@ public ChatOperationReasonDialog(Frame chatWindow, String title, reasonPanel.add(new JLabel(" "), BorderLayout.EAST); - JPanel reasonFieldPanel = new JPanel(new BorderLayout()); + reasonFieldPanel.add(reasonField, BorderLayout.NORTH); - + reasonFieldPanel.setOpaque(false); reasonPanel.add(reasonFieldPanel, BorderLayout.CENTER); reasonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); reasonPanel.setOpaque(false); @@ -191,6 +194,15 @@ public void changedUpdate(DocumentEvent arg0) this.pack(); } + /** + * Adds component to panel which contains the reason text field. + * @param comp the component to be added. + */ + public void addToReasonFieldPannel(Component comp) + { + reasonFieldPanel.add(comp, BorderLayout.CENTER); + } + /** * Enables the OK button if reason field is not empty and disables it if the * reason field is empty. diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomWrapper.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomWrapper.java index f7db38ed0..d1d8e7b96 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomWrapper.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ChatRoomWrapper.java @@ -6,10 +6,16 @@ */ package net.java.sip.communicator.impl.gui.main.chat.conference; +import java.awt.*; +import java.awt.event.*; + +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.*; import net.java.sip.communicator.impl.gui.utils.*; +import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -273,20 +279,34 @@ public void setAutoJoin(boolean value) chatRoomID, AUTOJOIN_PROPERTY_NAME, null); } } - + /** - * Opens a dialog with a field for the nickname and returns the nickname. + * Opens a dialog with a fields for the nickname and the subject of the room + * and returns them. * - * @return the nickname + * @return array with the nickname and subject values. */ - public String getNickname() + public String[] getJoinOptions() + { + return getJoinOptions(false); + } + + /** + * Opens a dialog with a fields for the nickname and the subject of the room + * and returns them. + * + * @param dontDisplaySubjectFields if true the subject fields will be hidden + * @return array with the nickname and subject values. + */ + public String[] getJoinOptions(boolean dontDisplaySubjectFields) { String nickName = null; - ChatOperationReasonDialog reasonDialog = - new ChatOperationReasonDialog(GuiActivator.getResources() + ChatRoomJoinOptionsDialog reasonDialog = + new ChatRoomJoinOptionsDialog(GuiActivator.getResources() .getI18NString("service.gui.CHANGE_NICKNAME"), GuiActivator .getResources().getI18NString( - "service.gui.CHANGE_NICKNAME_LABEL"), false, true); + "service.gui.CHANGE_NICKNAME_LABEL"), false, true, + dontDisplaySubjectFields); reasonDialog.setIcon(ImageLoader.getImage( ImageLoader.CHANGE_NICKNAME_ICON)); @@ -328,7 +348,99 @@ public String getNickname() getChatRoomID(), "userNickName", nickName); } + String[] joinOptions = {nickName, + (reasonDialog.isSubjectCheckboxChecked()? + reasonDialog.getSubject() : null)}; + return joinOptions; + } + + /** + * Dialog with fields for nickname and subject. + */ + private class ChatRoomJoinOptionsDialog extends ChatOperationReasonDialog + { + /** + * Checkbox that hides or displays the subject field. + */ + private JCheckBox setSubject = new SIPCommCheckBox(GuiActivator + .getResources().getI18NString("service.gui.SET_SUBJECT")); + + /** + * Text field for the subject. + */ + private JTextField subject = new JTextField(); + + /** + * Adds the subject fields to dialog. Sets action listeners. + * + * @param title the title of the dialog + * @param message the message shown in this dialog + * @param disableOKIfReasonIsEmpty if true the OK button will be + * disabled if the reason text is empty. + * @param showReasonLabel specify if we want the "Reason:" label + * @param dontDisplaySubjectFields if true the sibject fields will be + * hidden. + */ + public ChatRoomJoinOptionsDialog(String title, String message, + boolean showReasonLabel, + boolean disableOKIfReasonIsEmpty, + boolean dontDisplaySubjectFields) + { + super(title, + message, + showReasonLabel, + disableOKIfReasonIsEmpty); + subject.setVisible(false); + if(!dontDisplaySubjectFields) + { + JPanel subjectPannel = new JPanel(new BorderLayout()); + subjectPannel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); + subjectPannel.setOpaque(false); + subjectPannel.add(setSubject, BorderLayout.NORTH); + subjectPannel.add(subject, BorderLayout.CENTER); + addToReasonFieldPannel(subjectPannel); + setSubject.addActionListener(this); + this.pack(); + } + } - return nickName; + /** + * Handles the ActionEvent. + * + * @param e the ActionEvent that notified us + */ + public void actionPerformed(ActionEvent e) + { + if(e.getSource() instanceof JCheckBox) + { + subject.setVisible(setSubject.isSelected()); + this.pack(); + } + else + { + super.actionPerformed(e); + } + } + + /** + * Returns the text entered in the subject field. + * + * @return the text from the subject field. + */ + public String getSubject() + { + return subject.getText(); + } + + /** + * Checks if the subject checkbox is checked or not. + * + * @return true if the checkbox is checked and false if the checkbox is + * not checked. + */ + public boolean isSubjectCheckboxChecked() + { + return setSubject.isSelected(); + } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java index 8625dbeaf..eb49c932f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/conference/ConferenceChatManager.java @@ -659,6 +659,45 @@ public void rejectInvitation( multiUserChatAdHocOpSet.rejectInvitation(invitation, reason); } + /** + * Joins the given chat room with the given password and manages all the + * exceptions that could occur during the join process. + * + * @param chatRoomWrapper the chat room to join. + * @param nickName the nickname we choose for the given chat room. + * @param password the password. + * @param rememberPassword if true the password should be saved. + * @param isFirstAttempt is this the first attempt to join room, used + * to check whether to show some error messages + * @param subject the subject which will be set to the room after the user + * join successful. + */ + public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, + String nickName, + byte[] password, + boolean rememberPassword, + boolean isFirstAttempt, + String subject) + { + ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); + + if(chatRoom == null) + { + new ErrorDialog( + GuiActivator.getUIService().getMainFrame(), + GuiActivator.getResources().getI18NString("service.gui.WARNING"), + GuiActivator.getResources().getI18NString( + "service.gui.CHAT_ROOM_NOT_CONNECTED", + new String[]{chatRoomWrapper.getChatRoomName()})) + .showDialog(); + + return; + } + + new JoinChatRoomTask(chatRoomWrapper, nickName, password, + rememberPassword, isFirstAttempt, subject).execute(); + } + /** * Joins the given chat room with the given password and manages all the * exceptions that could occur during the join process. @@ -693,6 +732,23 @@ public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, byte[] password, boolean rememberPassword, boolean isFirstAttempt) + { + this.joinChatRoom( + chatRoomWrapper, nickName, password, rememberPassword, + isFirstAttempt, null); + } + + /** + * Joins the given chat room with the given password and manages all the + * exceptions that could occur during the join process. + * + * @param chatRoomWrapper the chat room to join. + * @param nickName the nickname we choose for the given chat room. + * @param password the password. + */ + public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, + String nickName, + byte[] password) { ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); @@ -709,8 +765,7 @@ public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, return; } - new JoinChatRoomTask(chatRoomWrapper, nickName, password, - rememberPassword, isFirstAttempt).execute(); + new JoinChatRoomTask(chatRoomWrapper, nickName, password).execute(); } /** @@ -720,10 +775,13 @@ public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, * @param chatRoomWrapper the chat room to join. * @param nickName the nickname we choose for the given chat room. * @param password the password. + * @param subject the subject which will be set to the room after the user + * join successful. */ public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, String nickName, - byte[] password) + byte[] password, + String subject) { ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); @@ -740,7 +798,8 @@ public void joinChatRoom( ChatRoomWrapper chatRoomWrapper, return; } - new JoinChatRoomTask(chatRoomWrapper, nickName, password).execute(); + new JoinChatRoomTask(chatRoomWrapper, nickName, password, subject) + .execute(); } /** @@ -1607,16 +1666,20 @@ private static class JoinChatRoomTask private final boolean rememberPassword; private final boolean isFirstAttempt; + + private final String subject; JoinChatRoomTask( ChatRoomWrapper chatRoomWrapper, String nickName, byte[] password, boolean rememberPassword, - boolean isFirstAttempt) + boolean isFirstAttempt, + String subject) { this.chatRoomWrapper = chatRoomWrapper; this.nickName = nickName; this.isFirstAttempt = isFirstAttempt; + this.subject = subject; if(password == null) { @@ -1641,7 +1704,15 @@ private static class JoinChatRoomTask String nickName, byte[] password) { - this(chatRoomWrapper, nickName, password, false, true); + this(chatRoomWrapper, nickName, password, false, true, null); + } + + JoinChatRoomTask( ChatRoomWrapper chatRoomWrapper, + String nickName, + byte[] password, + String subject) + { + this(chatRoomWrapper, nickName, password, false, true, subject); } /** @@ -1752,7 +1823,8 @@ protected void done() nickName, new String(authWindow.getPassword()).getBytes(), authWindow.isRememberPassword(), - false); + false, + subject); } } else if(REGISTRATION_REQUIRED.equals(returnCode)) @@ -1794,9 +1866,24 @@ else if(SUBSCRIPTION_ALREADY_EXISTS.equals(returnCode)) "service.gui.ERROR"), errorMessage).showDialog(); } - if (SUCCESS.equals(returnCode) && rememberPassword) + if (SUCCESS.equals(returnCode)) { - chatRoomWrapper.savePassword(new String(password)); + if(rememberPassword) + { + chatRoomWrapper.savePassword(new String(password)); + } + + if(subject != null) + { + try + { + chatRoomWrapper.getChatRoom().setSubject(subject); + } + catch(OperationFailedException ex) + { + logger.warn("Failed to set subject."); + } + } } } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomRightButtonMenu.java index 0df3adee5..ffeebc811 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomRightButtonMenu.java @@ -102,6 +102,8 @@ public void actionPerformed(ActionEvent e) ConferenceChatManager conferenceManager = GuiActivator.getUIService().getConferenceChatManager(); + String[] joinOptions; + String subject = null; if (itemName.equals("removeChatRoom")) { @@ -121,10 +123,15 @@ else if (itemName.equals("joinChatRoom")) .getProtocolProvider(), chatRoomWrapper .getChatRoomID(), "userNickName"); if(nickName == null) - nickName = chatRoomWrapper.getNickname(); + { + joinOptions = chatRoomWrapper.getJoinOptions(); + nickName = joinOptions[0]; + subject = joinOptions[1]; + } if (nickName != null) - conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null); + conferenceManager.joinChatRoom(chatRoomWrapper, nickName, null, + subject); } else if (itemName.equals("openChatRoom")) { @@ -154,11 +161,15 @@ else if (itemName.equals("openChatRoom")) .getProtocolProvider(), chatRoomWrapper .getChatRoomID(), "userNickName"); if(nickName == null) - nickName = chatRoomWrapper.getNickname(); + { + joinOptions = chatRoomWrapper.getJoinOptions(); + nickName = joinOptions[0]; + subject = joinOptions[1]; + } if (nickName != null) conferenceManager.joinChatRoom(chatRoomWrapper, - nickName, null); + nickName, null, subject); else return; } @@ -172,15 +183,16 @@ else if (itemName.equals("openChatRoom")) } else if(itemName.equals("joinAsChatRoom")) { - String nickName = chatRoomWrapper.getNickname(); - if(nickName == null) + joinOptions = chatRoomWrapper.getJoinOptions(); + if(joinOptions[0] == null) return; GuiActivator.getUIService().getConferenceChatManager() - .joinChatRoom(chatRoomWrapper, nickName, null); + .joinChatRoom(chatRoomWrapper, joinOptions[0], null, + joinOptions[1]); } else if(itemName.equals("nickNameChatRoom")) { - chatRoomWrapper.getNickname(); + chatRoomWrapper.getJoinOptions(true); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java index 8c601b08d..a496eb413 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java @@ -345,6 +345,8 @@ private JComboBox createProvidersCombobox() */ public void actionPerformed(ActionEvent e) { + String[] joinOptions; + String subject = null; JButton sourceButton = (JButton) e.getSource(); if(sourceButton.equals(addButton)) { @@ -361,7 +363,7 @@ public void actionPerformed(ActionEvent e) getSelectedProvider().getProtocolProvider(), new ArrayList(), "", false, true); - chatRoomWrapper.getNickname(); + chatRoomWrapper.getJoinOptions(true); } else if(sourceButton.equals(removeButton)) @@ -387,13 +389,14 @@ else if(sourceButton.equals(okButton)) false, false); - String nickName = chatRoomWrapper.getNickname(); - + joinOptions = chatRoomWrapper.getJoinOptions(); + String nickName = joinOptions[0]; + subject = joinOptions[1]; if(nickName == null) return; GuiActivator.getUIService().getConferenceChatManager() - .joinChatRoom(chatRoomWrapper, nickName, null); + .joinChatRoom(chatRoomWrapper, nickName, null, subject); ChatWindowManager chatWindowManager = GuiActivator.getUIService().getChatWindowManager(); @@ -418,13 +421,16 @@ else if(sourceButton.equals(okButton)) { - savedNick = selectedRoom.getNickname(); + joinOptions = selectedRoom.getJoinOptions(); + savedNick = joinOptions[0]; + subject = joinOptions[1]; if(savedNick == null) return; } GuiActivator.getUIService() .getConferenceChatManager() - .joinChatRoom(selectedRoom, savedNick, null); + .joinChatRoom(selectedRoom, savedNick, null, + subject); } else chatRoomsTableUI.openChatForSelection(); @@ -451,13 +457,15 @@ else if(sourceButton.equals(okButton)) if (savedNick == null) { - savedNick = chatRoomWrapper.getNickname(); + joinOptions = selectedRoom.getJoinOptions(); + savedNick = joinOptions[0]; + subject = joinOptions[1]; if(savedNick == null) return; } GuiActivator.getUIService().getConferenceChatManager() - .joinChatRoom(chatRoomWrapper,savedNick,null); + .joinChatRoom(chatRoomWrapper,savedNick,null, subject); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableUI.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableUI.java index 117784221..dace0a053 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableUI.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableUI.java @@ -177,14 +177,16 @@ void openChatForSelection() if (savedNick == null) { - String nickName = chatRoomWrapper.getNickname(); + String[] joinOptions = chatRoomWrapper.getJoinOptions(); + String nickName = joinOptions[0]; if(nickName == null) return; if (!chatRoomWrapper.getChatRoom().isJoined()) { GuiActivator.getUIService().getConferenceChatManager() - .joinChatRoom(chatRoomWrapper, nickName, null); + .joinChatRoom(chatRoomWrapper, nickName, null, + joinOptions[1]); } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java index 402c35181..dc9ebb209 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ChatRoomJabberImpl.java @@ -1860,7 +1860,7 @@ public void subjectUpdated(String subject, String from) logger.info("Subject updated to " + subject); // only fire event if subject has really changed, not for new one - if(oldSubject != null && !oldSubject.equals(subject)) + if(subject != null && !subject.equals(oldSubject)) { ChatRoomPropertyChangeEvent evt = new ChatRoomPropertyChangeEvent(