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

Print this page


   1 /*
   2  * Copyright (c) 1995, 2013, 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


 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      JDK1.1
 311      */
 312     public void insert(String str, int pos) {
 313         insertText(str, pos);
 314     }
 315 
 316     /**




 317      * @deprecated As of JDK version 1.1,
 318      * replaced by <code>insert(String, int)</code>.
 319      */
 320     @Deprecated
 321     public synchronized void insertText(String str, int pos) {
 322         TextAreaPeer peer = (TextAreaPeer)this.peer;
 323         if (peer != null) {
 324             peer.insert(str, pos);
 325         } else {
 326             text = text.substring(0, pos) + str + text.substring(pos);
 327         }
 328     }
 329 
 330     /**
 331      * Appends the given text to the text area's current text.
 332      * <p>Note that passing <code>null</code> or inconsistent
 333      * parameters is invalid and will result in unspecified
 334      * behavior.
 335      *
 336      * @param     str the non-<code>null</code> text to append
 337      * @see       java.awt.TextArea#insert
 338      * @since     JDK1.1
 339      */
 340     public void append(String str) {
 341         appendText(str);
 342     }
 343 
 344     /**


 345      * @deprecated As of JDK version 1.1,
 346      * replaced by <code>append(String)</code>.
 347      */
 348     @Deprecated
 349     public synchronized void appendText(String str) {
 350         if (peer != null) {
 351             insertText(str, getText().length());
 352         } else {
 353             text = text + str;
 354         }
 355     }
 356 
 357     /**
 358      * Replaces text between the indicated start and end positions
 359      * with the specified replacement text.  The text at the end
 360      * position will not be replaced.  The text at the start
 361      * position will be replaced (unless the start position is the
 362      * same as the end position).
 363      * The text position is zero-based.  The inserted substring may be
 364      * of a different length than the text it replaces.
 365      * <p>Note that passing <code>null</code> or inconsistent
 366      * parameters is invalid and will result in unspecified
 367      * behavior.
 368      *
 369      * @param     str      the non-<code>null</code> text to use as
 370      *                     the replacement
 371      * @param     start    the start position
 372      * @param     end      the end position
 373      * @see       java.awt.TextArea#insert
 374      * @since     JDK1.1
 375      */
 376     public void replaceRange(String str, int start, int end) {
 377         replaceText(str, start, end);
 378     }
 379 
 380     /**








 381      * @deprecated As of JDK version 1.1,
 382      * replaced by <code>replaceRange(String, int, int)</code>.
 383      */
 384     @Deprecated
 385     public synchronized void replaceText(String str, int start, int end) {
 386         TextAreaPeer peer = (TextAreaPeer)this.peer;
 387         if (peer != null) {
 388             peer.replaceRange(str, start, end);
 389         } else {
 390             text = text.substring(0, start) + str + text.substring(end);
 391         }
 392     }
 393 
 394     /**
 395      * Returns the number of rows in the text area.
 396      * @return    the number of rows in the text area
 397      * @see       #setRows(int)
 398      * @see       #getColumns()
 399      * @since     JDK1
 400      */


 475         return scrollbarVisibility;
 476     }
 477 
 478 
 479     /**
 480      * Determines the preferred size of a text area with the specified
 481      * number of rows and columns.
 482      * @param     rows   the number of rows
 483      * @param     columns   the number of columns
 484      * @return    the preferred dimensions required to display
 485      *                       the text area with the specified
 486      *                       number of rows and columns
 487      * @see       java.awt.Component#getPreferredSize
 488      * @since     JDK1.1
 489      */
 490     public Dimension getPreferredSize(int rows, int columns) {
 491         return preferredSize(rows, columns);
 492     }
 493 
 494     /**





 495      * @deprecated As of JDK version 1.1,
 496      * replaced by <code>getPreferredSize(int, int)</code>.
 497      */
 498     @Deprecated
 499     public Dimension preferredSize(int rows, int columns) {
 500         synchronized (getTreeLock()) {
 501             TextAreaPeer peer = (TextAreaPeer)this.peer;
 502             return (peer != null) ?
 503                        peer.getPreferredSize(rows, columns) :
 504                        super.preferredSize();
 505         }
 506     }
 507 
 508     /**
 509      * Determines the preferred size of this text area.
 510      * @return    the preferred dimensions needed for this text area
 511      * @see       java.awt.Component#getPreferredSize
 512      * @since     JDK1.1
 513      */
 514     public Dimension getPreferredSize() {


 527                         super.preferredSize();
 528         }
 529     }
 530 
 531     /**
 532      * Determines the minimum size of a text area with the specified
 533      * number of rows and columns.
 534      * @param     rows   the number of rows
 535      * @param     columns   the number of columns
 536      * @return    the minimum dimensions required to display
 537      *                       the text area with the specified
 538      *                       number of rows and columns
 539      * @see       java.awt.Component#getMinimumSize
 540      * @since     JDK1.1
 541      */
 542     public Dimension getMinimumSize(int rows, int columns) {
 543         return minimumSize(rows, columns);
 544     }
 545 
 546     /**





 547      * @deprecated As of JDK version 1.1,
 548      * replaced by <code>getMinimumSize(int, int)</code>.
 549      */
 550     @Deprecated
 551     public Dimension minimumSize(int rows, int columns) {
 552         synchronized (getTreeLock()) {
 553             TextAreaPeer peer = (TextAreaPeer)this.peer;
 554             return (peer != null) ?
 555                        peer.getMinimumSize(rows, columns) :
 556                        super.minimumSize();
 557         }
 558     }
 559 
 560     /**
 561      * Determines the minimum size of this text area.
 562      * @return    the preferred dimensions needed for this text area
 563      * @see       java.awt.Component#getPreferredSize
 564      * @since     JDK1.1
 565      */
 566     public Dimension getMinimumSize() {


   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


 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      JDK1.1
 311      */
 312     public void insert(String str, int pos) {
 313         insertText(str, pos);
 314     }
 315 
 316     /**
 317      * Inserts the specified text at the specified position
 318      * in this text area.
 319      * @param str  the non-{@code null} text to insert
 320      * @param pos  the position at which to insert
 321      * @deprecated As of JDK version 1.1,
 322      * replaced by <code>insert(String, int)</code>.
 323      */
 324     @Deprecated
 325     public synchronized void insertText(String str, int pos) {
 326         TextAreaPeer peer = (TextAreaPeer)this.peer;
 327         if (peer != null) {
 328             peer.insert(str, pos);
 329         } else {
 330             text = text.substring(0, pos) + str + text.substring(pos);
 331         }
 332     }
 333 
 334     /**
 335      * Appends the given text to the text area's current text.
 336      * <p>Note that passing <code>null</code> or inconsistent
 337      * parameters is invalid and will result in unspecified
 338      * behavior.
 339      *
 340      * @param     str the non-<code>null</code> text to append
 341      * @see       java.awt.TextArea#insert
 342      * @since     JDK1.1
 343      */
 344     public void append(String str) {
 345         appendText(str);
 346     }
 347 
 348     /**
 349      * Appends the given text to the text area's current text.
 350      * @param str  the text to append
 351      * @deprecated As of JDK version 1.1,
 352      * replaced by <code>append(String)</code>.
 353      */
 354     @Deprecated
 355     public synchronized void appendText(String str) {
 356         if (peer != null) {
 357             insertText(str, getText().length());
 358         } else {
 359             text = text + str;
 360         }
 361     }
 362 
 363     /**
 364      * Replaces text between the indicated start and end positions
 365      * with the specified replacement text.  The text at the end
 366      * position will not be replaced.  The text at the start
 367      * position will be replaced (unless the start position is the
 368      * same as the end position).
 369      * The text position is zero-based.  The inserted substring may be
 370      * of a different length than the text it replaces.
 371      * <p>Note that passing <code>null</code> or inconsistent
 372      * parameters is invalid and will result in unspecified
 373      * behavior.
 374      *
 375      * @param     str      the non-<code>null</code> text to use as
 376      *                     the replacement
 377      * @param     start    the start position
 378      * @param     end      the end position
 379      * @see       java.awt.TextArea#insert
 380      * @since     JDK1.1
 381      */
 382     public void replaceRange(String str, int start, int end) {
 383         replaceText(str, start, end);
 384     }
 385 
 386     /**
 387      * Replaces a range of characters between
 388      * the indicated start and end positions
 389      * with the specified replacement text (the text at the end
 390      * position will not be replaced).
 391      * @param   str  the non-{@code null} text to use as
 392      *               the replacement
 393      * @param   start  the start position
 394      * @param   end    the end position
 395      * @deprecated As of JDK version 1.1,
 396      * replaced by <code>replaceRange(String, int, int)</code>.
 397      */
 398     @Deprecated
 399     public synchronized void replaceText(String str, int start, int end) {
 400         TextAreaPeer peer = (TextAreaPeer)this.peer;
 401         if (peer != null) {
 402             peer.replaceRange(str, start, end);
 403         } else {
 404             text = text.substring(0, start) + str + text.substring(end);
 405         }
 406     }
 407 
 408     /**
 409      * Returns the number of rows in the text area.
 410      * @return    the number of rows in the text area
 411      * @see       #setRows(int)
 412      * @see       #getColumns()
 413      * @since     JDK1
 414      */


 489         return scrollbarVisibility;
 490     }
 491 
 492 
 493     /**
 494      * Determines the preferred size of a text area with the specified
 495      * number of rows and columns.
 496      * @param     rows   the number of rows
 497      * @param     columns   the number of columns
 498      * @return    the preferred dimensions required to display
 499      *                       the text area with the specified
 500      *                       number of rows and columns
 501      * @see       java.awt.Component#getPreferredSize
 502      * @since     JDK1.1
 503      */
 504     public Dimension getPreferredSize(int rows, int columns) {
 505         return preferredSize(rows, columns);
 506     }
 507 
 508     /**
 509      * Determines the preferred size of the text area with the specified
 510      * number of rows and columns.
 511      * @param   rows     the number of rows
 512      * @param   columns  the number of columns
 513      * @return  the preferred dimensions needed for the text area
 514      * @deprecated As of JDK version 1.1,
 515      * replaced by <code>getPreferredSize(int, int)</code>.
 516      */
 517     @Deprecated
 518     public Dimension preferredSize(int rows, int columns) {
 519         synchronized (getTreeLock()) {
 520             TextAreaPeer peer = (TextAreaPeer)this.peer;
 521             return (peer != null) ?
 522                        peer.getPreferredSize(rows, columns) :
 523                        super.preferredSize();
 524         }
 525     }
 526 
 527     /**
 528      * Determines the preferred size of this text area.
 529      * @return    the preferred dimensions needed for this text area
 530      * @see       java.awt.Component#getPreferredSize
 531      * @since     JDK1.1
 532      */
 533     public Dimension getPreferredSize() {


 546                         super.preferredSize();
 547         }
 548     }
 549 
 550     /**
 551      * Determines the minimum size of a text area with the specified
 552      * number of rows and columns.
 553      * @param     rows   the number of rows
 554      * @param     columns   the number of columns
 555      * @return    the minimum dimensions required to display
 556      *                       the text area with the specified
 557      *                       number of rows and columns
 558      * @see       java.awt.Component#getMinimumSize
 559      * @since     JDK1.1
 560      */
 561     public Dimension getMinimumSize(int rows, int columns) {
 562         return minimumSize(rows, columns);
 563     }
 564 
 565     /**
 566      * Determines the minimum size of the text area with the specified
 567      * number of rows and columns.
 568      * @param rows     the number of rows
 569      * @param columns  the number of columns
 570      * @return  the minimum size for the text area
 571      * @deprecated As of JDK version 1.1,
 572      * replaced by <code>getMinimumSize(int, int)</code>.
 573      */
 574     @Deprecated
 575     public Dimension minimumSize(int rows, int columns) {
 576         synchronized (getTreeLock()) {
 577             TextAreaPeer peer = (TextAreaPeer)this.peer;
 578             return (peer != null) ?
 579                        peer.getMinimumSize(rows, columns) :
 580                        super.minimumSize();
 581         }
 582     }
 583 
 584     /**
 585      * Determines the minimum size of this text area.
 586      * @return    the preferred dimensions needed for this text area
 587      * @see       java.awt.Component#getPreferredSize
 588      * @since     JDK1.1
 589      */
 590     public Dimension getMinimumSize() {