com.sas.util.login
Class LoginBeanSwingUtil

com.sas.util.login.LoginBeanSwingUtil
All Implemented Interfaces:
com.sas.util.login.LoginBeanActionInterface, java.awt.event.ActionListener, java.util.EventListener

public class LoginBeanSwingUtil
implements java.awt.event.ActionListener, com.sas.util.login.LoginBeanActionInterface

The LoginBeanSwingUtil class is a Swing utility class for the LoginBean. It's primary purpose is to create a Swing panel using the properties set on a LoginBean.

It also has a static showDialog convenience method which will create and display a Swing dialog with the Swing panel mentioned above.

The following example illustrates a typical use of the LoginBean in conjunction with this class.

 LoginBean bean = new LoginBean();
 bean.setTitle("Enter your username and password:");
 
 // Provide a default value for the username.
 bean.setUsername("James");
 
 // Allow 2 retry attempts before failing (default is 3).
 bean.setAttempts(2);
 
 // Instantiate the LoginBeanSwingUtil class using the constructor which sets the
 // login bean as the model.
 LoginBeanSwingUtil beanUtil = new LoginBeanSwingUtil(bean);
 
 // Set our LoginBeanSwingUtil instance as the action handler for the login bean.
 // Note that this class implements LoginBeanActionInterface as a convenience for
 // typical usage scenarios.
 bean.setActionHandler(beanUtil);
 
 // Call the showDialog method to display a model Swing dialog with a visual representation
 // of the login bean.
 beanUtil.showDialog("LoginBean", null);
 

Note that in this example, no validation is handled on the information entered by the user. To do so, you can create a class that implements LoginBeanValidateInterface and implement the validate method such that it validates the specified credentials against whatever authentication system you have in place. Then set an instance of this class as the validation handler as follows:

 bean.setValidateHandler(yourInstance);
 

See the LoginBeanBIPValidate class in this same package for an example that performs validation.


Field Summary
protected  int buttonSelected
          An index representing the selected button.
protected  javax.swing.JButton cancelButton
          The Cancel button.
protected  javax.swing.JButton closeButton
          The Close button.
protected  javax.swing.JDialog dialog
          The dialog used by the showDialog method.
protected  com.sas.util.login.LoginBean loginBean
          The associated LoginBean.
protected  javax.swing.JButton okButton
          The OK button.
protected  javax.swing.JPasswordField passwordTextField
          The text field representing the password.
protected  javax.swing.JLabel retryLabel
          The retry label.
protected  javax.swing.JTextField usernameTextField
          The text field representing the username.
 
Constructor Summary
LoginBeanSwingUtil()
          Default constructor.
LoginBeanSwingUtil(com.sas.util.login.LoginBean bean)
          Constructor allowing for the specification of a LoginBean
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          The event handler for the various Swing buttons.
 void cancelAction()
          Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.
 void closeAction()
          Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.
 javax.swing.JPanel createSwingPanel()
          Creates a Swing panel from the properties specified on the associated LoginBean.
 void failureAction()
          Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.
 com.sas.util.login.LoginBean getLoginBean()
          Returns the LoginBean instance associated with this class.
 int getSelectedButton()
          Returns the Swing button selected by the user.
static void main(java.lang.String[] argv)
          The main program serves as a testing facility for this class.
 void OKAction()
          Implementation of LoginBeanActionInterface.
 void retryAction()
          Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.
 void setLoginBean(com.sas.util.login.LoginBean bean)
          Sets the LoginBean associated with this util class.
 void showDialog(java.lang.String dialogTitle, java.awt.Frame owner)
          Displays a modal dialog containing a Swing JPanel for the LoginBean associated with the specified instance of LoginBeanSwingUtil.
static void showDialog(java.lang.String dialogTitle, java.awt.Frame owner, com.sas.util.login.LoginBean bean)
          Displays a modal dialog containing a Swing JPanel for the specified LoginBean.
 void successAction()
          Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.
 

Field Detail

