3909N/A * Copyright (c) 1997, 2011, 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 * <code>JTextComponent</code> is the base class for swing text 0N/A * components. It tries to be compatible with the 0N/A * <code>java.awt.TextComponent</code> class 0N/A * where it can reasonably do so. Also provided are other services 0N/A * for additional flexibility (beyond the pluggable UI and bean 0N/A * You can find information on how to use the functionality 0N/A * this class provides in 0N/A * a section in <em>The Java Tutorial.</em> 0N/A * <dt><b><font size=+1>Caret Changes</font></b> 0N/A * The caret is a pluggable object in swing text components. 0N/A * Notification of changes to the caret position and the selection 0N/A * are sent to implementations of the <code>CaretListener</code> 0N/A * interface that have been registered with the text component. 0N/A * The UI will install a default caret unless a customized caret 0N/A * has been set. <br> 0N/A * By default the caret tracks all the document changes 0N/A * performed on the Event Dispatching Thread and updates it's position 0N/A * accordingly if an insertion occurs before or at the caret position 0N/A * or a removal occurs before the caret position. <code>DefaultCaret</code> 0N/A * tries to make itself visible which may lead to scrolling 0N/A * of a text component within <code>JScrollPane</code>. The default caret 0N/A * behavior can be changed by the {@link DefaultCaret#setUpdatePolicy} method. 0N/A * <b>Note</b>: Non-editable text components also have a caret though 0N/A * it may not be painted. 0N/A * <dt><b><font size=+1>Commands</font></b> 0N/A * Text components provide a number of commands that can be used 0N/A * to manipulate the component. This is essentially the way that 0N/A * the component expresses its capabilities. These are expressed 0N/A * in terms of the swing <code>Action</code> interface, 0N/A * using the <code>TextAction</code> implementation. 0N/A * The set of commands supported by the text component can be 0N/A * found with the {@link #getActions} method. These actions 0N/A * can be bound to key events, fired from buttons, etc. 0N/A * <dt><b><font size=+1>Text Input</font></b> 0N/A * The text components support flexible and internationalized text input, using 0N/A * keymaps and the input method framework, while maintaining compatibility with 0N/A * the AWT listener model. 0N/A * A {@link javax.swing.text.Keymap} lets an application bind key 0N/A * strokes to actions. 0N/A * In order to allow keymaps to be shared across multiple text components, they 0N/A * can use actions that extend <code>TextAction</code>. 0N/A * <code>TextAction</code> can determine which <code>JTextComponent</code> 0N/A * most recently has or had focus and therefore is the subject of 0N/A * the action (In the case that the <code>ActionEvent</code> 0N/A * sent to the action doesn't contain the target text component as its source). 0N/A * lets text components interact with input methods, separate software 0N/A * components that preprocess events to let users enter thousands of 0N/A * different characters using keyboards with far fewer keys. 0N/A * <code>JTextComponent</code> is an <em>active client</em> of 0N/A * the framework, so it implements the preferred user interface for interacting 0N/A * with input methods. As a consequence, some key events do not reach the text 0N/A * component because they are handled by an input method, and some text input 0N/A * reaches the text component as committed text within an {@link 0N/A * java.awt.event.InputMethodEvent} instead of as a key event. 0N/A * The complete text input is the combination of the characters in 0N/A * <code>keyTyped</code> key events and committed text in input method events. 0N/A * The AWT listener model lets applications attach event listeners to 0N/A * components in order to bind events to actions. Swing encourages the 0N/A * use of keymaps instead of listeners, but maintains compatibility 0N/A * with listeners by giving the listeners a chance to steal an event 0N/A * Keyboard event and input method events are handled in the following stages, 0N/A * with each stage capable of consuming the event: 0N/A * <table border=1 summary="Stages of keyboard and input method event handling"> 0N/A * <th id="stage"><p align="left">Stage</p></th> 0N/A * <th id="ke"><p align="left">KeyEvent</p></th> 0N/A * <th id="ime"><p align="left">InputMethodEvent</p></th></tr> 0N/A * <tr><td headers="stage">1. </td> 0N/A * <td headers="ke">input methods </td> 0N/A * <td headers="ime">(generated here)</td></tr> 0N/A * <tr><td headers="stage">2. </td> 0N/A * <td headers="ke">focus manager </td> 0N/A * <td headers="ime"></td> 0N/A * <td headers="stage">3. </td> 0N/A * <td headers="ke">registered key listeners</td> 0N/A * <td headers="ime">registered input method listeners</tr> 0N/A * <td headers="stage">4. </td> 0N/A * <td headers="ke"></td> 0N/A * <td headers="ime">input method handling in JTextComponent</tr> 0N/A * <td headers="stage">5. </td><td headers="ke ime" colspan=2>keymap handling using the current keymap</td></tr> 0N/A * <tr><td headers="stage">6. </td><td headers="ke">keyboard handling in JComponent (e.g. accelerators, component navigation, etc.)</td> 0N/A * <td headers="ime"></td></tr> 0N/A * To maintain compatibility with applications that listen to key 0N/A * events but are not aware of input method events, the input 0N/A * method handling in stage 4 provides a compatibility mode for 0N/A * components that do not process input method events. For these 0N/A * components, the committed text is converted to keyTyped key events 0N/A * and processed in the key event pipeline starting at stage 3 0N/A * instead of in the input method event pipeline. 0N/A * By default the component will create a keymap (named <b>DEFAULT_KEYMAP</b>) 0N/A * that is shared by all JTextComponent instances as the default keymap. 0N/A * Typically a look-and-feel implementation will install a different keymap 0N/A * that resolves to the default keymap for those bindings not found in the 0N/A * different keymap. The minimal bindings include: 0N/A * <li>inserting content into the editor for the 0N/A * <li>removing content with the backspace and del 0N/A * <li>caret movement forward and backward 0N/A * The text components have a model-view split. A text component pulls 0N/A * together the objects used to represent the model, view, and controller. 0N/A * The text document model may be shared by other views which act as observers 0N/A * of the model (e.g. a document may be shared by multiple components). 0N/A * <p align=center><img src="doc-files/editor.gif" alt="Diagram showing interaction between Controller, Document, events, and ViewFactory" 0N/A * HEIGHT=358 WIDTH=587></p> 0N/A * The model is defined by the {@link Document} interface. 0N/A * This is intended to provide a flexible text storage mechanism 0N/A * that tracks change during edits and can be extended to more sophisticated 0N/A * models. The model interfaces are meant to capture the capabilities of 0N/A * expression given by SGML, a system used to express a wide variety of 0N/A * Each modification to the document causes notification of the 0N/A * details of the change to be sent to all observers in the form of a 0N/A * {@link DocumentEvent} which allows the views to stay up to date with the model. 0N/A * This event is sent to observers that have implemented the 0N/A * {@link DocumentListener} 0N/A * interface and registered interest with the model being observed. 0N/A * <dt><b><font size=+1>Location Information</font></b> 0N/A * The capability of determining the location of text in 0N/A * the view is provided. There are two methods, {@link #modelToView} 0N/A * and {@link #viewToModel} for determining this information. 0N/A * Support for an edit history mechanism is provided to allow 0N/A * undo/redo operations. The text component does not itself 0N/A * provide the history buffer by default, but does provide 0N/A * the <code>UndoableEdit</code> records that can be used in conjunction 0N/A * with a history buffer to provide the undo/redo support. 0N/A * The support is provided by the Document model, which allows 0N/A * one to attach UndoableEditListener implementations. 0N/A * <dt><b><font size=+1>Thread Safety</font></b> 0N/A * The swing text components provide some support of thread 0N/A * safe operations. Because of the high level of configurability 0N/A * of the text components, it is possible to circumvent the 0N/A * protection provided. The protection primarily comes from 0N/A * the model, so the documentation of <code>AbstractDocument</code> 0N/A * describes the assumptions of the protection provided. 0N/A * The methods that are safe to call asynchronously are marked 0N/A * <dt><b><font size=+1>Newlines</font></b> 0N/A * For a discussion on how newlines are handled, see 0N/A * <dt><b><font size=+1>Printing support</font></b> 0N/A * Several {@link #print print} methods are provided for basic 0N/A * document printing. If more advanced printing is needed, use the 0N/A * {@link #getPrintable} method. 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 * @author Timothy Prinzing 0N/A * @author Igor Kushnirskiy (printing support) 0N/A * @see DocumentEvent 0N/A * @see DocumentListener 0N/A * @see CaretListener 0N/A * Creates a new <code>JTextComponent</code>. 0N/A * Listeners for caret events are established, and the pluggable 0N/A * UI installed. The component is marked as editable. No layout manager 0N/A * is used, because layout is managed by the view subsystem of text. 0N/A * The document model is set to <code>null</code>. 0N/A // enable InputMethodEvent for on-the-spot pre-editing 0N/A * Fetches the user-interface factory for this text-oriented editor. 0N/A * @return the factory 0N/A * Sets the user-interface factory for this text-oriented editor. 0N/A * @param ui the factory 0N/A * Reloads the pluggable UI. The key used to fetch the 0N/A * new interface is <code>getUIClassID()</code>. The type of 0N/A * the UI is <code>TextUI</code>. <code>invalidate</code> 0N/A * is called after setting the UI. 0N/A * Adds a caret listener for notification of any changes 0N/A * @param listener the listener to be added 0N/A * @see javax.swing.event.CaretEvent 0N/A * Removes a caret listener. 0N/A * @param listener the listener to be removed 0N/A * @see javax.swing.event.CaretEvent 0N/A * Returns an array of all the caret listeners 0N/A * registered on this text component. 0N/A * @return all of this component's <code>CaretListener</code>s 0N/A * array if no caret listeners are currently registered 0N/A * @see #addCaretListener 0N/A * @see #removeCaretListener 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. The event instance 0N/A * is lazily created using the parameters passed into 0N/A * the fire method. The listener list is processed in a 0N/A * last-to-first manner. 0N/A * @param e the event 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A * Associates the editor with a text document. 0N/A * The currently registered factory is used to build a view for 0N/A * the document, which gets displayed by the editor after revalidation. 0N/A * A PropertyChange event ("document") is propagated to each listener. 0N/A * description: the text document model 0N/A * aquire a read lock on the old model to prevent notification of 0N/A * mutations while we disconnecting the old model. 0N/A // Set the document's run direction property to match the 0N/A // component's ComponentOrientation property. 0N/A * Fetches the model associated with the editor. This is 0N/A * primarily for the UI to get at the minimal amount of 0N/A * state required to be a text editor. Subclasses will 0N/A * return the actual type of the model which will typically 0N/A * be something that extends Document. 0N/A // Override of Component.setComponentOrientation 0N/A // Set the document's run direction property to match the 0N/A // ComponentOrientation property. 0N/A * Fetches the command list for the editor. This is 0N/A * the list of commands supported by the plugged-in UI 0N/A * augmented by the collection of commands that the 0N/A * editor itself supports. These are useful for binding 0N/A * to events, such as in a keymap. 0N/A * @return the command list 0N/A * Sets margin space between the text component's border 0N/A * and its text. The text component's default <code>Border</code> 0N/A * object will use this value to create the proper margin. 0N/A * However, if a non-default border is set on the text component, 0N/A * it is that <code>Border</code> object's responsibility to create the 0N/A * appropriate margin space (else this property will effectively 0N/A * be ignored). This causes a redraw of the component. 0N/A * A PropertyChange event ("margin") is sent to all listeners. 0N/A * @param m the space between the border and the text 0N/A * description: desired space between the border and text area 0N/A * Returns the margin between the text component's border and 0N/A * @return the margin 0N/A * Sets the <code>NavigationFilter</code>. <code>NavigationFilter</code> 0N/A * is used by <code>DefaultCaret</code> and the default cursor movement 0N/A * actions as a way to restrict the cursor movement. 0N/A * Returns the <code>NavigationFilter</code>. <code>NavigationFilter</code> 0N/A * is used by <code>DefaultCaret</code> and the default cursor movement 0N/A * actions as a way to restrict the cursor movement. A null return value 0N/A * implies the cursor movement and selection should not be restricted. 0N/A * @return the NavigationFilter 0N/A * Fetches the caret that allows text-oriented navigation over 0N/A * Sets the caret to be used. By default this will be set 0N/A * by the UI that gets installed. This can be changed to 0N/A * a custom caret if desired. Setting the caret results in a 0N/A * PropertyChange event ("caret") being fired. 0N/A * @param c the caret 0N/A * Fetches the object responsible for making highlights. 0N/A * @return the highlighter 0N/A * Sets the highlighter to be used. By default this will be set 0N/A * by the UI that gets installed. This can be changed to 0N/A * a custom highlighter if desired. The highlighter can be set to 0N/A * <code>null</code> to disable it. 0N/A * A PropertyChange event ("highlighter") is fired 0N/A * when a new highlighter is installed. 0N/A * @param h the highlighter 0N/A * @see #getHighlighter 0N/A * description: object responsible for background highlights 0N/A * Sets the keymap to use for binding events to 0N/A * actions. Setting to <code>null</code> effectively disables 0N/A * A PropertyChange event ("keymap") is fired when a new keymap 0N/A * @param map the keymap 0N/A * description: set of key event to action bindings to use 0N/A * Turns on or off automatic drag handling. In order to enable automatic 0N/A * drag handling, this property should be set to {@code true}, and the 0N/A * component's {@code TransferHandler} needs to be {@code non-null}. 0N/A * The default value of the {@code dragEnabled} property is {@code false}. 0N/A * The job of honoring this property, and recognizing a user drag gesture, 0N/A * lies with the look and feel implementation, and in particular, the component's 0N/A * {@code TextUI}. When automatic drag handling is enabled, most look and 0N/A * feels (including those that subclass {@code BasicLookAndFeel}) begin a 0N/A * drag and drop operation whenever the user presses the mouse button over 0N/A * a selection and then moves the mouse a few pixels. Setting this property to 0N/A * {@code true} can therefore have a subtle effect on how selections behave. 0N/A * If a look and feel is used that ignores this property, you can still 0N/A * begin a drag and drop operation by calling {@code exportAsDrag} on the 0N/A * component's {@code TransferHandler}. 0N/A * @param b whether or not to enable automatic drag handling 0N/A * @exception HeadlessException if 0N/A * <code>b</code> is <code>true</code> and 0N/A * <code>GraphicsEnvironment.isHeadless()</code> 0N/A * returns <code>true</code> 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * @see #getDragEnabled 0N/A * @see #setTransferHandler 0N/A * @see TransferHandler 0N/A * description: determines whether automatic drag handling is enabled 0N/A * Returns whether or not automatic drag handling is enabled. 0N/A * @return the value of the {@code dragEnabled} property 0N/A * @see #setDragEnabled 0N/A * Sets the drop mode for this component. For backward compatibility, 0N/A * the default for this property is <code>DropMode.USE_SELECTION</code>. 0N/A * Usage of <code>DropMode.INSERT</code> is recommended, however, 0N/A * for an improved user experience. It offers similar behavior of dropping 0N/A * between text locations, but does so without affecting the actual text 0N/A * selection and caret location. 0N/A * <code>JTextComponents</code> support the following drop modes: 0N/A * <li><code>DropMode.USE_SELECTION</code></li> 0N/A * <li><code>DropMode.INSERT</code></li> 0N/A * The drop mode is only meaningful if this component has a 0N/A * <code>TransferHandler</code> that accepts drops. 0N/A * @param dropMode the drop mode to use 0N/A * @throws IllegalArgumentException if the drop mode is unsupported 0N/A * or <code>null</code> 0N/A * @see #getDropLocation 0N/A * @see #setTransferHandler 0N/A * @see javax.swing.TransferHandler 0N/A * Returns the drop mode for this component. 0N/A * @return the drop mode for this component 0N/A * Calculates a drop location in this component, representing where a 0N/A * drop at the given point should insert data. 0N/A * Note: This method is meant to override 0N/A * <code>JComponent.dropLocationForPoint()</code>, which is package-private 0N/A * in javax.swing. <code>TransferHandler</code> will detect text components 0N/A * and call this method instead via reflection. It's name should therefore 0N/A * @param p the point to calculate a drop location for 0N/A * @return the drop location, or <code>null</code> 0N/A // viewToModel currently returns null for some HTML content 0N/A // when the point is within the component's top inset 0N/A * Called to set or clear the drop location during a DnD operation. 0N/A * In some cases, the component may need to use it's internal selection 0N/A * temporarily to indicate the drop location. To help facilitate this, 0N/A * this method returns and accepts as a parameter a state object. 0N/A * This state object can be used to store, and later restore, the selection 0N/A * state. Whatever this method returns will be passed back to it in 0N/A * future calls, as the state parameter. If it wants the DnD system to 0N/A * continue storing the same state, it must pass it back every time. 0N/A * Here's how this is used: 0N/A * Let's say that on the first call to this method the component decides 0N/A * to save some state (because it is about to use the selection to show 0N/A * a drop index). It can return a state object to the caller encapsulating 0N/A * any saved selection state. On a second call, let's say the drop location 0N/A * is being changed to something else. The component doesn't need to 0N/A * restore anything yet, so it simply passes back the same state object 0N/A * to have the DnD system continue storing it. Finally, let's say this 0N/A * method is messaged with <code>null</code>. This means DnD 0N/A * is finished with this component for now, meaning it should restore 0N/A * state. At this point, it can use the state parameter to restore 0N/A * said state, and of course return <code>null</code> since there's 0N/A * no longer anything to store. 0N/A * Note: This method is meant to override 0N/A * <code>JComponent.setDropLocation()</code>, which is package-private 0N/A * in javax.swing. <code>TransferHandler</code> will detect text components 0N/A * and call this method instead via reflection. It's name should therefore 0N/A * @param location the drop location (as calculated by 0N/A * <code>dropLocationForPoint</code>) or <code>null</code> 0N/A * if there's no longer a valid drop location 0N/A * @param state the state object saved earlier for this component, 0N/A * or <code>null</code> 0N/A * @param forDrop whether or not the method is being called because an 0N/A * actual drop occurred 0N/A * @return any saved state for this component, or <code>null</code> if none 0N/A * This object represents the state saved earlier. 0N/A * If the caret is a DefaultCaret it will be 0N/A * an Object array containing, in order: 0N/A * - the saved caret mark (Integer) 0N/A * - the saved caret dot (Integer) 0N/A * - the saved caret visibility (Boolean) 0N/A * - the saved mark bias (Position.Bias) 0N/A * - the saved dot bias (Position.Bias) 0N/A * If the caret is not a DefaultCaret it will 0N/A * be similar, but will not contain the dot 0N/A * Returns the location that this component should visually indicate 0N/A * as the drop location during a DnD operation over the component, 0N/A * or {@code null} if no location is to currently be shown. 0N/A * This method is not meant for querying the drop location 0N/A * from a {@code TransferHandler}, as the drop location is only 0N/A * set after the {@code TransferHandler}'s <code>canImport</code> 0N/A * has returned and has allowed for the location to be shown. 0N/A * When this property changes, a property change event with 0N/A * name "dropLocation" is fired by the component. 0N/A * @return the drop location 0N/A * @see TransferHandler#canImport(TransferHandler.TransferSupport) 0N/A * Updates the <code>InputMap</code>s in response to a 0N/A * <code>Keymap</code> change. 0N/A * @param oldKm the old <code>Keymap</code> 0N/A * @param newKm the new <code>Keymap</code> 0N/A // Locate the current KeymapWrapper. 0N/A // Found it, tweak the InputMap that points to it, as well 0N/A // as anything it points to. 0N/A // Couldn't find it. 0N/A // Set the parent of WHEN_FOCUSED InputMap to be the new one. 0N/A // Do the same thing with the ActionMap 0N/A // Found it, tweak the Actionap that points to it, as well 0N/A // as anything it points to. 0N/A // Couldn't find it. 0N/A // Set the parent of ActionMap to be the new one. 0N/A * Fetches the keymap currently active in this text 0N/A * @return the keymap 0N/A * Adds a new keymap into the keymap hierarchy. Keymap bindings 0N/A * resolve from bottom up so an attribute specified in a child 0N/A * will override an attribute specified in the parent. 0N/A * @param nm the name of the keymap (must be unique within the 0N/A * collection of named keymaps in the document); the name may 0N/A * be <code>null</code> if the keymap is unnamed, 0N/A * but the caller is responsible for managing the reference 0N/A * returned as an unnamed keymap can't 0N/A * be fetched by name 0N/A * @param parent the parent keymap; this may be <code>null</code> if 0N/A * unspecified bindings need not be resolved in some other keymap 0N/A * @return the keymap 0N/A // add a named keymap, a class of bindings 0N/A * Removes a named keymap previously added to the document. Keymaps 0N/A * with <code>null</code> names may not be removed in this way. 0N/A * @param nm the name of the keymap to remove 0N/A * @return the keymap that was removed 0N/A * Fetches a named keymap previously added to the document. 0N/A * This does not work with <code>null</code>-named keymaps. 0N/A * @param nm the name of the keymap 0N/A * @return the keymap 0N/A //initialize default keymap 0N/A * Binding record for creating key bindings. 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 * The name of the action for the key. 0N/A * Creates a new key binding. 0N/A * @param key the key 0N/A * @param actionName the name of the action for the key 0N/A * Loads a keymap with a bunch of 0N/A * bindings. This can be used to take a static table of 0N/A * definitions and load them into some keymap. The following 0N/A * example illustrates an example of binding some keys to 0N/A * the cut, copy, and paste actions associated with a 0N/A * JTextComponent. A code fragment to accomplish 0N/A * this might look as follows: 0N/A * static final JTextComponent.KeyBinding[] defaultBindings = { 0N/A * new JTextComponent.KeyBinding( 0N/A * KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), 0N/A * DefaultEditorKit.copyAction), 0N/A * new JTextComponent.KeyBinding( 0N/A * KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), 0N/A * DefaultEditorKit.pasteAction), 0N/A * new JTextComponent.KeyBinding( 0N/A * KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK), 0N/A * DefaultEditorKit.cutAction), 0N/A * JTextComponent c = new JTextPane(); 0N/A * Keymap k = c.getKeymap(); 0N/A * JTextComponent.loadKeymap(k, defaultBindings, c.getActions()); 0N/A * The sets of bindings and actions may be empty but must be 0N/A * non-<code>null</code>. 0N/A * @param map the keymap 0N/A * @param bindings the bindings 0N/A * @param actions the set of actions 0N/A * Returns true if <code>klass</code> is NOT a JTextComponent and it or 0N/A * one of its superclasses (stoping at JTextComponent) overrides 0N/A * <code>processInputMethodEvent</code>. It is assumed this will be 0N/A * invoked from within a <code>doPrivileged</code>, and it is also 0N/A * assumed <code>klass</code> extends <code>JTextComponent</code>. 0N/A // If our superclass has overriden it, then by definition klass 0N/A // klass's superclass didn't override it, check for an override in 0N/A * Fetches the current color used to render the 0N/A * Sets the current color used to render the caret. 0N/A * Setting to <code>null</code> effectively restores the default color. 0N/A * Setting the color results in a PropertyChange event ("caretColor") 0N/A * @param c the color 0N/A * @see #getCaretColor 0N/A * description: the color used to render the caret 0N/A * Fetches the current color used to render the 0N/A * Sets the current color used to render the selection. 0N/A * Setting the color to <code>null</code> is the same as setting 0N/A * <code>Color.white</code>. Setting the color results in a 0N/A * PropertyChange event ("selectionColor"). 0N/A * @param c the color 0N/A * @see #getSelectionColor 0N/A * description: color used to render selection background 0N/A * Fetches the current color used to render the 0N/A * Sets the current color used to render the selected text. 0N/A * Setting the color to <code>null</code> is the same as 0N/A * <code>Color.black</code>. Setting the color results in a 0N/A * PropertyChange event ("selectedTextColor") being fired. 0N/A * @param c the color 0N/A * @see #getSelectedTextColor 0N/A * description: color used to render selected text 0N/A * Fetches the current color used to render the 0N/A * Sets the current color used to render the 0N/A * disabled text. Setting the color fires off a 0N/A * PropertyChange event ("disabledTextColor"). 0N/A * @param c the color 0N/A * @see #getDisabledTextColor 0N/A * description: color used to render disabled text 0N/A * Replaces the currently selected content with new content 0N/A * represented by the given string. If there is no selection 0N/A * this amounts to an insert of the given text. If there 0N/A * is no replacement text this amounts to a removal of the 0N/A * current selection. 0N/A * This is the method that is used by the default implementation 0N/A * of the action for inserting content that gets bound to the 0N/A * @param content the content to replace the selection with 0N/A * Fetches a portion of the text represented by the 0N/A * component. Returns an empty string if length is 0. 0N/A * @param offs the offset >= 0 0N/A * @param len the length >= 0 0N/A * @exception BadLocationException if the offset or length are invalid 0N/A * Converts the given location in the model to a place in 0N/A * the view coordinate system. 0N/A * The component must have a positive size for 0N/A * this translation to be computed (i.e. layout cannot 0N/A * be computed until the component has been sized). The 0N/A * component does not have to be visible or painted. 0N/A * @param pos the position >= 0 0N/A * @return the coordinates as a rectangle, with (r.x, r.y) as the location 0N/A * in the coordinate system, or null if the component does 0N/A * not yet have a positive size. 0N/A * @exception BadLocationException if the given position does not 0N/A * represent a valid location in the associated document 0N/A * @see TextUI#modelToView 0N/A * Converts the given place in the view coordinate system 0N/A * to the nearest representative location in the model. 0N/A * The component must have a positive size for 0N/A * this translation to be computed (i.e. layout cannot 0N/A * be computed until the component has been sized). The 0N/A * component does not have to be visible or painted. 0N/A * @param pt the location in the view to translate 0N/A * @return the offset >= 0 from the start of the document, 0N/A * or -1 if the component does not yet have a positive 0N/A * @see TextUI#viewToModel 0N/A * Transfers the currently selected range in the associated 0N/A * text model to the system clipboard, removing the contents 0N/A * from the model. The current selection is reset. Does nothing 0N/A * for <code>null</code> selections. 0N/A * @see java.awt.Toolkit#getSystemClipboard 0N/A * @see java.awt.datatransfer.Clipboard 0N/A * Transfers the currently selected range in the associated 0N/A * text model to the system clipboard, leaving the contents 0N/A * in the text model. The current selection remains intact. 0N/A * Does nothing for <code>null</code> selections. 0N/A * @see java.awt.Toolkit#getSystemClipboard 0N/A * @see java.awt.datatransfer.Clipboard 0N/A * Transfers the contents of the system clipboard into the 0N/A * associated text model. If there is a selection in the 0N/A * associated view, it is replaced with the contents of the 0N/A * clipboard. If there is no selection, the clipboard contents 0N/A * are inserted in front of the current insert position in 0N/A * the associated view. If the clipboard is empty, does nothing. 0N/A * @see #replaceSelection 0N/A * @see java.awt.Toolkit#getSystemClipboard 0N/A * @see java.awt.datatransfer.Clipboard 0N/A * This is a conveniance method that is only useful for 0N/A * <code>cut</code>, <code>copy</code> and <code>paste</code>. If 0N/A * an <code>Action</code> with the name <code>name</code> does not 0N/A * exist in the <code>ActionMap</code>, this will attemp to install a 0N/A * <code>TransferHandler</code> and then use <code>altAction</code>. 0N/A * If the current <code>TransferHandler</code> is null, this will 0N/A * install a new one. 0N/A * Moves the caret to a new position, leaving behind a mark 0N/A * defined by the last time <code>setCaretPosition</code> was 0N/A * called. This forms a selection. 0N/A * If the document is <code>null</code>, does nothing. The position 0N/A * must be between 0 and the length of the component's text or else 0N/A * an exception is thrown. 0N/A * @param pos the position 0N/A * @exception IllegalArgumentException if the value supplied 0N/A * for <code>position</code> is less than zero or greater 0N/A * than the component's text length 0N/A * @see #setCaretPosition 0N/A * The bound property name for the focus accelerator. 0N/A * Sets the key accelerator that will cause the receiving text 0N/A * component to get the focus. The accelerator will be the 0N/A * key combination of the <em>alt</em> key and the character 0N/A * given (converted to upper case). By default, there is no focus 0N/A * accelerator key. Any previous key accelerator setting will be 0N/A * superseded. A '\0' key setting will be registered, and has the 0N/A * effect of turning off the focus accelerator. When the new key 0N/A * is set, a PropertyChange event (FOCUS_ACCELERATOR_KEY) will be fired. 0N/A * @param aKey the key 0N/A * @see #getFocusAccelerator 0N/A * description: accelerator character used to grab focus 0N/A // Fix for 4341002: value of FOCUS_ACCELERATOR_KEY is wrong. 0N/A // So we fire both FOCUS_ACCELERATOR_KEY, for compatibility, 0N/A // and the correct event here. 0N/A * Returns the key accelerator that will cause the receiving 0N/A * text component to get the focus. Return '\0' if no focus 0N/A * accelerator has been set. 0N/A * Initializes from a stream. This creates a 0N/A * model of the type appropriate for the component 0N/A * and initializes the model from the stream. 0N/A * By default this will load the model as plain 0N/A * text. Previous contents of the model are discarded. 0N/A * @param in the stream to read from 0N/A * @param desc an object describing the stream; this 0N/A * might be a string, a File, a URL, etc. Some kinds 0N/A * of documents (such as html for example) might be 0N/A * able to make use of this information; if non-<code>null</code>, 0N/A * it is added as a property of the document 0N/A * @exception IOException as thrown by the stream being 0N/A * used to initialize 0N/A * @see EditorKit#createDefaultDocument 0N/A * @see PlainDocument 0N/A * Stores the contents of the model into the given 0N/A * stream. By default this will store the model as plain 0N/A * @param out the output stream 0N/A * @exception IOException on any I/O error 0N/A // --- java.awt.TextComponent methods ------------------------ 0N/A * Sets the position of the text insertion caret for the 0N/A * <code>TextComponent</code>. Note that the caret tracks change, 0N/A * so this may move if the underlying text of the component is changed. 0N/A * If the document is <code>null</code>, does nothing. The position 0N/A * must be between 0 and the length of the component's text or else 0N/A * an exception is thrown. 0N/A * @param position the position 0N/A * @exception IllegalArgumentException if the value supplied 0N/A * for <code>position</code> is less than zero or greater 0N/A * than the component's text length 0N/A * description: the caret position 0N/A * Returns the position of the text insertion caret for the 0N/A * @return the position of the text insertion caret for the 0N/A * text component >= 0 0N/A * Sets the text of this <code>TextComponent</code> 0N/A * to the specified text. If the text is <code>null</code> 0N/A * or empty, has the effect of simply deleting the old text. 0N/A * When text has been inserted, the resulting caret location 0N/A * is determined by the implementation of the caret class. 0N/A * Note that text is not a bound property, so no <code>PropertyChangeEvent 0N/A * </code> is fired when it changes. To listen for changes to the text, 0N/A * use <code>DocumentListener</code>. 0N/A * @param t the new text to be set 0N/A * description: the text of this component 0N/A * Returns the text contained in this <code>TextComponent</code>. 0N/A * If the underlying document is <code>null</code>, 0N/A * will give a <code>NullPointerException</code>. 0N/A * Note that text is not a bound property, so no <code>PropertyChangeEvent 0N/A * </code> is fired when it changes. To listen for changes to the text, 0N/A * use <code>DocumentListener</code>. 0N/A * @exception NullPointerException if the document is <code>null</code> 0N/A * Returns the selected text contained in this 0N/A * <code>TextComponent</code>. If the selection is 0N/A * <code>null</code> or the document empty, returns <code>null</code>. 0N/A * @exception IllegalArgumentException if the selection doesn't 0N/A * have a valid mapping into the document for some reason 0N/A * Returns the boolean indicating whether this 0N/A * <code>TextComponent</code> is editable or not. 0N/A * @return the boolean value 0N/A * Sets the specified boolean to indicate whether or not this 0N/A * <code>TextComponent</code> should be editable. 0N/A * A PropertyChange event ("editable") is fired when the 0N/A * @param b the boolean to be set 0N/A * description: specifies if the text can be edited 0N/A * Returns the selected text's start position. Return 0 for an 0N/A * empty document, or the value of dot if no selection. 0N/A * @return the start position >= 0 0N/A * Sets the selection start to the specified position. The new 0N/A * starting point is constrained to be before or at the current 0N/A * This is available for backward compatibility to code 0N/A * that called this method on <code>java.awt.TextComponent</code>. 0N/A * This is implemented to forward to the <code>Caret</code> 0N/A * implementation which is where the actual selection is maintained. 0N/A * @param selectionStart the start position of the text >= 0 0N/A * description: starting location of the selection. 0N/A /* Route through select method to enforce consistent policy 0N/A * between selectionStart and selectionEnd. 0N/A * Returns the selected text's end position. Return 0 if the document 0N/A * is empty, or the value of dot if there is no selection. 0N/A * @return the end position >= 0 0N/A * Sets the selection end to the specified position. The new 0N/A * end point is constrained to be at or after the current 0N/A * This is available for backward compatibility to code 0N/A * that called this method on <code>java.awt.TextComponent</code>. 0N/A * This is implemented to forward to the <code>Caret</code> 0N/A * implementation which is where the actual selection is maintained. 0N/A * @param selectionEnd the end position of the text >= 0 0N/A * description: ending location of the selection. 0N/A /* Route through select method to enforce consistent policy 0N/A * between selectionStart and selectionEnd. 0N/A * Selects the text between the specified start and end positions. 0N/A * This method sets the start and end positions of the 0N/A * selected text, enforcing the restriction that the start position 0N/A * must be greater than or equal to zero. The end position must be 0N/A * greater than or equal to the start position, and less than or 0N/A * equal to the length of the text component's text. 0N/A * If the caller supplies values that are inconsistent or out of 0N/A * bounds, the method enforces these constraints silently, and 0N/A * without failure. Specifically, if the start position or end 0N/A * position is greater than the length of the text, it is reset to 0N/A * equal the text length. If the start position is less than zero, 0N/A * it is reset to zero, and if the end position is less than the 0N/A * start position, it is reset to the start position. 0N/A * This call is provided for backward compatibility. 0N/A * It is routed to a call to <code>setCaretPosition</code> 0N/A * followed by a call to <code>moveCaretPosition</code>. 0N/A * The preferred way to manage selection is by calling 0N/A * those methods directly. 0N/A * @param selectionStart the start position of the text 0N/A * @param selectionEnd the end position of the text 0N/A * @see #setCaretPosition 0N/A * @see #moveCaretPosition 0N/A // argument adjustment done by java.awt.TextComponent 0N/A * Selects all the text in the <code>TextComponent</code>. 0N/A * Does nothing on a <code>null</code> or empty document. 0N/A // --- Tooltip Methods --------------------------------------------- 0N/A * Returns the string to be used as the tooltip for <code>event</code>. 0N/A * This will return one of: 0N/A * <li>If <code>setToolTipText</code> has been invoked with a 0N/A * non-<code>null</code> 0N/A * value, it will be returned, otherwise 0N/A * <li>The value from invoking <code>getToolTipText</code> on 0N/A * the UI will be returned. 0N/A * By default <code>JTextComponent</code> does not register 0N/A * itself with the <code>ToolTipManager</code>. 0N/A * This means that tooltips will NOT be shown from the 0N/A * <code>TextUI</code> unless <code>registerComponent</code> has 0N/A * been invoked on the <code>ToolTipManager</code>. 0N/A * @param event the event in question 0N/A * @return the string to be used as the tooltip for <code>event</code> 0N/A * @see javax.swing.JComponent#setToolTipText 0N/A * @see javax.swing.plaf.TextUI#getToolTipText 0N/A * @see javax.swing.ToolTipManager#registerComponent 0N/A // --- Scrollable methods --------------------------------------------- 0N/A * Returns the preferred size of the viewport for a view component. 0N/A * This is implemented to do the default behavior of returning 0N/A * the preferred size of the component. 0N/A * @return the <code>preferredSize</code> of a <code>JViewport</code> 0N/A * whose view is this <code>Scrollable</code> 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. Ideally, 0N/A * components should handle a partially exposed row or column by 0N/A * returning the distance required to completely expose the item. 0N/A * The default implementation of this is to simply return 10% of 0N/A * the visible area. Subclasses are likely to be able to provide 0N/A * a much more reasonable value. 0N/A * @param visibleRect the view area visible within the viewport 0N/A * @param orientation either <code>SwingConstants.VERTICAL</code> or 0N/A * <code>SwingConstants.HORIZONTAL</code> 0N/A * @param direction less than zero to scroll up/left, greater than 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 * Components that display logical rows or columns should compute 0N/A * the scroll increment that will completely expose one block 0N/A * of rows or columns, depending on the value of orientation. 0N/A * The default implementation of this is to simply return the visible 0N/A * area. Subclasses will likely be able to provide a much more 0N/A * @param visibleRect the view area visible within the viewport 0N/A * @param orientation either <code>SwingConstants.VERTICAL</code> or 0N/A * <code>SwingConstants.HORIZONTAL</code> 0N/A * @param direction less than zero to scroll up/left, greater than zero 0N/A * @return the "block" increment for scrolling in the specified direction 0N/A * @exception IllegalArgumentException for an invalid orientation 0N/A * @see JScrollBar#setBlockIncrement 0N/A * Returns true if a viewport should always force the width of this 0N/A * <code>Scrollable</code> to match the width of the viewport. 0N/A * For example a normal text view that supported line wrapping 0N/A * would return true here, since it would be undesirable for 0N/A * wrapped lines to disappear beyond the right 0N/A * edge of the viewport. Note that returning true for a 0N/A * <code>Scrollable</code> whose ancestor is a <code>JScrollPane</code> 0N/A * effectively disables horizontal scrolling. 0N/A * Scrolling containers, like <code>JViewport</code>, 0N/A * will use this method each time they are validated. 0N/A * @return true if a viewport should force the <code>Scrollable</code>s 0N/A * width to match its own 0N/A * Returns true if a viewport should always force the height of this 0N/A * <code>Scrollable</code> to match the height of the viewport. 0N/A * For example a columnar text view that flowed text in left to 0N/A * right columns could effectively disable vertical scrolling by 0N/A * returning true here. 0N/A * Scrolling containers, like <code>JViewport</code>, 0N/A * will use this method each time they are validated. 0N/A * @return true if a viewport should force the Scrollables height 0N/A * A convenience print method that displays a print dialog, and then 0N/A * prints this {@code JTextComponent} in <i>interactive</i> mode with no 0N/A * header or footer text. Note: this method 0N/A * blocks until printing is done. 0N/A * Note: In <i>headless</i> mode, no dialogs will be shown. 0N/A * <p> This method calls the full featured 0N/A * {@link #print(MessageFormat, MessageFormat, boolean, PrintService, PrintRequestAttributeSet, boolean) 0N/A * print} method to perform printing. 0N/A * @return {@code true}, unless printing is canceled by the user 0N/A * @throws PrinterException if an error in the print system causes the job 0N/A * @throws SecurityException if this thread is not allowed to 0N/A * initiate a print job request 0N/A * @see #print(MessageFormat, MessageFormat, boolean, PrintService, PrintRequestAttributeSet, boolean) 0N/A * A convenience print method that displays a print dialog, and then 0N/A * prints this {@code JTextComponent} in <i>interactive</i> mode with 0N/A * the specified header and footer text. Note: this method 0N/A * blocks until printing is done. 0N/A * Note: In <i>headless</i> mode, no dialogs will be shown. 0N/A * <p> This method calls the full featured 0N/A * {@link #print(MessageFormat, MessageFormat, boolean, PrintService, PrintRequestAttributeSet, boolean) 0N/A * print} method to perform printing. 0N/A * @param headerFormat the text, in {@code MessageFormat}, to be 0N/A * used as the header, or {@code null} for no header 0N/A * @param footerFormat the text, in {@code MessageFormat}, to be 0N/A * used as the footer, or {@code null} for no footer 0N/A * @return {@code true}, unless printing is canceled by the user 0N/A * @throws PrinterException if an error in the print system causes the job 0N/A * @throws SecurityException if this thread is not allowed to 0N/A * initiate a print job request 0N/A * @see #print(MessageFormat, MessageFormat, boolean, PrintService, PrintRequestAttributeSet, boolean) 0N/A * @see java.text.MessageFormat 0N/A * Prints the content of this {@code JTextComponent}. Note: this method 0N/A * blocks until printing is done. 0N/A * Page header and footer text can be added to the output by providing 0N/A * {@code MessageFormat} arguments. The printing code requests 0N/A * {@code Strings} from the formats, providing a single item which may be 0N/A * included in the formatted string: an {@code Integer} representing the 0N/A * current page number. 0N/A * {@code showPrintDialog boolean} parameter allows you to specify whether 0N/A * a print dialog is displayed to the user. When it is, the user 0N/A * may use the dialog to change printing attributes or even cancel the 0N/A * {@code service} allows you to provide the initial 0N/A * {@code PrintService} for the print dialog, or to specify 0N/A * {@code PrintService} to print to when the dialog is not shown. 0N/A * {@code attributes} can be used to provide the 0N/A * initial values for the print dialog, or to supply any needed 0N/A * attributes when the dialog is not shown. {@code attributes} can 0N/A * be used to control how the job will print, for example 0N/A * <i>duplex</i> or <i>single-sided</i>. 0N/A * {@code interactive boolean} parameter allows you to specify 0N/A * whether to perform printing in <i>interactive</i> 0N/A * mode. If {@code true}, a progress dialog, with an abort option, 0N/A * is displayed for the duration of printing. This dialog is 0N/A * <i>modal</i> when {@code print} is invoked on the <i>Event Dispatch 0N/A * Thread</i> and <i>non-modal</i> otherwise. <b>Warning</b>: 0N/A * calling this method on the <i>Event Dispatch Thread</i> with {@code 0N/A * interactive false} blocks <i>all</i> events, including repaints, from 0N/A * being processed until printing is complete. It is only 0N/A * recommended when printing from an application with no 0N/A * Note: In <i>headless</i> mode, {@code showPrintDialog} and 0N/A * {@code interactive} parameters are ignored and no dialogs are 0N/A * This method ensures the {@code document} is not mutated during printing. 0N/A * To indicate it visually, {@code setEnabled(false)} is set for the 0N/A * duration of printing. 0N/A * This method uses {@link #getPrintable} to render document content. 0N/A * This method is thread-safe, although most Swing methods are not. Please 0N/A * How to Use Threads</A> for more information. 0N/A * <b>Sample Usage</b>. This code snippet shows a cross-platform print 0N/A * dialog and then prints the {@code JTextComponent} in <i>interactive</i> mode 0N/A * unless the user cancels the dialog: 0N/A * textComponent.print(new MessageFormat("My text component header"), 0N/A * new MessageFormat("Footer. Page - {0}"), true, null, null, true); 0N/A * Executing this code off the <i>Event Dispatch Thread</i> 0N/A * performs printing on the <i>background</i>. 0N/A * The following pattern might be used for <i>background</i> 0N/A * FutureTask<Boolean> future = 0N/A * new FutureTask<Boolean>( 0N/A * new Callable<Boolean>() { 0N/A * public Boolean call() { 0N/A * return textComponent.print(.....); 0N/A * executor.execute(future); 0N/A * @param headerFormat the text, in {@code MessageFormat}, to be 0N/A * used as the header, or {@code null} for no header 0N/A * @param footerFormat the text, in {@code MessageFormat}, to be 0N/A * used as the footer, or {@code null} for no footer 0N/A * @param showPrintDialog {@code true} to display a print dialog, 0N/A * {@code false} otherwise 0N/A * @param service initial {@code PrintService}, or {@code null} for the 0N/A * @param attributes the job attributes to be applied to the print job, or 0N/A * {@code null} for none 0N/A * @param interactive whether to print in an interactive mode 0N/A * @return {@code true}, unless printing is canceled by the user 0N/A * @throws PrinterException if an error in the print system causes the job 0N/A * @throws SecurityException if this thread is not allowed to 0N/A * initiate a print job request 0N/A * @see #getPrintable 0N/A * @see java.text.MessageFormat 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * @see java.util.concurrent.FutureTask 0N/A * there are three cases for printing: 0N/A * 1. print non interactively (! interactive || isHeadless) 0N/A * 2. print interactively off EDT 0N/A * 3. print interactively on EDT 0N/A * 1 and 2 prints on the current thread (3 prints on another thread) 0N/A * 2 and 3 deal with PrintingStatusDialog 0N/A //the printing is done successfully or otherwise. 0N/A //dialog is hidden if needed. 0N/A * Returns a {@code Printable} to use for printing the content of this 0N/A * {@code JTextComponent}. The returned {@code Printable} prints 0N/A * the document as it looks on the screen except being reformatted 0N/A * The returned {@code Printable} can be wrapped inside another 0N/A * {@code Printable} in order to create complex reports and 0N/A * The returned {@code Printable} shares the {@code document} with this 0N/A * {@code JTextComponent}. It is the responsibility of the developer to 0N/A * ensure that the {@code document} is not mutated while this {@code Printable} 0N/A * is used. Printing behavior is undefined when the {@code document} is 0N/A * mutated during printing. 0N/A * Page header and footer text can be added to the output by providing 0N/A * {@code MessageFormat} arguments. The printing code requests 0N/A * {@code Strings} from the formats, providing a single item which may be 0N/A * included in the formatted string: an {@code Integer} representing the 0N/A * current page number. 0N/A * The returned {@code Printable} when printed, formats the 0N/A * document content appropriately for the page size. For correct 0N/A * line wrapping the {@code imageable width} of all pages must be the 0N/A * same. See {@link java.awt.print.PageFormat#getImageableWidth}. 0N/A * This method is thread-safe, although most Swing methods are not. Please 0N/A * How to Use Threads</A> for more information. 0N/A * The returned {@code Printable} can be printed on any thread. 0N/A * This implementation returned {@code Printable} performs all painting on 0N/A * the <i>Event Dispatch Thread</i>, regardless of what thread it is 0N/A * @param headerFormat the text, in {@code MessageFormat}, to be 0N/A * used as the header, or {@code null} for no header 0N/A * @param footerFormat the text, in {@code MessageFormat}, to be 0N/A * used as the footer, or {@code null} for no footer 0N/A * @return a {@code Printable} for use in printing content of this 0N/A * {@code JTextComponent} 0N/A * @see java.awt.print.Printable 0N/A * @see java.awt.print.PageFormat 0N/A * @see javax.swing.text.Document#render(java.lang.Runnable) 0N/A// Accessibility support 0N/A * Gets the <code>AccessibleContext</code> associated with this 0N/A * <code>JTextComponent</code>. For text components, 0N/A * the <code>AccessibleContext</code> takes the form of an 0N/A * <code>AccessibleJTextComponent</code>. 0N/A * A new <code>AccessibleJTextComponent</code> instance 0N/A * is created if necessary. 0N/A * @return an <code>AccessibleJTextComponent</code> that serves as the 0N/A * <code>AccessibleContext</code> of this 0N/A * <code>JTextComponent</code> 0N/A * This class implements accessibility support for the 0N/A * <code>JTextComponent</code> class. It provides an implementation of 0N/A * the Java Accessibility API appropriate to menu user-interface elements. 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 * Constructs an AccessibleJTextComponent. Adds a listener to track 0N/A // Fire a ACCESSIBLE_VISIBLE_DATA_PROPERTY PropertyChangeEvent 0N/A // when the text component moves (e.g., when scrolling). 0N/A // Using an anonymous class since making AccessibleJTextComponent 0N/A // implement ComponentListener would be an API change. 0N/A * Handles caret updates (fire appropriate property change event, 0N/A * which are AccessibleContext.ACCESSIBLE_CARET_PROPERTY and 0N/A * AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY). 0N/A * This keeps track of the dot position internally. When the caret 0N/A * moves, the internal position is updated after firing the event. 0N/A * @param e the CaretEvent 0N/A // there is a selection 0N/A // DocumentListener methods 0N/A * Handles document insert (fire appropriate property change event 0N/A * which is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY). 0N/A * This tracks the changed offset via the event. 0N/A * @param e the DocumentEvent 0N/A * Handles document remove (fire appropriate property change event, 0N/A * which is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY). 0N/A * This tracks the changed offset via the event. 0N/A * @param e the DocumentEvent 0N/A * Handles document remove (fire appropriate property change event, 0N/A * which is AccessibleContext.ACCESSIBLE_TEXT_PROPERTY). 0N/A * This tracks the changed offset via the event. 0N/A * @param e the DocumentEvent 0N/A * Gets the state set of the JTextComponent. 0N/A * The AccessibleStateSet of an object is composed of a set of 0N/A * unique AccessibleState's. A change in the AccessibleStateSet 0N/A * of an object will cause a PropertyChangeEvent to be fired 0N/A * for the AccessibleContext.ACCESSIBLE_STATE_PROPERTY property. 0N/A * @return an instance of AccessibleStateSet containing the 0N/A * current state set of the object 0N/A * @see AccessibleStateSet 0N/A * @see AccessibleState 0N/A * @see #addPropertyChangeListener 0N/A * Gets the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * object (AccessibleRole.TEXT) 0N/A * @see AccessibleRole 0N/A * Get the AccessibleText associated with this object. In the 0N/A * implementation of the Java Accessibility API for this class, 0N/A * return this object, which is responsible for implementing the 0N/A * AccessibleText interface on behalf of itself. 0N/A * @return this object 0N/A // --- interface AccessibleText methods ------------------------ 0N/A * Many of these methods are just convenience methods; they 0N/A * just call the equivalent on the parent 0N/A * Given a point in local coordinates, return the zero-based index 0N/A * of the character under that Point. If the point is invalid, 0N/A * this method returns -1. 0N/A * @param p the Point in local coordinates 0N/A * @return the zero-based index of the character under Point p. 0N/A * Gets the editor's drawing rectangle. Stolen 0N/A * from the unfortunately named 0N/A * BasicTextUI.getVisibleEditorRect() 0N/A * @return the bounding box for the root view 0N/A * Determines the bounding box of the character at the given 0N/A * index into the string. The bounds are returned in local 0N/A * coordinates. If the index is invalid a null rectangle 0N/A * The screen coordinates returned are "unscrolled coordinates" 0N/A * if the JTextComponent is contained in a JScrollPane in which 0N/A * case the resulting rectangle should be composed with the parent 0N/A * coordinates. A good algorithm to use is: 0N/A * AccessibleText at = a.getAccessibleText(); 0N/A * AccessibleComponent ac = a.getAccessibleComponent(); 0N/A * Rectangle r = at.getCharacterBounds(); 0N/A * Point p = ac.getLocation(); 0N/A * Note: the JTextComponent must have a valid size (e.g. have 0N/A * been added to a parent container whose ancestor container 0N/A * is a valid top-level window) for this method to be able 0N/A * to return a meaningful (non-null) value. 0N/A * @param i the index into the String >= 0 0N/A * @return the screen coordinates of the character's bounding box 0N/A * Returns the number of characters (valid indices) 0N/A * @return the number of characters >= 0 0N/A * Returns the zero-based offset of the caret. 0N/A * Note: The character to the right of the caret will have the 0N/A * same index value as the offset (the caret is between 0N/A * @return the zero-based offset of the caret. 0N/A * Returns the AttributeSet for a given character (at a given index). 0N/A * @param i the zero-based index into the text 0N/A * @return the AttributeSet of the character 0N/A * Returns the start offset within the selected text. 0N/A * If there is no selection, but there is 0N/A * a caret, the start and end offsets will be the same. 0N/A * Return 0 if the text is empty, or the caret position 0N/A * @return the index into the text of the start of the selection >= 0 0N/A * Returns the end offset within the selected text. 0N/A * If there is no selection, but there is 0N/A * a caret, the start and end offsets will be the same. 0N/A * Return 0 if the text is empty, or the caret position 0N/A * @return the index into teh text of the end of the selection >= 0 0N/A * Returns the portion of the text that is selected. 0N/A * @return the text, null if no selection 0N/A * IndexedSegment extends Segment adding the offset into the 0N/A * the model the <code>Segment</code> was asked for. 0N/A * Offset into the model that the position represents. 0N/A * Returns the String at a given index. Whitespace 0N/A * between words is treated as a word. 0N/A * @param part the CHARACTER, WORD, or SENTENCE to retrieve 0N/A * @param index an index within the text 0N/A * @return the letter, word, or sentence. 0N/A * Returns the String after a given index. Whitespace 0N/A * between words is treated as a word. 0N/A * @param part the CHARACTER, WORD, or SENTENCE to retrieve 0N/A * @param index an index within the text 0N/A * @return the letter, word, or sentence. 0N/A * Returns the String before a given index. Whitespace 0N/A * between words is treated a word. 0N/A * @param part the CHARACTER, WORD, or SENTENCE to retrieve 0N/A * @param index an index within the text 0N/A * @return the letter, word, or sentence. 0N/A * Gets the word, sentence, or character at <code>index</code>. 0N/A * If <code>direction</code> is non-null this will find the 0N/A * Returns the paragraph element for the specified index. 0N/A * Returns a <code>Segment</code> containing the paragraph text 0N/A * at <code>index</code>, or null if <code>index</code> isn't 0N/A * Returns the Segment at <code>index</code> representing either 0N/A * the paragraph or sentence as identified by <code>part</code>, or 0N/A // begin AccessibleEditableText methods ----- 0N/A * Returns the AccessibleEditableText interface for 0N/A * this text component. 0N/A * @return the AccessibleEditableText interface 0N/A * Sets the text contents to the specified string. 0N/A * @param s the string to set the text contents 0N/A * Inserts the specified string at the given index 0N/A * @param index the index in the text where the string will 0N/A * @param s the string to insert in the text 0N/A * Returns the text string between two indices. 0N/A * @param startIndex the starting index in the text 0N/A * @param endIndex the ending index in the text 0N/A * @return the text string between the indices 0N/A * Deletes the text between two indices 0N/A * @param startIndex the starting index in the text 0N/A * @param endIndex the ending index in the text 0N/A * Cuts the text between two indices into the system clipboard. 0N/A * @param startIndex the starting index in the text 0N/A * @param endIndex the ending index in the text 0N/A * Pastes the text from the system clipboard into the text 0N/A * starting at the specified index. 0N/A * @param startIndex the starting index in the text 0N/A * Replaces the text between two indices with the specified 0N/A * @param startIndex the starting index in the text 0N/A * @param endIndex the ending index in the text 0N/A * @param s the string to replace the text between two indices 0N/A * Selects the text between two indices. 0N/A * @param startIndex the starting index in the text 0N/A * @param endIndex the ending index in the text 0N/A * Sets attributes for the text between two indices. 0N/A * @param startIndex the starting index in the text 0N/A * @param endIndex the ending index in the text 0N/A * @param as the attribute set 0N/A // Fixes bug 4487492 0N/A // ----- end AccessibleEditableText methods 0N/A // ----- begin AccessibleExtendedText methods 0N/A// Probably should replace the helper method getAtIndex() to return 0N/A// instead an AccessibleTextSequence also for LINE & ATTRIBUTE_RUN 0N/A// and then make the AccessibleText methods get[At|After|Before]Point 0N/A// call this new method instead and return only the string portion 0N/A * Returns the AccessibleTextSequence at a given <code>index</code>. 0N/A * If <code>direction</code> is non-null this will find the 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or 0N/A * <code>ATTRIBUTE_RUN</code> to retrieve 0N/A * @param index an index within the text 0N/A * @param direction is either -1, 0, or 1 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text 0N/A * if <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned. 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A return null;
// direction must be 1, 0, or -1 0N/A // we are intentionally silent; our contract says we return 0N/A // null if there is any failure in this method 0N/A }
// else we leave rangeSequence set to null 0N/A // we are intentionally silent; our contract says we return 0N/A // null if there is any failure in this method 0N/A // already validated 'direction' above... 0N/A // we are intentionally silent; our contract says we return 0N/A // null if there is any failure in this method 0N/A // assumptions: (1) that all characters in a single element 0N/A // share the same attribute set; (2) that adjacent elements 0N/A // *may* share the same attribute set 0N/A // going backwards, so find left edge of this run - 0N/A // that'll be the end of the previous run 0N/A // (off-by-one counting) 0N/A // now set ourselves up to find the left edge of the 0N/A // going forward, so find right edge of this run - 0N/A // that'll be the start of the next run 0N/A // (off-by-one counting) 0N/A // now set ourselves up to find the right edge of the 0N/A // interested in the current run, so nothing special to 0N/A // set up in advance... 0N/A // only those three values of direction allowed... 0N/A // set the unset edge; if neither set then we're getting 0N/A // both edges of the current run around our 'index' 0N/A // we are intentionally silent; our contract says we return 0N/A // null if there is any failure in this method 0N/A * Starting at text position <code>index</code>, and going in 0N/A * <code>direction</code>, return the edge of run that shares the 0N/A * same <code>AttributeSet</code> and parent element as those at 0N/A * <code>index</code>. 0N/A * Note: we assume the document is already locked... 0N/A // locate the Element at index 0N/A // cache the AttributeSet and parentElement atindex 0N/A // if we are already at edge of the first element in our parent 0N/A // then return that edge 0N/A // we already caught this case earlier; this is to satisfy 0N/A // getTextRange() not needed; defined in AccessibleEditableText 0N/A * Returns the <code>AccessibleTextSequence</code> at a given 0N/A * <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or 0N/A * <code>ATTRIBUTE_RUN</code> to retrieve 0N/A * @param index an index within the text 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text if 0N/A * <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A * Returns the <code>AccessibleTextSequence</code> after a given 0N/A * <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or 0N/A * <code>ATTRIBUTE_RUN</code> to retrieve 0N/A * @param index an index within the text 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text 0N/A * if <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A * Returns the <code>AccessibleTextSequence</code> before a given 0N/A * <code>index</code>. 0N/A * @param part the <code>CHARACTER</code>, <code>WORD</code>, 0N/A * <code>SENTENCE</code>, <code>LINE</code> or 0N/A * <code>ATTRIBUTE_RUN</code> to retrieve 0N/A * @param index an index within the text 0N/A * @return an <code>AccessibleTextSequence</code> specifying the text 0N/A * if <code>part</code> and <code>index</code> are valid. Otherwise, 0N/A * <code>null</code> is returned 0N/A * @see javax.accessibility.AccessibleText#CHARACTER 0N/A * @see javax.accessibility.AccessibleText#WORD 0N/A * @see javax.accessibility.AccessibleText#SENTENCE 0N/A * @see javax.accessibility.AccessibleExtendedText#LINE 0N/A * @see javax.accessibility.AccessibleExtendedText#ATTRIBUTE_RUN 0N/A * Returns the <code>Rectangle</code> enclosing the text between 0N/A * @param startIndex the start index in the text 0N/A * @param endIndex the end index in the text 0N/A * @return the bounding rectangle of the text if the indices are valid. 0N/A * Otherwise, <code>null</code> is returned 0N/A // ----- end AccessibleExtendedText methods 0N/A // --- interface AccessibleAction methods ------------------------ 0N/A * Returns the number of accessible actions available in this object 0N/A * If there are more than one, the first one is considered the 0N/A * "default" action of the object. 0N/A * @return the zero-based number of Actions in this object 0N/A * Returns a description of the specified action of the object. 0N/A * @param i zero-based index of the actions 0N/A * @return a String description of the action 0N/A * @see #getAccessibleActionCount 0N/A * Performs the specified Action on the object 0N/A * @param i zero-based index of actions 0N/A * @return true if the action was performed; otherwise false. 0N/A * @see #getAccessibleActionCount 0N/A // ----- end AccessibleAction methods 0N/A // --- serialization --------------------------------------------- 0N/A // --- member variables ---------------------------------- 0N/A * The document model. 0N/A * The caret used to display the insert position 0N/A * and navigate throughout the document. 0N/A * This should be serializable, default installed 0N/A * Object responsible for restricting the cursor navigation. 0N/A * The object responsible for managing highlights. 0N/A * This should be serializable, default installed 0N/A * The current key bindings in effect. 0N/A * This should be serializable, default installed 0N/A * The drop mode for this component. 0N/A * The drop location. 0N/A * Represents a drop location for <code>JTextComponent</code>s. 0N/A * @see #getDropLocation 0N/A * Returns the index where dropped data should be inserted into the 0N/A * associated component. This index represents a position between 0N/A * characters, as would be interpreted by a caret. 0N/A * @return the drop index 0N/A * Returns the bias for the drop index. 0N/A * @return the drop bias 0N/A * Returns a string representation of this drop location. 0N/A * This method is intended to be used for debugging purposes, 0N/A * and the content and format of the returned string may vary 0N/A * between implementations. 0N/A * @return a string representation of this drop location 0N/A * TransferHandler used if one hasn't been supplied by the UI. 0N/A * Maps from class name to Boolean indicating if 0N/A * <code>processInputMethodEvent</code> has been overriden. 0N/A * Returns a string representation of this <code>JTextComponent</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 0N/A * be <code>null</code>. 0N/A * Overriding <code>paramString</code> to provide information about the 0N/A * specific new aspects of the JFC components. 0N/A * @return a string representation of this <code>JTextComponent</code> 0N/A * A Simple TransferHandler that exports the data as a String, and 0N/A * imports the data from the String clipboard. This is only used 0N/A * if the UI hasn't supplied one, which would only happen if someone 0N/A * hasn't subclassed Basic. 0N/A // this may throw an IllegalStateException, 0N/A // but it will be caught and handled in the 0N/A // action that invoked this method 0N/A * Returns the JTextComponent that most recently had focus. The returned 0N/A * value may currently have focus. 0N/A // member variables used for on-the-spot input method 0N/A // editing style support 0N/A * Set to true after the check for the override of processInputMethodEvent 0N/A * Fetch the default action to fire if a 0N/A * key is typed (ie a KEY_TYPED KeyEvent is received) 0N/A * and there is no binding for it. Typically this 0N/A * would be some action that inserts text so that 0N/A * the keymap doesn't require an action for each 0N/A * Set the default action to fire if a key is typed. 0N/A // Determine local bindings first. 0N/A // See if the parent has any. 0N/A // Remove any bindings defined in the parent that 0N/A // are locally defined. 0N/A * String representation of the keymap... potentially 0N/A * a very long string. 0N/A * KeymapWrapper wraps a Keymap inside an InputMap. For KeymapWrapper 0N/A * to be useful it must be used with a KeymapActionMap. 0N/A * KeymapWrapper for the most part, is an InputMap with two parents. 0N/A * The first parent visited is ALWAYS the Keymap, with the second 0N/A * parent being the parent inherited from InputMap. If 0N/A * <code>keymap.getAction</code> returns null, implying the Keymap 0N/A * does not have a binding for the KeyStroke, 0N/A * the parent is then visited. If the Keymap has a binding, the 0N/A * Action is returned, if not and the KeyStroke represents a 0N/A * KeyTyped event and the Keymap has a defaultAction, 0N/A * <code>DefaultActionKey</code> is returned. 0N/A * <p>KeymapActionMap is then able to transate the object passed in 0N/A * to either message the Keymap, or message its default implementation. 0N/A // There may be some duplication here... 0N/A // There may be some duplication here... 0N/A // Implies this is a KeyTyped event, use the default 0N/A * Wraps a Keymap inside an ActionMap. This is used with 0N/A * a KeymapWrapper. If <code>get</code> is passed in 0N/A * <code>KeymapWrapper.DefaultActionKey</code>, the default action is 0N/A * returned, otherwise if the key is an Action, it is returned. 0N/A // There may be some duplication here... 0N/A // There may be some duplication here... 0N/A // This is a little iffy, technically an Action is 0N/A // a valid Key. We're assuming the Action came from 0N/A // the InputMap though. 0N/A * The default keymap that will be shared by all 0N/A * <code>JTextComponent</code> instances unless they 0N/A * have had a different keymap set. 0N/A * Event to use when firing a notification of change to caret 0N/A * position. This is mutable so that the event can be reused 0N/A * since caret events can be fairly high in bandwidth. 0N/A // --- CaretEvent methods ----------------------- 0N/A // --- ChangeListener methods ------------------- 0N/A // --- FocusListener methods ----------------------------------- 0N/A // --- MouseListener methods ----------------------------------- 0N/A * Requests focus on the associated 0N/A * text component, and try to set the cursor position. 0N/A * @param e the mouse event 0N/A * @see MouseListener#mousePressed 0N/A * Called when the mouse is released. 0N/A * @param e the mouse event 0N/A * @see MouseListener#mouseReleased 0N/A // Process any input method events that the component itself 0N/A // recognizes. The default on-the-spot handling for input method 0N/A // composed(uncommitted) text is done here after all input 0N/A // method listeners get called for stealing the events. 0N/A // let listeners handle the events 0N/A // Overrides this method to become an active input method client. 0N/A // Overrides this method to watch the listener installed. 0N/A // Default implementation of the InputMethodRequests interface. 0N/A // --- InputMethodRequests methods --- 0N/A * this is the case when this method is invoked 0N/A * from DocumentListener. At this point 0N/A * composedTextEnd and composedTextStart are 0N/A // --- DocumentListener methods --- 0N/A // Replaces the current input method (composed) text according to 0N/A // the passed input method event. This method also inserts the 0N/A // committed text into the document. 0N/A // old composed text deletion 0N/A // committed text insertion 0N/A // Remember latest committed text start index 0N/A // Need to generate KeyTyped events for the committed text for components 0N/A // that are not aware they are active input method clients. 0N/A // map it to an ActionEvent 0N/A // Remember latest committed text end index 0N/A // new composed text insertion 0N/A // Save the latest committed text information 0N/A // create attributed string with no attributes 1638N/A * Saves composed text around the specified position. 1638N/A * The composed text (if any) around the specified position is saved 1638N/A * in a backing store and removed from the document. 1638N/A * @param pos document position to identify the composed text location 1638N/A * @return {@code true} if the composed text exists and is saved, 1638N/A * @see #restoreComposedText 1638N/A * Restores composed text previously saved by {@code saveComposedText}. 1638N/A * The saved composed text is inserted back into the document. This method 1638N/A * should be invoked only if {@code saveComposedText} returns {@code true}. 0N/A // Map committed text to an ActionEvent. If the committed text length is 1, 0N/A // treat it as a KeyStroke, otherwise or there is no KeyStroke defined, 0N/A // treat it just as a default action. 0N/A // Sets the caret position according to the passed input method 0N/A // Sets composed text caret 0N/A // Scroll the component if needed so that the composed text 0N/A // Restores original caret 0N/A * Returns true if KeyEvents should be synthesized from an InputEvent. 0N/A // Checks whether the client code overrides processInputMethodEvent. If it is overridden, 0N/A // need not to generate KeyTyped events for committed text. If it's not, behave as an 0N/A // passive input method client. 0N/A // Checks whether a composed text in this text component 0N/A // Caret implementation for editing the composed text. 0N/A // Get the background color of the component 0N/A // Draw caret in XOR mode. 0N/A // can't render I guess 0N/A //System.err.println("Can't render cursor"); 0N/A // If some area other than the composed text is clicked by mouse, 0N/A // issue endComposition() to force commit the composed text. 0N/A // Issue endComposition 0N/A // Post a caret positioning runnable to assure that the positioning 0N/A // occurs *after* committing the composed text. 0N/A // Normal processing 0N/A // Runnable class for invokeLater() to set caret position later.