1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
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
275 * the same version of Swing. As of 1.4, support for long term storage
276 * of all JavaBeans™
277 * has been added to the <code>java.beans</code> package.
278 * Please see {@link java.beans.XMLEncoder}.
279 *
280 * @beaninfo
281 * attribute: isContainer false
282 *
283 * @author Timothy Prinzing
284 * @author Igor Kushnirskiy (printing support)
285 * @see Document
286 * @see DocumentEvent
287 * @see DocumentListener
288 * @see Caret
289 * @see CaretEvent
290 * @see CaretListener
291 * @see TextUI
292 * @see View
293 * @see ViewFactory
294 */
295 public abstract class JTextComponent extends JComponent implements Scrollable, Accessible
296 {
297 /**
298 * Creates a new <code>JTextComponent</code>.
299 * Listeners for caret events are established, and the pluggable
300 * UI installed. The component is marked as editable. No layout manager
301 * is used, because layout is managed by the view subsystem of text.
302 * The document model is set to <code>null</code>.
303 */
304 public JTextComponent() {
305 super();
306 // enable InputMethodEvent for on-the-spot pre-editing
307 enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.INPUT_METHOD_EVENT_MASK);
308 caretEvent = new MutableCaretEvent(this);
309 addMouseListener(caretEvent);
310 addFocusListener(caretEvent);
311 setEditable(true);
312 setDragEnabled(false);
313 setLayout(null); // layout is managed by View hierarchy
314 updateUI();
1101 Keymap binding = addKeymap(DEFAULT_KEYMAP, null);
1102 binding.setDefaultAction(new
1103 DefaultEditorKit.DefaultKeyTypedAction());
1104 }
1105 return keymapTable;
1106 }
1107 }
1108
1109 /**
1110 * Binding record for creating key bindings.
1111 * <p>
1112 * <strong>Warning:</strong>
1113 * Serialized objects of this class will not be compatible with
1114 * future Swing releases. The current serialization support is
1115 * appropriate for short term storage or RMI between applications running
1116 * the same version of Swing. As of 1.4, support for long term storage
1117 * of all JavaBeans™
1118 * has been added to the <code>java.beans</code> package.
1119 * Please see {@link java.beans.XMLEncoder}.
1120 */
1121 public static class KeyBinding {
1122
1123 /**
1124 * The key.
1125 */
1126 public KeyStroke key;
1127
1128 /**
1129 * The name of the action for the key.
1130 */
1131 public String actionName;
1132
1133 /**
1134 * Creates a new key binding.
1135 *
1136 * @param key the key
1137 * @param actionName the name of the action for the key
1138 */
1139 public KeyBinding(KeyStroke key, String actionName) {
1140 this.key = key;
2518 if (accessibleContext == null) {
2519 accessibleContext = new AccessibleJTextComponent();
2520 }
2521 return accessibleContext;
2522 }
2523
2524 /**
2525 * This class implements accessibility support for the
2526 * <code>JTextComponent</code> class. It provides an implementation of
2527 * the Java Accessibility API appropriate to menu user-interface elements.
2528 * <p>
2529 * <strong>Warning:</strong>
2530 * Serialized objects of this class will not be compatible with
2531 * future Swing releases. The current serialization support is
2532 * appropriate for short term storage or RMI between applications running
2533 * the same version of Swing. As of 1.4, support for long term storage
2534 * of all JavaBeans™
2535 * has been added to the <code>java.beans</code> package.
2536 * Please see {@link java.beans.XMLEncoder}.
2537 */
2538 public class AccessibleJTextComponent extends AccessibleJComponent
2539 implements AccessibleText, CaretListener, DocumentListener,
2540 AccessibleAction, AccessibleEditableText,
2541 AccessibleExtendedText {
2542
2543 int caretPos;
2544 Point oldLocationOnScreen;
2545
2546 /**
2547 * Constructs an AccessibleJTextComponent. Adds a listener to track
2548 * caret change.
2549 */
2550 public AccessibleJTextComponent() {
2551 Document doc = JTextComponent.this.getDocument();
2552 if (doc != null) {
2553 doc.addDocumentListener(this);
2554 }
2555 JTextComponent.this.addCaretListener(this);
2556 caretPos = getCaretPosition();
2557
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
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
275 * the same version of Swing. As of 1.4, support for long term storage
276 * of all JavaBeans™
277 * has been added to the <code>java.beans</code> package.
278 * Please see {@link java.beans.XMLEncoder}.
279 *
280 * @beaninfo
281 * attribute: isContainer false
282 *
283 * @author Timothy Prinzing
284 * @author Igor Kushnirskiy (printing support)
285 * @see Document
286 * @see DocumentEvent
287 * @see DocumentListener
288 * @see Caret
289 * @see CaretEvent
290 * @see CaretListener
291 * @see TextUI
292 * @see View
293 * @see ViewFactory
294 */
295 @SuppressWarnings("serial") // Same-version serialization only
296 public abstract class JTextComponent extends JComponent implements Scrollable, Accessible
297 {
298 /**
299 * Creates a new <code>JTextComponent</code>.
300 * Listeners for caret events are established, and the pluggable
301 * UI installed. The component is marked as editable. No layout manager
302 * is used, because layout is managed by the view subsystem of text.
303 * The document model is set to <code>null</code>.
304 */
305 public JTextComponent() {
306 super();
307 // enable InputMethodEvent for on-the-spot pre-editing
308 enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.INPUT_METHOD_EVENT_MASK);
309 caretEvent = new MutableCaretEvent(this);
310 addMouseListener(caretEvent);
311 addFocusListener(caretEvent);
312 setEditable(true);
313 setDragEnabled(false);
314 setLayout(null); // layout is managed by View hierarchy
315 updateUI();
1102 Keymap binding = addKeymap(DEFAULT_KEYMAP, null);
1103 binding.setDefaultAction(new
1104 DefaultEditorKit.DefaultKeyTypedAction());
1105 }
1106 return keymapTable;
1107 }
1108 }
1109
1110 /**
1111 * Binding record for creating key bindings.
1112 * <p>
1113 * <strong>Warning:</strong>
1114 * Serialized objects of this class will not be compatible with
1115 * future Swing releases. The current serialization support is
1116 * appropriate for short term storage or RMI between applications running
1117 * the same version of Swing. As of 1.4, support for long term storage
1118 * of all JavaBeans™
1119 * has been added to the <code>java.beans</code> package.
1120 * Please see {@link java.beans.XMLEncoder}.
1121 */
1122 @SuppressWarnings("serial") // Same-version serialization only
1123 public static class KeyBinding {
1124
1125 /**
1126 * The key.
1127 */
1128 public KeyStroke key;
1129
1130 /**
1131 * The name of the action for the key.
1132 */
1133 public String actionName;
1134
1135 /**
1136 * Creates a new key binding.
1137 *
1138 * @param key the key
1139 * @param actionName the name of the action for the key
1140 */
1141 public KeyBinding(KeyStroke key, String actionName) {
1142 this.key = key;
2520 if (accessibleContext == null) {
2521 accessibleContext = new AccessibleJTextComponent();
2522 }
2523 return accessibleContext;
2524 }
2525
2526 /**
2527 * This class implements accessibility support for the
2528 * <code>JTextComponent</code> class. It provides an implementation of
2529 * the Java Accessibility API appropriate to menu user-interface elements.
2530 * <p>
2531 * <strong>Warning:</strong>
2532 * Serialized objects of this class will not be compatible with
2533 * future Swing releases. The current serialization support is
2534 * appropriate for short term storage or RMI between applications running
2535 * the same version of Swing. As of 1.4, support for long term storage
2536 * of all JavaBeans™
2537 * has been added to the <code>java.beans</code> package.
2538 * Please see {@link java.beans.XMLEncoder}.
2539 */
2540 @SuppressWarnings("serial") // Same-version serialization only
2541 public class AccessibleJTextComponent extends AccessibleJComponent
2542 implements AccessibleText, CaretListener, DocumentListener,
2543 AccessibleAction, AccessibleEditableText,
2544 AccessibleExtendedText {
2545
2546 int caretPos;
2547 Point oldLocationOnScreen;
2548
2549 /**
2550 * Constructs an AccessibleJTextComponent. Adds a listener to track
2551 * caret change.
2552 */
2553 public AccessibleJTextComponent() {
2554 Document doc = JTextComponent.this.getDocument();
2555 if (doc != null) {
2556 doc.addDocumentListener(this);
2557 }
2558 JTextComponent.this.addCaretListener(this);
2559 caretPos = getCaretPosition();
2560
|