90 * @see #setSelectionStart(int)
91 */
92 int selectionStart;
93
94 /**
95 * The selection refers to the selected text, and the
96 * <code>selectionEnd</code>
97 * is the end position of the selected text.
98 *
99 * @serial
100 * @see #getSelectionEnd()
101 * @see #setSelectionEnd(int)
102 */
103 int selectionEnd;
104
105 // A flag used to tell whether the background has been set by
106 // developer code (as opposed to AWT code). Used to determine
107 // the background color of non-editable TextComponents.
108 boolean backgroundSetByClientCode = false;
109
110 /**
111 * True if this <code>TextComponent</code> has access
112 * to the System clipboard.
113 */
114 transient private boolean canAccessClipboard;
115
116 transient protected TextListener textListener;
117
118 /*
119 * JDK 1.1 serialVersionUID
120 */
121 private static final long serialVersionUID = -2214773872412987419L;
122
123 /**
124 * Constructs a new text component initialized with the
125 * specified text. Sets the value of the cursor to
126 * <code>Cursor.TEXT_CURSOR</code>.
127 * @param text the text to be displayed; if
128 * <code>text</code> is <code>null</code>, the empty
129 * string <code>""</code> will be displayed
130 * @exception HeadlessException if
131 * <code>GraphicsEnvironment.isHeadless</code>
132 * returns true
133 * @see java.awt.GraphicsEnvironment#isHeadless
134 * @see java.awt.Cursor
135 */
136 TextComponent(String text) throws HeadlessException {
137 GraphicsEnvironment.checkHeadless();
138 this.text = (text != null) ? text : "";
139 setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
140 checkSystemClipboardAccess();
141 }
142
143 private void enableInputMethodsIfNecessary() {
144 if (checkForEnableIM) {
145 checkForEnableIM = false;
146 try {
147 Toolkit toolkit = Toolkit.getDefaultToolkit();
148 boolean shouldEnable = false;
149 if (toolkit instanceof InputMethodSupport) {
150 shouldEnable = ((InputMethodSupport)toolkit)
151 .enableInputMethodsForTextComponent();
152 }
153 enableInputMethods(shouldEnable);
154 } catch (Exception e) {
155 // if something bad happens, just don't enable input methods
156 }
157 }
158 }
159
160 /**
715 * Returns a string representing the state of this
716 * <code>TextComponent</code>. This
717 * method is intended to be used only for debugging purposes, and the
718 * content and format of the returned string may vary between
719 * implementations. The returned string may be empty but may not be
720 * <code>null</code>.
721 *
722 * @return the parameter string of this text component
723 */
724 protected String paramString() {
725 String str = super.paramString() + ",text=" + getText();
726 if (editable) {
727 str += ",editable";
728 }
729 return str + ",selection=" + getSelectionStart() + "-" + getSelectionEnd();
730 }
731
732 /**
733 * Assigns a valid value to the canAccessClipboard instance variable.
734 */
735 private void checkSystemClipboardAccess() {
736 canAccessClipboard = true;
737 SecurityManager sm = System.getSecurityManager();
738 if (sm != null) {
739 try {
740 sm.checkSystemClipboardAccess();
741 }
742 catch (SecurityException e) {
743 canAccessClipboard = false;
744 }
745 }
746 }
747
748 /*
749 * Serialization support.
750 */
751 /**
752 * The textComponent SerializedDataVersion.
753 *
754 * @serial
755 */
756 private int textComponentSerializedDataVersion = 1;
757
758 /**
759 * Writes default serializable fields to stream. Writes
760 * a list of serializable TextListener(s) as optional data.
761 * The non-serializable TextListener(s) are detected and
762 * no attempt is made to serialize them.
763 *
764 * @serialData Null terminated sequence of zero or more pairs.
765 * A pair consists of a String and Object.
808 GraphicsEnvironment.checkHeadless();
809 s.defaultReadObject();
810
811 // Make sure the state we just read in for text,
812 // selectionStart and selectionEnd has legal values
813 this.text = (text != null) ? text : "";
814 select(selectionStart, selectionEnd);
815
816 Object keyOrNull;
817 while(null != (keyOrNull = s.readObject())) {
818 String key = ((String)keyOrNull).intern();
819
820 if (textListenerK == key) {
821 addTextListener((TextListener)(s.readObject()));
822 } else {
823 // skip value for unrecognized key
824 s.readObject();
825 }
826 }
827 enableInputMethodsIfNecessary();
828 checkSystemClipboardAccess();
829 }
830
831
832 /////////////////
833 // Accessibility support
834 ////////////////
835
836
837 /**
838 *
839 */
840 int getIndexAtPoint(Point p) {
841 return -1;
842 /* To be fully implemented in a future release
843 if (peer == null) {
844 return -1;
845 }
846 TextComponentPeer peer = (TextComponentPeer)this.peer;
847 return peer.getIndexAtPoint(p.x, p.y);
848 */
|
90 * @see #setSelectionStart(int)
91 */
92 int selectionStart;
93
94 /**
95 * The selection refers to the selected text, and the
96 * <code>selectionEnd</code>
97 * is the end position of the selected text.
98 *
99 * @serial
100 * @see #getSelectionEnd()
101 * @see #setSelectionEnd(int)
102 */
103 int selectionEnd;
104
105 // A flag used to tell whether the background has been set by
106 // developer code (as opposed to AWT code). Used to determine
107 // the background color of non-editable TextComponents.
108 boolean backgroundSetByClientCode = false;
109
110 transient protected TextListener textListener;
111
112 /*
113 * JDK 1.1 serialVersionUID
114 */
115 private static final long serialVersionUID = -2214773872412987419L;
116
117 /**
118 * Constructs a new text component initialized with the
119 * specified text. Sets the value of the cursor to
120 * <code>Cursor.TEXT_CURSOR</code>.
121 * @param text the text to be displayed; if
122 * <code>text</code> is <code>null</code>, the empty
123 * string <code>""</code> will be displayed
124 * @exception HeadlessException if
125 * <code>GraphicsEnvironment.isHeadless</code>
126 * returns true
127 * @see java.awt.GraphicsEnvironment#isHeadless
128 * @see java.awt.Cursor
129 */
130 TextComponent(String text) throws HeadlessException {
131 GraphicsEnvironment.checkHeadless();
132 this.text = (text != null) ? text : "";
133 setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
134 }
135
136 private void enableInputMethodsIfNecessary() {
137 if (checkForEnableIM) {
138 checkForEnableIM = false;
139 try {
140 Toolkit toolkit = Toolkit.getDefaultToolkit();
141 boolean shouldEnable = false;
142 if (toolkit instanceof InputMethodSupport) {
143 shouldEnable = ((InputMethodSupport)toolkit)
144 .enableInputMethodsForTextComponent();
145 }
146 enableInputMethods(shouldEnable);
147 } catch (Exception e) {
148 // if something bad happens, just don't enable input methods
149 }
150 }
151 }
152
153 /**
708 * Returns a string representing the state of this
709 * <code>TextComponent</code>. This
710 * method is intended to be used only for debugging purposes, and the
711 * content and format of the returned string may vary between
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.checkSystemClipboardAccess();
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.
753 *
754 * @serialData Null terminated sequence of zero or more pairs.
755 * A pair consists of a String and Object.
798 GraphicsEnvironment.checkHeadless();
799 s.defaultReadObject();
800
801 // Make sure the state we just read in for text,
802 // selectionStart and selectionEnd has legal values
803 this.text = (text != null) ? text : "";
804 select(selectionStart, selectionEnd);
805
806 Object keyOrNull;
807 while(null != (keyOrNull = s.readObject())) {
808 String key = ((String)keyOrNull).intern();
809
810 if (textListenerK == key) {
811 addTextListener((TextListener)(s.readObject()));
812 } else {
813 // skip value for unrecognized key
814 s.readObject();
815 }
816 }
817 enableInputMethodsIfNecessary();
818 }
819
820
821 /////////////////
822 // Accessibility support
823 ////////////////
824
825
826 /**
827 *
828 */
829 int getIndexAtPoint(Point p) {
830 return -1;
831 /* To be fully implemented in a future release
832 if (peer == null) {
833 return -1;
834 }
835 TextComponentPeer peer = (TextComponentPeer)this.peer;
836 return peer.getIndexAtPoint(p.x, p.y);
837 */
|