jdk/src/share/classes/java/awt/TextField.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 20451 4cedf4e1560a
child 21957 97758de70fbd
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
     2
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1964
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.TextFieldPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * A <code>TextField</code> object is a text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * that allows for the editing of a single line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * For example, the following image depicts a frame with four
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * text fields of varying widths. Two of these text fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * display the predefined text <code>"Hello"</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <img src="doc-files/TextField-1.gif" alt="The preceding text describes this image."
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20172
diff changeset
    45
 * style="float:center; margin: 7px 10px;">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Here is the code that produces these four text fields:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <hr><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * TextField tf1, tf2, tf3, tf4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * // a blank text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * tf1 = new TextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * // blank field of 20 columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * tf2 = new TextField("", 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * // predefined text displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * tf3 = new TextField("Hello!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * // predefined text in 30 columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * tf4 = new TextField("Hello", 30);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </pre></blockquote><hr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Every time the user types a key in the text field, one or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * more key events are sent to the text field.  A <code>KeyEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * may be one of three types: keyPressed, keyReleased, or keyTyped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The properties of a key event indicate which of these types
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * it is, as well as additional information about the event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * such as what modifiers are applied to the key event and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * time at which the event occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * The key event is passed to every <code>KeyListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * or <code>KeyAdapter</code> object which registered to receive such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * events using the component's <code>addKeyListener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * (<code>KeyAdapter</code> objects implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <code>KeyListener</code> interface.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * It is also possible to fire an <code>ActionEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * If action events are enabled for the text field, they may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * be fired by pressing the <code>Return</code> key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The <code>TextField</code> class's <code>processEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * method examines the action event and passes it along to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <code>processActionEvent</code>. The latter method redirects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * event to any <code>ActionListener</code> objects that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * registered to receive action events generated by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @see         java.awt.event.KeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @see         java.awt.event.KeyAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see         java.awt.event.KeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see         java.awt.event.ActionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @see         java.awt.Component#addKeyListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @see         java.awt.TextField#processEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @see         java.awt.TextField#processActionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @see         java.awt.TextField#addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
public class TextField extends TextComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The number of columns in the text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * A column is an approximate average character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * width that is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Guaranteed to be non-negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #setColumns(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see #getColumns()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    int columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The echo character, which is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * the user wishes to disguise the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * typed into the text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * The disguises are removed if echoChar = <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #getEchoChar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @see #setEchoChar(char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @see #echoCharIsSet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    char echoChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    transient ActionListener actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static final String base = "textfield";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static final long serialVersionUID = -2966288784432217853L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Initialize JNI field and method ids
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Constructs a new text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public TextField() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        this("", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Constructs a new text field initialized with the specified text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param      text       the text to be displayed. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *             <code>text</code> is <code>null</code>, the empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *             string <code>""</code> will be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public TextField(String text) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        this(text, (text != null) ? text.length() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Constructs a new empty text field with the specified number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * of columns.  A column is an approximate average character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * width that is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param      columns     the number of columns.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *             <code>columns</code> is less than <code>0</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *             <code>columns</code> is set to <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public TextField(int columns) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        this("", columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Constructs a new text field initialized with the specified text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * to be displayed, and wide enough to hold the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * number of columns. A column is an approximate average character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * width that is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param      text       the text to be displayed. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *             <code>text</code> is <code>null</code>, the empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *             string <code>""</code> will be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param      columns     the number of columns.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *             <code>columns</code> is less than <code>0</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *             <code>columns</code> is set to <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public TextField(String text, int columns) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        super(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        this.columns = (columns >= 0) ? columns : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Construct a name for this component.  Called by getName() when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        synchronized (TextField.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Creates the TextField's peer.  The peer allows us to modify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * appearance of the TextField without changing its functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (peer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                peer = getToolkit().createTextField(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Gets the character that is to be used for echoing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * An echo character is useful for text fields where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * user input should not be echoed to the screen, as in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * the case of a text field for entering a password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * If <code>echoChar</code> = <code>0</code>, user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * input is echoed to the screen unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * A Java platform implementation may support only a limited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * non-empty set of echo characters. This function returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * echo character originally requested via setEchoChar(). The echo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * character actually used by the TextField implementation might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return      the echo character for this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see         java.awt.TextField#echoCharIsSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see         java.awt.TextField#setEchoChar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public char getEchoChar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        return echoChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Sets the echo character for this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * An echo character is useful for text fields where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * user input should not be echoed to the screen, as in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * the case of a text field for entering a password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Setting <code>echoChar</code> = <code>0</code> allows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * user input to be echoed to the screen again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * A Java platform implementation may support only a limited,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * non-empty set of echo characters. Attempts to set an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * unsupported echo character will cause the default echo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * character to be used instead. Subsequent calls to getEchoChar()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * will return the echo character originally requested. This might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * or might not be identical to the echo character actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * used by the TextField implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param       c   the echo character for this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see         java.awt.TextField#echoCharIsSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see         java.awt.TextField#getEchoChar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public void setEchoChar(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        setEchoCharacter(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * replaced by <code>setEchoChar(char)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public synchronized void setEchoCharacter(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (echoChar != c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            echoChar = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            TextFieldPeer peer = (TextFieldPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (peer != null) {
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1183
diff changeset
   284
                peer.setEchoChar(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Sets the text that is presented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * text component to be the specified text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param       t   the new text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see         java.awt.TextComponent#getText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public void setText(String t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        super.setText(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // This could change the preferred size of the Component.
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   299
        invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Indicates whether or not this text field has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * character set for echoing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * An echo character is useful for text fields where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * user input should not be echoed to the screen, as in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * the case of a text field for entering a password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return     <code>true</code> if this text field has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *                 a character set for echoing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *                 <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see        java.awt.TextField#setEchoChar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see        java.awt.TextField#getEchoChar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public boolean echoCharIsSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return echoChar != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Gets the number of columns in this text field. A column is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * approximate average character width that is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return     the number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see        java.awt.TextField#setColumns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public int getColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Sets the number of columns in this text field. A column is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * approximate average character width that is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param      columns   the number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @see        java.awt.TextField#getColumns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception  IllegalArgumentException   if the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *                 supplied for <code>columns</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *                 is less than <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public void setColumns(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        int oldVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            oldVal = this.columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (columns < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                throw new IllegalArgumentException("columns less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            if (columns != oldVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                this.columns = columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (columns != oldVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Gets the preferred size of this text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * with the specified number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param     columns the number of columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *                 in this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @return    the preferred dimensions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *                 displaying this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @since     JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public Dimension getPreferredSize(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return preferredSize(columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * replaced by <code>getPreferredSize(int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public Dimension preferredSize(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            TextFieldPeer peer = (TextFieldPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            return (peer != null) ?
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1183
diff changeset
   379
                       peer.getPreferredSize(columns) :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                       super.preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * Gets the preferred size of this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @return     the preferred dimensions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *                         displaying this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * replaced by <code>getPreferredSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public Dimension preferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            return (columns > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                       preferredSize(columns) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                       super.preferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20451
diff changeset
   408
     * Gets the minimum dimensions for a text field with
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * the specified number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @param    columns   the number of columns in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *                          this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @since    JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public Dimension getMinimumSize(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return minimumSize(columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * replaced by <code>getMinimumSize(int)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public Dimension minimumSize(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            TextFieldPeer peer = (TextFieldPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return (peer != null) ?
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1183
diff changeset
   427
                       peer.getMinimumSize(columns) :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                       super.minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20451
diff changeset
   433
     * Gets the minimum dimensions for this text field.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @return     the minimum dimensions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *                  displaying this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * replaced by <code>getMinimumSize()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            return (columns > 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                       minimumSize(columns) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                       super.minimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Adds the specified action listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * action events from this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param      l the action listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @see        #removeActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @see        #getActionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see        java.awt.event.ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public synchronized void addActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        actionListener = AWTEventMulticaster.add(actionListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Removes the specified action listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * receives action events from this text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param           l the action listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @see             #addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * @see             #getActionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @see             java.awt.event.ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @since           JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    public synchronized void removeActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        actionListener = AWTEventMulticaster.remove(actionListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * Returns an array of all the action listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * registered on this textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @return all of this textfield's <code>ActionListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *         or an empty array if no action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @see #addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @see #removeActionListener
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 15318
diff changeset
   506
     * @see java.awt.event.ActionListener
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public synchronized ActionListener[] getActionListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 5506
diff changeset
   510
        return getListeners(ActionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * upon this <code>TextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <code>TextField</code> <code>t</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * for its action listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <pre>ActionListener[] als = (ActionListener[])(t.getListeners(ActionListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *          <code><em>Foo</em>Listener</code>s on this textfield,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @see #getActionListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if  (listenerType == ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            l = actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (e.id == ActionEvent.ACTION_PERFORMED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                actionListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Processes events on this text field. If the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * is an instance of <code>ActionEvent</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * it invokes the <code>processActionEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * method. Otherwise, it invokes <code>processEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * on the superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param      e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @see        java.awt.event.ActionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @see        java.awt.TextField#processActionEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @since      JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        if (e instanceof ActionEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            processActionEvent((ActionEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * Processes action events occurring on this text field by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * dispatching them to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * <code>ActionListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * This method is not called unless action events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * enabled for this component. Action events are enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * when one of the following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * <p><ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * <li>An <code>ActionListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * via <code>addActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <li>Action events are enabled via <code>enableEvents</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param       e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see         java.awt.event.ActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @see         java.awt.TextField#addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @see         java.awt.Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    protected void processActionEvent(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        ActionListener listener = actionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            listener.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Returns a string representing the state of this <code>TextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @return      the parameter string of this text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        String str = super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (echoChar != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            str += ",echo=" + echoChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * The textField Serialized Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    private int textFieldSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * a list of serializable ActionListener(s) as optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * The non-serializable ActionListener(s) are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @serialData Null terminated sequence of zero or more pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *             A pair consists of a String and Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *             The String indicates the type of object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *             is one of the following :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *             ActionListenerK indicating and ActionListener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @see java.awt.Component#actionListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        AWTEventMulticaster.save(s, actionListenerK, actionListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Read the ObjectInputStream and if it isn't null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * add a listener to receive action events fired by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * TextField.  Unrecognized keys or values will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <code>GraphicsEnvironment.isHeadless()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @see #removeActionListener(ActionListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @see #addActionListener(ActionListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // HeadlessException will be thrown by TextComponent's readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        // Make sure the state we just read in for columns has legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        if (columns < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            columns = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        // Read in listeners, if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (actionListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                addActionListener((ActionListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Gets the AccessibleContext associated with this TextField.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * For text fields, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * AccessibleAWTTextField.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * A new AccessibleAWTTextField instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * @return an AccessibleAWTTextField that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *         AccessibleContext of this TextField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            accessibleContext = new AccessibleAWTTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <code>TextField</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * Java Accessibility API appropriate to text field user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    protected class AccessibleAWTTextField extends AccessibleAWTTextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        private static final long serialVersionUID = 6219164359235943158L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         * @return an instance of AccessibleStateSet describing the states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            states.add(AccessibleState.SINGLE_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
}