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