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