jdk/src/share/classes/java/awt/TextComponent.java
author alanb
Wed, 18 Dec 2013 08:41:46 +0000
changeset 22060 cd4f9d7dbeda
parent 21278 ef8a3a2a72f2
child 24865 09b1d992ca72
permissions -rw-r--r--
8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission Reviewed-by: mchung, prr, art, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 16100
diff changeset
     2
 * Copyright (c) 1995, 2013, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.TextComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.text.BreakIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.im.InputMethodRequests;
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21278
diff changeset
    37
import sun.awt.AWTPermissions;
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21278
diff changeset
    38
import sun.awt.InputMethodSupport;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The <code>TextComponent</code> class is the superclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * any component that allows the editing of some text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A text component embodies a string of text.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <code>TextComponent</code> class defines a set of methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * that determine whether or not this text is editable. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * component is editable, it defines another set of methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * that supports a text insertion caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * In addition, the class defines methods that are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * to maintain a current <em>selection</em> from the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The text selection, a substring of the component's text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * is the target of editing operations. It is also referred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * to as the <em>selected text</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public class TextComponent extends Component implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The value of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * A <code>null</code> value is the same as "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @see #setText(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @see #getText()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * A boolean indicating whether or not this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>TextComponent</code> is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * It will be <code>true</code> if the text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * is editable and <code>false</code> if not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @see #isEditable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    boolean editable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * The selection refers to the selected text, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <code>selectionStart</code> is the start position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * of the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @see #getSelectionStart()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @see #setSelectionStart(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    int selectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * The selection refers to the selected text, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <code>selectionEnd</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * is the end position of the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @see #getSelectionEnd()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see #setSelectionEnd(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    int selectionEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // A flag used to tell whether the background has been set by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // developer code (as opposed to AWT code).  Used to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    // the background color of non-editable TextComponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    boolean backgroundSetByClientCode = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    transient protected TextListener textListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private static final long serialVersionUID = -2214773872412987419L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Constructs a new text component initialized with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * specified text. Sets the value of the cursor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>Cursor.TEXT_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param      text       the text to be displayed; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *             <code>text</code> is <code>null</code>, the empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *             string <code>""</code> will be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @exception  HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *             <code>GraphicsEnvironment.isHeadless</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *             returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @see        java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see        java.awt.Cursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    TextComponent(String text) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this.text = (text != null) ? text : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private void enableInputMethodsIfNecessary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (checkForEnableIM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            checkForEnableIM = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                Toolkit toolkit = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                boolean shouldEnable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                if (toolkit instanceof InputMethodSupport) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    shouldEnable = ((InputMethodSupport)toolkit)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                      .enableInputMethodsForTextComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                enableInputMethods(shouldEnable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                // if something bad happens, just don't enable input methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Enables or disables input method support for this text component. If input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * method support is enabled and the text component also processes key events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * incoming events are offered to the current input method and will only be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * processed by the component or dispatched to its listeners if the input method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * does not consume them. Whether and how input method support for this text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * component is enabled or disabled by default is implementation dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param enable true to enable, false to disable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @see #processKeyEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void enableInputMethods(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        checkForEnableIM = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        super.enableInputMethods(enable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    boolean areInputMethodsEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // moved from the constructor above to here and addNotify below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // this call will initialize the toolkit if not already initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (checkForEnableIM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            enableInputMethodsIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        // TextComponent handles key events without touching the eventMask or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // having a key listener, so just check whether the flag is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return (eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (peer != null) return peer.getInputMethodRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        else return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Makes this Component displayable by connecting it to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * native screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see       java.awt.TextComponent#removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        enableInputMethodsIfNecessary();
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
     * Removes the <code>TextComponent</code>'s peer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * The peer allows us to modify the appearance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <code>TextComponent</code> without changing its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * functionality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                text = peer.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                selectionStart = peer.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                selectionEnd = peer.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Sets the text that is presented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * text component to be the specified text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param       t   the new text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *                  if this parameter is <code>null</code> then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *                  the text is set to the empty string ""
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see         java.awt.TextComponent#getText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public synchronized void setText(String t) {
13357
6a75209a8aeb 7184365: closed/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest fails
alexsch
parents: 12813
diff changeset
   229
        boolean skipTextEvent = (text == null || text.isEmpty())
6a75209a8aeb 7184365: closed/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest fails
alexsch
parents: 12813
diff changeset
   230
                && (t == null || t.isEmpty());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        text = (t != null) ? t : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        TextComponentPeer peer = (TextComponentPeer)this.peer;
