Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Attributes | Protected Member Functions | Package Attributes | Static Private Member Functions | Private Attributes
SharpTools.PasswordDialog Class Reference

This class provides a password validating dialog. More...

Inheritance diagram for SharpTools.PasswordDialog:
Inheritance graph
[legend]
Collaboration diagram for SharpTools.PasswordDialog:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PasswordDialog (JFrame aFrame, String pass)
String getValidatedText ()
int getChoice ()
boolean isCancelled ()

Static Public Attributes

static final int CLOSED_OPTION = JOptionPane.CLOSED_OPTION
static final int YES_OPTION = JOptionPane.YES_OPTION
static final int NO_OPTION = JOptionPane.NO_OPTION
static final int OK_OPTION = JOptionPane.OK_OPTION
static final int CANCEL_OPTION = JOptionPane.CANCEL_OPTION

Protected Member Functions

boolean onOK ()
 This function is called when the OK button is pressed.
boolean onCancel ()
 This function is called when the Cancel button is pressed.
void onOpen ()
 I provide several hooks for the sublasses to override.
JRootPane createRootPane ()
 override this protected funciton to register ESCAPE with the root pane
boolean onClose ()
 This function is called when (1) the close button is clocked (2) Escape is pressed.
boolean onYes ()
 This function is called when the Yes button is pressed.
boolean onNo ()
 This function is called when the No button is pressed.
void setOptionPane (Object message, int messageType, int optionType, Icon icon)
 This is used by subclasses to set the JOptionPane component in the dialog.
void setOptionPane (Object message, int messageType, int optionType, Icon icon, int defaultIndex)
 This is used by subclasses to set the JOptionPane component in the dialog.

Package Attributes

final ImageIcon passwordIcon = new ImageIcon(getClass().getResource("/images/password32.gif"))
final ImageIcon okIcon = new ImageIcon(getClass().getResource("/images/ok.gif"))
final ImageIcon cancelIcon = new ImageIcon(getClass().getResource("/images/cancel.gif"))
final ImageIcon noIcon = new ImageIcon(getClass().getResource("/images/no.gif"))

Static Private Member Functions

static boolean fieldsAreTheSame (char[] input1, char[] input2)

Private Attributes

JFrame frame
String typedText = null
String password
final JPasswordField textField
final JPasswordField confirmField

Detailed Description

This class provides a password validating dialog.

User is prompted to enter and confirm a password If passwords do not much an error message is displayed and user is prompted to re-enter the passwords

Author:
Andrei Scudder
Hua Zhong (rewrote using SharpDialog)
Version:
Revision:
1.4

Definition at line 24 of file PasswordDialog.java.


Constructor & Destructor Documentation

SharpTools.PasswordDialog.PasswordDialog ( JFrame  aFrame,
String  pass 
) [inline]

Definition at line 36 of file PasswordDialog.java.

                                                      {
        
       super(aFrame, "Password", true);

       frame = aFrame;
       password = pass;
        
       //various properties of the dialog labels and text fields 
        final String msgString1 = SharpTools.translation.getProperty("Enter_password")+" : ";
        final String msgString2 = SharpTools.translation.getProperty("Confirm_Password")+" : ";
        textField = new JPasswordField(10);
       confirmField = new JPasswordField(10);    
       
       Object[] input = {msgString1, textField, msgString2, confirmField};
       Object[] verify = {msgString1, textField};
       Object[] array = password == null ? input : verify;

        setOptionPane(array, 
                    JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION,
                    passwordIcon); 
    }

Here is the call graph for this function:


Member Function Documentation

JRootPane SharpTools.SharpDialog.createRootPane ( ) [inline, protected, inherited]

override this protected funciton to register ESCAPE with the root pane

Returns:
a customized JRootPane object

Definition at line 126 of file SharpDialog.java.

                                         {
       KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
       JRootPane rootPane = new JRootPane();
       rootPane.registerKeyboardAction(
                                   new ActionListener() {
                                          public void actionPerformed
                                              (ActionEvent ev) {    
                                              if (onClose()) {
                                                 choice = CLOSED_OPTION;
                                                 setVisible(false);
                                              }
                                          }
                                       },
                                   stroke,
                                   JComponent.WHEN_IN_FOCUSED_WINDOW);
       return rootPane;
    }

