src/java.desktop/share/classes/java/awt/TextArea.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.awt.event.InputEvent;
  28 import java.awt.event.KeyEvent;
  29 import java.awt.peer.TextAreaPeer;
  30 import java.io.ObjectOutputStream;
  31 import java.io.ObjectInputStream;
  32 import java.io.IOException;

  33 import java.util.HashSet;
  34 import java.util.Set;
  35 import javax.accessibility.*;



  36 
  37 /**
  38  * A <code>TextArea</code> object is a multi-line region
  39  * that displays text. It can be set to allow editing or
  40  * to be read-only.
  41  * <p>
  42  * The following image shows the appearance of a text area:
  43  * <p>
  44  * <img src="doc-files/TextArea-1.gif" alt="A TextArea showing the word 'Hello!'"
  45  * style="float:center; margin: 7px 10px;">
  46  * <p>
  47  * This text area could be created by the following line of code:
  48  *
  49  * <hr><blockquote><pre>
  50  * new TextArea("Hello", 5, 40);
  51  * </pre></blockquote><hr>
  52  *
  53  * @author      Sami Shaio
  54  * @since       1.0
  55  */


 273     }
 274 
 275     /**
 276      * Construct a name for this component.  Called by <code>getName</code>
 277      * when the name is <code>null</code>.
 278      */
 279     String constructComponentName() {
 280         synchronized (TextArea.class) {
 281             return base + nameCounter++;
 282         }
 283     }
 284 
 285     /**
 286      * Creates the <code>TextArea</code>'s peer.  The peer allows us to modify
 287      * the appearance of the <code>TextArea</code> without changing any of its
 288      * functionality.
 289      */
 290     public void addNotify() {
 291         synchronized (getTreeLock()) {
 292             if (peer == null)
 293                 peer = getToolkit().createTextArea(this);
 294             super.addNotify();
 295         }
 296     }
 297 
 298     /**
 299      * Inserts the specified text at the specified position
 300      * in this text area.
 301      * <p>Note that passing <code>null</code> or inconsistent
 302      * parameters is invalid and will result in unspecified
 303      * behavior.
 304      *
 305      * @param      str the non-<code>null</code> text to insert
 306      * @param      pos the position at which to insert
 307      * @see        java.awt.TextComponent#setText
 308      * @see        java.awt.TextArea#replaceRange
 309      * @see        java.awt.TextArea#append
 310      * @since      1.1
 311      */
 312     public void insert(String str, int pos) {
 313         insertText(str, pos);


   1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 


  27 import java.awt.peer.TextAreaPeer;


  28 import java.io.IOException;
  29 import java.io.ObjectInputStream;
  30 import java.util.HashSet;
  31 import java.util.Set;
  32 
  33 import javax.accessibility.AccessibleContext;
  34 import javax.accessibility.AccessibleState;
  35 import javax.accessibility.AccessibleStateSet;
  36 
  37 /**
  38  * A <code>TextArea</code> object is a multi-line region
  39  * that displays text. It can be set to allow editing or
  40  * to be read-only.
  41  * <p>
  42  * The following image shows the appearance of a text area:
  43  * <p>
  44  * <img src="doc-files/TextArea-1.gif" alt="A TextArea showing the word 'Hello!'"
  45  * style="float:center; margin: 7px 10px;">
  46  * <p>
  47  * This text area could be created by the following line of code:
  48  *
  49  * <hr><blockquote><pre>
  50  * new TextArea("Hello", 5, 40);
  51  * </pre></blockquote><hr>
  52  *
  53  * @author      Sami Shaio
  54  * @since       1.0
  55  */


 273     }
 274 
 275     /**
 276      * Construct a name for this component.  Called by <code>getName</code>
 277      * when the name is <code>null</code>.
 278      */
 279     String constructComponentName() {
 280         synchronized (TextArea.class) {
 281             return base + nameCounter++;
 282         }
 283     }
 284 
 285     /**
 286      * Creates the <code>TextArea</code>'s peer.  The peer allows us to modify
 287      * the appearance of the <code>TextArea</code> without changing any of its
 288      * functionality.
 289      */
 290     public void addNotify() {
 291         synchronized (getTreeLock()) {
 292             if (peer == null)
 293                 peer = getComponentFactory().createTextArea(this);
 294             super.addNotify();
 295         }
 296     }
 297 
 298     /**
 299      * Inserts the specified text at the specified position
 300      * in this text area.
 301      * <p>Note that passing <code>null</code> or inconsistent
 302      * parameters is invalid and will result in unspecified
 303      * behavior.
 304      *
 305      * @param      str the non-<code>null</code> text to insert
 306      * @param      pos the position at which to insert
 307      * @see        java.awt.TextComponent#setText
 308      * @see        java.awt.TextArea#replaceRange
 309      * @see        java.awt.TextArea#append
 310      * @since      1.1
 311      */
 312     public void insert(String str, int pos) {
 313         insertText(str, pos);