com.ptc.wgmecad
Class PasswordDialog

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Dialog
                  extended byjavax.swing.JDialog
                      extended bycom.ptc.wgmecad.PasswordDialog
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants

public class PasswordDialog
extends JDialog

A modal dialog that asks the user for a user name and password. More information about this class is available from ostermiller.org.

 PasswordDialog p = new PasswordDialog(null, "Test");
 if(p.showDialog()){
     logger.debug("Name: " + p.getAssemblyName());
     logger.debug("Pass: " + p.getPass());
 } else {
     logger.debug("User selected cancel");
 }
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JDialog
JDialog.AccessibleJDialog
 
Nested classes inherited from class java.awt.Dialog
Dialog.AccessibleAWTDialog
 
Nested classes inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JButton cancelButton
          The cancel button.
(package private) static org.apache.log4j.Logger logger
           
protected  JTextField name
          Where the name is typed.
protected  JLabel nameLabel
          The label for the field in which the name is typed.
protected  JButton okButton
          The OK button.
protected  JPasswordField pass
          Where the password is typed.
protected  JLabel passLabel
          The label for the field in which the password is typed.
private  boolean pressed_OK
          update this variable when the user makes an action
 
Fields inherited from class javax.swing.JDialog
accessibleContext, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Dialog
 
Fields inherited from class java.awt.Window
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PasswordDialog(Frame owner)
           
PasswordDialog(JFrame parent, String title)
          Create this dialog with the given parent and title.
 
Method Summary
protected  void dialogInit()
          Called by constructors to initialize the dialog.
 String getName()
          Get the name that was entered into the dialog before the dialog was closed.
 String getPass()
          Get the password that was entered into the dialog before the dialog was closed.
static void main(String[] args)
          A simple example to show how this might be used.
 boolean okPressed()
          Finds out if user used the OK button or an equivalent action to close the dialog.
private static void resetContstraints(GridBagConstraints con, int gridx, int gridy, int anchor)
           
 void setCancelText(String cancel)
          Set the label on the cancel button.
 void setName(String name)
          Set the name that appears as the default An empty string will be used if this in not specified before the dialog is displayed.
 void setNameLabel(String name)
          Set the label for the field in which the name is entered.
 void setOKText(String ok)
          Set the label on the OK button.
 void setPass(String pass)
          Set the password that appears as the default An empty string will be used if this in not specified before the dialog is displayed.
 void setPassLabel(String pass)
          Set the label for the field in which the password is entered.
 boolean showDialog()
          Shows the dialog and returns true if the user pressed ok.
 
Methods inherited from class javax.swing.JDialog
addImpl, createRootPane, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Dialog
addNotify, dispose, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, finalize, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger

name

protected JTextField name
Where the name is typed.


pass

protected JPasswordField pass
Where the password is typed.


okButton

protected JButton okButton
The OK button.


cancelButton

protected JButton cancelButton
The cancel button.


nameLabel

protected JLabel nameLabel
The label for the field in which the name is typed.


passLabel

protected JLabel passLabel
The label for the field in which the password is typed.


pressed_OK

private boolean pressed_OK
update this variable when the user makes an action

Constructor Detail

PasswordDialog

public PasswordDialog(Frame owner)

PasswordDialog

public PasswordDialog(JFrame parent,
                      String title)
Create this dialog with the given parent and title.

Parameters:
parent - window from which this dialog is launched
title - the title for the dialog box window
Method Detail

setName

public void setName(String name)
Set the name that appears as the default An empty string will be used if this in not specified before the dialog is displayed.

Parameters:
name - default name to be displayed.

setPass

public void setPass(String pass)
Set the password that appears as the default An empty string will be used if this in not specified before the dialog is displayed.

Parameters:
pass - default password to be displayed.

setOKText

public void setOKText(String ok)
Set the label on the OK button. The default is a localized string.

Parameters:
ok - label for the ok button.

setCancelText

public void setCancelText(String cancel)
Set the label on the cancel button. The default is a localized string.

Parameters:
cancel - label for the cancel button.

setNameLabel

public void setNameLabel(String name)
Set the label for the field in which the name is entered. The default is a localized string.

Parameters:
name - label for the name field.

setPassLabel

public void setPassLabel(String pass)
Set the label for the field in which the password is entered. The default is a localized string.

Parameters:
pass - label for the password field.

getName

public String getName()
Get the name that was entered into the dialog before the dialog was closed.

Returns:
the name from the name field.

getPass

public String getPass()
Get the password that was entered into the dialog before the dialog was closed.

Returns:
the password from the password field.

okPressed

public boolean okPressed()
Finds out if user used the OK button or an equivalent action to close the dialog. Pressing enter in the password field may be the same as 'OK' but closing the dialog and pressing the cancel button are not.

Returns:
true if the the user hit OK, false if the user canceled.

dialogInit

protected void dialogInit()
Called by constructors to initialize the dialog.


resetContstraints

private static void resetContstraints(GridBagConstraints con,
                                      int gridx,
                                      int gridy,
                                      int anchor)

showDialog

public boolean showDialog()
Shows the dialog and returns true if the user pressed ok.

Returns:
true if the the user hit OK, false if the user canceled.

main

public static void main(String[] args)
A simple example to show how this might be used. If there are arguments passed to this program, the first is treated as the default name, the second as the default password

Parameters:
args - command line arguments: name and password (optional)