jdk/src/share/classes/javax/swing/JTextField.java
author rriggs
Tue, 03 Jun 2014 11:18:03 -0400
changeset 25122 1ecc464c69d2
parent 22574 7f8ce0c8c20a
child 25201 4adc75e0c4e5
permissions -rw-r--r--
8044460: Cleanup new Boolean and single character strings Reviewed-by: pchelko, serb, rriggs Contributed-by: otaviopolianasantana@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21592
diff changeset
     2
 * Copyright (c) 1997, 2014, 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
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21592
diff changeset
   164
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
public class JTextField extends JTextComponent implements SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Constructs a new <code>TextField</code>.  A default model is created,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * the initial string is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * and the number of columns is set to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public JTextField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        this(null, null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Constructs a new <code>TextField</code> initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * specified text. A default model is created and the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * columns is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param text the text to be displayed, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public JTextField(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this(null, text, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Constructs a new empty <code>TextField</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * A default model is created and the initial string is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param columns  the number of columns to use to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *   the preferred width; if columns is set to zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *   preferred width will be whatever naturally results from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *   the component implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public JTextField(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        this(null, null, columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Constructs a new <code>TextField</code> initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * specified text and columns.  A default model is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param text the text to be displayed, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param columns  the number of columns to use to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *   the preferred width; if columns is set to zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *   preferred width will be whatever naturally results from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *   the component implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public JTextField(String text, int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        this(null, text, columns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Constructs a new <code>JTextField</code> that uses the given text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * storage model and the given number of columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * This is the constructor through which the other constructors feed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * If the document is <code>null</code>, a default model is created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param doc  the text storage to use; if this is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *          a default will be provided by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *          <code>createDefaultModel</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param text  the initial string to display, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @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
   227
     *   the preferred width &gt;= 0; if <code>columns</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *   is set to zero, the preferred width will be whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *   naturally results from the component implementation
20157
cafca01a8e28 8025230: [cleanup] some more javadoc formatting fixes for swing
yan
parents: 7668
diff changeset
   230
     * @exception IllegalArgumentException if <code>columns</code> &lt; 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public JTextField(Document doc, String text, int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (columns < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            throw new IllegalArgumentException("columns less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        visibility = new DefaultBoundedRangeModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        visibility.addChangeListener(new ScrollRepainter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        this.columns = columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (doc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            doc = createDefaultModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            setText(text);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Gets the class ID for a UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @return the string "TextFieldUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return uiClassID;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Associates the editor with a text document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * The currently registered factory is used to build a view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * the document, which gets displayed by the editor after revalidation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * A PropertyChange event ("document") is propagated to each listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param doc  the document to display/edit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see #getDocument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *  description: the text document model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void setDocument(Document doc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (doc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            doc.putProperty("filterNewlines", Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        super.setDocument(doc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Calls to <code>revalidate</code> that come from within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * textfield itself will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * be handled by validating the textfield, unless the textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * is contained within a <code>JViewport</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * in which case this returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @return if the parent of this textfield is a <code>JViewPort</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *          return false, otherwise return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see JComponent#revalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @see JComponent#isValidateRoot
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3737
diff changeset
   292
     * @see java.awt.Container#isValidateRoot
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3737
diff changeset
   294
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public boolean isValidateRoot() {
5449
21bec46ee9e3 6899413: Fix for CR #6878399 should be refactored
alexp
parents: 4284
diff changeset
   296
        return !(SwingUtilities.getUnwrappedParent(this) instanceof JViewport);
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Returns the horizontal alignment of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Valid keys are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <li><code>JTextField.LEFT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <li><code>JTextField.CENTER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <li><code>JTextField.RIGHT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <li><code>JTextField.LEADING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <li><code>JTextField.TRAILING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return the horizontal alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public int getHorizontalAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Sets the horizontal alignment of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Valid keys are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <li><code>JTextField.LEFT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <li><code>JTextField.CENTER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <li><code>JTextField.RIGHT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <li><code>JTextField.LEADING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <li><code>JTextField.TRAILING</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <code>invalidate</code> and <code>repaint</code> are called when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * alignment is set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * and a <code>PropertyChange</code> event ("horizontalAlignment") is fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param alignment the alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @exception IllegalArgumentException if <code>alignment</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *  is not a valid key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * description: Set the field alignment to LEFT, CENTER, RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *              LEADING (the default) or TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *        enum: LEFT JTextField.LEFT CENTER JTextField.CENTER RIGHT JTextField.RIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *              LEADING JTextField.LEADING TRAILING JTextField.TRAILING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     public void setHorizontalAlignment(int alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        if (alignment == horizontalAlignment) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        int oldValue = horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if ((alignment == LEFT) || (alignment == CENTER) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            (alignment == RIGHT)|| (alignment == LEADING) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            (alignment == TRAILING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            horizontalAlignment = alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            throw new IllegalArgumentException("horizontalAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        firePropertyChange("horizontalAlignment", oldValue, horizontalAlignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Creates the default implementation of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * to be used at construction if one isn't explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * given.  An instance of <code>PlainDocument</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @return the default model implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    protected Document createDefaultModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return new PlainDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Returns the number of columns in this <code>TextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   371
     * @return the number of columns &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public int getColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Sets the number of columns in this <code>TextField</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * and then invalidate the layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   381
     * @param columns the number of columns &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @exception IllegalArgumentException if <code>columns</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *          is less than 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * description: the number of columns preferred for display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public void setColumns(int columns) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        int oldVal = this.columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (columns < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throw new IllegalArgumentException("columns less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (columns != oldVal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            this.columns = columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            invalidate();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Returns the column width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * The meaning of what a column is can be considered a fairly weak
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * notion for some fonts.  This method is used to define the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * of a column.  By default this is defined to be the width of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * character <em>m</em> for the font used.  This method can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * redefined to be some alternative amount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   406
     * @return the column width &gt;= 1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    protected int getColumnWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        if (columnWidth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            FontMetrics metrics = getFontMetrics(getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            columnWidth = metrics.charWidth('m');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Returns the preferred size <code>Dimensions</code> needed for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <code>TextField</code>.  If a non-zero number of columns has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * set, the width is set to the columns multiplied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * the column width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @return the dimension of this textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        Dimension size = super.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (columns != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            size.width = columns * getColumnWidth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Sets the current font.  This removes cached row height and column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * width so the new font will be reflected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <code>revalidate</code> is called after setting the font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @param f the new font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        columnWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * Adds the specified action listener to receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * action events from this textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @param l the action listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public synchronized void addActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        listenerList.add(ActionListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Removes the specified action listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * receives action events from this textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param l the action listener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public synchronized void removeActionListener(ActionListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        if ((l != null) && (getAction() == l)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            setAction(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            listenerList.remove(ActionListener.class, l);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Returns an array of all the <code>ActionListener</code>s added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * to this JTextField with addActionListener().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @return all of the <code>ActionListener</code>s added or an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *         array if no listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public synchronized ActionListener[] getActionListeners() {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 2
diff changeset
   479
        return listenerList.getListeners(ActionListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Notifies all listeners that have registered interest for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * notification on this event type.  The event instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * is lazily created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * The listener list is processed in last to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * first order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @see EventListenerList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    protected void fireActionPerformed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        int modifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        AWTEvent currentEvent = EventQueue.getCurrentEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (currentEvent instanceof InputEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            modifiers = ((InputEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        } else if (currentEvent instanceof ActionEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            modifiers = ((ActionEvent)currentEvent).getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        ActionEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                            (command != null) ? command : getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                            EventQueue.getMostRecentEventTime(), modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            if (listeners[i]==ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                ((ActionListener)listeners[i+1]).actionPerformed(e);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Sets the command string used for action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @param command the command string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    public void setActionCommand(String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        this.command = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private Action action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private PropertyChangeListener actionPropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Sets the <code>Action</code> for the <code>ActionEvent</code> source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * The new <code>Action</code> replaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * any previously set <code>Action</code> but does not affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * <code>ActionListeners</code> independently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * added with <code>addActionListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * If the <code>Action</code> is already a registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * for the <code>ActionEvent</code> source, it is not re-registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Setting the <code>Action</code> results in immediately changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * all the properties described in <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * Swing Components Supporting <code>Action</code></a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Subsequently, the textfield's properties are automatically updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * as the <code>Action</code>'s properties change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * This method uses three other methods to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * and help track the <code>Action</code>'s property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * It uses the <code>configurePropertiesFromAction</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * to immediately change the textfield's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * To track changes in the <code>Action</code>'s property values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * this method registers the <code>PropertyChangeListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * returned by <code>createActionPropertyChangeListener</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * default {@code PropertyChangeListener} invokes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * {@code actionPropertyChanged} method when a property in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * {@code Action} changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param a the <code>Action</code> for the <code>JTextField</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @see #getAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @see #createActionPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @see #actionPropertyChanged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *  description: the Action instance connected with this ActionEvent source
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public void setAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        Action oldValue = getAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (action==null || !action.equals(a)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            action = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            if (oldValue!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                removeActionListener(oldValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                oldValue.removePropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                actionPropertyChangeListener = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            if (action!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                // Don't add if it is already a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                if (!isListener(ActionListener.class, action)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    addActionListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                // Reverse linkage:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                actionPropertyChangeListener = createActionPropertyChangeListener(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                action.addPropertyChangeListener(actionPropertyChangeListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            firePropertyChange("action", oldValue, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    private boolean isListener(Class c, ActionListener a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        boolean isListener = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if (listeners[i]==c && listeners[i+1]==a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                    isListener=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return isListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Returns the currently set <code>Action</code> for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * <code>ActionEvent</code> source, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * if no <code>Action</code> is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @return the <code>Action</code> for this <code>ActionEvent</code> source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    public Action getAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * Sets the properties on this textfield to match those in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <code>Action</code>.  Refer to <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * Swing Components Supporting <code>Action</code></a> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * details as to which properties this sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @param a the <code>Action</code> from which to get the properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *          or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    protected void configurePropertiesFromAction(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        AbstractAction.setEnabledFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        AbstractAction.setToolTipTextFromAction(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        setActionCommandFromAction(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Updates the textfield's state in response to property changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * associated action. This method is invoked from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * {@code PropertyChangeListener} returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * {@code createActionPropertyChangeListener}. Subclasses do not normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * need to invoke this. Subclasses that support additional {@code Action}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * properties should override this and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * {@code configurePropertiesFromAction}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Refer to the table at <a href="Action.html#buttonActions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Swing Components Supporting <code>Action</code></a> for a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * the properties this method sets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @param action the <code>Action</code> associated with this textfield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @param propertyName the name of the property that changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @see #configurePropertiesFromAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    protected void actionPropertyChanged(Action action, String propertyName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (propertyName == Action.ACTION_COMMAND_KEY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            setActionCommandFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        } else if (propertyName == "enabled") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            AbstractAction.setEnabledFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        } else if (propertyName == Action.SHORT_DESCRIPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            AbstractAction.setToolTipTextFromAction(this, action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    private void setActionCommandFromAction(Action action) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        setActionCommand((action == null) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                         (String)action.getValue(Action.ACTION_COMMAND_KEY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * Creates and returns a <code>PropertyChangeListener</code> that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * responsible for listening for changes from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * <code>Action</code> and updating the appropriate properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * <b>Warning:</b> If you subclass this do not create an anonymous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * inner class.  If you do the lifetime of the textfield will be tied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * that of the <code>Action</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param a the textfield's action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @see Action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @see #setAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        return new TextFieldActionPropertyChangeListener(this, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    private static class TextFieldActionPropertyChangeListener extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                         ActionPropertyChangeListener<JTextField> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        TextFieldActionPropertyChangeListener(JTextField tf, Action a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            super(tf, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        protected void actionPropertyChanged(JTextField textField,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                             Action action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                                             PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            if (AbstractAction.shouldReconfigure(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                textField.configurePropertiesFromAction(action);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                textField.actionPropertyChanged(action, e.getPropertyName());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Fetches the command list for the editor.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * the list of commands supported by the plugged-in UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * augmented by the collection of commands that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * editor itself supports.  These are useful for binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * to events, such as in a keymap.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @return the command list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public Action[] getActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        return TextAction.augmentList(super.getActions(), defaultActions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * Processes action events occurring on this textfield by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * dispatching them to any registered <code>ActionListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * This is normally called by the controller registered with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * textfield.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    public void postActionEvent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        fireActionPerformed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    // --- Scrolling support -----------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Gets the visibility of the text field.  This can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * be adjusted to change the location of the visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * area if the size of the field is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * the area that was allocated to the field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * The fields look-and-feel implementation manages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * the values of the minimum, maximum, and extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * properties on the <code>BoundedRangeModel</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @return the visibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @see BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    public BoundedRangeModel getHorizontalVisibility() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        return visibility;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * Gets the scroll offset, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   748
     * @return the offset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public int getScrollOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        return visibility.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * Sets the scroll offset, in pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 20458
diff changeset
   757
     * @param scrollOffset the offset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    public void setScrollOffset(int scrollOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        visibility.setValue(scrollOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Scrolls the field left or right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @param r the region to scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public void scrollRectToVisible(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        // convert to coordinate system of the bounded range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        int x0 = r.x + visibility.getValue() - i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        int x1 = x0 + r.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        if (x0 < visibility.getValue()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            // Scroll to the left
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            visibility.setValue(x0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        } else if(x1 > visibility.getValue() + visibility.getExtent()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            // Scroll to the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            visibility.setValue(x1 - visibility.getExtent());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * Returns true if the receiver has an <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    boolean hasActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // Guaranteed to return a non-null array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        // Process the listeners last to first, notifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        // those that are interested in this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        for (int i = listeners.length-2; i>=0; i-=2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            if (listeners[i]==ActionListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    // --- variables -------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * Name of the action to send notification that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * contents of the field have been accepted.  Typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * this is bound to a carriage-return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public static final String notifyAction = "notify-field-accept";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    private BoundedRangeModel visibility;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    private int horizontalAlignment = LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    private int columns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    private int columnWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    private String command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    private static final Action[] defaultActions = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        new NotifyAction()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    private static final String uiClassID = "TextFieldUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    // --- Action implementations -----------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    // Note that JFormattedTextField.CommitAction extends this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    static class NotifyAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        NotifyAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            super(notifyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            JTextComponent target = getFocusedComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            if (target instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                JTextField field = (JTextField) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                field.postActionEvent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            JTextComponent target = getFocusedComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            if (target instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                return ((JTextField)target).hasActionListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    class ScrollRepainter implements ChangeListener, Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        public void stateChanged(ChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            repaint();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * See <code>readObject</code> and <code>writeObject</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * <code>JComponent</code> for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                ui.installUI(this);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * Returns a string representation of this <code>JTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * and the content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @return  a string representation of this <code>JTextField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        String horizontalAlignmentString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        if (horizontalAlignment == LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            horizontalAlignmentString = "LEFT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        } else if (horizontalAlignment == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            horizontalAlignmentString = "CENTER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        } else if (horizontalAlignment == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            horizontalAlignmentString = "RIGHT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        } else if (horizontalAlignment == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            horizontalAlignmentString = "LEADING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        } else if (horizontalAlignment == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            horizontalAlignmentString = "TRAILING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        } else horizontalAlignmentString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        String commandString = (command != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                                command : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        ",columns=" + columns +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        ",columnWidth=" + columnWidth +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        ",command=" + commandString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        ",horizontalAlignment=" + horizontalAlignmentString;
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
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
// Accessibility support
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * <code>JTextField</code>. For <code>JTextFields</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * the <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * <code>AccessibleJTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * A new <code>AccessibleJTextField</code> instance is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @return an <code>AccessibleJTextField</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *         <code>AccessibleContext</code> of this <code>JTextField</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            accessibleContext = new AccessibleJTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * <code>JTextField</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * Java Accessibility API appropriate to text field user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * 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
   943
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21592
diff changeset
   947
    @SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    protected class AccessibleJTextField extends AccessibleJTextComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * Gets the state set of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * @return an instance of AccessibleStateSet describing the states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         * of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            states.add(AccessibleState.SINGLE_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
}