public class JXLoginPane extends JXPanel
JXLoginPane is a specialized JPanel that implements a Login dialog with support for saving passwords supplied for future use in a secure manner. LoginService is invoked to perform authentication and optional PasswordStore can be provided to store the user login information.
In order to perform the authentication, JXLoginPane
calls the authenticate
method of the LoginService
. In order to perform the persistence of the password,
JXLoginPane calls the put method of the
PasswordStore object that is supplied. If
the PasswordStore is null
, then the password
is not saved. Similarly, if a PasswordStore is
supplied and the password is null, then the PasswordStore
will be queried for the password using the get
method.
Example:
final JXLoginPane panel = new JXLoginPane(new LoginService() {
public boolean authenticate(String name, char[] password,
String server) throws Exception {
// perform authentication and return true on success.
return false;
}});
final JFrame frame = JXLoginPane.showLoginFrame(panel);
Modifier and Type | Class and Description |
---|---|
private static class |
JXLoginPane.CancelAction
Action that cancels the login procedure.
|
private class |
JXLoginPane.ComboNamePanel
If a UserNameStore is used, then this combo box is presented allowing the user
to select a previous login name, or type in a new login name
|
private static class |
JXLoginPane.JXBtnPanel |
static class |
JXLoginPane.JXLoginDialog |
static class |
JXLoginPane.JXLoginFrame |
private static class |
JXLoginPane.LoginAction
Action that initiates a login procedure.
|
protected class |
JXLoginPane.LoginListenerImpl
Listener class to track state in the LoginService
|
private class |
JXLoginPane.LoginPaneLayout |
private static interface |
JXLoginPane.NameComponent |
private static class |
JXLoginPane.NullLoginService
Simple login service that allows everybody to login.
|
private static class |
JXLoginPane.NullPasswordStore
Simple PasswordStore that does not remember passwords
|
static class |
JXLoginPane.SaveMode
The JXLoginPane can attempt to save certain user information such as
the username, password, or both to their respective stores.
|
private class |
JXLoginPane.SimpleNamePanel
If a UserNameStore is not used, then this text field is presented allowing the user
to simply enter their user name
|
static class |
JXLoginPane.Status
Returns the status of the login process
|
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private JXImagePanel |
banner
An optional banner at the top of the panel
|
private String |
bannerText
Text that should appear on the banner
|
private JXLoginPane.JXBtnPanel |
buttonPanel
Login/cancel control pane;
|
static String |
CANCEL_LOGIN_ACTION_COMMAND
Action key for an Action in the ActionMap that cancels the Login
procedure
|
private JLabel |
capsOn
Label displayed whenever caps lock is on.
|
private static String |
CLASS_NAME
Used as a prefix when pulling data out of UIManager for i18n
|
private JPanel |
contentCardPane
Card pane holding user/pwd fields view and the progress view.
|
private JXPanel |
contentPanel
The panel on which the input fields, messageLabel, and errorMessageLabel
are placed.
|
private LoginListener |
defaultLoginListener
The default login listener used by this panel.
|
private JXLabel |
errorMessageLabel
Shows an error message such as "user name or password incorrect" or
"could not contact server" or something like that if something
goes wrong
|
private boolean |
isErrorMessageSet |
private static Logger |
LOG
The Logger
|
static String |
LOGIN_ACTION_COMMAND
Action key for an Action in the ActionMap that initiates the Login
procedure
|
private JXPanel |
loginPanel
A Panel containing all of the input fields, check boxes, etc necessary
for the user to do their job.
|
private LoginService |
loginService
The LoginService to use.
|
private JLabel |
messageLabel
Custom label allowing the developer to display some message to the user
|
private JXLoginPane.NameComponent |
namePanel
This is the area in which the name field is placed.
|
private boolean |
namePanelEnabled |
private Cursor |
oldCursor
Tracks the cursor at the time that authentication was started, and restores to that
cursor after authentication ends, or is canceled;
|
private JPasswordField |
passwordField
The password field presented allowing the user to enter their password
|
private PasswordStore |
passwordStore
Optional: a PasswordStore to use for storing and retrieving passwords for a specific
user.
|
private JLabel |
progressMessageLabel
A JLabel on the progressPanel that is used for informing the user
of the status of the login procedure (logging in..., canceling login...)
|
private JXPanel |
progressPanel
A special panel that displays a progress bar and cancel button, and
which notify the user of the login process, and allow them to cancel
that process.
|
private JCheckBox |
saveCB
Check box presented if a PasswordStore is used, allowing the user to decide whether to
save their password
|
private JXLoginPane.SaveMode |
saveMode
Whether to save password or username or both.
|
private static long |
serialVersionUID
Comment for
serialVersionUID |
private JComboBox |
serverCombo
A combo box presenting the user with a list of servers to which they
may log in.
|
private List<String> |
servers
A list of servers where each server is represented by a String.
|
private JXLoginPane.Status |
status
The current login status for this panel
|
static String |
uiClassID
UI Class ID
|
private UserNameStore |
userNameStore
Optional: a UserNameStore to use for storing user names and retrieving them
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXLoginPane()
Create a
JXLoginPane that always accepts the user, never stores
passwords or user ids, and has no target servers. |
JXLoginPane(LoginService service)
Create a
JXLoginPane with the specified LoginService
that does not store user ids or passwords and has no target servers. |
JXLoginPane(LoginService service,
PasswordStore passwordStore,
UserNameStore userStore)
Create a
JXLoginPane with the specified LoginService ,
PasswordStore , and UserNameStore , but without a server
list. |
JXLoginPane(LoginService service,
PasswordStore passwordStore,
UserNameStore userStore,
List<String> servers)
Create a
JXLoginPane with the specified LoginService ,
PasswordStore , UserNameStore , and server list. |
Modifier and Type | Method and Description |
---|---|
protected void |
cancelLogin()
Cancels the login procedure.
|
protected Action |
createCancelAction()
Create and return an Action for canceling login
|
protected Action |
createLoginAction()
Create and return an Action for logging in
|
protected Image |
createLoginBanner()
Create and return an image to use for the Banner.
|
private JXPanel |
createLoginPanel()
Creates and returns a new LoginPanel, based on the SaveMode state of
the login panel.
|
Image |
getBanner()
Return the image used as the banner
|
String |
getBannerText()
Returns text used when creating the banner
|
private LoginListener |
getDefaultLoginListener() |
String |
getErrorMessage()
Returns the error message for this login panel
|
LoginService |
getLoginService()
Gets the LoginService for this panel.
|
String |
getMessage()
Returns the custom message for this login panel
|
char[] |
getPassword()
Gets the Password for this panel.
|
PasswordStore |
getPasswordStore()
Gets the PasswordStore for this panel.
|
JXLoginPane.SaveMode |
getSaveMode() |
List<String> |
getServers() |
JXLoginPane.Status |
getStatus()
Returns the panel's status
|
LoginPaneUI |
getUI() |
String |
getUIClassID()
Returns the name of the L&F class that renders this component.
|
String |
getUserName()
Gets the User name for this panel.
|
UserNameStore |
getUserNameStore()
Gets the
UserNameStore for this panel. |
private void |
initComponents()
Create all of the UI components for the login panel
|
(package private) static void |
initWindow(Window w,
JXLoginPane panel)
Utility method for initializing a Window for displaying a LoginDialog.
|
boolean |
isCapsLockOn()
Gets current state of the caps lock as seen by the login panel.
|
boolean |
isRememberPassword() |
boolean |
isUserNameEnabled()
Gets current state of the user name field.
|
protected void |
recreateLoginPanel()
Recreates the login panel, and replaces the current one with the new one
|
private void |
reinitLocales(Locale l)
Populates UIDefaults with the localizable Strings we will use
in the Login panel.
|
protected void |
savePassword()
Puts the password into the password store.
|
void |
setBanner(Image img)
Set the image to use for the banner.
|
void |
setBannerText(String text)
Set the text to use when creating the banner.
|
private void |
setButtonPanel(JXLoginPane.JXBtnPanel buttonPanel) |
void |
setComponentOrientation(ComponentOrientation orient)
This method adds functionality to support bidi languages within this
component
|
void |
setErrorMessage(String errorMessage)
Sets the error message for this login panel
|
void |
setLocale(Locale l) |
void |
setLoginService(LoginService service)
Sets the
LoginService for this panel. |
void |
setMessage(String message)
Sets a custom message for this login panel
|
void |
setPassword(char[] password)
Sets the Password for this panel.
|
void |
setPasswordStore(PasswordStore store)
Sets the PasswordStore for this panel.
|
void |
setSaveMode(JXLoginPane.SaveMode saveMode)
The save mode indicates whether the "save" password is checked by default.
|
void |
setServers(List<String> servers)
Sets the list of servers.
|
protected void |
setStatus(JXLoginPane.Status newStatus)
Change the status
|
void |
setUI(LoginPaneUI ui)
Sets the look and feel (L&F) object that renders this component.
|
void |
setUserName(String username)
Sets the User name for this panel.
|
void |
setUserNameEnabled(boolean enabled)
Enables or disables User name for this panel.
|
void |
setUserNameStore(UserNameStore store)
Sets the user name store for this panel.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
JXLoginPane panel)
Shows a login dialog.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
LoginService svc)
Shows a login dialog.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
LoginService svc,
PasswordStore ps,
UserNameStore us)
Shows a login dialog.
|
static JXLoginPane.Status |
showLoginDialog(Component parent,
LoginService svc,
PasswordStore ps,
UserNameStore us,
List<String> servers)
Shows a login dialog.
|
static JXLoginPane.JXLoginFrame |
showLoginFrame(JXLoginPane panel) |
static JXLoginPane.JXLoginFrame |
showLoginFrame(LoginService svc)
Shows a login frame.
|
static JXLoginPane.JXLoginFrame |
showLoginFrame(LoginService svc,
PasswordStore ps,
UserNameStore us) |
static JXLoginPane.JXLoginFrame |
showLoginFrame(LoginService svc,
PasswordStore ps,
UserNameStore us,
List<String> servers) |
protected void |
startLogin()
Initiates the login procedure.
|
private void |
updatePassword(String username) |
void |
updateUI()
Notification from the
UIManager that the L&F has changed. |
getAlpha, getBackgroundPainter, getEffectiveAlpha, getPainterChangeListener, getPreferredScrollableViewportSize, getScrollableBlockIncrement, getScrollableHeightHint, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollableWidthHint, installRepaintManager, isInheritAlpha, isPaintBorderInsets, paint, paintComponent, setAlpha, setBackground, setBackgroundPainter, setInheritAlpha, setPaintBorderInsets, setScrollableHeightHint, setScrollableTracksViewportHeight, setScrollableTracksViewportWidth, setScrollableWidthHint, uninstallRepaintManager
getAccessibleContext, paramString, setUI
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final long serialVersionUID
serialVersionUID
public static final String uiClassID
public static final String LOGIN_ACTION_COMMAND
public static final String CANCEL_LOGIN_ACTION_COMMAND
private static String CLASS_NAME
private JXLoginPane.Status status
private JXImagePanel banner
private String bannerText
private JLabel messageLabel
private JXLabel errorMessageLabel
private JXPanel loginPanel
private JXPanel contentPanel
private JXLoginPane.NameComponent namePanel
private JPasswordField passwordField
private JComboBox serverCombo
private JCheckBox saveCB
private JXPanel progressPanel
private JLabel progressMessageLabel
private LoginService loginService
private PasswordStore passwordStore
private UserNameStore userNameStore
private List<String> servers
private JXLoginPane.SaveMode saveMode
private Cursor oldCursor
private boolean namePanelEnabled
private LoginListener defaultLoginListener
private JXLoginPane.JXBtnPanel buttonPanel
private JPanel contentCardPane
private boolean isErrorMessageSet
public JXLoginPane()
JXLoginPane
that always accepts the user, never stores
passwords or user ids, and has no target servers.
This constructor should NOT be used in a real application. It is provided for compliance to the bean specification and for use with visual editors.
public JXLoginPane(LoginService service)
JXLoginPane
with the specified LoginService
that does not store user ids or passwords and has no target servers.service
- the LoginService
to use for logging inpublic JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore)
JXLoginPane
with the specified LoginService
,
PasswordStore
, and UserNameStore
, but without a server
list.
If you do not want to store passwords or user ids, those parameters can
be null
. SaveMode
is autoconfigured from passed in store
parameters.
service
- the LoginService
to use for logging inpasswordStore
- the PasswordStore
to use for storing password
informationuserStore
- the UserNameStore
to use for storing user informationpublic JXLoginPane(LoginService service, PasswordStore passwordStore, UserNameStore userStore, List<String> servers)
JXLoginPane
with the specified LoginService
,
PasswordStore
, UserNameStore
, and server list.
If you do not want to store passwords or user ids, those parameters can
be null
. SaveMode
is autoconfigured from passed in store
parameters.
Setting the server list to null
will unset all of the servers.
The server list is guaranteed to be non-null
.
service
- the LoginService
to use for logging inpasswordStore
- the PasswordStore
to use for storing password
informationuserStore
- the UserNameStore
to use for storing user informationservers
- a list of servers to authenticate againstprivate void reinitLocales(Locale l)
public boolean isCapsLockOn()
isCapsLockDetectionSupported()
returns false.public LoginPaneUI getUI()
public void setUI(LoginPaneUI ui)
ui
- the LoginPaneUI L&F objectUIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
UIManager
that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager
.updateUI
in class JPanel
JComponent.updateUI()
public String getUIClassID()
getUIClassID
in class JPanel
uiClassID
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
protected void recreateLoginPanel()
private JXPanel createLoginPanel()
public void setComponentOrientation(ComponentOrientation orient)
setComponentOrientation
in class Component
private void initComponents()
protected Image createLoginBanner()
protected Action createLoginAction()
protected Action createCancelAction()
public JXLoginPane.SaveMode getSaveMode()
public void setSaveMode(JXLoginPane.SaveMode saveMode)
saveMode
- The saveMode to set either SAVE_NONE, SAVE_PASSWORD or SAVE_USERNAMEpublic boolean isRememberPassword()
public List<String> getServers()
public void setServers(List<String> servers)
private LoginListener getDefaultLoginListener()
public void setLoginService(LoginService service)
LoginService
for this panel. Setting the login service
to null
will actually set the service to use
NullLoginService
.service
- the service to set. If service == null
, then a
NullLoginService
is used.public LoginService getLoginService()
public void setPasswordStore(PasswordStore store)
store
- PasswordStorepublic UserNameStore getUserNameStore()
UserNameStore
for this panel.UserNameStore
public void setUserNameStore(UserNameStore store)
store
- public PasswordStore getPasswordStore()
public void setUserName(String username)
username
- User namepublic void setUserNameEnabled(boolean enabled)
enabled
- public boolean isUserNameEnabled()
public String getUserName()
public void setPassword(char[] password)
password
- Passwordpublic char[] getPassword()
public void setBanner(Image img)
img
is null
,
then no image will be displayed.img
- the image to displaypublic void setBannerText(String text)
text
is null
, then
no text is displayed.text
- the text to displaypublic String getBannerText()
public String getMessage()
public void setMessage(String message)
public String getErrorMessage()
public void setErrorMessage(String errorMessage)
public JXLoginPane.Status getStatus()
protected void setStatus(JXLoginPane.Status newStatus)
protected void startLogin()
getSynchronous()
returns true.protected void cancelLogin()
startAuthentications()
and only when
authentication is performed asynchronously (getSynchronous()
returns false).protected void savePassword()
private void updatePassword(String username)
public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc)
public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us)
public static JXLoginPane.Status showLoginDialog(Component parent, LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers)
public static JXLoginPane.Status showLoginDialog(Component parent, JXLoginPane panel)
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc)
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us)
public static JXLoginPane.JXLoginFrame showLoginFrame(LoginService svc, PasswordStore ps, UserNameStore us, List<String> servers)
public static JXLoginPane.JXLoginFrame showLoginFrame(JXLoginPane panel)
static void initWindow(Window w, JXLoginPane panel)
private void setButtonPanel(JXLoginPane.JXBtnPanel buttonPanel)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses