src/share/classes/java/awt/TextComponent.java

Print this page




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.awt.peer.TextComponentPeer;
  28 import java.awt.event.*;
  29 import java.util.EventListener;
  30 import java.io.ObjectOutputStream;
  31 import java.io.ObjectInputStream;
  32 import java.io.IOException;
  33 import sun.awt.InputMethodSupport;
  34 import java.text.BreakIterator;
  35 import javax.swing.text.AttributeSet;
  36 import javax.accessibility.*;
  37 import java.awt.im.InputMethodRequests;

  38 
  39 /**
  40  * The <code>TextComponent</code> class is the superclass of
  41  * any component that allows the editing of some text.
  42  * <p>
  43  * A text component embodies a string of text.  The
  44  * <code>TextComponent</code> class defines a set of methods
  45  * that determine whether or not this text is editable. If the
  46  * component is editable, it defines another set of methods
  47  * that supports a text insertion caret.
  48  * <p>
  49  * In addition, the class defines methods that are used
  50  * to maintain a current <em>selection</em> from the text.
  51  * The text selection, a substring of the component's text,
  52  * is the target of editing operations. It is also referred
  53  * to as the <em>selected text</em>.
  54  *
  55  * @author      Sami Shaio
  56  * @author      Arthur van Hoff
  57  * @since       JDK1.0


 711      * implementations. The returned string may be empty but may not be
 712      * <code>null</code>.
 713      *
 714      * @return      the parameter string of this text component
 715      */
 716     protected String paramString() {
 717         String str = super.paramString() + ",text=" + getText();
 718         if (editable) {
 719             str += ",editable";
 720         }
 721         return str + ",selection=" + getSelectionStart() + "-" + getSelectionEnd();
 722     }
 723 
 724     /**
 725      * Assigns a valid value to the canAccessClipboard instance variable.
 726      */
 727     private boolean canAccessClipboard() {
 728         SecurityManager sm = System.getSecurityManager();
 729         if (sm == null) return true;
 730         try {
 731             sm.checkSystemClipboardAccess();
 732             return true;
 733         } catch (SecurityException e) {}
 734         return false;
 735     }
 736 
 737     /*
 738      * Serialization support.
 739      */
 740     /**
 741      * The textComponent SerializedDataVersion.
 742      *
 743      * @serial
 744      */
 745     private int textComponentSerializedDataVersion = 1;
 746 
 747     /**
 748      * Writes default serializable fields to stream.  Writes
 749      * a list of serializable TextListener(s) as optional data.
 750      * The non-serializable TextListener(s) are detected and
 751      * no attempt is made to serialize them.




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.awt.peer.TextComponentPeer;
  28 import java.awt.event.*;
  29 import java.util.EventListener;
  30 import java.io.ObjectOutputStream;
  31 import java.io.ObjectInputStream;
  32 import java.io.IOException;
  33 import sun.awt.InputMethodSupport;
  34 import java.text.BreakIterator;
  35 import javax.swing.text.AttributeSet;
  36 import javax.accessibility.*;
  37 import java.awt.im.InputMethodRequests;
  38 import sun.security.util.SecurityConstants;
  39 
  40 /**
  41  * The <code>TextComponent</code> class is the superclass of
  42  * any component that allows the editing of some text.
  43  * <p>
  44  * A text component embodies a string of text.  The
  45  * <code>TextComponent</code> class defines a set of methods
  46  * that determine whether or not this text is editable. If the
  47  * component is editable, it defines another set of methods
  48  * that supports a text insertion caret.
  49  * <p>
  50  * In addition, the class defines methods that are used
  51  * to maintain a current <em>selection</em> from the text.
  52  * The text selection, a substring of the component's text,
  53  * is the target of editing operations. It is also referred
  54  * to as the <em>selected text</em>.
  55  *
  56  * @author      Sami Shaio
  57  * @author      Arthur van Hoff
  58  * @since       JDK1.0


 712      * implementations. The returned string may be empty but may not be
 713      * <code>null</code>.
 714      *
 715      * @return      the parameter string of this text component
 716      */
 717     protected String paramString() {
 718         String str = super.paramString() + ",text=" + getText();
 719         if (editable) {
 720             str += ",editable";
 721         }
 722         return str + ",selection=" + getSelectionStart() + "-" + getSelectionEnd();
 723     }
 724 
 725     /**
 726      * Assigns a valid value to the canAccessClipboard instance variable.
 727      */
 728     private boolean canAccessClipboard() {
 729         SecurityManager sm = System.getSecurityManager();
 730         if (sm == null) return true;
 731         try {
 732             sm.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION);
 733             return true;
 734         } catch (SecurityException e) {}
 735         return false;
 736     }
 737 
 738     /*
 739      * Serialization support.
 740      */
 741     /**
 742      * The textComponent SerializedDataVersion.
 743      *
 744      * @serial
 745      */
 746     private int textComponentSerializedDataVersion = 1;
 747 
 748     /**
 749      * Writes default serializable fields to stream.  Writes
 750      * a list of serializable TextListener(s) as optional data.
 751      * The non-serializable TextListener(s) are detected and
 752      * no attempt is made to serialize them.