TextArea.java revision 2362
2362N/A * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A <code>TextArea</code> object is a multi-line region 0N/A * that displays text. It can be set to allow editing or 0N/A * The following image shows the appearance of a text area: 0N/A * ALIGN=center HSPACE=10 VSPACE=7> 0N/A * This text area could be created by the following line of code: 0N/A * <hr><blockquote><pre> 0N/A * new TextArea("Hello", 5, 40); 0N/A * </pre></blockquote><hr> 0N/A * @author Sami Shaio 0N/A * The number of rows in the <code>TextArea</code>. 0N/A * This parameter will determine the text area's height. 0N/A * Guaranteed to be non-negative. 0N/A * @see #setRows(int) 0N/A * The number of columns in the <code>TextArea</code>. 0N/A * A column is an approximate average character 0N/A * width that is platform-dependent. 0N/A * This parameter will determine the text area's width. 0N/A * Guaranteed to be non-negative. 0N/A * @see #setColumns(int) 0N/A * @see #getColumns() 0N/A * Create and display both vertical and horizontal scrollbars. 0N/A * Create and display vertical scrollbar only. 0N/A * Create and display horizontal scrollbar only. 0N/A * Do not create or display any scrollbars for the text area. 0N/A * Determines which scrollbars are created for the 0N/A * text area. It can be one of four values : 0N/A * <code>SCROLLBARS_BOTH</code> = both scrollbars.<BR> 0N/A * <code>SCROLLBARS_HORIZONTAL_ONLY</code> = Horizontal bar only.<BR> 0N/A * <code>SCROLLBARS_VERTICAL_ONLY</code> = Vertical bar only.<BR> 0N/A * <code>SCROLLBARS_NONE</code> = No scrollbars.<BR> 0N/A * @see #getScrollbarVisibility() 0N/A * Cache the Sets of forward and backward traversal keys so we need not 0N/A * look them up each time. 0N/A * JDK 1.1 serialVersionUID 0N/A * Initialize JNI field and method ids 0N/A /* ensure that the necessary native libraries are loaded */ 0N/A * Constructs a new text area with the empty string as text. 0N/A * This text area is created with scrollbar visibility equal to 0N/A * {@link #SCROLLBARS_BOTH}, so both vertical and horizontal 0N/A * scrollbars will be visible for this text area. 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns true 0N/A * @see java.awt.GraphicsEnvironment#isHeadless() 0N/A * Constructs a new text area with the specified text. 0N/A * This text area is created with scrollbar visibility equal to 0N/A * {@link #SCROLLBARS_BOTH}, so both vertical and horizontal 0N/A * scrollbars will be visible for this text area. 0N/A * @param text the text to be displayed; if 0N/A * <code>text</code> is <code>null</code>, the empty 0N/A * string <code>""</code> will be displayed 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns true 0N/A * @see java.awt.GraphicsEnvironment#isHeadless() 0N/A * Constructs a new text area with the specified number of 0N/A * rows and columns and the empty string as text. 0N/A * A column is an approximate average character 0N/A * width that is platform-dependent. The text area is created with 0N/A * scrollbar visibility equal to {@link #SCROLLBARS_BOTH}, so both 0N/A * vertical and horizontal scrollbars will be visible for this 0N/A * @param rows the number of rows 0N/A * @param columns the number of columns 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns true 0N/A * @see java.awt.GraphicsEnvironment#isHeadless() 0N/A * Constructs a new text area with the specified text, 0N/A * and with the specified number of rows and columns. 0N/A * A column is an approximate average character 0N/A * width that is platform-dependent. The text area is created with 0N/A * scrollbar visibility equal to {@link #SCROLLBARS_BOTH}, so both 0N/A * vertical and horizontal scrollbars will be visible for this 0N/A * @param text the text to be displayed; if 0N/A * <code>text</code> is <code>null</code>, the empty 0N/A * string <code>""</code> will be displayed 0N/A * @param rows the number of rows 0N/A * @param columns the number of columns 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns true 0N/A * @see java.awt.GraphicsEnvironment#isHeadless() 0N/A * Constructs a new text area with the specified text, 0N/A * and with the rows, columns, and scroll bar visibility 0N/A * as specified. All <code>TextArea</code> constructors defer to 0N/A * The <code>TextArea</code> class defines several constants 0N/A * that can be supplied as values for the 0N/A * <code>scrollbars</code> argument: 0N/A * <li><code>SCROLLBARS_BOTH</code>, 0N/A * <li><code>SCROLLBARS_VERTICAL_ONLY</code>, 0N/A * <li><code>SCROLLBARS_HORIZONTAL_ONLY</code>, 0N/A * <li><code>SCROLLBARS_NONE</code>. 0N/A * Any other value for the 0N/A * <code>scrollbars</code> argument is invalid and will result in 0N/A * this text area being created with scrollbar visibility equal to 0N/A * the default value of {@link #SCROLLBARS_BOTH}. 0N/A * @param text the text to be displayed; if 0N/A * <code>text</code> is <code>null</code>, the empty 0N/A * string <code>""</code> will be displayed 0N/A * @param rows the number of rows; if 0N/A * <code>rows</code> is less than <code>0</code>, 0N/A * <code>rows</code> is set to <code>0</code> 0N/A * @param columns the number of columns; if 0N/A * <code>columns</code> is less than <code>0</code>, 0N/A * <code>columns</code> is set to <code>0</code> 0N/A * @param scrollbars a constant that determines what 0N/A * scrollbars are created to view the text area 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns true 0N/A * @see java.awt.GraphicsEnvironment#isHeadless() 0N/A * Construct a name for this component. Called by <code>getName</code> 0N/A * when the name is <code>null</code>. 0N/A * Creates the <code>TextArea</code>'s peer. The peer allows us to modify 0N/A * the appearance of the <code>TextArea</code> without changing any of its 0N/A * Inserts the specified text at the specified position 0N/A * in this text area. 0N/A * <p>Note that passing <code>null</code> or inconsistent 0N/A * parameters is invalid and will result in unspecified 0N/A * @param str the non-<code>null</code> text to insert 0N/A * @param pos the position at which to insert 0N/A * @see java.awt.TextComponent#setText 0N/A * @see java.awt.TextArea#replaceRange 0N/A * @see java.awt.TextArea#append 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>insert(String, int)</code>. 0N/A * Appends the given text to the text area's current text. 0N/A * <p>Note that passing <code>null</code> or inconsistent 0N/A * parameters is invalid and will result in unspecified 0N/A * @param str the non-<code>null</code> text to append 0N/A * @see java.awt.TextArea#insert 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>append(String)</code>. 0N/A * Replaces text between the indicated start and end positions 0N/A * with the specified replacement text. The text at the end 0N/A * position will not be replaced. The text at the start 0N/A * position will be replaced (unless the start position is the 0N/A * same as the end position). 0N/A * The text position is zero-based. The inserted substring may be 0N/A * of a different length than the text it replaces. 0N/A * <p>Note that passing <code>null</code> or inconsistent 0N/A * parameters is invalid and will result in unspecified 0N/A * @param str the non-<code>null</code> text to use as 0N/A * @param start the start position 0N/A * @param end the end position 0N/A * @see java.awt.TextArea#insert 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>replaceRange(String, int, int)</code>. 0N/A * Returns the number of rows in the text area. 0N/A * @return the number of rows in the text area 0N/A * @see #setRows(int) 0N/A * @see #getColumns() 0N/A * Sets the number of rows for this text area. 0N/A * @param rows the number of rows 0N/A * @see #setColumns(int) 0N/A * @exception IllegalArgumentException if the value 0N/A * supplied for <code>rows</code> 0N/A * is less than <code>0</code> 0N/A * Returns the number of columns in this text area. 0N/A * @return the number of columns in the text area 0N/A * @see #setColumns(int) 0N/A * Sets the number of columns for this text area. 0N/A * @param columns the number of columns 0N/A * @see #getColumns() 0N/A * @see #setRows(int) 0N/A * @exception IllegalArgumentException if the value 0N/A * supplied for <code>columns</code> 0N/A * is less than <code>0</code> 0N/A * Returns an enumerated value that indicates which scroll bars 0N/A * the text area uses. 0N/A * The <code>TextArea</code> class defines four integer constants 0N/A * that are used to specify which scroll bars are available. 0N/A * <code>TextArea</code> has one constructor that gives the 0N/A * application discretion over scroll bars. 0N/A * @return an integer that indicates which scroll bars are used 0N/A * @see java.awt.TextArea#SCROLLBARS_BOTH 0N/A * @see java.awt.TextArea#SCROLLBARS_VERTICAL_ONLY 0N/A * @see java.awt.TextArea#SCROLLBARS_HORIZONTAL_ONLY 0N/A * @see java.awt.TextArea#SCROLLBARS_NONE 0N/A * @see java.awt.TextArea#TextArea(java.lang.String, int, int, int) 0N/A * Determines the preferred size of a text area with the specified 0N/A * number of rows and columns. 0N/A * @param rows the number of rows 0N/A * @param columns the number of columns 0N/A * @return the preferred dimensions required to display 0N/A * the text area with the specified 0N/A * number of rows and columns 0N/A * @see java.awt.Component#getPreferredSize 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>getPreferredSize(int, int)</code>. 0N/A * Determines the preferred size of this text area. 0N/A * @return the preferred dimensions needed for this text area 0N/A * @see java.awt.Component#getPreferredSize 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>getPreferredSize()</code>. 0N/A * Determines the minimum size of a text area with the specified 0N/A * number of rows and columns. 0N/A * @param rows the number of rows 0N/A * @param columns the number of columns 0N/A * @return the minimum dimensions required to display 0N/A * the text area with the specified 0N/A * number of rows and columns 0N/A * @see java.awt.Component#getMinimumSize 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>getMinimumSize(int, int)</code>. 0N/A * Determines the minimum size of this text area. 0N/A * @return the preferred dimensions needed for this text area 0N/A * @see java.awt.Component#getPreferredSize 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>getMinimumSize()</code>. 0N/A * Returns a string representing the state of this <code>TextArea</code>. 0N/A * This method is intended to be used only for debugging purposes, and the 0N/A * content and format of the returned string may vary between 0N/A * implementations. The returned string may be empty but may not be 0N/A * <code>null</code>. 0N/A * @return the parameter string of this text area 0N/A * Serialization support. 0N/A * The textArea Serialized Data Version. 0N/A * Read the ObjectInputStream. 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A // HeadlessException will be thrown by TextComponent's readObject 0N/A // Make sure the state we just read in for columns, rows, 0N/A // and scrollbarVisibility has legal values 0N/A// Accessibility support 0N/A * Returns the <code>AccessibleContext</code> associated with 0N/A * this <code>TextArea</code>. For text areas, the 0N/A * <code>AccessibleContext</code> takes the form of an 0N/A * <code>AccessibleAWTTextArea</code>. 0N/A * A new <code>AccessibleAWTTextArea</code> instance is created if necessary. 0N/A * @return an <code>AccessibleAWTTextArea</code> that serves as the 0N/A * <code>AccessibleContext</code> of this <code>TextArea</code> 0N/A * This class implements accessibility support for the 0N/A * <code>TextArea</code> class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to text area user-interface elements. 0N/A * JDK 1.3 serialVersionUID 0N/A * Gets the state set of this object. 0N/A * @return an instance of AccessibleStateSet describing the states 0N/A * @see AccessibleStateSet