0N/A/*
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 *
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 *
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 *
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.
0N/A *
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
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport javax.swing.text.*;
0N/Aimport javax.swing.plaf.*;
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.io.*;
0N/Aimport java.util.Arrays;
0N/A
0N/A/**
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 href="http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html">How to Use Text Fields</a>,
0N/A * a section in <em>The Java Tutorial.</em>
0N/A * <p>
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 * <p>
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 * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
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 * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @beaninfo
0N/A * attribute: isContainer false
0N/A * description: Allows the editing of a line of text but doesn't show the characters.
0N/A *
0N/A * @author Timothy Prinzing
0N/A */
0N/Apublic class JPasswordField extends JTextField {
0N/A
0N/A /**
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 */
0N/A public JPasswordField() {
0N/A this(null,null,0);
0N/A }
0N/A
0N/A /**
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 *
0N/A * @param text the text to be displayed, <code>null</code> if none
0N/A */
0N/A public JPasswordField(String text) {
0N/A this(null, text, 0);
0N/A }
0N/A
0N/A /**
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 *
0N/A * @param columns the number of columns >= 0
0N/A */
0N/A public JPasswordField(int columns) {
0N/A this(null, null, columns);
0N/A }
0N/A
0N/A /**
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 * the default.
0N/A *
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 */
0N/A public JPasswordField(String text, int columns) {
0N/A this(null, text, columns);
0N/A }
0N/A
0N/A /**
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 *
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 */
0N/A public JPasswordField(Document doc, String txt, int columns) {
0N/A super(doc, txt, columns);
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 enableInputMethods(false);
0N/A }
0N/A
0N/A /**
0N/A * Returns the name of the L&F class that renders this component.
0N/A *
0N/A * @return the string "PasswordFieldUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.6
0N/A */
0N/A public void updateUI() {
0N/A if(!echoCharSet) {
0N/A echoChar = '*';
0N/A }
0N/A super.updateUI();
0N/A }
0N/A
0N/A /**
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 *
0N/A * @return the echo character, 0 if unset
0N/A * @see #setEchoChar
0N/A * @see #echoCharIsSet
0N/A */
0N/A public char getEchoChar() {
0N/A return echoChar;
0N/A }
0N/A
0N/A /**
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 *
0N/A * @param c the echo character to display
0N/A * @see #echoCharIsSet
0N/A * @see #getEchoChar
0N/A * @beaninfo
0N/A * description: character to display in place of the real characters
0N/A * attribute: visualUpdate true
0N/A */
0N/A public void setEchoChar(char c) {
0N/A echoChar = c;
0N/A echoCharSet = true;
0N/A repaint();
0N/A revalidate();
0N/A }
0N/A
0N/A /**
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 *
0N/A * @return true if a character is set for echoing
0N/A * @see #setEchoChar
0N/A * @see #getEchoChar
0N/A */
0N/A public boolean echoCharIsSet() {
0N/A return echoChar != 0;
0N/A }
0N/A
0N/A // --- JTextComponent methods ----------------------------------
0N/A
0N/A /**
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 */
0N/A public void cut() {
0N/A if (getClientProperty("JPasswordField.cutCopyAllowed") != Boolean.TRUE) {
0N/A UIManager.getLookAndFeel().provideErrorFeedback(this);
0N/A } else {
0N/A super.cut();
0N/A }
0N/A }
0N/A
0N/A /**
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 */
0N/A public void copy() {
0N/A if (getClientProperty("JPasswordField.cutCopyAllowed") != Boolean.TRUE) {
0N/A UIManager.getLookAndFeel().provideErrorFeedback(this);
0N/A } else {
0N/A super.copy();
0N/A }
0N/A }
0N/A
0N/A /**
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 * <p>
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 * @return the text
0N/A */
0N/A @Deprecated
0N/A public String getText() {
0N/A return super.getText();
0N/A }
0N/A
0N/A /**
0N/A * Fetches a portion of the text represented by the
0N/A * component. Returns an empty string if length is 0.
0N/A * <p>
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 * @return the text
0N/A * @exception BadLocationException if the offset or length are invalid
0N/A */
0N/A @Deprecated
0N/A public String getText(int offs, int len) throws BadLocationException {
0N/A return super.getText(offs, len);
0N/A }
0N/A
0N/A /**
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 *
0N/A * @return the text
0N/A */
0N/A public char[] getPassword() {
0N/A Document doc = getDocument();
0N/A Segment txt = new Segment();
0N/A try {
0N/A doc.getText(0, doc.getLength(), txt); // use the non-String API
0N/A } catch (BadLocationException e) {
0N/A return null;
0N/A }
0N/A char[] retValue = new char[txt.count];
0N/A System.arraycopy(txt.array, txt.offset, retValue, 0, txt.count);
0N/A return retValue;
0N/A }
0N/A
0N/A /**
0N/A * See readObject() and writeObject() in JComponent for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A s.defaultWriteObject();
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // --- variables -----------------------------------------------
0N/A
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "PasswordFieldUI";
0N/A
0N/A private char echoChar;
0N/A
0N/A private boolean echoCharSet = false;
0N/A
0N/A
0N/A /**
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 *
0N/A * @return a string representation of this <code>JPasswordField</code>
0N/A */
0N/A protected String paramString() {
0N/A return super.paramString() +
0N/A ",echoChar=" + echoChar;
0N/A }
0N/A
0N/A
0N/A /**
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 */
0N/A boolean customSetUIProperty(String propertyName, Object value) {
0N/A if (propertyName == "echoChar") {
0N/A if (!echoCharSet) {
0N/A setEchoChar((Character)value);
0N/A echoCharSet = false;
0N/A }
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A
0N/A /**
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 * if necessary.
0N/A *
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 */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJPasswordField();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
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 * elements.
0N/A * <p>
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 * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJPasswordField extends AccessibleJTextField {
0N/A
0N/A /**
0N/A * Gets the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object (AccessibleRole.PASSWORD_TEXT)
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.PASSWORD_TEXT;
0N/A }
0N/A
0N/A /**
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 *
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 *
0N/A * @since 1.6
0N/A */
0N/A public AccessibleText getAccessibleText() {
0N/A return this;
0N/A }
0N/A
0N/A /*
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 */
0N/A private String getEchoString(String str) {
0N/A if (str == null) {
0N/A return null;
0N/A }
0N/A char[] buffer = new char[str.length()];
0N/A Arrays.fill(buffer, getEchoChar());
0N/A return new String(buffer);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>String</code> at a given <code>index</code>.
0N/A *
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 *
0N/A * @see javax.accessibility.AccessibleText#CHARACTER
0N/A * @see javax.accessibility.AccessibleText#WORD
0N/A * @see javax.accessibility.AccessibleText#SENTENCE
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public String getAtIndex(int part, int index) {
0N/A String str = null;
0N/A if (part == AccessibleText.CHARACTER) {
0N/A str = super.getAtIndex(part, index);
0N/A } else {
0N/A // Treat the text displayed in the JPasswordField
0N/A // as one word and sentence.
0N/A char password[] = getPassword();
0N/A if (password == null ||
0N/A index < 0 || index >= password.length) {
0N/A return null;
0N/A }
0N/A str = new String(password);
0N/A }
0N/A return getEchoString(str);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>String</code> after a given <code>index</code>.
0N/A *
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 *
0N/A * @see javax.accessibility.AccessibleText#CHARACTER
0N/A * @see javax.accessibility.AccessibleText#WORD
0N/A * @see javax.accessibility.AccessibleText#SENTENCE
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public String getAfterIndex(int part, int index) {
0N/A if (part == AccessibleText.CHARACTER) {
0N/A String str = super.getAfterIndex(part, index);
0N/A return getEchoString(str);
0N/A } else {
0N/A // There is no word or sentence after the text
0N/A // displayed in the JPasswordField.
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>String</code> before a given <code>index</code>.
0N/A *
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 *
0N/A * @see javax.accessibility.AccessibleText#CHARACTER
0N/A * @see javax.accessibility.AccessibleText#WORD
0N/A * @see javax.accessibility.AccessibleText#SENTENCE
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public String getBeforeIndex(int part, int index) {
0N/A if (part == AccessibleText.CHARACTER) {
0N/A String str = super.getBeforeIndex(part, index);
0N/A return getEchoString(str);
0N/A } else {
0N/A // There is no word or sentence before the text
0N/A // displayed in the JPasswordField.
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the text between two <code>indices</code>.
0N/A *
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 *
0N/A * @since 1.6
0N/A */
0N/A public String getTextRange(int startIndex, int endIndex) {
0N/A String str = super.getTextRange(startIndex, endIndex);
0N/A return getEchoString(str);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the <code>AccessibleTextSequence</code> at a given
0N/A * <code>index</code>.
0N/A *
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 * retrieve
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 *
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 *
0N/A * @since 1.6
0N/A */
0N/A public AccessibleTextSequence getTextSequenceAt(int part, int index) {
0N/A if (part == AccessibleText.CHARACTER) {
0N/A AccessibleTextSequence seq = super.getTextSequenceAt(part, index);
0N/A if (seq == null) {
0N/A return null;
0N/A }
0N/A return new AccessibleTextSequence(seq.startIndex, seq.endIndex,
0N/A getEchoString(seq.text));
0N/A } else {
0N/A // Treat the text displayed in the JPasswordField
0N/A // as one word, sentence, line and attribute run
0N/A char password[] = getPassword();
0N/A if (password == null ||
0N/A index < 0 || index >= password.length) {
0N/A return null;
0N/A }
0N/A String text = new String(password);
0N/A return new AccessibleTextSequence(0, password.length - 1,
0N/A getEchoString(text));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>AccessibleTextSequence</code> after a given
0N/A * <code>index</code>.
0N/A *
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 * retrieve
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 *
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 *
0N/A * @since 1.6
0N/A */
0N/A public AccessibleTextSequence getTextSequenceAfter(int part, int index) {
0N/A if (part == AccessibleText.CHARACTER) {
0N/A AccessibleTextSequence seq = super.getTextSequenceAfter(part, index);
0N/A if (seq == null) {
0N/A return null;
0N/A }
0N/A return new AccessibleTextSequence(seq.startIndex, seq.endIndex,
0N/A getEchoString(seq.text));
0N/A } else {
0N/A // There is no word, sentence, line or attribute run
0N/A // after the text displayed in the JPasswordField.
0N/A return null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>AccessibleTextSequence</code> before a given
0N/A * <code>index</code>.
0N/A *
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 * retrieve
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 *
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 *
0N/A * @since 1.6
0N/A */
0N/A public AccessibleTextSequence getTextSequenceBefore(int part, int index) {
0N/A if (part == AccessibleText.CHARACTER) {
0N/A AccessibleTextSequence seq = super.getTextSequenceBefore(part, index);
0N/A if (seq == null) {
0N/A return null;
0N/A }
0N/A return new AccessibleTextSequence(seq.startIndex, seq.endIndex,
0N/A getEchoString(seq.text));
0N/A } else {
0N/A // There is no word, sentence, line or attribute run
0N/A // before the text displayed in the JPasswordField.
0N/A return null;
0N/A }
0N/A }
0N/A }
0N/A}