loginBean

protected com.sas.util.login.LoginBean loginBean
The associated LoginBean.


usernameTextField

protected javax.swing.JTextField usernameTextField
The text field representing the username.


passwordTextField

protected javax.swing.JPasswordField passwordTextField
The text field representing the password.


dialog

protected javax.swing.JDialog dialog
The dialog used by the showDialog method.


okButton

protected javax.swing.JButton okButton
The OK button.


cancelButton

protected javax.swing.JButton cancelButton
The Cancel button.


closeButton

protected javax.swing.JButton closeButton
The Close button.


retryLabel

protected javax.swing.JLabel retryLabel
The retry label.


buttonSelected

protected int buttonSelected
An index representing the selected button.

Constructor Detail

LoginBeanSwingUtil

public LoginBeanSwingUtil()
Default constructor.


LoginBeanSwingUtil

public LoginBeanSwingUtil(com.sas.util.login.LoginBean bean)
Constructor allowing for the specification of a LoginBean

Parameters:
bean - An instance of LoginBean associated with this util class.
Method Detail

setLoginBean

public void setLoginBean(com.sas.util.login.LoginBean bean)
Sets the LoginBean associated with this util class.

Parameters:
bean - An instance of LoginBean to associate with this class.
See Also:
getLoginBean()

getLoginBean

public com.sas.util.login.LoginBean getLoginBean()
Returns the LoginBean instance associated with this class.

Returns:
The instance of LoginBean.
See Also:
setLoginBean(LoginBean)

getSelectedButton

public int getSelectedButton()
Returns the Swing button selected by the user.

Returns:
The value of the button selected. Valid values are: LoginBean.BUTTON_OK; LoginBean.BUTTON_CANCEL; LoginBean.BUTTON_CLOSE;

createSwingPanel

public javax.swing.JPanel createSwingPanel()
Creates a Swing panel from the properties specified on the associated LoginBean.

Returns:
The JPanel containing the Swing elements.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
The event handler for the various Swing buttons.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
evt - The ActionEvent.

OKAction

public void OKAction()
Implementation of LoginBeanActionInterface. This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.

Specified by:
OKAction in interface com.sas.util.login.LoginBeanActionInterface

cancelAction

public void cancelAction()
Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.

Specified by:
cancelAction in interface com.sas.util.login.LoginBeanActionInterface

closeAction

public void closeAction()
Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.

Specified by:
closeAction in interface com.sas.util.login.LoginBeanActionInterface

successAction

public void successAction()
Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.

Specified by:
successAction in interface com.sas.util.login.LoginBeanActionInterface

failureAction

public void failureAction()
Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.

Specified by:
failureAction in interface com.sas.util.login.LoginBeanActionInterface

retryAction

public void retryAction()
Implementation of LoginBeanActionInterface This method is included here to support the testing feature of the main program, and to serve as an example of how to implement this interface.

Specified by:
retryAction in interface com.sas.util.login.LoginBeanActionInterface

showDialog

public void showDialog(java.lang.String dialogTitle,
                       java.awt.Frame owner)
Displays a modal dialog containing a Swing JPanel for the LoginBean associated with the specified instance of LoginBeanSwingUtil.

Parameters:
dialogTitle - The title of the dialog window.
owner - The Frame serving as the owner of the dialog.

showDialog

public static void showDialog(java.lang.String dialogTitle,
                              java.awt.Frame owner,
                              com.sas.util.login.LoginBean bean)
Displays a modal dialog containing a Swing JPanel for the specified LoginBean.

Parameters:
dialogTitle - The title of the dialog window.
owner - The Frame serving as the owner of the dialog.
bean - The login bean to display in the dialog.

main

public static void main(java.lang.String[] argv)
The main program serves as a testing facility for this class. It instantiates LoginBean and LoginBeanSwingUtil, sets various properties, and then calls the showDialog method to display a modal dialog.




Copyright © 2009 SAS Institute Inc. All Rights Reserved.