Here is the call graph for this function:

static boolean SharpTools.PasswordDialog.fieldsAreTheSame ( char[]  input1,
char[]  input2 
) [inline, static, private]

Definition at line 67 of file PasswordDialog.java.

                                                                          {
        
        if (input1.length != input2.length)
            return false;
        for (int i = 0;  i < input1.length; i ++)
            if (input1[i] != input2[i])
                return false;
        return true;
    }

Here is the caller graph for this function:

int SharpTools.SharpDialog.getChoice ( ) [inline, inherited]
Returns:
user choice

Definition at line 344 of file SharpDialog.java.

                           {
       return choice;
    }

Here is the caller graph for this function:

Definition at line 62 of file PasswordDialog.java.

                                     {
        return typedText;
    }

Here is the caller graph for this function:

Returns:
whether this operation was cancelled

Definition at line 351 of file SharpDialog.java.

                                 {
       return choice == CANCEL_OPTION || choice == CLOSED_OPTION;
    }

Here is the caller graph for this function:

This function is called when the Cancel button is pressed.

Returns:
whether the dialog should be closed

Reimplemented from SharpTools.SharpDialog.

Definition at line 120 of file PasswordDialog.java.

                                 {
       typedText = null;
       return true;
    }
boolean SharpTools.SharpDialog.onClose ( ) [inline, protected, inherited]

This function is called when (1) the close button is clocked (2) Escape is pressed.

By default, we think it's the same as clicking Cancel button

Returns:
whether the dialog should be closed

Reimplemented in SharpTools.NewFileDialog.

Definition at line 167 of file SharpDialog.java.

                                {
       return onCancel();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

boolean SharpTools.SharpDialog.onNo ( ) [inline, protected, inherited]

This function is called when the No button is pressed.

Returns:
whether the dialog should be closed

Definition at line 207 of file SharpDialog.java.

                             {
       return true;
    }

Here is the caller graph for this function:

boolean SharpTools.PasswordDialog.onOK ( ) [inline, protected]

This function is called when the OK button is pressed.

Returns:
whether the dialog should be closed

Reimplemented from SharpTools.SharpDialog.

Definition at line 77 of file PasswordDialog.java.

                             {
       typedText = new String(textField.getPassword());
       
       if (password != null) {
           // verify password
           if (!typedText.equals(password)) {
              SharpOptionPane.showMessageDialog
                  (PasswordDialog.this,
                   SharpTools.translation.getProperty("Password_Incorrect")+" !" , SharpTools.translation.getProperty("Password"),
                   JOptionPane.ERROR_MESSAGE);
              textField.setText(null);
              textField.requestFocus();
              return false;
           }
           else
              return true;
       }
       
       //validate password
       if (fieldsAreTheSame(textField.getPassword(),
                          confirmField.getPassword())) {
           //compare the dialogs
           return true;
       } else { 
           // passwords dont match
           
           textField.selectAll();
           SharpOptionPane.showMessageDialog
              (this,
               SharpTools.translation.getProperty("Passwords_do_not_match_Please_try_again"),
               SharpTools.translation.getProperty("Password"),
               JOptionPane.ERROR_MESSAGE,
               null);
           
           typedText = null;
                  
           textField.setText(null);
           confirmField.setText(null);
           textField.requestFocus();
           return false;
       }
    }

Here is the call graph for this function:

void SharpTools.PasswordDialog.onOpen ( ) [inline, protected]

I provide several hooks for the sublasses to override.

This function is called when the dialog window is opened.

Reimplemented from SharpTools.SharpDialog.

Definition at line 125 of file PasswordDialog.java.

                            {
       // set the initial focus to textField
       textField.requestFocus();
    }
boolean SharpTools.SharpDialog.onYes ( ) [inline, protected, inherited]

This function is called when the Yes button is pressed.

Returns:
whether the dialog should be closed

Definition at line 197 of file SharpDialog.java.

                              {
       return true;
    }

Here is the caller graph for this function:

void SharpTools.SharpDialog.setOptionPane ( Object  message,
int  messageType,
int  optionType,
Icon  icon 
) [inline, protected, inherited]

This is used by subclasses to set the JOptionPane component in the dialog.

Parameters:
messagethe message box
messageTypethe message type
optionTypethe option type
iconthe icon to display

Definition at line 220 of file SharpDialog.java.

                                        {
       
       setOptionPane(message, messageType, optionType, icon, 0);
    }

Here is the caller graph for this function:

void SharpTools.SharpDialog.setOptionPane ( Object  message,
int  messageType,
int  optionType,
Icon  icon,
int  defaultIndex 
) [inline, protected, inherited]

This is used by subclasses to set the JOptionPane component in the dialog.

Parameters:
messagethe message box
messageTypethe message type
optionTypethe option type
iconthe icon to display
defaultIndexthe default index

Definition at line 238 of file SharpDialog.java.

                                               {
       
       addWindowListener(new WindowAdapter() {

              public void windowOpened(WindowEvent we) {
                  // set the initial focus to rowField
                  onOpen();
              }
              
                public void windowClosing(WindowEvent we) {
                  if (onClose()) {
                     choice = CLOSED_OPTION;
                     setVisible(false);
                  }
              }
           });
       
       // handle this by onClose()
       setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

       okButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onOK()) {
                     choice = OK_OPTION;
                     setVisible(false);
                  }
              }
           });

       cancelButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onCancel()) {
                     choice = CANCEL_OPTION;
                     setVisible(false);
                  }
              }
           });
       
       yesButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onYes()) {
                     choice = YES_OPTION;
                     setVisible(false);
                  }
              }
           });
       
       noButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  if (onNo()) {
                     choice = NO_OPTION;
                     setVisible(false);
                  }
              }
           });

       // setup Mnemonic
       okButton.setMnemonic (KeyEvent.VK_O);
       cancelButton.setMnemonic (KeyEvent.VK_C);
       yesButton.setMnemonic (KeyEvent.VK_Y);
       noButton.setMnemonic (KeyEvent.VK_N);
       
       Object[] buttons = setButtons(optionType);
       JOptionPane optionPane = new JOptionPane(message, messageType,
                                           optionType, icon,
                                           buttons,
                                           buttons[defaultIndex]);
       
       setContentPane(optionPane);

       pack();
       setLocationRelativeTo(getParent());
    }

