diff options
Diffstat (limited to 'src/net/java/sip/communicator/impl')
14 files changed, 135 insertions, 570 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index 598dbe6..23fe52e 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -417,7 +417,6 @@ public class UIServiceImpl public void initExportedWindows() { registerExportedWindow(new AddContactDialog(mainFrame)); - registerExportedWindow(new AuthenticationExportedWindow(mainFrame)); } /** @@ -673,34 +672,6 @@ public class UIServiceImpl } /** - * Returns an instance of <tt>AuthenticationWindow</tt> for the given - * protocol provider, realm and user credentials. - * - * @param protocolProvider the protocol provider, for which we'd like to - * obtain an authentication window - * @param realm the realm to use in the authentication window - * @param userCredentials the <tt>UserCredentials</tt>, which would carry - * the information entered by the user - * @param isUserNameEditable indicates if the user name is editable or not - * @return the <tt>ExportedWindow</tt>, corresponding to the authentication - * window - */ - public ExportedWindow getAuthenticationWindow( - ProtocolProviderService protocolProvider, - String realm, - UserCredentials userCredentials, - boolean isUserNameEditable) - { - return - new AuthenticationExportedWindow( - new AuthenticationWindow(mainFrame, - protocolProvider, - realm, - userCredentials, - isUserNameEditable)); - } - - /** * Returns a default implementation of the <tt>SecurityAuthority</tt> * interface that can be used by non-UI components that would like to launch * the registration process for a protocol provider. Initially this method diff --git a/src/net/java/sip/communicator/impl/gui/main/account/Account.java b/src/net/java/sip/communicator/impl/gui/main/account/Account.java index c750e19..ea9823f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/account/Account.java +++ b/src/net/java/sip/communicator/impl/gui/main/account/Account.java @@ -231,7 +231,7 @@ public class Account { ProtocolIcon protocolIcon = protocolProvider.getProtocolIcon(); Image protocolImage - = ImageLoader.getBytesInImage( + = GuiUtils.getBytesInImage( protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_32x32)); if (protocolImage != null) @@ -240,14 +240,13 @@ public class Account } else { - protocolImage = ImageLoader.getBytesInImage( + protocolImage = GuiUtils.getBytesInImage( protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_48x48)); if (protocolImage == null) protocolImage - = ImageLoader - .getBytesInImage( - protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_64x64)); + = GuiUtils.getBytesInImage( + protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_64x64)); if (protocolImage != null) return ImageUtils.scaleIconWithinBounds(protocolImage, 32, 32); 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 0964008..dc366b8 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 @@ -1298,7 +1298,7 @@ public class ChatPanel if (transportSelectorBox == null) { transportSelectorBox = new ChatTransportSelectorBox( - this, chatSession, chatSession.getCurrentChatTransport()); + chatSession, chatSession.getCurrentChatTransport()); sendViaLabel = new JLabel( GuiActivator.getResources().getI18NString( diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatTransportSelectorBox.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatTransportSelectorBox.java index d280817..bcd3656 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatTransportSelectorBox.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatTransportSelectorBox.java @@ -40,10 +40,12 @@ public class ChatTransportSelectorBox private final ChatSession chatSession; /** - * @param chatPanel Currently not used + * Creates an instance of <tt>ChatTransportSelectorBox</tt>. + * + * @param chatSession the corresponding chat session + * @param selectedChatTransport the chat transport to select by default */ - public ChatTransportSelectorBox(ChatPanel chatPanel, - ChatSession chatSession, + public ChatTransportSelectorBox(ChatSession chatSession, ChatTransport selectedChatTransport) { this.chatSession = chatSession; @@ -121,6 +123,8 @@ public class ChatTransportSelectorBox /** * The listener of the chat transport selector box. + * + * @param e the <tt>ActionEvent</tt> that notified us */ public void actionPerformed(ActionEvent e) { @@ -157,7 +161,7 @@ public class ChatTransportSelectorBox { return ImageLoader.badgeImageWithProtocolIndex( - ImageLoader.getBytesInImage( + GuiUtils.getBytesInImage( chatTransport.getStatus().getStatusIcon()), chatTransport.getProtocolProvider()); } @@ -256,8 +260,9 @@ public class ChatTransportSelectorBox /** * Searches online contacts in the send via combo box. * - * @return TRUE if the send via combo box contains online contacts, otherwise - * returns FALSE. + * @param chatTransport the chat transport to check + * @return TRUE if the send via combo box contains online contacts, + * otherwise returns FALSE. */ private boolean containsOtherOnlineContacts(ChatTransport chatTransport) { diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java index ab3de90..b764ec1 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java @@ -18,7 +18,6 @@ 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.contactlist.addgroup.*; -import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.protocol.*; @@ -462,7 +461,7 @@ public class AddContactDialog if (provider != null) { Image protocolImg - = ImageLoader.getBytesInImage(provider.getProtocolIcon() + = GuiUtils.getBytesInImage(provider.getProtocolIcon() .getIcon(ProtocolIcon.ICON_SIZE_16x16)); if (protocolImg != null) diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java index 4d75b1f..3af0051 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/MetaContactRightButtonMenu.java @@ -753,7 +753,7 @@ public class MetaContactRightButtonMenu { return ImageLoader.badgeImageWithProtocolIndex( - ImageLoader.getBytesInImage( + GuiUtils.getBytesInImage( protoContact.getPresenceStatus().getStatusIcon()), protoContact.getProtocolProvider()); } diff --git a/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationExportedWindow.java b/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationExportedWindow.java deleted file mode 100644 index 97a8e9f..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationExportedWindow.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SIP Communicator, 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.login; - -import net.java.sip.communicator.impl.gui.main.*; -import net.java.sip.communicator.service.gui.*; - -/** - * Implements <code>ExportedWindow</code> for <code>AuthenticationWindow</code> - * in order to delay its creation and spare memory and execution time on statup. - * - * @author Lubomir Marinov - */ -public class AuthenticationExportedWindow - extends AbstractExportedWindow<AuthenticationWindow> -{ - - /** - * The argument required by the constructor of - * <code>AuthenticationWindow</code>. - */ - private final MainFrame mainFrame; - - public AuthenticationExportedWindow(AuthenticationWindow window) - { - this.window = window; - this.mainFrame = null; - } - - public AuthenticationExportedWindow(MainFrame mainFrame) - { - this.mainFrame = mainFrame; - } - - /* - * Implements AbstractExportedWindow#createWindow(). - */ - public AuthenticationWindow createWindow() - { - return new AuthenticationWindow(mainFrame); - } - - /* - * Implements ExportedWindow#getIdentifier(). - */ - public WindowID getIdentifier() - { - return ExportedWindow.AUTHENTICATION_WINDOW; - } - - /* - * Overrides AbstractExportedWindow#setParams(Object[]). Delegates to - * AuthenticationWindow. - */ - public void setParams(Object[] windowParams) - { - getWindow().setParams(windowParams); - } -} diff --git a/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationWindow.java b/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationWindow.java deleted file mode 100644 index df9cbdf..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationWindow.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * SIP Communicator, 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.login; - -import java.awt.*; -import java.awt.event.*; - -import javax.swing.*; - -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.impl.gui.main.*; -import net.java.sip.communicator.impl.gui.utils.*; -import net.java.sip.communicator.service.protocol.*; -import net.java.sip.communicator.util.swing.*; - -/** - * The <tt>LoginWindow</tt> is the window where the user should type his - * user identifier and password to login. - * - * @author Yana Stamcheva - */ -public class AuthenticationWindow - extends SIPCommFrame - implements ActionListener -{ - private final JTextArea realmTextArea = new JTextArea(); - - private JComponent uinValue; - - private final JPasswordField passwdField = new JPasswordField(15); - - private final JButton loginButton = new JButton( - GuiActivator.getResources().getI18NString("service.gui.OK")); - - private final JButton cancelButton = new JButton( - GuiActivator.getResources().getI18NString("service.gui.CANCEL")); - - private final TransparentPanel labelsPanel - = new TransparentPanel(new GridLayout(0, 1, 8, 8)); - - private final TransparentPanel textFieldsPanel - = new TransparentPanel(new GridLayout(0, 1, 8, 8)); - - private final TransparentPanel mainPanel - = new TransparentPanel(new BorderLayout(10, 10)); - - private final TransparentPanel buttonsPanel - = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); - - private final JCheckBox rememberPassCheckBox - = new SIPCommCheckBox(GuiActivator.getResources() - .getI18NString("service.gui.REMEMBER_PASSWORD")); - - private LoginWindowBackground backgroundPanel; - - private UserCredentials userCredentials; - - private final Object lock = new Object(); - - private String realm; - - private final boolean isUserNameEditable; - - /** - * Creates an instance of the <tt>LoginWindow</tt>. - * @param mainFrame the parent <tt>MainFrame</tt> window. - * @param protocolProvider the protocol provider. - * @param realm the realm - * @param userCredentials the user credentials - * @param isUserNameEditable indicates if the user name should be editable - * by the user or not. - */ - public AuthenticationWindow(MainFrame mainFrame, - ProtocolProviderService protocolProvider, - String realm, - UserCredentials userCredentials, - boolean isUserNameEditable) - { - this.userCredentials = userCredentials; - - this.realm = realm; - - this.isUserNameEditable = isUserNameEditable; - - Image logoImage = null; - if(protocolProvider != null) - { - ProtocolIcon protocolIcon = protocolProvider.getProtocolIcon(); - - if(protocolIcon.isSizeSupported(ProtocolIcon.ICON_SIZE_64x64)) - logoImage = ImageLoader.getBytesInImage( - protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_64x64)); - else if(protocolIcon.isSizeSupported(ProtocolIcon.ICON_SIZE_48x48)) - logoImage = ImageLoader.getBytesInImage( - protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_48x48)); - - this.setTitle(GuiActivator.getResources().getI18NString( - "service.gui.AUTHENTICATION_WINDOW_TITLE", - new String[]{protocolProvider.getProtocolName()})); - } - - backgroundPanel = new LoginWindowBackground(logoImage); - this.backgroundPanel.setBorder( - BorderFactory.createEmptyBorder(20, 5, 5, 5)); - this.backgroundPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); - this.backgroundPanel.setPreferredSize(new Dimension(420, 230)); - - this.getContentPane().setLayout(new BorderLayout()); - - this.init(); - - this.getContentPane().add(backgroundPanel, BorderLayout.CENTER); - - this.setResizable(false); - - this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - - this.enableKeyActions(); - } - - /** - * Creates an instance of the <tt>LoginWindow</tt>. - * @param mainFrame the parent <tt>MainFrame</tt> window. - */ - public AuthenticationWindow(MainFrame mainFrame) - { - this(mainFrame, null, null, null, false); - } - - /** - * Creates an instance of the <tt>LoginWindow</tt>. - * @param mainFrame the parent <tt>MainFrame</tt> window. - * @param protocolProvider the protocol provider. - * @param realm the realm - * @param userCredentials the user credentials - * @param isUserNameEditable indicates if the user name should be editable - * by the user or not. - * @param errorMessage an error message explaining a reason for opening - * the authentication dialog (when a wrong password was provided, etc.) - */ - public AuthenticationWindow(MainFrame mainFrame, - ProtocolProviderService protocolProvider, - String realm, - UserCredentials userCredentials, - boolean isUserNameEditable, - String errorMessage) - { - this( mainFrame, - protocolProvider, - realm, - userCredentials, - isUserNameEditable); - - this.realmTextArea.setForeground(Color.RED); - this.realmTextArea.setText(errorMessage); - } - - /** - * Constructs the <tt>LoginWindow</tt>. - */ - private void init() - { - if(userCredentials != null) - { - if(!isUserNameEditable) - this.uinValue = new JLabel(userCredentials.getUserName()); - else - this.uinValue = new JTextField(userCredentials.getUserName()); - - char[] password = userCredentials.getPassword(); - if (password != null) - { - this.passwdField.setText(String.valueOf(password)); - } - } - else - { - // no user credentials just an empty field - this.uinValue = new JTextField(); - } - - this.realmTextArea.setEditable(false); - this.realmTextArea.setOpaque(false); - this.realmTextArea.setLineWrap(true); - this.realmTextArea.setWrapStyleWord(true); - this.realmTextArea.setFont( - realmTextArea.getFont().deriveFont(Font.BOLD)); - this.realmTextArea.setText( - GuiActivator.getResources().getI18NString( - "service.gui.SECURITY_AUTHORITY_REALM", - new String[]{realm})); - - JLabel uinLabel - = new JLabel( - GuiActivator.getResources().getI18NString( - "service.gui.IDENTIFIER")); - uinLabel.setFont(uinLabel.getFont().deriveFont(Font.BOLD)); - - JLabel passwdLabel - = new JLabel( - GuiActivator.getResources().getI18NString( - "service.gui.PASSWORD")); - passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD)); - - this.labelsPanel.add(uinLabel); - this.labelsPanel.add(passwdLabel); - this.labelsPanel.add(new JLabel()); - - this.rememberPassCheckBox.setOpaque(false); - - this.textFieldsPanel.add(uinValue); - this.textFieldsPanel.add(passwdField); - this.textFieldsPanel.add(rememberPassCheckBox); - - this.buttonsPanel.add(loginButton); - this.buttonsPanel.add(cancelButton); - - this.mainPanel.add(realmTextArea, BorderLayout.NORTH); - this.mainPanel.add(labelsPanel, BorderLayout.WEST); - this.mainPanel.add(textFieldsPanel, BorderLayout.CENTER); - this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH); - - this.backgroundPanel.add(mainPanel, BorderLayout.CENTER); - - this.loginButton.setName("ok"); - this.cancelButton.setName("cancel"); - - this.loginButton.setMnemonic( - GuiActivator.getResources().getI18nMnemonic("service.gui.OK")); - this.cancelButton.setMnemonic( - GuiActivator.getResources().getI18nMnemonic("service.gui.CANCEL")); - - this.loginButton.addActionListener(this); - this.cancelButton.addActionListener(this); - - this.getRootPane().setDefaultButton(loginButton); - - this.setTransparent(true); - } - - /** - * Sets transparent background to all components in the login window, - * because of the non-white background. - * @param transparent <code>true</code> to set a transparent background, - * <code>false</code> otherwise. - */ - private void setTransparent(boolean transparent) - { - this.mainPanel.setOpaque(!transparent); - this.labelsPanel.setOpaque(!transparent); - this.textFieldsPanel.setOpaque(!transparent); - this.buttonsPanel.setOpaque(!transparent); - } - - /** - * Handles the <tt>ActionEvent</tt> triggered when one of the buttons is - * clicked. When "Login" button is choosen installs a new account from - * the user input and logs in. - * - * @param evt the action event that has just occurred. - */ - public void actionPerformed(ActionEvent evt) - { - JButton button = (JButton) evt.getSource(); - String buttonName = button.getName(); - - if ("ok".equals(buttonName)) - { - if(uinValue instanceof JLabel) - userCredentials.setUserName(((JLabel)uinValue).getText()); - else if(uinValue instanceof JTextField) - userCredentials.setUserName(((JTextField)uinValue).getText()); - - userCredentials.setPassword( - passwdField.getPassword()); - userCredentials.setPasswordPersistent( - rememberPassCheckBox.isSelected()); - } - else - { - // if userCredentials are created outside the exported window - // by specifying null username we note that the window was canceled - if (this.userCredentials != null) - { - this.userCredentials.setUserName(null); - this.userCredentials = null; - } - } - - synchronized (lock) - { - lock.notify(); - } - - this.dispose(); - } - - /** - * The <tt>LoginWindowBackground</tt> is a <tt>JPanel</tt> that overrides - * the <code>paintComponent</code> method to provide a custom background - * image for this window. - */ - private static class LoginWindowBackground - extends TransparentPanel - { - private final Image bgImage; - - LoginWindowBackground(Image bgImage) - { - this.bgImage = bgImage; - } - - @Override - protected void paintComponent(Graphics g) - { - super.paintComponent(g); - - if (bgImage != null) - { - g = g.create(); - try - { - AntialiasingManager.activateAntialiasing(g); - - g.drawImage(bgImage, 30, 30, null); - } - finally - { - g.dispose(); - } - } - } - } - - /** - * Enables the actions when a key is pressed, for now - * closes the window when esc is pressed. - */ - private void enableKeyActions() - { - UIAction act = new UIAction() - { - public void actionPerformed(ActionEvent e) - { - AuthenticationWindow.this.setVisible(false); - } - }; - - getRootPane().getActionMap().put("close", act); - - InputMap imap = this.getRootPane().getInputMap( - JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close"); - } - - @Override - protected void close(boolean isEscaped) - { - this.cancelButton.doClick(); - } - - /** - * Shows this modal dialog. - * - * @param isVisible specifies whether we should be showing or hiding the - * window. - */ - @Override - public void setVisible(boolean isVisible) - { - this.setName("AUTHENTICATION"); - - super.setVisible(isVisible); - - if(isVisible) - { - this.passwdField.requestFocus(); - - synchronized (lock) - { - try - { - lock.wait(); - } - catch (InterruptedException e) - { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - } - - void setParams(Object[] windowParams) - { - if(windowParams != null && windowParams.length > 0) - { - Object param = windowParams[0]; - if(param instanceof UserCredentials) - { - this.userCredentials = (UserCredentials)param; - } - } - } -} 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 03fe01e..2f95c01 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 @@ -6,9 +6,11 @@ */ package net.java.sip.communicator.impl.gui.main.login; -import net.java.sip.communicator.impl.gui.*; -import net.java.sip.communicator.service.gui.*; +import javax.swing.*; + +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.swing.AuthenticationWindow; /** * Utility class that can be used in cases where components other than the main @@ -30,6 +32,9 @@ public class DefaultSecurityAuthority /** * Creates this authority for a particular provider. + * + * @param provider the protocol provider, for which this security authority + * is about */ public DefaultSecurityAuthority(ProtocolProviderService provider) { @@ -66,15 +71,33 @@ public class DefaultSecurityAuthority UserCredentials userCredentials, int reasonCode) { - ExportedWindow loginWindow - = GuiActivator.getUIService() - .getAuthenticationWindow(provider, + String userName = userCredentials.getUserName(); + char[] password = userCredentials.getPassword(); + ImageIcon icon = ImageLoader.getAuthenticationWindowIcon(provider); + + AuthenticationWindow loginWindow + = new AuthenticationWindow( userName, + password, realm, - userCredentials, - isUserNameEditable); + isUserNameEditable, + icon); + loginWindow.pack(); loginWindow.setVisible(true); + if (!loginWindow.isCanceled()) + { + userCredentials.setUserName(loginWindow.getUserName()); + userCredentials.setPassword(loginWindow.getPassword()); + userCredentials.setPasswordPersistent( + loginWindow.isRememberPassword()); + } + else + { + userCredentials.setUserName(null); + userCredentials = null; + } + return userCredentials; } diff --git a/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java b/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java index 0d723e6..224d6d6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/login/LoginManager.java @@ -61,8 +61,8 @@ public class LoginManager */ public void login(ProtocolProviderService protocolProvider) { - SecurityAuthorityImpl secAuth = new SecurityAuthorityImpl(mainFrame, - protocolProvider); + SecurityAuthorityImpl secAuth + = new SecurityAuthorityImpl(protocolProvider); mainFrame.getAccountStatusPanel().startConnecting(protocolProvider); diff --git a/src/net/java/sip/communicator/impl/gui/main/login/SecurityAuthorityImpl.java b/src/net/java/sip/communicator/impl/gui/main/login/SecurityAuthorityImpl.java index 65f3a85..f60c133 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/SecurityAuthorityImpl.java +++ b/src/net/java/sip/communicator/impl/gui/main/login/SecurityAuthorityImpl.java @@ -6,9 +6,12 @@ */ 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.main.*; +import net.java.sip.communicator.impl.gui.utils.*; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.swing.*; /** * The <tt>SecurityAuthorityImpl</tt> is an implementation of the @@ -16,25 +19,21 @@ import net.java.sip.communicator.service.protocol.*; * * @author Yana Stamcheva */ -public class SecurityAuthorityImpl implements SecurityAuthority { - - private MainFrame mainFrame; - +public class SecurityAuthorityImpl + implements SecurityAuthority +{ private ProtocolProviderService protocolProvider; private boolean isUserNameEditable = false; /** * Creates an instance of <tt>SecurityAuthorityImpl</tt>. - * @param mainFrame The parent window of the <tt>AuthenticationWIndow</tt> - * created in this class. + * * @param protocolProvider The <tt>ProtocolProviderService</tt> for this * <tt>SecurityAuthority</tt>. */ - public SecurityAuthorityImpl(MainFrame mainFrame, - ProtocolProviderService protocolProvider) + public SecurityAuthorityImpl(ProtocolProviderService protocolProvider) { - this.mainFrame = mainFrame; this.protocolProvider = protocolProvider; } @@ -67,24 +66,44 @@ public class SecurityAuthorityImpl implements SecurityAuthority { } AuthenticationWindow loginWindow = null; - + + String userName = userCredentials.getUserName(); + char[] password = userCredentials.getPassword(); + ImageIcon icon + = ImageLoader.getAuthenticationWindowIcon(protocolProvider); + if (errorMessage == null) - loginWindow = new AuthenticationWindow( mainFrame, - protocolProvider, - realm, - userCredentials, - isUserNameEditable); + loginWindow = new AuthenticationWindow( + userName, + password, + realm, + isUserNameEditable, + icon); else - loginWindow = new AuthenticationWindow( mainFrame, - protocolProvider, + loginWindow = new AuthenticationWindow( + userName, + password, realm, - userCredentials, isUserNameEditable, + icon, errorMessage); loginWindow.pack(); loginWindow.setVisible(true); + if (!loginWindow.isCanceled()) + { + userCredentials.setUserName(loginWindow.getUserName()); + userCredentials.setPassword(loginWindow.getPassword()); + userCredentials.setPasswordPersistent( + loginWindow.isRememberPassword()); + } + else + { + userCredentials.setUserName(null); + userCredentials = null; + } + return userCredentials; } diff --git a/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusMenu.java b/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusMenu.java index 208be26..1b8425f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/presence/SimpleStatusMenu.java @@ -46,7 +46,7 @@ public class SimpleStatusMenu { this(protocolProvider, protocolProvider.getAccountID().getDisplayName(), - ImageLoader.getBytesInImage( + GuiUtils.getBytesInImage( protocolProvider.getProtocolIcon().getIcon( ProtocolIcon.ICON_SIZE_16x16))); } @@ -100,6 +100,8 @@ public class SimpleStatusMenu /** * Handles the <tt>ActionEvent</tt> triggered when one of the items in the * list is selected. + * + * @param e the <tt>ActionEvent</tt> that notified us */ public void actionPerformed(ActionEvent e) { @@ -165,13 +167,13 @@ public class SimpleStatusMenu public void loadSkin() { super.loadSkin(); - setIcon(new ImageIcon(ImageLoader.getBytesInImage( + setIcon(new ImageIcon(GuiUtils.getBytesInImage( protocolProvider.getProtocolIcon().getIcon( ProtocolIcon.ICON_SIZE_16x16)))); onlineItem.setIcon(getIcon()); offlineItem.setIcon( new ImageIcon(LightGrayFilter.createDisabledImage( - ImageLoader.getBytesInImage( + GuiUtils.getBytesInImage( protocolProvider.getProtocolIcon().getIcon( ProtocolIcon.ICON_SIZE_16x16))))); } 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 6a4c0e8..2bf04a4 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java +++ b/src/net/java/sip/communicator/impl/gui/utils/ImageLoader.java @@ -1263,27 +1263,6 @@ public class ImageLoader } /** - * Loads an image from a given bytes array. - * @param imageBytes The bytes array to load the image from. - * @return The image for the given bytes array. - */ - public static Image getBytesInImage(byte[] imageBytes) - { - Image image = null; - try - { - image = ImageIO.read( - new ByteArrayInputStream(imageBytes)); - - } - catch (Exception e) - { - logger.error("Failed to convert bytes to image.", e); - } - return image; - } - - /** * Returns the URI corresponding to the image with the given image * identifier. * @@ -1326,13 +1305,13 @@ public class ImageLoader Image statusImage; if (presence != null) { - statusImage = ImageLoader.getBytesInImage( + statusImage = GuiUtils.getBytesInImage( presence.getPresenceStatus().getStatusIcon()); } else { statusImage - = ImageLoader.getBytesInImage(pps.getProtocolIcon().getIcon( + = GuiUtils.getBytesInImage(pps.getProtocolIcon().getIcon( ProtocolIcon.ICON_SIZE_16x16)); if (!pps.isRegistered()) @@ -1430,4 +1409,34 @@ public class ImageLoader { loadedImages.clear(); } + + /** + * 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 = GuiUtils.getBytesInImage( + protocolIcon.getIcon(ProtocolIcon.ICON_SIZE_64x64)); + else if(protocolIcon.isSizeSupported(ProtocolIcon.ICON_SIZE_48x48)) + image = GuiUtils.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/protocol/yahoo/ProtocolProviderServiceYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java index 6446479..f855ec4 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/ProtocolProviderServiceYahooImpl.java @@ -145,6 +145,16 @@ public class ProtocolProviderServiceYahooImpl credentials, authReasonCode); + // in case user has canceled the login window + if(credentials == null) + { + fireRegistrationStateChanged( + getRegistrationState(), + RegistrationState.UNREGISTERED, + RegistrationStateChangeEvent.REASON_USER_REQUEST, ""); + return; + } + //extract the password the user passed us. char[] pass = credentials.getPassword(); |