|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
com.ccg.awt.LoginPanel
public class LoginPanel
A simple Login panel. Seems like one is always running across the condition where a simple login/password screen is required. This object attempts to create the panel in a generic means that can be used by many applications. It provides the following:
TextField for the user to enter
their login ID in (as well as a Label to appear
next to the text field).
TextField for the user to enter
their login password in (as well as a Label
to appear next to the text field).
authenticate() and cancel(), which
allow one to authenticate the ID/password entered by the user or
perform any special actions when the user cancel's the login
process.
ActionListener objects to
monitor when the user enters a valid login/password or gives up (by
pressing cancel).
It should be noted that the default "authentication" provided by this class is to simply return "true". Almost all implementations will want to override this default behavior with whatever authentication protocol they want to use. Some applications, may choose to live with this and simply authenticate the ID/password after the window has been closed (and then maybe pop it back up if they are unable to verify the ID/password).
The example program LoginDemo.java has been provided which demonstrates how one could use this class. It demonstrates the following:
authenticate() method. The authentciation
rule used by this demo should not be used in practice.
ActionListener objects can detect when the user has entered a
valid password/login combination or given up and pressed the cancel
button.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
(package private) int |
_authenticateCnt
|
(package private) int |
_cancelCnt
|
(package private) boolean |
_cancelLogin
|
(package private) boolean |
_isAuthenticated
|
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
LoginPanel()
Default constructor for the object. |
|
| Method Summary | |
|---|---|
void |
actionPerformed(ActionEvent e)
This routine handles the events from the GUI. |
void |
addActionListener(ActionListener al)
Register a ActionListener
to be notified of action events. |
protected boolean |
authenticate()
Verify that the login ID/password are valid. |
protected boolean |
cancel()
Should the user be allowed to "cancel" the login process. |
void |
doSmartFocus()
Attempt to put the text focus in a "smart" position. |
int |
getCancelAttempts()
Get number of attempts user tried to cancel login. |
int |
getLoginAttempts()
Get number of attempts user attempted to login. |
String |
getLoginId()
Get the login ID the user currently has specified on the panel. |
String |
getPassword()
Get the login password the user currently has specified on the panel. |
boolean |
isAborting()
Does the user want to "abort" the login process. |
boolean |
isAuthenticated()
Indicates whether the user has successfully logged in. |
void |
removeActionListener(ActionListener al)
Register a ActionListener
to be notified of action events. |
void |
setLoginId(String val)
Set the login ID to show on the panel. |
void |
setPassword(String val)
Set the password for the panel. |
void |
setProperties(TagLookup from)
Set the text properties associated with the object. |
boolean |
showDialog(Frame owner,
String title,
boolean modal)
Easy way to present a pop-up window that waits for valid login or abort. |
void |
zero()
Reset counters/flags. |
| Methods inherited from class java.awt.Panel |
|---|
addNotify, getAccessibleContext |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
int _cancelCnt
int _authenticateCnt
boolean _isAuthenticated
boolean _cancelLogin
| Constructor Detail |
|---|
public LoginPanel()
addActionListener(java.awt.event.ActionListener),
setProperties(com.ccg.util.TagLookup)| Method Detail |
|---|
public void zero()
LoginPanel object, it is possible
that you will want to clear/reset/zero out its internal counters
and flags before presenting it back to the user. This method
clears all internal counters and most developers will want to
invoke it prior to displaying the panel to the user. However,
doing so is optional.
public void addActionListener(ActionListener al)
ActionListener
to be notified of action events.
Use this method to register a ActionListener to be notified any
time the user attempts to login or cancel a login attempt. Your
action listener can use the isAuthenticated() and/or
isAborting() methods to determine what the user wants to
do. Its possible that both of these will return false (if the
user entered a login ID/password that wasn't valid according to
authenticate()).
al - Listener you want to have notified when login attempts/aborts
are done by the user.removeActionListener(java.awt.event.ActionListener)public void removeActionListener(ActionListener al)
ActionListener
to be notified of action events.
Use this method to register a ActionListener to be notified any
time the user attempts to login or cancel a login attempt. Your
action listener can use the isAuthenticated() and/or
isAborting() methods to determine what the user wants to
do. Its possible that both of these will return false (if the
user entered a login ID/password that wasn't valid according to
authenticate()).
al - Listener you want to have notified when login attempts/aborts
are done by the user.addActionListener(java.awt.event.ActionListener)protected boolean authenticate()
IMPORTANT: This default implementation always returns true indicating that the login ID/password look OK as far as this object is concerned. This leaves a developer the following choices as to how to do real authentication:
LoginPanel and implement a
real authenticate() method. This is the preferred
solution.
addActionListener(java.awt.event.ActionListener)) do the authentication itself by checking the
login ID/password which the object contains (using the values
returned by getLoginId() and getPassword()
methods).
cancel()public boolean isAuthenticated()
This method indicates whether this object considers the user as
successfully logged in. In order for this to occur, the user must
have performed a action that they wanted to login (such as
pressing the "Login" button), and the authenticate()
method must have validated that the users login was valid. This
method is typically used by action listeners who are monitoring
this object.
It should be noted that both isAuthenticated() and
isAborting() will return false for the following
situations:
zeroed/reset/cleared.
authenticate()
method rejected the user's login ID/password.
authenticate() indicated it was OK.isAborting()public boolean isAborting()
cancel() method was invoked. If it returns true, it indicates
that the user wants to cancel the login process and the cancel() method allowed the cancellation. This means that the
user has NOT been authenticated.
isAuthenticated()protected boolean cancel()
If you want the option to reject a user from being able to cancel the login window (which I would not recommend), you can return false.
authenticate()public void actionPerformed(ActionEvent e)
authenticate() or cancel()
method (depending on what the user pressed). This in turn will
update internal flags indicating whether the object isAuthenticated() or isAborting().
ActionListeners notifying them
that the user has attempted/succeeded/canceled the login process.
actionPerformed in interface ActionListenere - Event which occurredauthenticate(),
cancel(),
addActionListener(java.awt.event.ActionListener)public String getLoginId()
public void setLoginId(String val)
val - Set the login ID to show in the panel (you can pass null, but
it will be changed to "").public String getPassword()
public void setPassword(String val)
val - Set the password to show in the panel (you can pass null, but
it will be changed to "").public int getLoginAttempts()
zeroed.public int getCancelAttempts()
zeroed.public void setProperties(TagLookup from)
resource bundle this example
demonstrates how to use this method to create a localizable login
panel.
The following properties are loaded into the object (they are all optional):
props - Where to look up setting for the object.
public boolean showDialog(Frame owner,
String title,
boolean modal)
LoginPanel class, this method is a
very simple way to pop-up a window to the user and wait until the
user enters a valid login/password combination (as determined by
your implementation of authenticate()) or the user gives
up and cancels attempting to login.
Refer to the LoginDemo.java example program which demonstrates how to use this method.
Don't forget that this method doesn't return until the user enters a vaild login/password, or gives up and presses the "Cancel" button (or the window manager's close action for the window is invoked).
owner - The parent Frame to associate with the Login
dialog box.title - Title to set for the window frame used to present the login
panel with (may be null if you don't want to set a title).modal - Set to true (typical setting) to cause the method to wait
until the user enters a valid ID/password or gives up and
presses the "Cancel" button. Set to "false" if you don't want
to be blocked waiting for the user to login (you'll want to
monitor the state using addActionListener(java.awt.event.ActionListener) in this
case).
public void doSmartFocus()
login ID hasn't been set, then the
focus will be put on this field to allow the user to enter their
login ID first.
login ID has already been set,
then the focus wull be put on the password entry field (assuming
that the user probably won't need to edit their login ID).
It should be noted that you can not invoke this method until
the login panel is visible. Typically you will call this method
from the windowOpened(WindowEvent) method of a listener associated with
the Frame containing the LoginPanel.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||