2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * <code>JPasswordField</code> is a lightweight component that allows 0N/A * the editing of a single line of text where the view indicates 0N/A * something was typed, but does not show the original characters. 0N/A * You can find further information and examples in 0N/A * a section in <em>The Java Tutorial.</em> 0N/A * <code>JPasswordField</code> is intended 0N/A * to be source-compatible with <code>java.awt.TextField</code> 0N/A * used with <code>echoChar</code> set. It is provided separately 0N/A * to make it easier to safely change the UI for the 0N/A * <code>JTextField</code> without affecting password entries. 0N/A * <strong>NOTE:</strong> 0N/A * By default, JPasswordField disables input methods; otherwise, input 0N/A * characters could be visible while they were composed using input methods. 0N/A * If an application needs the input methods support, please use the 0N/A * inherited method, <code>enableInputMethods(true)</code>. 0N/A * <strong>Warning:</strong> Swing is not thread safe. For more 0N/A * information see <a 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * attribute: isContainer false 0N/A * description: Allows the editing of a line of text but doesn't show the characters. 0N/A * @author Timothy Prinzing 0N/A * Constructs a new <code>JPasswordField</code>, 0N/A * with a default document, <code>null</code> starting 0N/A * text string, and 0 column width. 0N/A * Constructs a new <code>JPasswordField</code> initialized 0N/A * with the specified text. The document model is set to the 0N/A * default, and the number of columns to 0. 0N/A * @param text the text to be displayed, <code>null</code> if none 0N/A * Constructs a new empty <code>JPasswordField</code> with the specified 0N/A * number of columns. A default model is created, and the initial string 0N/A * is set to <code>null</code>. 0N/A * @param columns the number of columns >= 0 0N/A * Constructs a new <code>JPasswordField</code> initialized with 0N/A * the specified text and columns. The document model is set to 0N/A * @param text the text to be displayed, <code>null</code> if none 0N/A * @param columns the number of columns >= 0 0N/A * Constructs a new <code>JPasswordField</code> that uses the 0N/A * given text storage model and the given number of columns. 0N/A * This is the constructor through which the other constructors feed. 0N/A * The echo character is set to '*', but may be changed by the current 0N/A * Look and Feel. If the document model is 0N/A * <code>null</code>, a default one will be created. 0N/A * @param doc the text storage to use 0N/A * @param txt the text to be displayed, <code>null</code> if none 0N/A * @param columns the number of columns to use to calculate 0N/A * the preferred width >= 0; if columns is set to zero, the 0N/A * preferred width will be whatever naturally results from 0N/A * the component implementation 0N/A // We could either leave this on, which wouldn't be secure, 0N/A // or obscure the composted text, which essentially makes displaying 0N/A // it useless. Therefore, we turn off input methods. 0N/A * Returns the name of the L&F class that renders this component. 0N/A * @return the string "PasswordFieldUI" 0N/A * @see JComponent#getUIClassID 0N/A * @see UIDefaults#getUI 0N/A * Returns the character to be used for echoing. The default is '*'. 0N/A * The default may be different depending on the currently running Look 0N/A * and Feel. For example, Metal/Ocean's default is a bullet character. 0N/A * @return the echo character, 0 if unset 0N/A * @see #echoCharIsSet 0N/A * Sets the echo character for this <code>JPasswordField</code>. 0N/A * Note that this is largely a suggestion, since the 0N/A * view that gets installed can use whatever graphic techniques 0N/A * it desires to represent the field. Setting a value of 0 indicates 0N/A * that you wish to see the text as it is typed, similar to 0N/A * the behavior of a standard <code>JTextField</code>. 0N/A * @param c the echo character to display 0N/A * @see #echoCharIsSet 0N/A * description: character to display in place of the real characters 0N/A * attribute: visualUpdate true 0N/A * Returns true if this <code>JPasswordField</code> has a character 0N/A * set for echoing. A character is considered to be set if the echo 0N/A * character is not 0. 0N/A * @return true if a character is set for echoing 0N/A // --- JTextComponent methods ---------------------------------- 0N/A * Invokes <code>provideErrorFeedback</code> on the current 0N/A * look and feel, which typically initiates an error beep. 0N/A * The normal behavior of transferring the 0N/A * currently selected range in the associated text model 0N/A * to the system clipboard, and removing the contents from 0N/A * the model, is not acceptable for a password field. 0N/A * Invokes <code>provideErrorFeedback</code> on the current 0N/A * look and feel, which typically initiates an error beep. 0N/A * The normal behavior of transferring the 0N/A * currently selected range in the associated text model 0N/A * to the system clipboard, and leaving the contents from 0N/A * the model, is not acceptable for a password field. 0N/A * Returns the text contained in this <code>TextComponent</code>. 0N/A * If the underlying document is <code>null</code>, will give a 0N/A * <code>NullPointerException</code>. 0N/A * For security reasons, this method is deprecated. Use the 0N/A <code>* getPassword</code> method instead. 0N/A * @deprecated As of Java 2 platform v1.2, 0N/A * replaced by <code>getPassword</code>. 0N/A * Fetches a portion of the text represented by the 0N/A * component. Returns an empty string if length is 0. 0N/A * For security reasons, this method is deprecated. Use the 0N/A * <code>getPassword</code> method instead. 0N/A * @deprecated As of Java 2 platform v1.2, 0N/A * replaced by <code>getPassword</code>. 0N/A * @param offs the offset >= 0 0N/A * @param len the length >= 0 0N/A * @exception BadLocationException if the offset or length are invalid 0N/A * Returns the text contained in this <code>TextComponent</code>. 0N/A * If the underlying document is <code>null</code>, will give a 0N/A * <code>NullPointerException</code>. For stronger 0N/A * security, it is recommended that the returned character array be 0N/A * cleared after use by setting each character to zero. 0N/A * See readObject() and writeObject() in JComponent for more 0N/A * information about serialization in Swing. 0N/A // --- variables ----------------------------------------------- 0N/A * @see #getUIClassID 0N/A * Returns a string representation of this <code>JPasswordField</code>. 0N/A * This method is intended to be used only for debugging purposes, and the 0N/A * content and format of the returned string may vary between 0N/A * implementations. The returned string may be empty but may not 0N/A * be <code>null</code>. 0N/A * @return a string representation of this <code>JPasswordField</code> 0N/A * This method is a hack to get around the fact that we cannot 0N/A * directly override setUIProperty because part of the inheritance heirarchy 0N/A * goes outside of the javax.swing package, and therefore calling a package 0N/A * private method isn't allowed. This method should return true if the property 0N/A * was handled, and false otherwise. 0N/A// Accessibility support 0N/A * Returns the <code>AccessibleContext</code> associated with this 0N/A * <code>JPasswordField</code>. For password fields, the 0N/A * <code>AccessibleContext</code> takes the form of an 0N/A * <code>AccessibleJPasswordField</code>. 0N/A * A new <code>AccessibleJPasswordField</code> instance is created 0N/A * @return an <code>AccessibleJPasswordField</code> that serves as the 0N/A * <code>AccessibleContext</code> of this 0N/A * <code>JPasswordField</code> 0N/A * This class implements accessibility support for the 0N/A * <code>JPasswordField</code> class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to password field user-interface 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * Gets the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * object (AccessibleRole.PASSWORD_TEXT) 0N/A * @see AccessibleRole 0N/A * Gets the <code>AccessibleText</code> for the <code>JPasswordField</code>. 0N/A * The returned object also implements the 0N/A * <code>AccessibleExtendedText</code> interface. 0N/A * @return <code>AccessibleText</code> for the JPasswordField 0N/A * @see javax.accessibility.AccessibleContext 0N/A * @see javax.accessibility.AccessibleContext#getAccessibleText 0N/A * @see javax.accessibility.AccessibleText 0N/A * @see javax.accessibility.AccessibleExtendedText 0N/A * Returns a String filled with password echo characters. The String 0N/A * contains one echo character for each character (including whitespace) 0N/A * that the user entered in the JPasswordField. 0N/A * Returns the <code>String</code> at a given <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code> or 0N/A * <code>SENTENCE</code> to retrieve 0N/A * @param index an index within the text 0N/A * @return a <code>String</code> if <code>part</code> and 0N/A * <code>index</code> are valid. 0N/A * Otherwise, <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A // Treat the text displayed in the JPasswordField 0N/A // as one word and sentence. 0N/A * Returns the <code>String</code> after a given <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code> or 0N/A * <code>SENTENCE</code> to retrieve 0N/A * @param index an index within the text 0N/A * @return a <code>String</code> if <code>part</code> and 0N/A * <code>index</code> are valid. 0N/A * Otherwise, <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A // There is no word or sentence after the text 0N/A // displayed in the JPasswordField. 0N/A * Returns the <code>String</code> before a given <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code> or 0N/A * <code>SENTENCE</code> to retrieve 0N/A * @param index an index within the text 0N/A * @return a <code>String</code> if <code>part</code> and 0N/A * <code>index</code> are valid. 0N/A * Otherwise, <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A // There is no word or sentence before the text 0N/A // displayed in the JPasswordField. 0N/A * Returns the text between two <code>indices</code>. 0N/A * @param startIndex the start index in the text 0N/A * @param endIndex the end index in the text 0N/A * @return the text string if the indices are valid. 0N/A * Otherwise, <code>null</code> is returned 0N/A * Returns the <code>AccessibleTextSequence</code> at a given 0N/A * <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or <code>ATTRIBUTE_RUN</code> to 0N/A * @param index an index within the text 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text if 0N/A * <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A // Treat the text displayed in the JPasswordField 0N/A // as one word, sentence, line and attribute run 0N/A * Returns the <code>AccessibleTextSequence</code> after a given 0N/A * <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or <code>ATTRIBUTE_RUN</code> to 0N/A * @param index an index within the text 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text if 0N/A * <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A // There is no word, sentence, line or attribute run 0N/A // after the text displayed in the JPasswordField. 0N/A * Returns the <code>AccessibleTextSequence</code> before a given 0N/A * <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or <code>ATTRIBUTE_RUN</code> to 0N/A * @param index an index within the text 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text if 0N/A * <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A // There is no word, sentence, line or attribute run 0N/A // before the text displayed in the JPasswordField.