jdk/src/share/classes/javax/swing/JTextField.java
author cl
Mon, 07 Oct 2013 11:34:44 -0700
changeset 20458 f2423fb3fd19
parent 20455 f6f9a0c2796b
child 21592 da6abe91602a
permissions -rw-r--r--
8025840: Fix all the doclint warnings about trademark Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2010, 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: 5449
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: 5449
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: 5449
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5449
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
3737
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 1639
diff changeset
    27
import sun.swing.SwingUtilities2;
83fb4621a129 6824395: Several Swing core components prevent using them in wrapper classes
alexp
parents: 1639
diff changeset
    28
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>JTextField</code> is a lightweight component that allows the editing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * of a single line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * For information on and examples of using text fields,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * see
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 20157
diff changeset
    47
 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/textfield.html">How to Use Text Fields</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * in <em>The Java Tutorial.</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>JTextField</code> is intended to be source-compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * with <code>java.awt.TextField</code> where it is reasonable to do so.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * component has capabilities not found in the <code>java.awt.TextField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * class.  The superclass should be consulted for additional capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>JTextField</code> has a method to establish the string used as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * command string for the action event that gets fired.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>java.awt.TextField</code> used the text of the field as the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * string for the <code>ActionEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>JTextField</code> will use the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * string set with the <code>setActionCommand</code> method if not <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * otherwise it will use the text of the field as a compatibility with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>java.awt.TextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The method <code>setEchoChar</code> and <code>getEchoChar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * are not provided directly to avoid a new implementation of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * pluggable look-and-feel inadvertently exposing password characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * To provide password-like services a separate class <code>JPasswordField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * extends <code>JTextField</code> to provide this service with an independently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * pluggable look-and-feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The <code>java.awt.TextField</code> could be monitored for changes by adding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * a <code>TextListener</code> for <code>TextEvent</code>'s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * In the <code>JTextComponent</code> based
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * components, changes are broadcasted from the model via a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <code>DocumentEvent</code> to <code>DocumentListeners</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * The <code>DocumentEvent</code> gives
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * the location of the change and the kind of change if desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The code fragment might look something like:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * &nbsp;   DocumentListener myListener = ??;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * &nbsp;   JTextField myArea = ??;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * &nbsp;   myArea.getDocument().addDocumentListener(myListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * The horizontal alignment of <code>JTextField</code> can be set to be left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * justified, leading justified, centered, right justified or trailing justified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Right/trailing justification is useful if the required size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * of the field text is smaller than the size allocated to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * This is determined by the <code>setHorizontalAlignment</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * and <code>getHorizontalAlignment</code> methods.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * is to be leading justified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * How the text field consumes VK_ENTER events depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * on whether the text field has any action listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * If so, then VK_ENTER results in the listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * getting an ActionEvent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * and the VK_ENTER event is consumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * This is compatible with how AWT text fields handle VK_ENTER events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * If the text field has no action listeners, then as of v 1.3 the VK_ENTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * event is not consumed.  Instead, the bindings of ancestor components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * are processed, which enables the default button feature of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * JFC/Swing to work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * Customized fields can easily be created by extending the model and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * changing the default model provided.  For example, the following piece
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * of code will create a field that holds only upper case characters.  It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * will work even if text is pasted into from the clipboard or it is altered via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * programmatic changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
&nbsp;public class UpperCaseField extends JTextField {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
&nbsp;    public UpperCaseField(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
&nbsp;        super(cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
&nbsp;    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
&nbsp;    protected Document createDefaultModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
&nbsp;        return new UpperCaseDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
&nbsp;    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
&nbsp;    static class UpperCaseDocument extends PlainDocument {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
&nbsp;        public void insertString(int offs, String str, AttributeSet a)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
&nbsp;            throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
&nbsp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
&nbsp;            if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
&nbsp;                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
&nbsp;            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
&nbsp;            char[] upper = str.toCharArray();
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 7668
diff changeset
   131
&nbsp;            for (int i = 0; i &lt; upper.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
&nbsp;                upper[i] = Character.toUpperCase(upper[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
&nbsp;            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
&nbsp;            super.insertString(offs, new String(upper), a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
&nbsp;        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
&nbsp;    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
&nbsp;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   151
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *   attribute: isContainer false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * description: A component which allows for the editing of a single line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * @see #setActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * @see JPasswordField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * @see #addActionListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
public class JTextField extends JTextComponent implements SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Constructs a new <code>TextField</code>.  A default model is created,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * the initial string is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * and the number of columns is set to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public JTextField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        this(null, null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Constructs a new <code>TextField</code> initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * specified text. A default model is created and the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * columns is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param text the text to be displayed, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public JTextField(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        this(null, text, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Constructs a new empty <code>TextField</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * A default model is created and the initial string is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param columns  the number of columns to use to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *   the preferred width; if columns is set to zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *   preferred width will be whatever naturally results from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *   the component implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public JTextField(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this(null, null, columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Constructs a new <code>TextField</code> initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * specified text and columns.  A default model is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param text the text to be displayed, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param columns  the number of columns to use to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *   the preferred width; if columns is set to zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *   preferred width will be whatever naturally results from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *   the component implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public JTextField(String text, int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        this(null, text, columns);
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
     * Constructs a new <code>JTextField</code> that uses the given text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * storage model and the given number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * This is the constructor through which the other constructors feed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * If the document is <code>null</code>, a default model is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param doc  the text storage to use; if this is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *          a default will be provided by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *          <code>createDefaultModel</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param text  the initial string to display, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param columns  the number of columns to use to calculate
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 7668
diff changeset
   226
     *   the preferred width &gt;= 0; if <code>columns</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *   is set to zero, the preferred width will be whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *   naturally results from the component implementation
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 7668
diff changeset
   229
     * @exception IllegalArgumentException if <code>columns</code> &lt; 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public JTextField(Document doc, String text, int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (columns < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            throw new IllegalArgumentException("columns less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        visibility = new DefaultBoundedRangeModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        visibility.addChangeListener(new ScrollRepainter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        this.columns = columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (doc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            doc = createDefaultModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Gets the class ID for a UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return the string "TextFieldUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Associates the editor with a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * The currently registered factory is used to build a view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * the document, which gets displayed by the editor after revalidation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * A PropertyChange event ("document") is propagated to each listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param doc  the document to display/edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @see #getDocument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *  description: the text document model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    public void setDocument(Document doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        if (doc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            doc.putProperty("filterNewlines", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        super.setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Calls to <code>revalidate</code> that come from within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * textfield itself will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * be handled by validating the textfield, unless the textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * is contained within a <code>JViewport</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * in which case this returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @return if the parent of this textfield is a <code>JViewPort</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *          return false, otherwise return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @see JComponent#revalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see JComponent#isValidateRoot
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3737
diff changeset
   291
     * @see java.awt.Container#isValidateRoot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3737
diff changeset
   293
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public boolean isValidateRoot() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4284
diff changeset
   295
        return !(SwingUtilities.getUnwrappedParent(this) instanceof JViewport);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Returns the horizontal alignment of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Valid keys are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <li><code>JTextField.LEFT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <li><code>JTextField.CENTER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <li><code>JTextField.RIGHT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <li><code>JTextField.LEADING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <li><code>JTextField.TRAILING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the horizontal alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public int getHorizontalAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Sets the horizontal alignment of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Valid keys are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <li><code>JTextField.LEFT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <li><code>JTextField.CENTER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <li><code>JTextField.RIGHT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <li><code>JTextField.LEADING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <li><code>JTextField.TRAILING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <code>invalidate</code> and <code>repaint</code> are called when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * alignment is set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * and a <code>PropertyChange</code> event ("horizontalAlignment") is fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param alignment the alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @exception IllegalArgumentException if <code>alignment</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *  is not a valid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * description: Set the field alignment to LEFT, CENTER, RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *              LEADING (the default) or TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *        enum: LEFT JTextField.LEFT CENTER JTextField.CENTER RIGHT JTextField.RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *              LEADING JTextField.LEADING TRAILING JTextField.TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     public void setHorizontalAlignment(int alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (alignment == horizontalAlignment) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        int oldValue = horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if ((alignment == LEFT) || (alignment == CENTER) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            (alignment == RIGHT)|| (alignment == LEADING) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            (alignment == TRAILING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            horizontalAlignment = alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            throw new IllegalArgumentException("horizontalAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        firePropertyChange("horizontalAlignment", oldValue, horizontalAlignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        repaint();
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
     * Creates the default implementation of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * to be used at construction if one isn't explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * given.  An instance of <code>PlainDocument</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @return the default model implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    protected Document createDefaultModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return new PlainDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * Returns the number of columns in this <code>TextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return the number of columns >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public int getColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Sets the number of columns in this <code>TextField</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * and then invalidate the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @param columns the number of columns >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @exception IllegalArgumentException if <code>columns</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *          is less than 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * description: the number of columns preferred for display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public void setColumns(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        int oldVal = this.columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (columns < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            throw new IllegalArgumentException("columns less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if (columns != oldVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            this.columns = columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Returns the column width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * The meaning of what a column is can be considered a fairly weak
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * notion for some fonts.  This method is used to define the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * of a column.  By default this is defined to be the width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * character <em>m</em> for the font used.  This method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * redefined to be some alternative amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @return the column width >= 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    protected int getColumnWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (columnWidth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            FontMetrics metrics = getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            columnWidth = metrics.charWidth('m');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Returns the preferred size <code>Dimensions</code> needed for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * <code>TextField</code>.  If a non-zero number of columns has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * set, the width is set to the columns multiplied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * the column width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @return the dimension of this textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        Dimension size = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (columns != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            size.width = columns * getColumnWidth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Sets the current font.  This removes cached row height and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * width so the new font will be reflected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * <code>revalidate</code> is called after setting the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param f the new font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        columnWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Adds the specified action listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * action events from this textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @param l the action listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public synchronized void addActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        listenerList.add(ActionListener.class, l);
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
     * Removes the specified action listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * receives action events from this textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param l the action listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public synchronized void removeActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if ((l != null) && (getAction() == l)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            setAction(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            listenerList.remove(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Returns an array of all the <code>ActionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * to this JTextField with addActionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @return all of the <code>ActionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public synchronized ActionListener[] getActionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   478
        return listenerList.getListeners(ActionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * is lazily created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * The listener list is processed in last to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * first order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    protected void fireActionPerformed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        int modifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        AWTEvent currentEvent = EventQueue.getCurrentEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (currentEvent instanceof InputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            modifiers = ((InputEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        } else if (currentEvent instanceof ActionEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            modifiers = ((ActionEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        ActionEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                            (command != null) ? command : getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                            EventQueue.getMostRecentEventTime(), modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            if (listeners[i]==ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                ((ActionListener)listeners[i+1]).actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        }
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
     * Sets the command string used for action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @param command the command string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    public void setActionCommand(String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    private Action action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private PropertyChangeListener actionPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Sets the <code>Action</code> for the <code>ActionEvent</code> source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * The new <code>Action</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * any previously set <code>Action</code> but does not affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * <code>ActionListeners</code> independently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * added with <code>addActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * If the <code>Action</code> is already a registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * for the <code>ActionEvent</code> source, it is not re-registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * Setting the <code>Action</code> results in immediately changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * all the properties described in <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * Swing Components Supporting <code>Action</code></a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Subsequently, the textfield's properties are automatically updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * as the <code>Action</code>'s properties change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * This method uses three other methods to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * and help track the <code>Action</code>'s property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * It uses the <code>configurePropertiesFromAction</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * to immediately change the textfield's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * To track changes in the <code>Action</code>'s property values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * this method registers the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * returned by <code>createActionPropertyChangeListener</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * default {@code PropertyChangeListener} invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * {@code actionPropertyChanged} method when a property in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * {@code Action} changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @param a the <code>Action</code> for the <code>JTextField</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see #getAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see #createActionPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @see #actionPropertyChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *  description: the Action instance connected with this ActionEvent source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public void setAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        Action oldValue = getAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (action==null || !action.equals(a)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            action = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            if (oldValue!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                removeActionListener(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                oldValue.removePropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                actionPropertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (action!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                // Don't add if it is already a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                if (!isListener(ActionListener.class, action)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    addActionListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                // Reverse linkage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                actionPropertyChangeListener = createActionPropertyChangeListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                action.addPropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            firePropertyChange("action", oldValue, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    private boolean isListener(Class c, ActionListener a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        boolean isListener = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            if (listeners[i]==c && listeners[i+1]==a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    isListener=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        return isListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Returns the currently set <code>Action</code> for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <code>ActionEvent</code> source, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * if no <code>Action</code> is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @return the <code>Action</code> for this <code>ActionEvent</code> source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    public Action getAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Sets the properties on this textfield to match those in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <code>Action</code>.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * details as to which properties this sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @param a the <code>Action</code> from which to get the properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    protected void configurePropertiesFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        AbstractAction.setEnabledFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        AbstractAction.setToolTipTextFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        setActionCommandFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * Updates the textfield's state in response to property changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * associated action. This method is invoked from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * {@code PropertyChangeListener} returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * {@code createActionPropertyChangeListener}. Subclasses do not normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * need to invoke this. Subclasses that support additional {@code Action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * properties should override this and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * {@code configurePropertiesFromAction}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * Refer to the table at <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Swing Components Supporting <code>Action</code></a> for a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * the properties this method sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param action the <code>Action</code> associated with this textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param propertyName the name of the property that changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    protected void actionPropertyChanged(Action action, String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (propertyName == Action.ACTION_COMMAND_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            setActionCommandFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        } else if (propertyName == "enabled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            AbstractAction.setEnabledFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        } else if (propertyName == Action.SHORT_DESCRIPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            AbstractAction.setToolTipTextFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    private void setActionCommandFromAction(Action action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        setActionCommand((action == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                         (String)action.getValue(Action.ACTION_COMMAND_KEY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Creates and returns a <code>PropertyChangeListener</code> that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * responsible for listening for changes from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * <code>Action</code> and updating the appropriate properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <b>Warning:</b> If you subclass this do not create an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * inner class.  If you do the lifetime of the textfield will be tied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * that of the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @param a the textfield's action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        return new TextFieldActionPropertyChangeListener(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    private static class TextFieldActionPropertyChangeListener extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                         ActionPropertyChangeListener<JTextField> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        TextFieldActionPropertyChangeListener(JTextField tf, Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            super(tf, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        protected void actionPropertyChanged(JTextField textField,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                             Action action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                             PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (AbstractAction.shouldReconfigure(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                textField.configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                textField.actionPropertyChanged(action, e.getPropertyName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * Fetches the command list for the editor.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * the list of commands supported by the plugged-in UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * augmented by the collection of commands that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * editor itself supports.  These are useful for binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * to events, such as in a keymap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @return the command list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public Action[] getActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return TextAction.augmentList(super.getActions(), defaultActions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Processes action events occurring on this textfield by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * dispatching them to any registered <code>ActionListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * This is normally called by the controller registered with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    public void postActionEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        fireActionPerformed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    // --- Scrolling support -----------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * Gets the visibility of the text field.  This can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * be adjusted to change the location of the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * area if the size of the field is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * the area that was allocated to the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * The fields look-and-feel implementation manages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * the values of the minimum, maximum, and extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * properties on the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @return the visibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    public BoundedRangeModel getHorizontalVisibility() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        return visibility;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Gets the scroll offset, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return the offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public int getScrollOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return visibility.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Sets the scroll offset, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @param scrollOffset the offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    public void setScrollOffset(int scrollOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        visibility.setValue(scrollOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Scrolls the field left or right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @param r the region to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
    public void scrollRectToVisible(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        // convert to coordinate system of the bounded range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        int x0 = r.x + visibility.getValue() - i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        int x1 = x0 + r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        if (x0 < visibility.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            // Scroll to the left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            visibility.setValue(x0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        } else if(x1 > visibility.getValue() + visibility.getExtent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            // Scroll to the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            visibility.setValue(x1 - visibility.getExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Returns true if the receiver has an <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    boolean hasActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (listeners[i]==ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    // --- variables -------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Name of the action to send notification that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * contents of the field have been accepted.  Typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * this is bound to a carriage-return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public static final String notifyAction = "notify-field-accept";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    private BoundedRangeModel visibility;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    private int horizontalAlignment = LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    private int columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    private int columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    private String command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    private static final Action[] defaultActions = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        new NotifyAction()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    private static final String uiClassID = "TextFieldUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    // --- Action implementations -----------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    // Note that JFormattedTextField.CommitAction extends this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    static class NotifyAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        NotifyAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            super(notifyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            JTextComponent target = getFocusedComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            if (target instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                JTextField field = (JTextField) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                field.postActionEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            JTextComponent target = getFocusedComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            if (target instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                return ((JTextField)target).hasActionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    class ScrollRepainter implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * Returns a string representation of this <code>JTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * and the content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @return  a string representation of this <code>JTextField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        String horizontalAlignmentString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if (horizontalAlignment == LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            horizontalAlignmentString = "LEFT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        } else if (horizontalAlignment == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            horizontalAlignmentString = "CENTER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        } else if (horizontalAlignment == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            horizontalAlignmentString = "RIGHT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        } else if (horizontalAlignment == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            horizontalAlignmentString = "LEADING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        } else if (horizontalAlignment == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            horizontalAlignmentString = "TRAILING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        } else horizontalAlignmentString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        String commandString = (command != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                                command : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        ",columns=" + columns +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        ",columnWidth=" + columnWidth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        ",command=" + commandString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        ",horizontalAlignment=" + horizontalAlignmentString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * <code>JTextField</code>. For <code>JTextFields</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * the <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * <code>AccessibleJTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * A new <code>AccessibleJTextField</code> instance is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @return an <code>AccessibleJTextField</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     *         <code>AccessibleContext</code> of this <code>JTextField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            accessibleContext = new AccessibleJTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * <code>JTextField</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * Java Accessibility API appropriate to text field user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
   942
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    protected class AccessibleJTextField extends AccessibleJTextComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
         * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * @return an instance of AccessibleStateSet describing the states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            states.add(AccessibleState.SINGLE_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
}