13357
6a75209a8aeb 7184365: closed/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest fails
alexsch
parents: 12813
diff changeset
   233
        // Please note that we do not want to post an event
6a75209a8aeb 7184365: closed/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest fails
alexsch
parents: 12813
diff changeset
   234
        // if TextArea.setText() or TextField.setText() replaces an empty text
6a75209a8aeb 7184365: closed/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest fails
alexsch
parents: 12813
diff changeset
   235
        // by an empty text, that is, if component's text remains unchanged.
6a75209a8aeb 7184365: closed/java/awt/event/TextEvent/TextEventSequenceTest/TextEventSequenceTest fails
alexsch
parents: 12813
diff changeset
   236
        if (peer != null && !skipTextEvent) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            peer.setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Returns the text that is presented by this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * By default, this is an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @return the value of this <code>TextComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see     java.awt.TextComponent#setText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public synchronized String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            text = peer.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Returns the selected text from the text that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * presented by this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @return      the selected text of this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @see         java.awt.TextComponent#select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public synchronized String getSelectedText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return getText().substring(getSelectionStart(), getSelectionEnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Indicates whether or not this text component is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return     <code>true</code> if this text component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *                  editable; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @see        java.awt.TextComponent#setEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @since      JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public boolean isEditable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return editable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Sets the flag that determines whether or not this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * text component is editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * If the flag is set to <code>true</code>, this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * becomes user editable. If the flag is set to <code>false</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * the user cannot change the text of this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * By default, non-editable text components have a background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * of SystemColor.control.  This default can be overridden by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * calling setBackground.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param     b   a flag indicating whether this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *                      is user editable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see       java.awt.TextComponent#isEditable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @since     JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public synchronized void setEditable(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (editable == b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        editable = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            peer.setEditable(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Gets the background color of this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * By default, non-editable text components have a background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * of SystemColor.control.  This default can be overridden by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * calling setBackground.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @return This text component's background color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *         If this text component does not have a background color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *         the background color of its parent is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @see #setBackground(Color)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (!editable && !backgroundSetByClientCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            return SystemColor.control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return super.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Sets the background color of this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param c The color to become this text component's color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *        If this parameter is null then this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *        will inherit the background color of its parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @see #getBackground()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @since JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        backgroundSetByClientCode = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * Gets the start position of the selected text in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @return      the start position of the selected text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @see         java.awt.TextComponent#setSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @see         java.awt.TextComponent#getSelectionEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public synchronized int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            selectionStart = peer.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return selectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Sets the selection start for this text component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * the specified position. The new start point is constrained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * to be at or before the current selection end. It also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * cannot be set to less than zero, the beginning of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * component's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * If the caller supplies a value for <code>selectionStart</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * that is out of bounds, the method enforces these constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * silently, and without failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param       selectionStart   the start position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *                        selected text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @see         java.awt.TextComponent#getSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @see         java.awt.TextComponent#setSelectionEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public synchronized void setSelectionStart(int selectionStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        /* Route through select method to enforce consistent policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
         * between selectionStart and selectionEnd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        select(selectionStart, getSelectionEnd());
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
     * Gets the end position of the selected text in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @return      the end position of the selected text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @see         java.awt.TextComponent#setSelectionEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see         java.awt.TextComponent#getSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public synchronized int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            selectionEnd = peer.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return selectionEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Sets the selection end for this text component to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * the specified position. The new end point is constrained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * to be at or after the current selection start. It also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * cannot be set beyond the end of the component's text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * If the caller supplies a value for <code>selectionEnd</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * that is out of bounds, the method enforces these constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * silently, and without failure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param       selectionEnd   the end position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *                        selected text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see         java.awt.TextComponent#getSelectionEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see         java.awt.TextComponent#setSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @since       JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public synchronized void setSelectionEnd(int selectionEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        /* Route through select method to enforce consistent policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * between selectionStart and selectionEnd.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        select(getSelectionStart(), selectionEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Selects the text between the specified start and end positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * This method sets the start and end positions of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * selected text, enforcing the restriction that the start position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * must be greater than or equal to zero.  The end position must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * greater than or equal to the start position, and less than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * equal to the length of the text component's text.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * character positions are indexed starting with zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * The length of the selection is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <code>endPosition</code> - <code>startPosition</code>, so the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * character at <code>endPosition</code> is not selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * If the start and end positions of the selected text are equal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * all text is deselected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * If the caller supplies values that are inconsistent or out of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * bounds, the method enforces these constraints silently, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * without failure. Specifically, if the start position or end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * position is greater than the length of the text, it is reset to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * equal the text length. If the start position is less than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * it is reset to zero, and if the end position is less than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * start position, it is reset to the start position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @param        selectionStart the zero-based index of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                       character (<code>char</code> value) to be selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param        selectionEnd the zero-based end position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                       text to be selected; the character (<code>char</code> value) at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                       <code>selectionEnd</code> is not selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see          java.awt.TextComponent#setSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @see          java.awt.TextComponent#setSelectionEnd
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see          java.awt.TextComponent#selectAll
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public synchronized void select(int selectionStart, int selectionEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        String text = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        if (selectionStart < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            selectionStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (selectionStart > text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            selectionStart = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (selectionEnd > text.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            selectionEnd = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (selectionEnd < selectionStart) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            selectionEnd = selectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        this.selectionStart = selectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        this.selectionEnd = selectionEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            peer.select(selectionStart, selectionEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * Selects all the text in this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @see        java.awt.TextComponent#select
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public synchronized void selectAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        this.selectionStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        this.selectionEnd = getText().length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            peer.select(selectionStart, selectionEnd);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * Sets the position of the text insertion caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * The caret position is constrained to be between 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * and the last character of the text, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * If the passed-in value is greater than this range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * the value is set to the last character (or 0 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * the <code>TextComponent</code> contains no text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * and no error is returned.  If the passed-in value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * less than 0, an <code>IllegalArgumentException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param        position the position of the text insertion caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @exception    IllegalArgumentException if <code>position</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *               is less than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public synchronized void setCaretPosition(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (position < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            throw new IllegalArgumentException("position less than zero.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        int maxposition = getText().length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (position > maxposition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            position = maxposition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            peer.setCaretPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            select(position, position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the position of the text insertion caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * The caret position is constrained to be between 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * and the last character of the text, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * If the text or caret have not been set, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * caret position is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * @return       the position of the text insertion caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @see #setCaretPosition(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @since        JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public synchronized int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        int position = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            position = peer.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            position = selectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        int maxposition = getText().length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (position > maxposition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            position = maxposition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        return position;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Adds the specified text event listener to receive text events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * from this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * If <code>l</code> is <code>null</code>, no exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @param l the text event listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @see             #removeTextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @see             #getTextListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @see             java.awt.event.TextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    public synchronized void addTextListener(TextListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        textListener = AWTEventMulticaster.add(textListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Removes the specified text event listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * receives text events from this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * If <code>l</code> is <code>null</code>, no exception is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @param           l     the text listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @see             #addTextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @see             #getTextListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @see             java.awt.event.TextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @since           JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public synchronized void removeTextListener(TextListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        textListener = AWTEventMulticaster.remove(textListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Returns an array of all the text listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * registered on this text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @return all of this text component's <code>TextListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *         or an empty array if no text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * @see #addTextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * @see #removeTextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    public synchronized TextListener[] getTextListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 13357
diff changeset
   600
        return getListeners(TextListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * as <code><em>Foo</em>Listener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * upon this <code>TextComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * You can specify the <code>listenerType</code> argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * For example, you can query a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * <code>TextComponent</code> <code>t</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * for its text listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <pre>TextListener[] tls = (TextListener[])(t.getListeners(TextListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *          should specify an interface that descends from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *          <code><em>Foo</em>Listener</code>s on this text component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *          listeners have been added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @exception ClassCastException if <code>listenerType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *          doesn't specify a class or interface that implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *          <code>java.util.EventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @see #getTextListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        if  (listenerType == TextListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            l = textListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    // REMIND: remove when filtering is done at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        if (e.id == TextEvent.TEXT_VALUE_CHANGED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            if ((eventMask & AWTEvent.TEXT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                textListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Processes events on this text component. If the event is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * <code>TextEvent</code>, it invokes the <code>processTextEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * method else it invokes its superclass's <code>processEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        if (e instanceof TextEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            processTextEvent((TextEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Processes text events occurring on this text component by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * dispatching them to any registered <code>TextListener</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * NOTE: This method will not be called unless text events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * are enabled for this component. This happens when one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * <li>A <code>TextListener</code> object is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * via <code>addTextListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * <li>Text events are enabled via <code>enableEvents</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <p>Note that if the event parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * @param e the text event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @see Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    protected void processTextEvent(TextEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        TextListener listener = textListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            int id = e.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            switch (id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            case TextEvent.TEXT_VALUE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                listener.textValueChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Returns a string representing the state of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * <code>TextComponent</code>. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @return      the parameter string of this text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        String str = super.paramString() + ",text=" + getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        if (editable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            str += ",editable";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        return str + ",selection=" + getSelectionStart() + "-" + getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Assigns a valid value to the canAccessClipboard instance variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     */
16097
6277cf02aeac 7186952: Improve clipboard access
denis
parents: 13357
diff changeset
   728
    private boolean canAccessClipboard() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        SecurityManager sm = System.getSecurityManager();
16097
6277cf02aeac 7186952: Improve clipboard access
denis
parents: 13357
diff changeset
   730
        if (sm == null) return true;
6277cf02aeac 7186952: Improve clipboard access
denis
parents: 13357
diff changeset
   731
        try {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21278
diff changeset
   732
            sm.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION);
16097
6277cf02aeac 7186952: Improve clipboard access
denis
parents: 13357
diff changeset
   733
            return true;
6277cf02aeac 7186952: Improve clipboard access
denis
parents: 13357
diff changeset
   734
        } catch (SecurityException e) {}
6277cf02aeac 7186952: Improve clipboard access
denis
parents: 13357
diff changeset
   735
        return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * The textComponent SerializedDataVersion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    private int textComponentSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * a list of serializable TextListener(s) as optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * The non-serializable TextListener(s) are detected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * no attempt is made to serialize them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @serialData Null terminated sequence of zero or more pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *             A pair consists of a String and Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *             The String indicates the type of object and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *             is one of the following :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *             textListenerK indicating and TextListener object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @see java.awt.Component#textListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        // Serialization support.  Since the value of the fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        // selectionStart, selectionEnd, and text aren't necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        // up to date, we sync them up with the peer before serializing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        TextComponentPeer peer = (TextComponentPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            text = peer.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            selectionStart = peer.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            selectionEnd = peer.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        AWTEventMulticaster.save(s, textListenerK, textListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        s.writeObject(null);
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
     * Read the ObjectInputStream, and if it isn't null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * add a listener to receive text events fired by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * TextComponent.  Unrecognized keys or values will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * <code>GraphicsEnvironment.isHeadless()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @see #removeTextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * @see #addTextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        // Make sure the state we just read in for text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        // selectionStart and selectionEnd has legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        this.text = (text != null) ? text : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        select(selectionStart, selectionEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            if (textListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                addTextListener((TextListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        enableInputMethodsIfNecessary();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Gets the AccessibleContext associated with this TextComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * For text components, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * AccessibleAWTTextComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * A new AccessibleAWTTextComponent instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @return an AccessibleAWTTextComponent that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *         AccessibleContext of this TextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            accessibleContext = new AccessibleAWTTextComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <code>TextComponent</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Java Accessibility API appropriate to text component user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    protected class AccessibleAWTTextComponent extends AccessibleAWTComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        implements AccessibleText, TextListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        private static final long serialVersionUID = 3631432373506317811L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
         * Constructs an AccessibleAWTTextComponent.  Adds a listener to track
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
         * caret change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        public AccessibleAWTTextComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            TextComponent.this.addTextListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * TextListener notification of a text value change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        public void textValueChanged(TextEvent textEvent)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            Integer cpos = Integer.valueOf(TextComponent.this.getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            firePropertyChange(ACCESSIBLE_TEXT_PROPERTY, null, cpos);
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
         * Gets the state set of the TextComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         * The AccessibleStateSet of an object is composed of a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         * unique AccessibleStates.  A change in the AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         * of an object will cause a PropertyChangeEvent to be fired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         * for the AccessibleContext.ACCESSIBLE_STATE_PROPERTY property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * @return an instance of AccessibleStateSet containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * current state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         * @see AccessibleStateSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            if (TextComponent.this.isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                states.add(AccessibleState.EDITABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         * Gets the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
         * object (AccessibleRole.TEXT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            return AccessibleRole.TEXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
         * Get the AccessibleText associated with this object.  In the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
         * implementation of the Java Accessibility API for this class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
         * return this object, which is responsible for implementing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
         * AccessibleText interface on behalf of itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
         * @return this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        // --- interface AccessibleText methods ------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
         * Many of these methods are just convenience methods; they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
         * just call the equivalent on the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * Given a point in local coordinates, return the zero-based index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         * of the character under that Point.  If the point is invalid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
         * this method returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
         * @param p the Point in local coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
         * @return the zero-based index of the character under Point p.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        public int getIndexAtPoint(Point p) {
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20172
diff changeset
   935
            return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
         * Determines the bounding box of the character at the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
         * index into the string.  The bounds are returned in local
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
         * coordinates.  If the index is invalid a null rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
         * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         *
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
   944
         * @param i the index into the String &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
         * @return the screen coordinates of the character's bounding box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        public Rectangle getCharacterBounds(int i) {
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20172
diff changeset
   948
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         * Returns the number of characters (valid indicies)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         *
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
   954
         * @return the number of characters &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        public int getCharCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            return TextComponent.this.getText().length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
         * Returns the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
         * Note: The character to the right of the caret will have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
         * same index value as the offset (the caret is between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
         * two characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
         * @return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return TextComponent.this.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
         * Returns the AttributeSet for a given character (at a given index).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
         * @param i the zero-based index into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
         * @return the AttributeSet of the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        public AttributeSet getCharacterAttribute(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            return null; // No attributes in TextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
         * Returns the start offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
         * Return 0 if the text is empty, or the caret position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
         * if no selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         *
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
   990
         * @return the index into the text of the start of the selection &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            return TextComponent.this.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
         * Returns the end offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         * Return 0 if the text is empty, or the caret position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         * if no selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20469
diff changeset
  1003
         * @return the index into the text of the end of the selection &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            return TextComponent.this.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
         * Returns the portion of the text that is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         * @return the text, null if no selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        public String getSelectedText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            String selText = TextComponent.this.getSelectedText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            // Fix for 4256662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            if (selText == null || selText.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            return selText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         * Returns the String at a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
         * or AccessibleText.SENTENCE to retrieve
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  1028
         * @param index an index within the text &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
         * @return the letter, word, or sentence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
         *   null for an invalid index or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        public String getAtIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            if (index < 0 || index >= TextComponent.this.getText().length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                return TextComponent.this.getText().substring(index, index+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            case AccessibleText.WORD:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                    String s = TextComponent.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    BreakIterator words = BreakIterator.getWordInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                    int end = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                    return s.substring(words.previous(), end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            case AccessibleText.SENTENCE:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                    String s = TextComponent.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    BreakIterator sentence = BreakIterator.getSentenceInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                    int end = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    return s.substring(sentence.previous(), end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        private static final boolean NEXT = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        private static final boolean PREVIOUS = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
         * Needed to unify forward and backward searching.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
         * The method assumes that s is the text assigned to words.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        private int findWordLimit(int index, BreakIterator words, boolean direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                                         String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            // Fix for 4256660 and 4256661.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            // Words iterator is different from character and sentence iterators
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            // in that end of one word is not necessarily start of another word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            // Please see java.text.BreakIterator JavaDoc. The code below is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            // based on nextWordStartAfter example from BreakIterator.java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            int last = (direction == NEXT) ? words.following(index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                           : words.preceding(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            int current = (direction == NEXT) ? words.next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                                              : words.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            while (current != BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                for (int p = Math.min(last, current); p < Math.max(last, current); p++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    if (Character.isLetter(s.charAt(p))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                        return last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                last = current;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                current = (direction == NEXT) ? words.next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                                              : words.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            return BreakIterator.DONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
         * Returns the String after a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
         * or AccessibleText.SENTENCE to retrieve
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  1094
         * @param index an index within the text &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
         * @return the letter, word, or sentence, null for an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
         *  index or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        public String getAfterIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            if (index < 0 || index >= TextComponent.this.getText().length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                if (index+1 >= TextComponent.this.getText().length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                   return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                return TextComponent.this.getText().substring(index+1, index+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            case AccessibleText.WORD:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                    String s = TextComponent.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                    BreakIterator words = BreakIterator.getWordInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                    int start = findWordLimit(index, words, NEXT, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                    if (start == BreakIterator.DONE || start >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    int end = words.following(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                    if (end == BreakIterator.DONE || end >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            case AccessibleText.SENTENCE:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                    String s = TextComponent.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                    BreakIterator sentence = BreakIterator.getSentenceInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                    int start = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                    if (start == BreakIterator.DONE || start >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                    int end = sentence.following(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                    if (end == BreakIterator.DONE || end >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
         * Returns the String before a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
         *   or AccessibleText.SENTENCE to retrieve
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  1147
         * @param index an index within the text &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
         * @return the letter, word, or sentence, null for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
         *  or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        public String getBeforeIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            if (index < 0 || index > TextComponent.this.getText().length()-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                if (index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                return TextComponent.this.getText().substring(index-1, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            case AccessibleText.WORD:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                    String s = TextComponent.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                    BreakIterator words = BreakIterator.getWordInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                    int end = findWordLimit(index, words, PREVIOUS, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                    if (end == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                    int start = words.preceding(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                    if (start == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            case AccessibleText.SENTENCE:  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                    String s = TextComponent.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                    BreakIterator sentence = BreakIterator.getSentenceInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                    int end = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    end = sentence.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    int start = sentence.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                    if (start == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }  // end of AccessibleAWTTextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    private boolean checkForEnableIM = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
}