diff options
Diffstat (limited to 'src/net/java/sip/communicator/impl')
20 files changed, 789 insertions, 856 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index a4eec98..d9bac36 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -34,6 +34,7 @@ import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.Container; import net.java.sip.communicator.service.gui.event.*; +import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.shutdown.*; import net.java.sip.communicator.util.*; @@ -55,6 +56,7 @@ import com.sun.jna.platform.WindowUtils; * @author Lyubomir Marinov * @author Dmitri Melnikov * @author Adam Netocny + * @author Hristo Terezov */ public class UIServiceImpl implements UIService, @@ -1542,6 +1544,38 @@ public class UIServiceImpl else throw new IllegalArgumentException("participants"); } + + /** + * Opens a chat room window for the given <tt>ChatRoomWrapper</tt> instance. + * + * @param chatRoom the chat room associated with the chat room window + */ + public void openChatRoomWindow(ChatRoomWrapper chatRoom) + { + ChatWindowManager chatWindowManager + = getChatWindowManager(); + ChatPanel chatPanel + = chatWindowManager.getMultiChat(chatRoom, true); + + chatWindowManager.openChat(chatPanel, true); + } + + /** + * Closes the chat room window for the given <tt>ChatRoomWrapper</tt> + * instance. + * + * @param chatRoom the chat room associated with the chat room window. + */ + public void closeChatRoomWindow(ChatRoomWrapper chatRoom) + { + ChatWindowManager chatWindowManager + = getChatWindowManager(); + ChatPanel chatPanel + = chatWindowManager.getMultiChat(chatRoom, false); + + if (chatPanel != null) + chatWindowManager.closeChat(chatPanel); + } /** * Creates a contact list component. diff --git a/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java b/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java deleted file mode 100644 index 2832a34..0000000 --- a/src/net/java/sip/communicator/impl/gui/customcontrols/MessageDialog.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.customcontrols; - -import java.awt.*; -import java.awt.event.*; -import java.lang.reflect.*; - -import javax.swing.*; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.utils.*; -import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.util.skin.*; - -/** - * The <tt>MessageDialog</tt> is a <tt>JDialog</tt> that contains a question - * message, two buttons to confirm or cancel the question and a check box that - * allows user to choose to not be questioned any more over this subject. - * <p> - * The message and the name of the "OK" button could be configured. - * - * @author Yana Stamcheva - * @author Adam Netocny - */ -public class MessageDialog - extends SIPCommDialog - implements ActionListener, - Skinnable -{ - private static final long serialVersionUID = 1L; - - private JButton cancelButton = new JButton( - GuiActivator.getResources().getI18NString("service.gui.CANCEL")); - - protected JButton okButton = new JButton( - GuiActivator.getResources().getI18NString("service.gui.OK")); - - private JCheckBox doNotAskAgain = new SIPCommCheckBox( - GuiActivator.getResources() - .getI18NString("service.gui.DO_NOT_ASK_AGAIN")); - - private JLabel iconLabel = new JLabel(new ImageIcon(ImageLoader - .getImage(ImageLoader.WARNING_ICON))); - - private StyledHTMLEditorPane messageArea = new StyledHTMLEditorPane(); - - private TransparentPanel buttonsPanel - = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); - - private TransparentPanel checkBoxPanel - = new TransparentPanel(new FlowLayout(FlowLayout.LEADING)); - - private TransparentPanel mainPanel - = new TransparentPanel(new BorderLayout(5, 5)); - - private boolean isConfirmationEnabled = true; - - private int returnCode; - - /** - * Indicates that the OK button is pressed. - */ - public static final int OK_RETURN_CODE = 0; - - /** - * Indicates that the Cancel button is pressed. - */ - public static final int CANCEL_RETURN_CODE = 1; - - /** - * Indicates that the OK button is pressed and the Don't ask check box is - * checked. - */ - public static final int OK_DONT_ASK_CODE = 2; - - /** - * The maximum width that we allow message dialogs to have. - */ - private static final int MAX_MSG_PANE_WIDTH = 600; - - /** - * The maximum height that we allow message dialogs to have. - */ - private static final int MAX_MSG_PANE_HEIGHT = 800; - - /** - * Creates an instance of <tt>MessageDialog</tt> by specifying the - * owner window and the message to be displayed. - * @param owner the dialog owner - * @param title the title of the message - * @param message the message to be displayed - * @param okButtonName ok button name - * @param isConfirmationEnabled indicates whether the "Do not ask again" - * button should be enabled or not - */ - public MessageDialog(Frame owner, - String title, - String message, - String okButtonName, - boolean isConfirmationEnabled) - { - super(owner, false); - - this.isConfirmationEnabled = isConfirmationEnabled; - - this.getContentPane().setLayout(new BorderLayout(5, 5)); - - this.messageArea.setOpaque(false); - this.messageArea.setEditable(false); - this.messageArea.setContentType("text/html"); - - this.messageArea.setBorder( - BorderFactory.createEmptyBorder(10, 10, 0, 10)); - this.checkBoxPanel.setBorder( - BorderFactory.createEmptyBorder(0, 10, 10, 10)); - - this.init(); - - this.setTitle(title); - - setMessage(message); - - if(okButtonName != null) - { - this.okButton.setText(okButtonName); - this.okButton.setMnemonic(okButtonName.charAt(0)); - } - } - - /** - * Creates an instance of <tt>MessageDialog</tt> by specifying the - * owner window and the message to be displayed. - * @param owner the dialog owner - * @param title the title of the message - * @param message the message to be displayed - * @param okButtonName ok button name - */ - public MessageDialog( Frame owner, - String title, - String message, - String okButtonName) - { - this(owner, title, message, okButtonName, true); - } - - /** - * Creates an instance of <tt>MessageDialog</tt> by specifying the - * owner window and the message to be displayed. - * @param owner the dialog owner - * @param title the title of the message - * @param message the message to be displayed - * @param isCancelButtonEnabled <code>true</code> to show the Cancel button, - * <code>false</code> - otherwise - */ - public MessageDialog( Frame owner, - String title, - String message, - boolean isCancelButtonEnabled) - { - this(owner, title, message, null, true); - - if(!isCancelButtonEnabled) - { - doNotAskAgain.setText(GuiActivator.getResources() - .getI18NString("service.gui.DO_NOT_SHOW_AGAIN")); - - buttonsPanel.remove(cancelButton); - } - } - - /** - * Initializes this dialog. - */ - private void init() - { - this.getRootPane().setDefaultButton(okButton); - - if(isConfirmationEnabled) - this.checkBoxPanel.add(doNotAskAgain); - - this.buttonsPanel.add(okButton); - this.buttonsPanel.add(cancelButton); - - this.okButton.addActionListener(this); - this.cancelButton.addActionListener(this); - - this.cancelButton.setMnemonic(cancelButton.getText().charAt(0)); - - this.mainPanel.add(messageArea, BorderLayout.NORTH); - this.mainPanel.add(checkBoxPanel, BorderLayout.CENTER); - - TransparentPanel iconPanel = new TransparentPanel(new BorderLayout()); - iconPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 0)); - iconPanel.add(iconLabel, BorderLayout.NORTH); - - this.getContentPane().add(iconPanel, BorderLayout.WEST); - this.getContentPane().add(mainPanel, BorderLayout.CENTER); - this.getContentPane().add(buttonsPanel, BorderLayout.SOUTH); - } - - public void replaceCheckBoxPanel(Component comp) - { - this.mainPanel.add(comp, BorderLayout.CENTER); - } - - /** - * Sets the message to be displayed. - * @param message The message to be displayed. - */ - public void setMessage(String message) - { - this.messageArea.setText(message); - - setMaxWidth(600); - } - - /** - * try to reevaluate the preferred size of the message pane. - * (this is definitely not a neat way to do it ... but it works). - */ - public void setMaxWidth(int maxWidth) - { - //try to reevaluate the preferred size of the message pane. - //(this is definitely not a neat way to do it ... but it works). - this.messageArea.setSize( - new Dimension(MAX_MSG_PANE_WIDTH, MAX_MSG_PANE_HEIGHT)); - int height = this.messageArea.getPreferredSize().height; - this.messageArea.setPreferredSize(new Dimension(maxWidth, height)); - } - - /** - * Shows the dialog. - * @return The return code that should indicate what was the choice of - * the user. If the user chooses cancel, the return code is the - * CANCEL_RETURN_CODE. - */ - public int showDialog() - { - if (!SwingUtilities.isEventDispatchThread()) - { - final int[] returnCodes = new int[1]; - Exception exception = null; - try - { - SwingUtilities.invokeAndWait(new Runnable() - { - public void run() - { - returnCodes[0] = showDialog(); - } - }); - } - catch (InterruptedException ex) - { - exception = ex; - } - catch (InvocationTargetException ex) - { - exception = ex; - } - if (exception != null) - throw new UndeclaredThrowableException(exception); - return returnCodes[0]; - } - - pack(); - - setModal(true); - setVisible(true); - - return returnCode; - } - - /** - * Handles the <tt>ActionEvent</tt>. Depending on the user choice sets - * the return code to the appropriate value. - * - * @param e the <tt>ActionEvent</tt> that notified us - */ - public void actionPerformed(ActionEvent e) - { - JButton button = (JButton)e.getSource(); - - if(button.equals(okButton)) - { - if (doNotAskAgain.isSelected()) - { - this.returnCode = OK_DONT_ASK_CODE; - } - else - { - this.returnCode = OK_RETURN_CODE; - } - } - else - { - this.returnCode = CANCEL_RETURN_CODE; - } - - this.dispose(); - } - - /** - * Visually clicks the cancel button on close. - * - * @param isEscaped indicates if the window was close by pressing the escape - * button - */ - @Override - protected void close(boolean isEscaped) - { - this.cancelButton.doClick(); - } - - /** - * Reloads icon. - */ - public void loadSkin() - { - iconLabel.setIcon(new ImageIcon(ImageLoader - .getImage(ImageLoader.WARNING_ICON))); - } - - /** - * Changes the icon in the dialog. - * @param image - */ - public void setIcon(Image image) - { - iconLabel.setIcon(new ImageIcon(image)); - } -} diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactRightButtonMenu.java index 52b6c6f..fbd03d8 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatContactRightButtonMenu.java @@ -12,9 +12,9 @@ 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.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.plugin.desktoputil.chat.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; 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 deleted file mode 100644 index b8f518e..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatOperationReasonDialog.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ -package net.java.sip.communicator.impl.gui.main.chat; - -import java.awt.*; - -import javax.swing.*; -import javax.swing.event.*; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.customcontrols.*; - -/** - * - * @author Yana Stamcheva - * @author Valentin Martinet - */ -public class ChatOperationReasonDialog extends MessageDialog -{ - private static final long serialVersionUID = 3290030744711759011L; - - private final JTextField reasonField = new JTextField(); - - private final JPanel reasonFieldPanel = new JPanel(new BorderLayout()); - - /** - * Creates an instance of <tt>ChatOperationReasonDialog</tt> using the - * default title and message. - */ - public ChatOperationReasonDialog() - { - this(null, - GuiActivator.getResources().getI18NString( - "service.gui.REASON"), - GuiActivator.getResources().getI18NString( - "service.gui.SPECIFY_REASON"), - GuiActivator.getResources().getI18NString( - "service.gui.OK"), true, false); - - - } - - /** - * Creates an instance of <tt>ChatOperationReasonDialog</tt> using the - * default title and message. - * - * @param disableOKIfReasonIsEmpty if true the OK button will be disabled if - * the reason text is empty. - */ - public ChatOperationReasonDialog(boolean disableOKIfReasonIsEmpty) - { - this(null, - GuiActivator.getResources().getI18NString( - "service.gui.REASON"), - GuiActivator.getResources().getI18NString( - "service.gui.SPECIFY_REASON"), - GuiActivator.getResources().getI18NString( - "service.gui.OK"), true, disableOKIfReasonIsEmpty); - - - } - - /** - * Creates an instance of <tt>ChatOperationReasonDialog</tt> by specifying - * the title and the message shown in the dialog. - * @param title the title of this dialog - * @param message the message shown in this dialog - */ - public ChatOperationReasonDialog(String title, String message) - { - this(null, - title, - message, - GuiActivator.getResources().getI18NString("service.gui.OK"), - true, - false); - - } - - /** - * Creates an instance of <tt>ChatOperationReasonDialog</tt> by specifying - * the title and the message shown in the dialog. - * @param title the title of this 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 - */ - public ChatOperationReasonDialog(String title, String message, - boolean showReasonLabel, - boolean disableOKIfReasonIsEmpty) - { - this(null, - title, - message, - GuiActivator.getResources().getI18NString("service.gui.OK"), - showReasonLabel, - disableOKIfReasonIsEmpty); - } - - /** - * Creates an instance of <tt>ChatOperationReasonDialog</tt> by specifying - * the parent window, the title and the message to show. - * @param chatWindow the parent window - * @param title the title of this dialog - * @param message the message shown in this dialog - * @param okButtonName the custom name of the ok button - * @param showReasonLabel specify if we want the "Reason:" label - */ - public ChatOperationReasonDialog(Frame chatWindow, String title, - String message, String okButtonName, boolean showReasonLabel) - { - this(chatWindow, - title, - message, - okButtonName, - showReasonLabel, - false); - } - - /** - * Creates an instance of <tt>ChatOperationReasonDialog</tt> by specifying - * the parent window, the title and the message to show. - * - * @param chatWindow the parent window - * @param title the title of this dialog - * @param message the message shown in this dialog - * @param okButtonName the custom name of the ok button - * @param showReasonLabel specify if we want the "Reason:" label - * @param disableOKIfReasonIsEmpty if true the OK button will be disabled if - * the reason text is empty. - */ - public ChatOperationReasonDialog(Frame chatWindow, String title, - String message, String okButtonName, boolean showReasonLabel, - boolean disableOKIfReasonIsEmpty) - { - super(chatWindow, title, message, okButtonName, false); - - JPanel reasonPanel = new JPanel(new BorderLayout()); - JLabel reasonLabel - = new JLabel( - showReasonLabel - ? (GuiActivator.getResources().getI18NString( - "service.gui.REASON") - + ":") - : ""); - - reasonPanel.add(reasonLabel, BorderLayout.WEST); - reasonPanel.add(new JLabel(" "), BorderLayout.EAST); - - reasonFieldPanel.add(reasonField, BorderLayout.NORTH); - reasonFieldPanel.setOpaque(false); - reasonPanel.add(reasonFieldPanel, BorderLayout.CENTER); - reasonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - reasonPanel.setOpaque(false); - - replaceCheckBoxPanel(reasonPanel); - - if(disableOKIfReasonIsEmpty) - { - updateOKButtonState(); - reasonField.getDocument().addDocumentListener( - new DocumentListener() - { - public void removeUpdate(DocumentEvent ev) - { - updateOKButtonState(); - } - - public void insertUpdate(DocumentEvent ev) - { - updateOKButtonState(); - } - - public void changedUpdate(DocumentEvent ev) - { - updateOKButtonState(); - } - }); - } - 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. - */ - private void updateOKButtonState() - { - okButton.setEnabled(!reasonField.getText().trim().equals("")); - } - - /** - * Returns the text entered in the reason field. - * @return the text entered in the reason field - */ - public String getReason() - { - return reasonField.getText(); - } - - /** - * Sets a default value for the reason field. - * @param value the text to set as default text for the reason field - */ - public void setReasonFieldText(String value) - { - reasonField.setText(value); - } - - /** - * Sets the message to be displayed. - * @param message The message to be displayed. - */ - public void setMessage(String message) - { - super.setMessage(message); - - setMaxWidth(400); - } -} 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 847f0e3..9733e60 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 @@ -6,18 +6,15 @@ */ package net.java.sip.communicator.impl.gui.main.chat.conference; -import java.awt.*; -import java.awt.event.*; import java.util.*; import java.util.concurrent.*; 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.main.chat.history.*; import net.java.sip.communicator.impl.gui.main.chatroomslist.*; -import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.plugin.desktoputil.chat.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; @@ -29,8 +26,6 @@ import org.jdesktop.swingworker.SwingWorker; import org.osgi.framework.*; import javax.swing.*; -// Java 1.6 has javax.swing.SwingWorker so we have to disambiguate. -import javax.swing.border.*; /** * The <tt>ConferenceChatManager</tt> is the one that manages both chat room and @@ -535,7 +530,8 @@ public class ConferenceChatManager { if(chatRoomWrapper != null) { - this.closeChatRoom(chatRoomWrapper); + GuiActivator.getUIService() + .closeChatRoomWindow(chatRoomWrapper); // Need to refresh the chat room's list in order to change // the state of the chat room to offline. @@ -701,7 +697,7 @@ public class ConferenceChatManager if (chatRoom != null) leaveChatRoom(chatRoomWrapper); - this.closeChatRoom(chatRoomWrapper); + GuiActivator.getUIService().closeChatRoomWindow(chatRoomWrapper); GuiActivator.getMUCService().removeChatRoom(chatRoomWrapper); @@ -755,7 +751,7 @@ public class ConferenceChatManager ChatRoomWrapper leavedRoomWrapped = GuiActivator.getMUCService().leaveChatRoom(chatRoomWrapper); if(leavedRoomWrapped != null) - this.closeChatRoom(leavedRoomWrapped); + GuiActivator.getUIService().closeChatRoomWindow(leavedRoomWrapped); } /** @@ -879,23 +875,6 @@ public class ConferenceChatManager } } - /** - * Closes the chat corresponding to the given chat room wrapper, if such - * exists. - * - * @param chatRoomWrapper the chat room wrapper for which we search a chat - * to close. - */ - public void closeChatRoom(ChatRoomWrapper chatRoomWrapper) - { - ChatWindowManager chatWindowManager - = GuiActivator.getUIService().getChatWindowManager(); - ChatPanel chatPanel - = chatWindowManager.getMultiChat(chatRoomWrapper, false); - - if (chatPanel != null) - chatWindowManager.closeChat(chatPanel); - } /** * Closes the chat corresponding to the given ad-hoc chat room wrapper, if @@ -1316,7 +1295,7 @@ public class ConferenceChatManager if (savedNick == null) { - String[] joinOptions = getJoinOptions( + String[] joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( room.getParentProvider().getProtocolProvider(), room.getChatRoomID()); String nickName = joinOptions[0]; @@ -1336,186 +1315,9 @@ public class ConferenceChatManager GuiActivator.getMUCService().joinChatRoom(room, savedNick, null); } - ChatWindowManager chatWindowManager - = GuiActivator.getUIService().getChatWindowManager(); - ChatPanel chatPanel - = chatWindowManager.getMultiChat(room, true); - - chatWindowManager.openChat(chatPanel, true); + GuiActivator.getUIService().openChatRoomWindow(room); } - /** - * Opens a dialog with a fields for the nickname and the subject of the room - * and returns them. - * - * @param pps the protocol provider associated with the chat room. - * @param chatRoomId the id of the chat room. - * @return array with the nickname and subject values. - */ - public String[] getJoinOptions(ProtocolProviderService pps, - String chatRoomId) - { - return getJoinOptions(false, pps, chatRoomId); - } - - /** - * 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, - ProtocolProviderService pps, String chatRoomId) - { - String nickName = null; - ChatRoomJoinOptionsDialog reasonDialog = - new ChatRoomJoinOptionsDialog(GuiActivator.getResources() - .getI18NString("service.gui.CHANGE_NICKNAME"), GuiActivator - .getResources().getI18NString( - "service.gui.CHANGE_NICKNAME_LABEL"), false, true, - dontDisplaySubjectFields); - reasonDialog.setIcon(ImageLoader.getImage( - ImageLoader.CHANGE_NICKNAME_ICON)); - - final OperationSetServerStoredAccountInfo accountInfoOpSet - = pps.getOperationSet( - OperationSetServerStoredAccountInfo.class); - - String displayName = ""; - if (accountInfoOpSet != null) - { - displayName = AccountInfoUtils.getDisplayName(accountInfoOpSet); - } - - if(displayName == null || displayName.length() == 0) - { - displayName = GuiActivator.getGlobalDisplayDetailsService() - .getGlobalDisplayName(); - if(displayName == null || displayName.length() == 0) - { - displayName = pps.getAccountID().getUserID(); - if(displayName != null) - { - int atIndex = displayName.lastIndexOf("@"); - if (atIndex > 0) - displayName = displayName.substring(0, atIndex); - } - } - } - reasonDialog.setReasonFieldText(displayName); - - int result = reasonDialog.showDialog(); - - if (result == MessageDialog.OK_RETURN_CODE) - { - nickName = reasonDialog.getReason().trim(); - ConfigurationUtils.updateChatRoomProperty( - pps, - chatRoomId, "userNickName", nickName); - - } - String[] joinOptions = {nickName, reasonDialog.getSubject()}; - return joinOptions; - } - - /** - * Dialog with fields for nickname and subject. - */ - private class ChatRoomJoinOptionsDialog extends ChatOperationReasonDialog - { - /** - * Text field for the subject. - */ - private SIPCommTextField subject = new SIPCommTextField(GuiActivator - .getResources().getI18NString("service.gui.SUBJECT")); - - /** - * Label that hides and shows the subject fields panel on click. - */ - private JLabel cmdExpandSubjectFields; - - /** - * Panel that holds the subject fields. - */ - private JPanel subjectFieldsPannel = new JPanel(new BorderLayout()); - - /** - * 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); - - if(dontDisplaySubjectFields) - return; - - JPanel subjectPanel = new JPanel(new BorderLayout()); - subjectPanel.setOpaque(false); - subjectPanel.setBorder( - BorderFactory.createEmptyBorder(10, 0, 0, 0)); - - subjectFieldsPannel.setBorder( - BorderFactory.createEmptyBorder(10, 30, 0, 0)); - subjectFieldsPannel.setOpaque(false); - subjectFieldsPannel.add(subject, BorderLayout.CENTER); - subjectFieldsPannel.setVisible(false); - subject.setFont(getFont().deriveFont(12f)); - - cmdExpandSubjectFields = new JLabel(); - cmdExpandSubjectFields.setBorder(new EmptyBorder(0, 5, 0, 0)); - cmdExpandSubjectFields.setIcon(GuiActivator.getResources() - .getImage("service.gui.icons.RIGHT_ARROW_ICON")); - cmdExpandSubjectFields.setText(GuiActivator - .getResources().getI18NString("service.gui.SET_SUBJECT")); - cmdExpandSubjectFields.addMouseListener(new MouseAdapter() - { - @Override - public void mouseClicked(MouseEvent e) - { - cmdExpandSubjectFields.setIcon( - UtilActivator.getResources().getImage( - subjectFieldsPannel.isVisible() - ? "service.gui.icons.RIGHT_ARROW_ICON" - : "service.gui.icons.DOWN_ARROW_ICON")); - - subjectFieldsPannel.setVisible( - !subjectFieldsPannel.isVisible()); - - pack(); - } - }); - subjectPanel.add(cmdExpandSubjectFields,BorderLayout.NORTH); - subjectPanel.add(subjectFieldsPannel,BorderLayout.CENTER); - addToReasonFieldPannel(subjectPanel); - this.pack(); - } - - /** - * Returns the text entered in the subject field. - * - * @return the text from the subject field. - */ - public String getSubject() - { - return subject.getText(); - } - } - @Override public void chatRoomProviderWrapperAdded(ChatRoomProviderWrapper provider) {} @@ -1524,6 +1326,6 @@ public class ConferenceChatManager public void chatRoomProviderWrapperRemoved(ChatRoomProviderWrapper provider) { for(int i = 0; i < provider.countChatRooms(); i++) - closeChatRoom(provider.getChatRoom(i)); + GuiActivator.getUIService().closeChatRoomWindow(provider.getChatRoom(i)); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java index 7d0d5eb..31f53f7 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java @@ -488,10 +488,14 @@ public class MainToolBar } else if (buttonText.equals("leave")) { - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); - conferenceManager.leaveChatRoom( - (ChatRoomWrapper)chatPanel.getChatSession().getDescriptor()); + ChatRoomWrapper chatRoomWrapper + = (ChatRoomWrapper)chatPanel.getChatSession().getDescriptor(); + ChatRoomWrapper leavedRoomWrapped + = GuiActivator.getMUCService().leaveChatRoom( + chatRoomWrapper); + if(leavedRoomWrapped != null) + GuiActivator.getUIService().closeChatRoomWindow( + leavedRoomWrapped); } else if (buttonText.equals("call")) { 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 fa59379..a1ca465 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 @@ -16,6 +16,7 @@ import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.impl.gui.main.chat.conference.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.plugin.desktoputil.chat.*; import net.java.sip.communicator.service.muc.ChatRoomWrapper; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.resources.*; @@ -125,7 +126,7 @@ public class ChatRoomRightButtonMenu .getChatRoomID(), "userNickName"); if(nickName == null) { - joinOptions = conferenceManager.getJoinOptions( + joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID()); nickName = joinOptions[0]; @@ -165,7 +166,7 @@ public class ChatRoomRightButtonMenu .getChatRoomID(), "userNickName"); if(nickName == null) { - joinOptions = conferenceManager.getJoinOptions( + joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( chatRoomWrapper.getParentProvider() .getProtocolProvider(), chatRoomWrapper.getChatRoomID()); @@ -189,7 +190,7 @@ public class ChatRoomRightButtonMenu } else if(itemName.equals("joinAsChatRoom")) { - joinOptions = conferenceManager.getJoinOptions( + joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID()); if(joinOptions[0] == null) @@ -200,7 +201,7 @@ public class ChatRoomRightButtonMenu } else if(itemName.equals("nickNameChatRoom")) { - conferenceManager.getJoinOptions(true, + ChatRoomJoinOptionsDialog.getJoinOptions(true, chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID()); } 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 66197e3..95259bd 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 @@ -17,9 +17,9 @@ import javax.swing.event.*; import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.chat.*; -import net.java.sip.communicator.impl.gui.main.chat.conference.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.plugin.desktoputil.SwingWorker; +import net.java.sip.communicator.plugin.desktoputil.chat.*; import net.java.sip.communicator.service.muc.ChatRoomList; import net.java.sip.communicator.service.muc.ChatRoomProviderWrapper; import net.java.sip.communicator.service.muc.ChatRoomWrapper; @@ -351,8 +351,6 @@ public class ChatRoomTableDialog String[] joinOptions; String subject = null; JButton sourceButton = (JButton) e.getSource(); - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); if(sourceButton.equals(addButton)) { String chatRoomName = editor.getText(); @@ -365,7 +363,7 @@ public class ChatRoomTableDialog getSelectedProvider().getProtocolProvider(), new ArrayList<String>(), "", false, true, true); - conferenceManager.getJoinOptions(true, + ChatRoomJoinOptionsDialog.getJoinOptions(true, chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID()); @@ -393,7 +391,7 @@ public class ChatRoomTableDialog false, false); - joinOptions = conferenceManager.getJoinOptions( + joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID()); String nickName = joinOptions[0]; @@ -427,10 +425,11 @@ public class ChatRoomTableDialog { - joinOptions = conferenceManager.getJoinOptions( - selectedRoom.getParentProvider() - .getProtocolProvider(), - selectedRoom.getChatRoomID()); + joinOptions = ChatRoomJoinOptionsDialog + .getJoinOptions( + selectedRoom.getParentProvider() + .getProtocolProvider(), + selectedRoom.getChatRoomID()); savedNick = joinOptions[0]; subject = joinOptions[1]; if(savedNick == null) @@ -464,7 +463,7 @@ public class ChatRoomTableDialog if (savedNick == null) { - joinOptions = conferenceManager.getJoinOptions( + joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( selectedRoom.getParentProvider() .getProtocolProvider(), selectedRoom.getChatRoomID()); 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 43c5901..b5cb1ca 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 @@ -19,6 +19,7 @@ import net.java.sip.communicator.impl.gui.main.chat.*; import net.java.sip.communicator.impl.gui.main.chat.conference.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; +import net.java.sip.communicator.plugin.desktoputil.chat.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.*; @@ -176,9 +177,7 @@ public class ChatRoomTableUI if (savedNick == null) { - ConferenceChatManager conferenceManager - = GuiActivator.getUIService().getConferenceChatManager(); - String[] joinOptions = conferenceManager.getJoinOptions( + String[] joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID()); String nickName = joinOptions[0]; diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/SourceContactRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/SourceContactRightButtonMenu.java index ad940dc..81f7fb8 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/SourceContactRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/SourceContactRightButtonMenu.java @@ -93,7 +93,9 @@ public class SourceContactRightButtonMenu add(initCallMenu()); // Only create the menu if the add contact functionality is enabled. - if (!ConfigurationUtils.isAddContactDisabled()) + if ((sourceContact.getPreferredContactDetail( + OperationSetMultiUserChat.class) == null) + && !ConfigurationUtils.isAddContactDisabled()) { addContactComponent = TreeContactList.createAddContactMenu(sourceContact); @@ -101,6 +103,12 @@ public class SourceContactRightButtonMenu if (addContactComponent != null) add(addContactComponent); + + for(JMenuItem item : + sourceUIContact.getContactCustomActionMenuItems(true)) + { + add(item); + } } /** diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ExternalContactSource.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ExternalContactSource.java index 74a272b..d20d2a5 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ExternalContactSource.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/ExternalContactSource.java @@ -28,6 +28,7 @@ import java.util.List; * <tt>ContactSourceService</tt>. * * @author Yana Stamcheva + * @author Hristo Terezov */ public class ExternalContactSource implements UIContactSource @@ -59,6 +60,12 @@ public class ExternalContactSource */ private static Map<ContactAction<SourceContact>, SIPCommButton> customContactActionButtons; + + /** + * The list of right menu action items for this source contact. + */ + private static Map<ContactActionMenuItem<SourceContact>, JMenuItem> + customContactActionMenuItems; /** * The list of action buttons for this source service. @@ -174,8 +181,7 @@ public class ExternalContactSource SIPCommButton actionButton = customContactActionButtons.get(contactAction); - if (isContactActionVisible( contactAction, - sourceContact)) + if (isContactActionVisible( contactAction, sourceContact)) { availableCustomActionButtons.add(actionButton); } @@ -183,6 +189,44 @@ public class ExternalContactSource return availableCustomActionButtons; } + + /** + * Returns all custom action menu items for this contact. + * + * @param initActions if <tt>true</tt> the actions will be reloaded. + * @param sourceContact the contact. + * @return a list of all custom action menu items for this contact. + */ + public Collection<JMenuItem> getContactCustomActionMenuItems( + final SourceContact sourceContact, boolean initActions) + { + customActionContact = sourceContact; + + if (initActions || (customContactActionMenuItems == null)) + initCustomContactActionMenuItems(); + + Iterator<ContactActionMenuItem<SourceContact>> customActionsIter + = customContactActionMenuItems.keySet().iterator(); + + Collection<JMenuItem> availableCustomActionMenuItems + = new LinkedList<JMenuItem>(); + + while (customActionsIter.hasNext()) + { + ContactActionMenuItem<SourceContact> contactAction + = customActionsIter.next(); + + JMenuItem actionMenuItem = + customContactActionMenuItems.get(contactAction); + + if (isContactActionVisible( contactAction, sourceContact)) + { + availableCustomActionMenuItems.add(actionMenuItem); + } + } + + return availableCustomActionMenuItems; + } /** * Indicates if the given <tt>ContactAction</tt> should be visible for the @@ -202,6 +246,25 @@ public class ExternalContactSource return false; } + + /** + * Indicates if the given <tt>ContactActionMenuItem</tt> should be visible + * for the given <tt>SourceContact</tt>. + * + * @param contactAction the <tt>ContactActionMenuItem</tt> to verify + * if the given action should be visible + * @return <tt>true</tt> if the given <tt>ContactActionMenuItem</tt> is + * visible for the given <tt>SourceContact</tt>, <tt>false</tt> - otherwise + */ + private static boolean isContactActionVisible( + ContactActionMenuItem<SourceContact> contactAction, + SourceContact contact) + { + if (contactAction.isVisible(contact)) + return true; + + return false; + } /** * Initializes custom action buttons for this contact source. @@ -222,12 +285,36 @@ public class ExternalContactSource { final ContactAction<SourceContact> ca = actionIterator.next(); - initActionButton(ca, SourceContact.class); } } } } + + /** + * Initializes custom action menu items for this contact source. + */ + private void initCustomContactActionMenuItems() + { + customContactActionMenuItems + = new LinkedHashMap<ContactActionMenuItem<SourceContact>, JMenuItem>(); + for (CustomContactActionsService<SourceContact> ccas + : getContactActionsServices()) + { + Iterator<ContactActionMenuItem<SourceContact>> actionIterator + = ccas.getCustomContactActionsMenuItems(); + + if (actionIterator!= null) + { + while (actionIterator.hasNext()) + { + final ContactActionMenuItem<SourceContact> ca + = actionIterator.next(); + initActionMenuItem(ca); + } + } + } + } /** * Initializes custom action buttons for this source service. @@ -247,7 +334,6 @@ public class ExternalContactSource while (actionIterator!= null && actionIterator.hasNext()) { final ContactAction<ContactSourceService> ca = actionIterator.next(); - initActionButton(ca, ContactSourceService.class); } } @@ -352,6 +438,63 @@ public class ExternalContactSource } } } + + /** + * Initializes an action menu item. + * + * @param ca the <tt>ContactActionMenuItem</tt> corresponding to the item. + */ + private void initActionMenuItem( + final ContactActionMenuItem<SourceContact> ca) + { + JMenuItem actionMenuItem; + + actionMenuItem = customContactActionMenuItems.get(ca); + + if (actionMenuItem == null) + { + if(ca.isCheckBox()) + { + actionMenuItem = new JCheckBoxMenuItem(); + } + else + { + actionMenuItem = new JMenuItem(); + } + + actionMenuItem.setText(ca.getText()); + + actionMenuItem.setMnemonic(ca.getMnemonics()); + + byte[] icon = ca.getIcon(); + if(icon != null) + actionMenuItem.setIcon( + new ImageIcon(icon)); + + actionMenuItem.setSelected(ca.isSelected(customActionContact)); + actionMenuItem.setEnabled(ca.isEnabled(customActionContact)); + + actionMenuItem.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent event) + { + try + { + ca.actionPerformed(customActionContact); + } + catch (OperationFailedException e) + { + new ErrorDialog(null, + GuiActivator.getResources() + .getI18NString("service.gui.ERROR"), + e.getMessage()); + } + } + }); + + customContactActionMenuItems.put(ca, actionMenuItem); + } + } /** * Returns a list of all custom contact action services. diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java index 3cddd53..517f790 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java @@ -16,11 +16,9 @@ import org.jitsi.service.resources.*; import org.jitsi.util.*; import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.main.chatroomslist.*; import net.java.sip.communicator.impl.gui.main.contactlist.*; import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.contactsource.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; @@ -32,6 +30,7 @@ import net.java.sip.communicator.util.*; * <tt>ExternalContactSource</tt>. * * @author Yana Stamcheva + * @author Hristo Terezov */ public class SourceUIContact extends UIContactImpl @@ -413,19 +412,7 @@ public class SourceUIContact @Override public JPopupMenu getRightButtonMenu() { - if(!(sourceContact instanceof MetaContact) && - (sourceContact.getPreferredContactDetail( - OperationSetMultiUserChat.class) - != null)) - { - return new ChatRoomRightButtonMenu( - GuiActivator.getMUCService() - .findChatRoomWrapperFromSourceContact(sourceContact)); - } - else - { - return new SourceContactRightButtonMenu(this); - } + return new SourceContactRightButtonMenu(this); } /** @@ -708,4 +695,21 @@ public class SourceUIContact return null; } + + /** + * Returns all custom action menu items for this contact. + * + * @param initActions if <tt>true</tt> the actions will be reloaded. + * @return a list of all custom action menu items for this contact. + */ + @Override + public Collection<JMenuItem> getContactCustomActionMenuItems( + boolean initActions) + { + if (sourceContact != null) + return uiGroup.getParentUISource() + .getContactCustomActionMenuItems(sourceContact, initActions); + + return null; + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/login/DefaultSecurityAuthority.java b/src/net/java/sip/communicator/impl/gui/main/login/DefaultSecurityAuthority.java index df798c0..288cab6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/DefaultSecurityAuthority.java +++ b/src/net/java/sip/communicator/impl/gui/main/login/DefaultSecurityAuthority.java @@ -9,7 +9,6 @@ package net.java.sip.communicator.impl.gui.main.login; import javax.swing.*; import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.protocol.*; @@ -71,7 +70,7 @@ public class DefaultSecurityAuthority String userName = userCredentials.getUserName(); char[] password = userCredentials.getPassword(); ImageIcon icon - = ImageLoader.getAuthenticationWindowIcon(protocolProvider); + = AuthenticationWindow.getAuthenticationWindowIcon(protocolProvider); if (errorMessage == null) loginWindow = new AuthenticationWindow( diff --git a/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java b/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java index 56f84e7..00d5dea 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java +++ b/src/net/java/sip/communicator/impl/gui/main/login/LoginRendererSwingImpl.java @@ -7,9 +7,9 @@ package net.java.sip.communicator.impl.gui.main.login; import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.customcontrols.*; import net.java.sip.communicator.impl.gui.main.*; import net.java.sip.communicator.impl.gui.main.authorization.*; +import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.util.account.*; diff --git a/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf b/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf index 607dffc..38041b9 100644 --- a/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf +++ b/src/net/java/sip/communicator/impl/gui/swing.ui.manifest.mf @@ -80,4 +80,5 @@ Import-Package: com.apple.eawt, org.osgi.framework, say.swing, net.java.sip.communicator.service.credentialsstorage, - net.java.sip.communicator.service.muc + net.java.sip.communicator.service.muc, + net.java.sip.communicator.plugin.desktoputil.chat diff --git a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java index c2dba57..51af8c6 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java @@ -1718,34 +1718,4 @@ public class ImageLoader { getImageLoaderService().clearCache(); } - - /** - * Returns the icon corresponding to the given <tt>protocolProvider</tt>. - * - * @param protocolProvider the <tt>ProtocolProviderService</tt>, which icon - * we're looking for - * @return the icon to show on the authentication window - */ - public static ImageIcon getAuthenticationWindowIcon( - ProtocolProviderService protocolProvider) - { - Image image = null; - - if(protocolProvider != null) - { - ProtocolIcon protocolIcon = protocolProvider.getProtocolIcon(); - - if(protocolIcon.isSizeSupported(ProtocolIcon.ICON_SIZE_64x64)) - image = ImageUtils.getBytesInImage( - protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_64x64)); - else if(protocolIcon.isSizeSupported(ProtocolIcon.ICON_SIZE_48x48)) - image = ImageUtils.getBytesInImage( - protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_48x48)); - } - - if (image != null) - return new ImageIcon(image); - - return null; - } } diff --git a/src/net/java/sip/communicator/impl/muc/MUCActivator.java b/src/net/java/sip/communicator/impl/muc/MUCActivator.java index 5e6d086..37a943b 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCActivator.java +++ b/src/net/java/sip/communicator/impl/muc/MUCActivator.java @@ -10,6 +10,7 @@ import java.util.*; import net.java.sip.communicator.service.contactsource.*; import net.java.sip.communicator.service.credentialsstorage.*; +import net.java.sip.communicator.service.customcontactactions.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; @@ -79,6 +80,16 @@ public class MUCActivator * The credential storage service. */ private static CredentialsStorageService credentialsService; + + /** + * The custom actions service. + */ + private static MUCCustomContactActionService mucCustomActionService; + + /** + * The UI service. + */ + private static UIService uiService = null; /** * Starts this bundle. @@ -98,6 +109,11 @@ public class MUCActivator MUCService.class.getName(), mucService, null); + mucCustomActionService = new MUCCustomContactActionService(); + bundleContext.registerService( + CustomContactActionsService.class.getName(), + mucCustomActionService, + null); } public void stop(BundleContext context) throws Exception @@ -343,4 +359,22 @@ public class MUCActivator if (chatRoomProviders.contains(protocolProvider)) chatRoomProviders.remove(protocolProvider); } + + /** + * Returns the <tt>UIService</tt> obtained from the bundle + * context. + * @return the <tt>UIService</tt> obtained from the bundle + * context + */ + public static UIService getUIService() + { + if(uiService == null) + { + uiService + = ServiceUtils.getService( + bundleContext, + UIService.class); + } + return uiService; + } } diff --git a/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java b/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java new file mode 100644 index 0000000..2d3884e --- /dev/null +++ b/src/net/java/sip/communicator/impl/muc/MUCCustomContactActionService.java @@ -0,0 +1,503 @@ +/*
+ * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package net.java.sip.communicator.impl.muc;
+
+import java.util.*;
+
+import org.jitsi.service.resources.*;
+
+import net.java.sip.communicator.plugin.desktoputil.chat.*;
+import net.java.sip.communicator.service.contactsource.*;
+import net.java.sip.communicator.service.customcontactactions.*;
+import net.java.sip.communicator.service.muc.*;
+import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.util.*;
+
+/**
+ * Implements <tt>CustomContactActionsService</tt> for MUC contact source.
+ *
+ * @author Hristo Terezov
+ */
+public class MUCCustomContactActionService
+ implements CustomContactActionsService<SourceContact>
+{
+ /**
+ * List of custom menu items.
+ */
+ private final List<ContactActionMenuItem<SourceContact>> MUCActionMenuItems
+ = new LinkedList<ContactActionMenuItem<SourceContact>>();
+
+ /**
+ * Array of labels for the custom menu items.
+ */
+ private String[] actionsLabels = {
+ "service.gui.OPEN", "service.gui.JOIN",
+ "service.gui.JOIN_AS", "service.gui.LEAVE",
+ "service.gui.REMOVE", "service.gui.CHANGE_NICK",
+ "service.gui.JOIN_AUTOMATICALLY"
+ };
+
+ /**
+ * Array of icons for the custom menu items.
+ */
+ private String[] actionsIcons = {
+ "service.gui.icons.CHAT_ROOM_16x16_ICON", "service.gui.icons.JOIN_ICON",
+ "service.gui.icons.JOIN_AS_ICON", "service.gui.icons.LEAVE_ICON",
+ "service.gui.icons.REMOVE_CHAT_ICON",
+ "service.gui.icons.RENAME_16x16_ICON",
+ null
+ };
+
+ /**
+ * Array of <tt>MUCCustomActionRunnable</tt> objects for the custom menu
+ * items. They will be executed when the item is pressed.
+ */
+ private MUCCustomActionRunnable[] actionsRunnable = {
+ new MUCCustomActionRunnable()
+ {
+ @Override
+ public void run()
+ {
+ String[] joinOptions;
+ String subject = null;
+ if(chatRoomWrapper.getChatRoom() == null)
+ {
+ // this is not a server persistent room we must create it
+ // and join
+ chatRoomWrapper =
+ MUCActivator.getMUCService().createChatRoom(
+ chatRoomWrapper.getChatRoomName(),
+ chatRoomWrapper.getParentProvider()
+ .getProtocolProvider(),
+ new ArrayList<String>(),
+ "",
+ false,
+ false,
+ true);
+ }
+
+ if(!chatRoomWrapper.getChatRoom().isJoined())
+ {
+ String nickName = null;
+
+ nickName =
+ ConfigurationUtils.getChatRoomProperty(
+ chatRoomWrapper.getParentProvider()
+ .getProtocolProvider(), chatRoomWrapper
+ .getChatRoomID(), "userNickName");
+ if(nickName == null)
+ {
+ joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions(
+ chatRoomWrapper.getParentProvider()
+ .getProtocolProvider(),
+ chatRoomWrapper.getChatRoomID());
+ nickName = joinOptions[0];
+ subject = joinOptions[1];
+ }
+
+ if (nickName != null)
+ MUCActivator.getMUCService().joinChatRoom(chatRoomWrapper,
+ nickName, null, subject);
+ else
+ return;
+ }
+
+ MUCActivator.getUIService().openChatRoomWindow(chatRoomWrapper);
+ }
+ },
+ new MUCCustomActionRunnable()
+ {
+
+ @Override
+ public void run()
+ {
+ String[] joinOptions;
+ String subject = null;
+ String nickName = null;
+
+ nickName =
+ ConfigurationUtils.getChatRoomProperty(
+ chatRoomWrapper.getParentProvider()
+ .getProtocolProvider(), chatRoomWrapper
+ .getChatRoomID(), "userNickName");
+ if(nickName == null)
+ {
+ joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions(
+ chatRoomWrapper.getParentProvider()
+ .getProtocolProvider(),
+ chatRoomWrapper.getChatRoomID());
+ nickName = joinOptions[0];
+ subject = joinOptions[1];
+ }
+
+ if (nickName != null)
+ MUCActivator.getMUCService().joinChatRoom(chatRoomWrapper,
+ nickName, null, subject);
+ }
+ },
+ new MUCCustomActionRunnable()
+ {
+
+ @Override
+ public void run()
+ {
+ String[] joinOptions;
+ joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions(
+ chatRoomWrapper.getParentProvider().getProtocolProvider(),
+ chatRoomWrapper.getChatRoomID());
+ if(joinOptions[0] == null)
+ return;
+ MUCActivator.getMUCService()
+ .joinChatRoom(chatRoomWrapper, joinOptions[0], null,
+ joinOptions[1]);
+ }
+ },
+ new MUCCustomActionRunnable()
+ {
+
+ @Override
+ public void run()
+ {
+ ChatRoomWrapper leavedRoomWrapped
+ = MUCActivator.getMUCService().leaveChatRoom(
+ chatRoomWrapper);
+ if(leavedRoomWrapped != null)
+ MUCActivator.getUIService().closeChatRoomWindow(
+ leavedRoomWrapped);
+ }
+ },
+ new MUCCustomActionRunnable()
+ {
+
+ @Override
+ public void run()
+ {
+ ChatRoom chatRoom = chatRoomWrapper.getChatRoom();
+
+ if (chatRoom != null)
+ {
+ ChatRoomWrapper leavedRoomWrapped
+ = MUCActivator.getMUCService().leaveChatRoom(
+ chatRoomWrapper);
+ if(leavedRoomWrapped != null)
+ MUCActivator.getUIService().closeChatRoomWindow(
+ leavedRoomWrapped);
+ }
+
+ MUCActivator.getUIService().closeChatRoomWindow(chatRoomWrapper);
+
+ MUCActivator.getMUCService().removeChatRoom(chatRoomWrapper);
+ }
+ },
+ new MUCCustomActionRunnable()
+ {
+
+ @Override
+ public void run()
+ {
+ ChatRoomJoinOptionsDialog.getJoinOptions(true,
+ chatRoomWrapper.getParentProvider().getProtocolProvider(),
+ chatRoomWrapper.getChatRoomID());
+ }
+ },
+ new MUCCustomActionRunnable()
+ {
+
+ @Override
+ public void run()
+ {
+ chatRoomWrapper.setAutoJoin(!chatRoomWrapper.isAutojoin());
+ }
+ }
+ };
+
+ /**
+ * Array of <tt>EnableChecker</tt> objects for the custom menu items. They
+ * are used to check if the item is enabled or disabled.
+ */
+ private EnableChecker[] actionsEnabledCheckers = {
+ null,
+ new JoinEnableChecker(),
+ new JoinEnableChecker(),
+ new LeaveEnableChecker(),
+ null,
+ null,
+ null
+ };
+
+ /**
+ * Array for the custom menu items that describes the type of the menu item.
+ * If <tt>true</tt> - the item is check box.
+ */
+ private boolean[] actionsIsCheckBox = {
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ true
+ };
+
+ /**
+ * The resource management service instance.
+ */
+ ResourceManagementService resources = MUCActivator.getResources();
+
+ /**
+ * Constructs the custom actions.
+ */
+ public MUCCustomContactActionService()
+ {
+ for(int i = 0; i < actionsLabels.length; i++)
+ {
+ MUCActionMenuItems item = new MUCActionMenuItems(actionsLabels[i],
+ actionsIcons[i], actionsRunnable[i], actionsIsCheckBox[i]);
+ MUCActionMenuItems.add(item);
+ if(actionsEnabledCheckers[i] != null)
+ item.setEnabled(actionsEnabledCheckers[i]);
+ }
+
+ }
+
+ /**
+ * Returns the template class that this service has been initialized with
+ *
+ * @return the template class
+ */
+ public Class<SourceContact> getContactSourceClass()
+ {
+ return SourceContact.class;
+ }
+
+ @Override
+ public Iterator<ContactActionMenuItem<SourceContact>>
+ getCustomContactActionsMenuItems()
+ {
+ return MUCActionMenuItems.iterator();
+ }
+
+
+ @Override
+ public Iterator<ContactAction<SourceContact>> getCustomContactActions()
+ {
+ return null;
+ }
+
+ /**
+ * Implements the MUC custom menu items.
+ */
+ private class MUCActionMenuItems
+ implements ContactActionMenuItem<SourceContact>
+ {
+ /**
+ * The key used to retrieve the label for the menu item.
+ */
+ private String textKey;
+
+ /**
+ * The key used to retrieve the icon for the menu item.
+ */
+ private String imageKey;
+
+ /**
+ * The action executed when the menu item is pressed.
+ */
+ private MUCCustomActionRunnable actionPerformed;
+
+ /**
+ * Object that is used to check if the item is enabled or disabled.
+ */
+ private EnableChecker enabled;
+
+ /**
+ * if <tt>true</tt> the item should be check box and if <tt>false</tt>
+ * it is standard menu item.
+ */
+ private boolean isCheckBox;
+
+ /**
+ * Constructs <tt>MUCActionMenuItems</tt> instance.
+ *
+ * @param textKey the key used to retrieve the label for the menu item.
+ * @param imageKey the key used to retrieve the icon for the menu item.
+ * @param actionPerformed the action executed when the menu item is
+ * pressed.
+ * @param isCheckBox if <tt>true</tt> the item should be check box.
+ */
+ public MUCActionMenuItems(String textKey, String imageKey,
+ MUCCustomActionRunnable actionPerformed, boolean isCheckBox)
+ {
+ this.textKey = textKey;
+ this.imageKey = imageKey;
+ this.actionPerformed = actionPerformed;
+ this.enabled = new EnableChecker();
+ this.isCheckBox = isCheckBox;
+ }
+
+ @Override
+ public void actionPerformed(SourceContact actionSource)
+ throws OperationFailedException
+ {
+ if(!(actionSource instanceof ChatRoomSourceContact))
+ return;
+ actionPerformed.setContact(actionSource);
+ new Thread(actionPerformed).start();
+ }
+
+ @Override
+ public byte[] getIcon()
+ {
+ return (imageKey == null)? null :
+ resources.getImageInBytes(imageKey);
+ }
+
+
+ @Override
+ public String getText()
+ {
+ return resources.getI18NString(textKey);
+ }
+
+ @Override
+ public boolean isVisible(SourceContact actionSource)
+ {
+ return (actionSource instanceof ChatRoomSourceContact);
+ }
+
+ @Override
+ public char getMnemonics()
+ {
+ return resources.getI18nMnemonic(textKey);
+ }
+
+ @Override
+ public boolean isEnabled(SourceContact actionSource)
+ {
+ return enabled.check(actionSource);
+ }
+
+ /**
+ * Sets <tt>EnabledChecker</tt> instance that will be used to check if
+ * the item should be enabled or disabled.
+ *
+ * @param enabled the <tt>EnabledChecker</tt> instance.
+ */
+ public void setEnabled(EnableChecker enabled)
+ {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public boolean isCheckBox()
+ {
+ return isCheckBox;
+ }
+
+ @Override
+ public boolean isSelected(SourceContact contact)
+ {
+ ChatRoomWrapper chatRoomWrapper = MUCActivator.getMUCService()
+ .findChatRoomWrapperFromSourceContact(contact);
+ return chatRoomWrapper.isAutojoin();
+ }
+
+ }
+
+ /**
+ * Checks if the menu item should be enabled or disabled. This is default
+ * implementation. Always returns that the item should be enabled.
+ */
+ private class EnableChecker
+ {
+ /**
+ * Checks if the menu item should be enabled or disabled.
+ *
+ * @param contact the contact associated with the menu item.
+ * @return always <tt>true</tt>
+ */
+ public boolean check(SourceContact contact)
+ {
+ return true;
+ }
+ }
+
+ /**
+ * Implements <tt>EnableChecker</tt> for the join menu items.
+ */
+ private class JoinEnableChecker extends EnableChecker
+ {
+ /**
+ * Checks if the menu item should be enabled or disabled.
+ *
+ * @param contact the contact associated with the menu item.
+ * @return <tt>true</tt> if the item should be enabled and
+ * <tt>false</tt> if not.
+ */
+ public boolean check(SourceContact contact)
+ {
+ ChatRoomWrapper chatRoomWrapper = MUCActivator.getMUCService()
+ .findChatRoomWrapperFromSourceContact(contact);
+ ChatRoom chatRoom = null;
+ if(chatRoomWrapper != null)
+ {
+ chatRoom = chatRoomWrapper.getChatRoom();
+ }
+
+ if((chatRoom != null) && chatRoom.isJoined())
+ return false;
+ return true;
+ }
+ }
+
+ /**
+ * Implements <tt>EnableChecker</tt> for the leave menu item.
+ */
+ private class LeaveEnableChecker extends JoinEnableChecker
+ {
+ /**
+ * Checks if the menu item should be enabled or disabled.
+ *
+ * @param contact the contact associated with the menu item.
+ * @return <tt>true</tt> if the item should be enabled and
+ * <tt>false</tt> if not.
+ */
+ public boolean check(SourceContact contact)
+ {
+ return !super.check(contact);
+ }
+ }
+
+ /**
+ * Implements base properties for the MUC menu items.These properties are
+ * used when the menu item is pressed.
+ */
+ private abstract class MUCCustomActionRunnable implements Runnable
+ {
+ /**
+ * The contact associated with the menu item.
+ */
+ protected SourceContact contact;
+
+ /**
+ * The contact associated with the menu item.
+ */
+ protected ChatRoomWrapper chatRoomWrapper;
+
+ /**
+ * Sets the source contact.
+ * @param contact the contact to set
+ */
+ public void setContact(SourceContact contact)
+ {
+ this.contact = contact;
+ chatRoomWrapper = MUCActivator.getMUCService()
+ .findChatRoomWrapperFromSourceContact(contact);
+ }
+
+ }
+}
diff --git a/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java b/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java index 0fa21b3..5a62c80 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java +++ b/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java @@ -11,7 +11,7 @@ import java.util.*; import org.jitsi.service.resources.*;
-import net.java.sip.communicator.impl.gui.utils.*;
+import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.muc.*;
@@ -737,7 +737,7 @@ public class MUCServiceImpl authWindowsService.create(
null, null, null, false,
chatRoomWrapper.isPersistent(),
- ImageLoader.getAuthenticationWindowIcon(
+ AuthenticationWindow.getAuthenticationWindowIcon(
chatRoomWrapper.getParentProvider()
.getProtocolProvider()),
resources.getI18NString(
diff --git a/src/net/java/sip/communicator/impl/muc/muc.manifest.mf b/src/net/java/sip/communicator/impl/muc/muc.manifest.mf index 6427cbf..21c5d9a 100644 --- a/src/net/java/sip/communicator/impl/muc/muc.manifest.mf +++ b/src/net/java/sip/communicator/impl/muc/muc.manifest.mf @@ -13,5 +13,8 @@ Import-Package: org.osgi.framework, org.jitsi.service.configuration, net.java.sip.communicator.service.protocol.event, net.java.sip.communicator.service.credentialsstorage, - net.java.sip.communicator.service.gui + net.java.sip.communicator.service.gui, + net.java.sip.communicator.service.customcontactactions, + net.java.sip.communicator.plugin.desktoputil, + net.java.sip.communicator.plugin.desktoputil.chat Export-Package: net.java.sip.communicator.service.muc |