From 4f6aaa3ee7f718dbdb18ba0b5fa5ff6af89ee588 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Fri, 23 Jul 2010 09:09:16 +0000 Subject: [PATCH] Commits Dmitri Melnikov's dialogs.patch provided in the dev mailing list thread "Password Storage in trunk". --- .../gui/utils/MasterPasswordInputDialog.java | 46 +++++++++++++++++-- .../MasterPasswordChangeDialog.java | 3 ++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/utils/MasterPasswordInputDialog.java b/src/net/java/sip/communicator/impl/gui/utils/MasterPasswordInputDialog.java index 066b7ad43..29d5a7ede 100644 --- a/src/net/java/sip/communicator/impl/gui/utils/MasterPasswordInputDialog.java +++ b/src/net/java/sip/communicator/impl/gui/utils/MasterPasswordInputDialog.java @@ -21,7 +21,8 @@ */ public class MasterPasswordInputDialog extends SIPCommDialog - implements ActionListener + implements ActionListener, + KeyListener { /** * Instance of this class. @@ -106,6 +107,7 @@ private void initComponents() // password fields currentPasswdField = new JPasswordField(15); + currentPasswdField.addKeyListener(this); currentPasswdField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) @@ -118,13 +120,12 @@ public void actionPerformed(ActionEvent arg0) // OK and cancel buttons okButton = new JButton(resources.getI18NString("service.gui.OK")); - okButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic( - "service.gui.OK")); + okButton.setMnemonic(resources.getI18nMnemonic("service.gui.OK")); okButton.addActionListener(this); cancelButton = new JButton(resources.getI18NString("service.gui.CANCEL")); - cancelButton.setMnemonic(GuiActivator.getResources().getI18nMnemonic( + cancelButton.setMnemonic(resources.getI18nMnemonic( "service.gui.CANCEL")); cancelButton.addActionListener(this); @@ -206,12 +207,47 @@ protected void close(boolean escaped) /** * Resets the password by clearing the input field and setting - * password to null. + * password to null. Disables the OK button. */ private void resetPassword() { password = null; currentPasswdField.setText(""); currentPasswdField.requestFocusInWindow(); + okButton.setEnabled(false); + } + + /** + * Disables OK button if the password input field is empty. + * + * @param event key event + */ + public void keyReleased(KeyEvent event) + { + JPasswordField source = (JPasswordField) event.getSource(); + if (currentPasswdField.equals(source)) + { + String password = new String(currentPasswdField.getPassword()); + okButton.setEnabled(password.length() > 0); + password = null; + } + } + + /** + * Not overriding. + * + * @param arg0 key event + */ + public void keyPressed(KeyEvent arg0) + { + } + + /** + * Not overriding. + * + * @param arg0 key event + */ + public void keyTyped(KeyEvent arg0) + { } } diff --git a/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java b/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java index ce5f24f22..ee97d1fcf 100644 --- a/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java +++ b/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java @@ -192,10 +192,13 @@ public void actionPerformed(ActionEvent e) // OK and cancel buttons okButton = new JButton(resources.getI18NString("service.gui.OK")); + okButton.setMnemonic(resources.getI18nMnemonic("service.gui.OK")); okButton.addActionListener(this); okButton.setEnabled(false); cancelButton = new JButton(resources.getI18NString("service.gui.CANCEL")); + cancelButton.setMnemonic(resources.getI18nMnemonic( + "service.gui.CANCEL")); cancelButton.addActionListener(this); passwordQualityBar =