home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
jfc.bin
/
JPasswordField.java
< prev
next >
Wrap
Text File
|
1998-02-26
|
6KB
|
201 lines
/*
* @(#)JPasswordField.java 1.18 98/02/12
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package com.sun.java.swing;
import com.sun.java.swing.text.*;
import com.sun.java.swing.plaf.*;
import com.sun.java.accessibility.*;
/**
* JTextField is a lightweight component that allows the editing
* of a single line of text where the view indicates something was
* typed, but does not show the original characters. It is intended
* to be source-compatible with java.awt.TextField used with echoChar
* set. It is provided seperately to make it easier to safely change
* the ui for the JTextField without affecting password entries.
* <p>
* Warning: serialized objects of this class will not be compatible with
* future swing releases. The current serialization support is appropriate
* for short term storage or RMI between Swing1.0 applications. It will
* not be possible to load serialized Swing1.0 objects with future releases
* of Swing. The JDK1.2 release of Swing will be the compatibility
* baseline for the serialized form of Swing objects.
*
* @beaninfo
* attribute: isContainer false
*
* @author Timothy Prinzing
* @version 1.18, 02/12/98
*/
public class JPasswordField extends JTextField {
/**
* Constructs a new JPasswordField.
*/
public JPasswordField() {
this(null,null,0);
}
/**
* Constructs a new JPasswordField initialized with the specified text.
*
* @param text the text to be displayed
*/
public JPasswordField(String text) {
this(null, text, 0);
}
/**
* Constructs a new empty JPasswordField with the specified
* number of columns.
*
* @param columns the number of columns
*/
public JPasswordField(int columns) {
this(null, null, columns);
}
/**
* Constructs a new JPasswordField initialized with the specified text
* and columns.
*
* @param text the text to be displayed
* @param columns the number of columns
*/
public JPasswordField(String text, int columns) {
this(null, text, columns);
}
/**
* Constructs a new JPasswordField that uses the given text storage
* model and the given number of columns. This is the constructor
* through which the other constructors feed.
*
* @param doc the text storage to use
* @param txt the text to be displayed
* @param columns the number of columns to use to calculate
* the preferred width. If columns is set to zero, the
* preferred width will be whatever naturally results from
* the component implementation.
*/
public JPasswordField(Document doc, String txt, int columns) {
super(doc, txt, columns);
setName(base + nameCounter++);
echoChar = '*';
}
/**
* Returns the name of the L&F class that renders this component.
*
* @return "PasswordFieldUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
public String getUIClassID() {
return "PasswordFieldUI";
}
/**
* Returns the character to be used for echoing.
*
* @return the echo character
* @see #setEchoChar
* @see #echoCharIsSet
*/
public char getEchoChar() {
return echoChar;
}
/**
* Sets the echo character for this JPasswordField. Note
* that this is largely a suggestion to the view as the
* view that gets installed can use whatever graphic techniques
* it desires to represent the field.
*
* @param c the echo character to display
* @see #echoCharIsSet
* @see #getEchoChar
* @beaninfo
* description: character to display in place of the real characters
*/
public void setEchoChar(char c) {
echoChar = c;
}
/**
* Returns true if this JPasswordField has a character set for
* echoing.
*
* @return true if a character is set for echoing
* @see #setEchoChar
* @see #getEchoChar
*/
public boolean echoCharIsSet() {
return echoChar != 0;
}
private char echoChar;
private static final String base = "password";
private static int nameCounter = 0;
/////////////////
// Accessibility support
////////////////
/**
* Get the AccessibleContext associated with this JPasswordField
*
* @return the AccessibleContext of this JPasswordField
*/
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJPasswordField();
}
return accessibleContext;
}
/**
* The class used to obtain the accessible role for this object.
* <p>
* Warning: serialized objects of this class will not be compatible with
* future swing releases. The current serialization support is appropriate
* for short term storage or RMI between Swing1.0 applications. It will
* not be possible to load serialized Swing1.0 objects with future releases
* of Swing. The JDK1.2 release of Swing will be the compatibility
* baseline for the serialized form of Swing objects.
*/
protected class AccessibleJPasswordField extends AccessibleJTextField {
/**
* Gets the role of this object.
*
* @return an instance of AccessibleRole describing the role of the
* object
* @see AccessibleRole
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.PASSWORD_TEXT;
}
}
}