|
Java example source code file (JTextComponent.java)
The JTextComponent.java Java example source code
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.swing.text;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.beans.Transient;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
import java.util.Map;
import java.util.concurrent.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.*;
import java.awt.datatransfer.*;
import java.awt.im.InputContext;
import java.awt.im.InputMethodRequests;
import java.awt.font.TextHitInfo;
import java.awt.font.TextAttribute;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import javax.print.PrintService;
import javax.print.attribute.PrintRequestAttributeSet;
import java.text.*;
import java.text.AttributedCharacterIterator.Attribute;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.accessibility.*;
import javax.print.attribute.*;
import sun.awt.AppContext;
import sun.swing.PrintingStatus;
import sun.swing.SwingUtilities2;
import sun.swing.text.TextComponentPrintable;
import sun.swing.SwingAccessor;
/**
* <code>JTextComponent is the base class for swing text
* components. It tries to be compatible with the
* <code>java.awt.TextComponent class
* where it can reasonably do so. Also provided are other services
* for additional flexibility (beyond the pluggable UI and bean
* support).
* You can find information on how to use the functionality
* this class provides in
* <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/generaltext.html">General Rules for Using Text Components,
* a section in <em>The Java Tutorial.
*
* <dl>
* <dt>Caret Changes
* <dd>
* The caret is a pluggable object in swing text components.
* Notification of changes to the caret position and the selection
* are sent to implementations of the <code>CaretListener
* interface that have been registered with the text component.
* The UI will install a default caret unless a customized caret
* has been set. <br>
* By default the caret tracks all the document changes
* performed on the Event Dispatching Thread and updates it's position
* accordingly if an insertion occurs before or at the caret position
* or a removal occurs before the caret position. <code>DefaultCaret
* tries to make itself visible which may lead to scrolling
* of a text component within <code>JScrollPane. The default caret
* behavior can be changed by the {@link DefaultCaret#setUpdatePolicy} method.
* <br>
* <b>Note: Non-editable text components also have a caret though
* it may not be painted.
*
* <dt>Commands
* <dd>
* Text components provide a number of commands that can be used
* to manipulate the component. This is essentially the way that
* the component expresses its capabilities. These are expressed
* in terms of the swing <code>Action interface,
* using the <code>TextAction implementation.
* The set of commands supported by the text component can be
* found with the {@link #getActions} method. These actions
* can be bound to key events, fired from buttons, etc.
*
* <dt>Text Input
* <dd>
* The text components support flexible and internationalized text input, using
* keymaps and the input method framework, while maintaining compatibility with
* the AWT listener model.
* <p>
* A {@link javax.swing.text.Keymap} lets an application bind key
* strokes to actions.
* In order to allow keymaps to be shared across multiple text components, they
* can use actions that extend <code>TextAction.
* <code>TextAction can determine which | 1. | * <td headers="ke">input methods * <td headers="ime">(generated here) * <tr>2. | * <td headers="ke">focus manager * <td headers="ime"> * </tr> * <tr> * <td headers="stage">3. * <td headers="ke">registered key listeners * <td headers="ime">registered input method listeners * <tr> * <td headers="stage">4. * <td headers="ke"> * <td headers="ime">input method handling in JTextComponent * <tr> * <td headers="stage">5.keymap handling using the current keymap | * <tr>6. | keyboard handling in JComponent (e.g. accelerators, component navigation, etc.) | * <td headers="ime"> * </table> * * <p> * To maintain compatibility with applications that listen to key * events but are not aware of input method events, the input * method handling in stage 4 provides a compatibility mode for * components that do not process input method events. For these * components, the committed text is converted to keyTyped key events * and processed in the key event pipeline starting at stage 3 * instead of in the input method event pipeline. * <p> * By default the component will create a keymap (named <b>DEFAULT_KEYMAP) * that is shared by all JTextComponent instances as the default keymap. * Typically a look-and-feel implementation will install a different keymap * that resolves to the default keymap for those bindings not found in the * different keymap. The minimal bindings include: * <ul> * <li>inserting content into the editor for the * printable keys. * <li>removing content with the backspace and del * keys. * <li>caret movement forward and backward * </ul> * * <dt>Model/View Split * <dd> * The text components have a model-view split. A text component pulls * together the objects used to represent the model, view, and controller. * The text document model may be shared by other views which act as observers * of the model (e.g. a document may be shared by multiple components). * * <p style="text-align:center">
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.