2362N/A * Copyright (c) 1997, 2008, 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>JTextArea</code> is a multi-line area that displays plain text. 0N/A * It is intended to be a lightweight component that provides source 0N/A * compatibility with the <code>java.awt.TextArea</code> class where it can 0N/A * You can find information and examples of using all the text components in 0N/A * a section in <em>The Java Tutorial.</em> 0N/A * This component has capabilities not found in the 0N/A * <code>java.awt.TextArea</code> class. The superclass should be 0N/A * consulted for additional capabilities. 0N/A * Alternative multi-line text classes with 0N/A * more capabilities are <code>JTextPane</code> and <code>JEditorPane</code>. 0N/A * The <code>java.awt.TextArea</code> internally handles scrolling. 0N/A * <code>JTextArea</code> is different in that it doesn't manage scrolling, 0N/A * but implements the swing <code>Scrollable</code> interface. This allows it 0N/A * to be placed inside a <code>JScrollPane</code> if scrolling 0N/A * behavior is desired, and used directly if scrolling is not desired. 0N/A * The <code>java.awt.TextArea</code> has the ability to do line wrapping. 0N/A * This was controlled by the horizontal scrolling policy. Since 0N/A * scrolling is not done by <code>JTextArea</code> directly, backward 0N/A * compatibility must be provided another way. <code>JTextArea</code> has 0N/A * a bound property for line wrapping that controls whether or 0N/A * not it will wrap lines. By default, the line wrapping property 0N/A * is set to false (not wrapped). 0N/A * <code>java.awt.TextArea</code> has two properties <code>rows</code> 0N/A * and <code>columns</code> that are used to determine the preferred size. 0N/A * <code>JTextArea</code> uses these properties to indicate the 0N/A * preferred size of the viewport when placed inside a <code>JScrollPane</code> 0N/A * to match the functionality provided by <code>java.awt.TextArea</code>. 0N/A * <code>JTextArea</code> has a preferred size of what is needed to 0N/A * display all of the text, so that it functions properly inside of 0N/A * a <code>JScrollPane</code>. If the value for <code>rows</code> 0N/A * or <code>columns</code> is equal to zero, 0N/A * the preferred size along that axis is used for 0N/A * the viewport preferred size along the same axis. 0N/A * The <code>java.awt.TextArea</code> could be monitored for changes by adding 0N/A * a <code>TextListener</code> for <code>TextEvent</code>s. 0N/A * In the <code>JTextComponent</code> based 0N/A * components, changes are broadcasted from the model via a 0N/A * <code>DocumentEvent</code> to <code>DocumentListeners</code>. 0N/A * The <code>DocumentEvent</code> gives 0N/A * the location of the change and the kind of change if desired. 0N/A * The code fragment might look something like: 0N/A * DocumentListener myListener = ??; 0N/A * JTextArea myArea = ??; 0N/A * myArea.getDocument().addDocumentListener(myListener); 0N/A * <dt><b><font size=+1>Newlines</font></b> 0N/A * For a discussion on how newlines are handled, see 0N/A * <strong>Warning:</strong> Swing is not thread safe. For more 0N/A * information see <a 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * attribute: isContainer false 0N/A * description: A multi-line area that displays plain text. 0N/A * @author Timothy Prinzing 0N/A * @see #getUIClassID 0N/A * Constructs a new TextArea. A default model is set, the initial string 0N/A * Constructs a new TextArea with the specified text displayed. 0N/A * @param text the text to be displayed, or null 0N/A * Constructs a new empty TextArea with the specified number of 0N/A * rows and columns. A default model is created, and the initial 0N/A * @param rows the number of rows >= 0 0N/A * @param columns the number of columns >= 0 0N/A * @exception IllegalArgumentException if the rows or columns 0N/A * arguments are negative. 0N/A * Constructs a new TextArea with the specified text and number 0N/A * of rows and columns. A default model is created. 0N/A * @param text the text to be displayed, or null 0N/A * @param rows the number of rows >= 0 0N/A * @param columns the number of columns >= 0 0N/A * @exception IllegalArgumentException if the rows or columns 0N/A * arguments are negative. 0N/A * Constructs a new JTextArea with the given document model, and defaults 0N/A * for all of the other arguments (null, 0, 0). 0N/A * @param doc the model to use 0N/A * Constructs a new JTextArea with the specified number of rows 0N/A * and columns, and the given model. All of the constructors 0N/A * feed through this constructor. 0N/A * @param doc the model to use, or create a default one if null 0N/A * @param text the text to be displayed, null if none 0N/A * @param rows the number of rows >= 0 0N/A * @param columns the number of columns >= 0 0N/A * @exception IllegalArgumentException if the rows or columns 0N/A * arguments are negative. 0N/A "focusTraversalKeysForward",
0N/A "focusTraversalKeysBackward",
0N/A * Returns the class ID for the UI. 0N/A * @return the ID ("TextAreaUI") 0N/A * @see JComponent#getUIClassID 0N/A * @see UIDefaults#getUI 0N/A * Creates the default implementation of the model 0N/A * to be used at construction if one isn't explicitly 0N/A * given. A new instance of PlainDocument is returned. 0N/A * @return the default document model 0N/A * Sets the number of characters to expand tabs to. 0N/A * This will be multiplied by the maximum advance for 0N/A * variable width fonts. A PropertyChange event ("tabSize") is fired 0N/A * when the tab size changes. 0N/A * @param size number of characters to expand to 0N/A * description: the number of characters to expand tabs to 0N/A * Gets the number of characters used to expand tabs. If the document is 0N/A * null or doesn't have a tab setting, return a default of 8. 0N/A * @return the number of characters 0N/A * Sets the line-wrapping policy of the text area. If set 0N/A * to true the lines will be wrapped if they are too long 0N/A * to fit within the allocated width. If set to false, 0N/A * the lines will always be unwrapped. A <code>PropertyChange</code> 0N/A * event ("lineWrap") is fired when the policy is changed. 0N/A * By default this property is false. 0N/A * @param wrap indicates if lines should be wrapped 0N/A * description: should lines be wrapped 0N/A * Gets the line-wrapping policy of the text area. If set 0N/A * to true the lines will be wrapped if they are too long 0N/A * to fit within the allocated width. If set to false, 0N/A * the lines will always be unwrapped. 0N/A * @return if lines will be wrapped 0N/A * Sets the style of wrapping used if the text area is wrapping 0N/A * lines. If set to true the lines will be wrapped at word 0N/A * boundaries (whitespace) if they are too long 0N/A * to fit within the allocated width. If set to false, 0N/A * the lines will be wrapped at character boundaries. 0N/A * By default this property is false. 0N/A * @param word indicates if word boundaries should be used 0N/A * @see #getWrapStyleWord 0N/A * description: should wrapping occur at word boundaries 0N/A * Gets the style of wrapping used if the text area is wrapping 0N/A * lines. If set to true the lines will be wrapped at word 0N/A * boundaries (ie whitespace) if they are too long 0N/A * to fit within the allocated width. If set to false, 0N/A * the lines will be wrapped at character boundaries. 0N/A * @return if the wrap style should be word boundaries 0N/A * instead of character boundaries 0N/A * @see #setWrapStyleWord 0N/A * Translates an offset into the components text to a 0N/A * @param offset the offset >= 0 0N/A * @return the line number >= 0 0N/A * @exception BadLocationException thrown if the offset is 0N/A * less than zero or greater than the document length. 0N/A * Determines the number of lines contained in the area. 0N/A * @return the number of lines > 0 0N/A * Determines the offset of the start of the given line. 0N/A * @param line the line number to translate >= 0 0N/A * @return the offset >= 0 0N/A * @exception BadLocationException thrown if the line is 0N/A * less than zero or greater or equal to the number of 0N/A * lines contained in the document (as reported by 0N/A * Determines the offset of the end of the given line. 0N/A * @param line the line >= 0 0N/A * @return the offset >= 0 0N/A * @exception BadLocationException Thrown if the line is 0N/A * less than zero or greater or equal to the number of 0N/A * lines contained in the document (as reported by 0N/A // hide the implicit break at the end of the document 0N/A // --- java.awt.TextArea methods --------------------------------- 0N/A * Inserts the specified text at the specified position. Does nothing 0N/A * if the model is null or if the text is null or empty. 0N/A * @param str the text to insert 0N/A * @param pos the position at which to insert >= 0 0N/A * @exception IllegalArgumentException if pos is an 0N/A * invalid position in the model 0N/A * @see TextComponent#setText 0N/A * @see #replaceRange 0N/A * Appends the given text to the end of the document. Does nothing if 0N/A * the model is null or the string is null or empty. 0N/A * @param str the text to insert 0N/A * Replaces text from the indicated start to end position with the 0N/A * new text specified. Does nothing if the model is null. Simply 0N/A * does a delete if the new string is null or empty. 0N/A * @param str the text to use as the replacement 0N/A * @param start the start position >= 0 0N/A * @param end the end position >= start 0N/A * @exception IllegalArgumentException if part of the range is an 0N/A * invalid position in the model 0N/A * @see #replaceRange 0N/A * Returns the number of rows in the TextArea. 0N/A * @return the number of rows >= 0 0N/A * Sets the number of rows for this TextArea. Calls invalidate() after 0N/A * setting the new value. 0N/A * @param rows the number of rows >= 0 0N/A * @exception IllegalArgumentException if rows is less than 0 0N/A * description: the number of rows preferred for display 0N/A * Defines the meaning of the height of a row. This defaults to 0N/A * the height of the font. 0N/A * @return the height >= 1 0N/A * Returns the number of columns in the TextArea. 0N/A * @return number of columns >= 0 0N/A * Sets the number of columns for this TextArea. Does an invalidate() 0N/A * after setting the new value. 0N/A * @param columns the number of columns >= 0 0N/A * @exception IllegalArgumentException if columns is less than 0 0N/A * description: the number of columns preferred for display 0N/A * Gets column width. 0N/A * The meaning of what a column is can be considered a fairly weak 0N/A * notion for some fonts. This method is used to define the width 0N/A * of a column. By default this is defined to be the width of the 0N/A * character <em>m</em> for the font used. This method can be 0N/A * redefined to be some alternative amount. 0N/A * @return the column width >= 1 0N/A // --- Component methods ----------------------------------------- 0N/A * Returns the preferred size of the TextArea. This is the 0N/A * maximum of the size needed to display the text and the 0N/A * size requested for the viewport. 0N/A * Sets the current font. This removes cached row height and column 0N/A * width so the new font will be reflected, and calls revalidate(). 0N/A * @param f the font to use as the current font 0N/A * Returns a string representation of this JTextArea. This method 0N/A * 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 0N/A * be <code>null</code>. 0N/A * @return a string representation of this JTextArea. 0N/A // --- Scrollable methods ---------------------------------------- 0N/A * Returns true if a viewport should always force the width of this 0N/A * Scrollable to match the width of the viewport. This is implemented 0N/A * to return true if the line wrapping policy is true, and false 0N/A * if lines are not being wrapped. 0N/A * @return true if a viewport should force the Scrollables width 0N/A * Returns the preferred size of the viewport if this component 0N/A * is embedded in a JScrollPane. This uses the desired column 0N/A * and row settings if they have been set, otherwise the superclass 0N/A * @return The preferredSize of a JViewport whose view is this Scrollable. 0N/A * @see JViewport#getPreferredSize 0N/A * Components that display logical rows or columns should compute 0N/A * the scroll increment that will completely expose one new row 0N/A * or column, depending on the value of orientation. This is implemented 0N/A * to use the values returned by the <code>getRowHeight</code> and 0N/A * <code>getColumnWidth</code> methods. 0N/A * Scrolling containers, like JScrollPane, will use this method 0N/A * each time the user requests a unit scroll. 0N/A * @param visibleRect the view area visible within the viewport 0N/A * @param orientation Either SwingConstants.VERTICAL or 0N/A * SwingConstants.HORIZONTAL. 0N/A * @param direction Less than zero to scroll up/left, 0N/A * @return The "unit" increment for scrolling in the specified direction 0N/A * @exception IllegalArgumentException for an invalid orientation 0N/A * @see JScrollBar#setUnitIncrement 0N/A * @see #getRowHeight 0N/A * @see #getColumnWidth 0N/A * See readObject() and writeObject() in JComponent for more 0N/A * information about serialization in Swing. 0N/A// Accessibility support 0N/A * Gets the AccessibleContext associated with this JTextArea. 0N/A * For JTextAreas, the AccessibleContext takes the form of an 0N/A * AccessibleJTextArea. 0N/A * A new AccessibleJTextArea instance is created if necessary. 0N/A * @return an AccessibleJTextArea that serves as the 0N/A * AccessibleContext of this JTextArea 0N/A * This class implements accessibility support for the 0N/A * <code>JTextArea</code> class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to text area user-interface 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * Gets the state set of this object. 0N/A * @return an instance of AccessibleStateSet describing the states 0N/A * @see AccessibleStateSet 0N/A // --- variables -------------------------------------------------