Here is the call graph for this function:


Member Data Documentation

final int SharpTools.SharpDialog.CANCEL_OPTION = JOptionPane.CANCEL_OPTION [static, inherited]

Definition at line 26 of file SharpDialog.java.

final ImageIcon SharpTools.SharpDialog.cancelIcon = new ImageIcon(getClass().getResource("/images/cancel.gif")) [package, inherited]

Definition at line 28 of file SharpDialog.java.

final int SharpTools.SharpDialog.CLOSED_OPTION = JOptionPane.CLOSED_OPTION [static, inherited]

Definition at line 22 of file SharpDialog.java.

final JPasswordField SharpTools.PasswordDialog.confirmField [private]

Definition at line 30 of file PasswordDialog.java.

Definition at line 26 of file PasswordDialog.java.

final int SharpTools.SharpDialog.NO_OPTION = JOptionPane.NO_OPTION [static, inherited]

Definition at line 24 of file SharpDialog.java.

final ImageIcon SharpTools.SharpDialog.noIcon = new ImageIcon(getClass().getResource("/images/no.gif")) [package, inherited]

Definition at line 29 of file SharpDialog.java.

final int SharpTools.SharpDialog.OK_OPTION = JOptionPane.OK_OPTION [static, inherited]

Definition at line 25 of file SharpDialog.java.

final ImageIcon SharpTools.SharpDialog.okIcon = new ImageIcon(getClass().getResource("/images/ok.gif")) [package, inherited]

Definition at line 27 of file SharpDialog.java.

Definition at line 28 of file PasswordDialog.java.

final ImageIcon SharpTools.PasswordDialog.passwordIcon = new ImageIcon(getClass().getResource("/images/password32.gif")) [package]

Definition at line 31 of file PasswordDialog.java.

final JPasswordField SharpTools.PasswordDialog.textField [private]

Definition at line 29 of file PasswordDialog.java.

String SharpTools.PasswordDialog.typedText = null [private]

Definition at line 27 of file PasswordDialog.java.

final int SharpTools.SharpDialog.YES_OPTION = JOptionPane.YES_OPTION [static, inherited]

Definition at line 23 of file SharpDialog.java.


The documentation for this class was generated from the following file: