diff options
author | Yana Stamcheva <yana@jitsi.org> | 2010-09-29 07:37:36 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2010-09-29 07:37:36 +0000 |
commit | 15dc7d7c095970bfbe58af45b68cb9a88f6b2d06 (patch) | |
tree | a89073d35fe0a634179325d91e848e54198351c2 /src/net | |
parent | 5c166b35f0116b4936c3ff0f85d024c9b9061414 (diff) | |
download | jitsi-15dc7d7c095970bfbe58af45b68cb9a88f6b2d06.zip jitsi-15dc7d7c095970bfbe58af45b68cb9a88f6b2d06.tar.gz jitsi-15dc7d7c095970bfbe58af45b68cb9a88f6b2d06.tar.bz2 |
Moves the authentication window to the util package and removes any dependency to the protocol service and security authority.
Diffstat (limited to 'src/net')
16 files changed, 352 insertions, 314 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/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(); diff --git a/src/net/java/sip/communicator/service/gui/UIService.java b/src/net/java/sip/communicator/service/gui/UIService.java index 002e4eb..edf94f8 100644 --- a/src/net/java/sip/communicator/service/gui/UIService.java +++ b/src/net/java/sip/communicator/service/gui/UIService.java @@ -264,28 +264,6 @@ public interface UIService public void setCurrentPhoneNumber(String phoneNumber); /** - * Returns an <tt>ExportableComponent</tt> that corresponds to an - * authentication window for the given protocol provider and user - * information. Initially this method is meant to be used by the - * <tt>SystrayService</tt> in order to show a login window when user tries - * to connect using the systray menu. - * - * @param protocolProvider the <tt>ProtocolProviderService</tt> for which - * the authentication window is about. - * @param realm the realm - * @param userCredentials the <tt>UserCredentials</tt>, where the username - * and password details are stored - * @param isUserNameEditable indicates if the user name could be changed by - * user. - * @return an <tt>ExportableComponent</tt> that corresponds to an - * authentication window for the given protocol provider and user - * information. - */ - public ExportedWindow getAuthenticationWindow( - ProtocolProviderService protocolProvider, String realm, - UserCredentials userCredentials, boolean 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/util/GuiUtils.java b/src/net/java/sip/communicator/util/GuiUtils.java index 4bcdd6f..ace1efe 100644 --- a/src/net/java/sip/communicator/util/GuiUtils.java +++ b/src/net/java/sip/communicator/util/GuiUtils.java @@ -9,8 +9,10 @@ package net.java.sip.communicator.util; import java.awt.*; import java.awt.font.*; import java.awt.geom.*; +import java.io.*; import java.util.*; +import javax.imageio.*; import javax.swing.*; /** @@ -24,6 +26,11 @@ import javax.swing.*; public class GuiUtils { /** + * The logger for this class. + */ + private static Logger logger = Logger.getLogger(GuiUtils.class); + + /** * List of all windows owned by the app. */ private static final ArrayList<Window> WINDOW_LIST @@ -498,4 +505,25 @@ public class GuiUtils } } } + + /** + * 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; + } } diff --git a/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationWindow.java b/src/net/java/sip/communicator/util/swing/AuthenticationWindow.java index df9cbdf..46e112e 100644 --- a/src/net/java/sip/communicator/impl/gui/main/login/AuthenticationWindow.java +++ b/src/net/java/sip/communicator/util/swing/AuthenticationWindow.java @@ -4,22 +4,18 @@ * Distributable under LGPL license. * See terms of license at gnu.org. */ -package net.java.sip.communicator.impl.gui.main.login; +package net.java.sip.communicator.util.swing; 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.*; +import net.java.sip.communicator.util.*; /** - * The <tt>LoginWindow</tt> is the window where the user should type his - * user identifier and password to login. + * The <tt>AuthenticationWindow</tt> is the window where the user should type + * his user identifier and password to login. * * @author Yana Stamcheva */ @@ -27,81 +23,115 @@ public class AuthenticationWindow extends SIPCommFrame implements ActionListener { - private final JTextArea realmTextArea = new JTextArea(); + /** + * Info text area. + */ + private final JTextArea infoTextArea = new JTextArea(); + /** + * The uin component. + */ private JComponent uinValue; + /** + * The password field. + */ private final JPasswordField passwdField = new JPasswordField(15); + /** + * The login button. + */ private final JButton loginButton = new JButton( - GuiActivator.getResources().getI18NString("service.gui.OK")); + UtilActivator.getResources().getI18NString("service.gui.OK")); + /** + * The cancel button. + */ private final JButton cancelButton = new JButton( - GuiActivator.getResources().getI18NString("service.gui.CANCEL")); + UtilActivator.getResources().getI18NString("service.gui.CANCEL")); + /** + * The labels panel. + */ private final TransparentPanel labelsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8)); + /** + * The text fields panel. + */ private final TransparentPanel textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8)); + /** + * The panel containing all other components. + */ private final TransparentPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10)); + /** + * The panel containing all buttons. + */ private final TransparentPanel buttonsPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); + /** + * The check box indicating if the password should be remembered. + */ private final JCheckBox rememberPassCheckBox - = new SIPCommCheckBox(GuiActivator.getResources() + = new SIPCommCheckBox(UtilActivator.getResources() .getI18NString("service.gui.REMEMBER_PASSWORD")); + /** + * The background of the login window. + */ private LoginWindowBackground backgroundPanel; - private UserCredentials userCredentials; + private String server; - private final Object lock = new Object(); + /** + * The user name. + */ + private String userName; + + /** + * The password. + */ + private char[] password; + + /** + * Indicates if the password should be remembered. + */ + private boolean isRememberPassword = false; - private String realm; + /** + * Indicates if the window has been canceled. + */ + private boolean isCanceled = false; - private final boolean isUserNameEditable; + /** + * A lock used to synchronize data setting. + */ + private final Object lock = new Object(); /** * 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 server the server name + * @param isUserNameEditable indicates if the user name is editable + * @param icon the icon to display on the left of the authentication window */ - public AuthenticationWindow(MainFrame mainFrame, - ProtocolProviderService protocolProvider, - String realm, - UserCredentials userCredentials, - boolean isUserNameEditable) + public AuthenticationWindow(String server, + boolean isUserNameEditable, + ImageIcon icon) { - this.userCredentials = userCredentials; - - this.realm = realm; + this.server = server; - this.isUserNameEditable = isUserNameEditable; + Image logoImage = icon.getImage(); - 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()})); - } + if(!isUserNameEditable) + this.uinValue = new JLabel(); + else + this.uinValue = new JTextField(); backgroundPanel = new LoginWindowBackground(logoImage); this.backgroundPanel.setBorder( @@ -115,8 +145,6 @@ public class AuthenticationWindow this.getContentPane().add(backgroundPanel, BorderLayout.CENTER); - this.setResizable(false); - this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.enableKeyActions(); @@ -124,39 +152,58 @@ public class AuthenticationWindow /** * Creates an instance of the <tt>LoginWindow</tt>. - * @param mainFrame the parent <tt>MainFrame</tt> window. + * + * @param userName the user name to set by default + * @param password the password to set by default + * @param server the server name this authentication window is about + * @param isUserNameEditable indicates if the user name should be editable + * by the user or not + * @param icon the icon displayed on the left of the authentication window + * @param errorMessage an error message explaining a reason for opening + * the authentication dialog (when a wrong password was provided, etc.) */ - public AuthenticationWindow(MainFrame mainFrame) + public AuthenticationWindow(String userName, + char[] password, + String server, + boolean isUserNameEditable, + ImageIcon icon, + String errorMessage) { - this(mainFrame, null, null, null, false); + this(userName, password, server, isUserNameEditable, icon); + + this.infoTextArea.setForeground(Color.RED); + this.infoTextArea.setText(errorMessage); } /** * 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 userName the user name to set by default + * @param password the password to set by default + * @param server the server name this authentication window is about * @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.) + * by the user or not + * @param icon the icon displayed on the left of the authentication window */ - public AuthenticationWindow(MainFrame mainFrame, - ProtocolProviderService protocolProvider, - String realm, - UserCredentials userCredentials, + public AuthenticationWindow( + String userName, + char[] password, + String server, boolean isUserNameEditable, - String errorMessage) + ImageIcon icon) { - this( mainFrame, - protocolProvider, - realm, - userCredentials, - isUserNameEditable); - - this.realmTextArea.setForeground(Color.RED); - this.realmTextArea.setText(errorMessage); + this(server, isUserNameEditable, icon); + + if (userName != null) + { + if (uinValue instanceof JLabel) + ((JLabel) uinValue).setText(userName); + else if (uinValue instanceof JTextField) + ((JTextField) uinValue).setText(userName); + } + + if (password != null) + passwdField.setText(new String(password)); } /** @@ -164,45 +211,27 @@ public class AuthenticationWindow */ 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})); + setTitle(UtilActivator.getResources().getI18NString( + "service.gui.AUTHENTICATION_WINDOW_TITLE", new String[]{server})); + + this.infoTextArea.setEditable(false); + this.infoTextArea.setOpaque(false); + this.infoTextArea.setLineWrap(true); + this.infoTextArea.setWrapStyleWord(true); + this.infoTextArea.setFont( + infoTextArea.getFont().deriveFont(Font.BOLD)); + this.infoTextArea.setText( + UtilActivator.getResources().getI18NString( + "service.gui.AUTHENTICATION_REQUESTED_SERVER", + new String[]{server})); JLabel uinLabel - = new JLabel( - GuiActivator.getResources().getI18NString( + = new JLabel(UtilActivator.getResources().getI18NString( "service.gui.IDENTIFIER")); uinLabel.setFont(uinLabel.getFont().deriveFont(Font.BOLD)); JLabel passwdLabel - = new JLabel( - GuiActivator.getResources().getI18NString( + = new JLabel(UtilActivator.getResources().getI18NString( "service.gui.PASSWORD")); passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD)); @@ -219,7 +248,7 @@ public class AuthenticationWindow this.buttonsPanel.add(loginButton); this.buttonsPanel.add(cancelButton); - this.mainPanel.add(realmTextArea, BorderLayout.NORTH); + this.mainPanel.add(infoTextArea, BorderLayout.NORTH); this.mainPanel.add(labelsPanel, BorderLayout.WEST); this.mainPanel.add(textFieldsPanel, BorderLayout.CENTER); this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH); @@ -230,9 +259,9 @@ public class AuthenticationWindow this.cancelButton.setName("cancel"); this.loginButton.setMnemonic( - GuiActivator.getResources().getI18nMnemonic("service.gui.OK")); + UtilActivator.getResources().getI18nMnemonic("service.gui.OK")); this.cancelButton.setMnemonic( - GuiActivator.getResources().getI18nMnemonic("service.gui.CANCEL")); + UtilActivator.getResources().getI18nMnemonic("service.gui.CANCEL")); this.loginButton.addActionListener(this); this.cancelButton.addActionListener(this); @@ -258,7 +287,7 @@ public class AuthenticationWindow /** * Handles the <tt>ActionEvent</tt> triggered when one of the buttons is - * clicked. When "Login" button is choosen installs a new account from + * clicked. When "Login" button is chosen installs a new account from * the user input and logs in. * * @param evt the action event that has just occurred. @@ -271,24 +300,16 @@ public class AuthenticationWindow if ("ok".equals(buttonName)) { if(uinValue instanceof JLabel) - userCredentials.setUserName(((JLabel)uinValue).getText()); + userName = ((JLabel) uinValue).getText(); else if(uinValue instanceof JTextField) - userCredentials.setUserName(((JTextField)uinValue).getText()); + userName = ((JTextField) uinValue).getText(); - userCredentials.setPassword( - passwdField.getPassword()); - userCredentials.setPasswordPersistent( - rememberPassCheckBox.isSelected()); + password = passwdField.getPassword(); + isRememberPassword = 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; - } + isCanceled = true; } synchronized (lock) @@ -357,6 +378,12 @@ public class AuthenticationWindow imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close"); } + /** + * Automatically clicks the cancel button, when this window is closed. + * + * @param isEscaped indicates if the window has been closed by pressing the + * Esc key + */ @Override protected void close(boolean isEscaped) { @@ -395,15 +422,46 @@ public class AuthenticationWindow } } - void setParams(Object[] windowParams) + /** + * Indicates if this window has been canceled. + * + * @return <tt>true</tt> if this window has been canceled, <tt>false</tt> - + * otherwise + */ + public boolean isCanceled() + { + return isCanceled; + } + + /** + * Returns the user name entered by the user or previously set if the + * user name is not editable. + * + * @return the user name + */ + public String getUserName() { - if(windowParams != null && windowParams.length > 0) - { - Object param = windowParams[0]; - if(param instanceof UserCredentials) - { - this.userCredentials = (UserCredentials)param; - } - } + return userName; + } + + /** + * Returns the password entered by the user. + * + * @return the password + */ + public char[] getPassword() + { + return password; + } + + /** + * Indicates if the password should be remembered. + * + * @return <tt>true</tt> if the password should be remembered, + * <tt>false</tt> - otherwise + */ + public boolean isRememberPassword() + { + return isRememberPassword; } } |