📄 jtextcomponent.java
字号:
/* JTextComponent.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing.text;import java.awt.AWTEvent;import java.awt.Color;import java.awt.Dimension;import java.awt.Insets;import java.awt.Point;import java.awt.Rectangle;import java.awt.datatransfer.Clipboard;import java.awt.datatransfer.DataFlavor;import java.awt.datatransfer.StringSelection;import java.awt.datatransfer.Transferable;import java.awt.datatransfer.UnsupportedFlavorException;import java.awt.event.ActionEvent;import java.awt.event.InputMethodListener;import java.awt.event.KeyEvent;import java.awt.event.MouseEvent;import java.io.IOException;import java.io.Reader;import java.io.Writer;import java.util.Enumeration;import java.util.Hashtable;import javax.accessibility.Accessible;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleStateSet;import javax.accessibility.AccessibleText;import javax.swing.Action;import javax.swing.ActionMap;import javax.swing.InputMap;import javax.swing.JComponent;import javax.swing.JViewport;import javax.swing.KeyStroke;import javax.swing.Scrollable;import javax.swing.SwingConstants;import javax.swing.TransferHandler;import javax.swing.UIManager;import javax.swing.event.CaretEvent;import javax.swing.event.CaretListener;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;import javax.swing.plaf.ActionMapUIResource;import javax.swing.plaf.InputMapUIResource;import javax.swing.plaf.TextUI;public abstract class JTextComponent extends JComponent implements Scrollable, Accessible{ /** * AccessibleJTextComponent */ // FIXME: This inner class is a complete stub and needs to be implemented. public class AccessibleJTextComponent extends AccessibleJComponent implements AccessibleText, CaretListener, DocumentListener { private static final long serialVersionUID = 7664188944091413696L; /** * Constructor AccessibleJTextComponent */ public AccessibleJTextComponent() { // Nothing to do here. } /** * getCaretPosition * @return int */ public int getCaretPosition() { return 0; // TODO } /** * getSelectedText * @return String */ public String getSelectedText() { return null; // TODO } /** * getSelectionStart * @return int */ public int getSelectionStart() { return 0; // TODO } /** * getSelectionEnd * @return int */ public int getSelectionEnd() { return 0; // TODO } /** * caretUpdate * @param value0 TODO */ public void caretUpdate(CaretEvent value0) { // TODO } /** * getAccessibleStateSet * @return AccessibleStateSet */ public AccessibleStateSet getAccessibleStateSet() { return null; // TODO } /** * getAccessibleRole * @return AccessibleRole */ public AccessibleRole getAccessibleRole() { return null; // TODO } /** * getAccessibleText * @return AccessibleText */ public AccessibleText getAccessibleText() { return null; // TODO } /** * insertUpdate * @param value0 TODO */ public void insertUpdate(DocumentEvent value0) { // TODO } /** * removeUpdate * @param value0 TODO */ public void removeUpdate(DocumentEvent value0) { // TODO } /** * changedUpdate * @param value0 TODO */ public void changedUpdate(DocumentEvent value0) { // TODO } /** * getIndexAtPoint * @param value0 TODO * @return int */ public int getIndexAtPoint(Point value0) { return 0; // TODO } /** * getRootEditorRect * @return Rectangle */ Rectangle getRootEditorRect() { return null; } /** * getCharacterBounds * @param value0 TODO * @return Rectangle */ public Rectangle getCharacterBounds(int value0) { return null; // TODO } /** * getCharCount * @return int */ public int getCharCount() { return 0; // TODO } /** * getCharacterAttribute * @param value0 TODO * @return AttributeSet */ public AttributeSet getCharacterAttribute(int value0) { return null; // TODO } /** * getAtIndex * @param value0 TODO * @param value1 TODO * @return String */ public String getAtIndex(int value0, int value1) { return null; // TODO } /** * getAfterIndex * @param value0 TODO * @param value1 TODO * @return String */ public String getAfterIndex(int value0, int value1) { return null; // TODO } /** * getBeforeIndex * @param value0 TODO * @param value1 TODO * @return String */ public String getBeforeIndex(int value0, int value1) { return null; // TODO } } public static class KeyBinding { public KeyStroke key; public String actionName; /** * Creates a new <code>KeyBinding</code> instance. * * @param key a <code>KeyStroke</code> value * @param actionName a <code>String</code> value */ public KeyBinding(KeyStroke key, String actionName) { this.key = key; this.actionName = actionName; } } /** * According to <a * href="http://java.sun.com/products/jfc/tsc/special_report/kestrel/keybindings.html">this * report</a>, a pair of private classes wraps a {@link * javax.swing.text.Keymap} in the new {@link InputMap} / {@link * ActionMap} interfaces, such that old Keymap-using code can make use of * the new framework. * * <p>A little bit of experimentation with these classes reveals the following * structure: * * <ul> * * <li>KeymapWrapper extends {@link InputMap} and holds a reference to * the underlying {@link Keymap}.</li> * * <li>KeymapWrapper maps {@link KeyStroke} objects to {@link Action} * objects, by delegation to the underlying {@link Keymap}.</li> * * <li>KeymapActionMap extends {@link ActionMap} also holds a reference to * the underlying {@link Keymap} but only appears to use it for listing * its keys. </li> * * <li>KeymapActionMap maps all {@link Action} objects to * <em>themselves</em>, whether they exist in the underlying {@link * Keymap} or not, and passes other objects to the parent {@link * ActionMap} for resolving. * * </ul> */ private class KeymapWrapper extends InputMap { Keymap map; public KeymapWrapper(Keymap k) { map = k; } public int size() { return map.getBoundKeyStrokes().length + super.size(); } public Object get(KeyStroke ks) { Action mapped = null; Keymap m = map; while(mapped == null && m != null) { mapped = m.getAction(ks); if (mapped == null && ks.getKeyEventType() == KeyEvent.KEY_TYPED) mapped = m.getDefaultAction(); if (mapped == null) m = m.getResolveParent(); } if (mapped == null) return super.get(ks); else return mapped; } public KeyStroke[] keys() { KeyStroke[] superKeys = super.keys(); KeyStroke[] mapKeys = map.getBoundKeyStrokes(); KeyStroke[] bothKeys = new KeyStroke[superKeys.length + mapKeys.length]; for (int i = 0; i < superKeys.length; ++i) bothKeys[i] = superKeys[i]; for (int i = 0; i < mapKeys.length; ++i) bothKeys[i + superKeys.length] = mapKeys[i]; return bothKeys; } public KeyStroke[] allKeys() { KeyStroke[] superKeys = super.allKeys(); KeyStroke[] mapKeys = map.getBoundKeyStrokes(); KeyStroke[] bothKeys = new KeyStroke[superKeys.length + mapKeys.length]; for (int i = 0; i < superKeys.length; ++i) bothKeys[i] = superKeys[i]; for (int i = 0; i < mapKeys.length; ++i) bothKeys[i + superKeys.length] = mapKeys[i]; return bothKeys; } } private class KeymapActionMap extends ActionMap { Keymap map; public KeymapActionMap(Keymap k) { map = k; } public Action get(Object cmd) { if (cmd instanceof Action) return (Action) cmd; else return super.get(cmd); } public int size() { return map.getBoundKeyStrokes().length + super.size(); } public Object[] keys() { Object[] superKeys = super.keys(); Object[] mapKeys = map.getBoundKeyStrokes(); Object[] bothKeys = new Object[superKeys.length + mapKeys.length]; for (int i = 0; i < superKeys.length; ++i) bothKeys[i] = superKeys[i]; for (int i = 0; i < mapKeys.length; ++i) bothKeys[i + superKeys.length] = mapKeys[i]; return bothKeys; } public Object[] allKeys() { Object[] superKeys = super.allKeys(); Object[] mapKeys = map.getBoundKeyStrokes(); Object[] bothKeys = new Object[superKeys.length + mapKeys.length]; for (int i = 0; i < superKeys.length; ++i) bothKeys[i] = superKeys[i]; for (int i = 0; i < mapKeys.length; ++i) bothKeys[i + superKeys.length] = mapKeys[i]; return bothKeys; } } static class DefaultKeymap implements Keymap { String name; Keymap parent; Hashtable map; Action defaultAction; public DefaultKeymap(String name) { this.name = name; this.map = new Hashtable(); } public void addActionForKeyStroke(KeyStroke key, Action a) { map.put(key, a); } /** * Looks up a KeyStroke either in the current map or the parent Keymap; * does <em>not</em> return the default action if lookup fails. * * @param key The KeyStroke to look up an Action for. * * @return The mapping for <code>key</code>, or <code>null</code> * if no mapping exists in this Keymap or any of its parents. */ public Action getAction(KeyStroke key) { if (map.containsKey(key)) return (Action) map.get(key); else if (parent != null) return parent.getAction(key); else return null; } public Action[] getBoundActions() { Action [] ret = new Action[map.size()]; Enumeration e = map.elements(); int i = 0; while (e.hasMoreElements()) { ret[i++] = (Action) e.nextElement(); } return ret; } public KeyStroke[] getBoundKeyStrokes() { KeyStroke [] ret = new KeyStroke[map.size()]; Enumeration e = map.keys(); int i = 0; while (e.hasMoreElements()) { ret[i++] = (KeyStroke) e.nextElement(); } return ret; } public Action getDefaultAction() { return defaultAction; } public KeyStroke[] getKeyStrokesForAction(Action a) { int i = 0; Enumeration e = map.keys(); while (e.hasMoreElements()) { if (map.get(e.nextElement()).equals(a)) ++i; } KeyStroke [] ret = new KeyStroke[i]; i = 0; e = map.keys(); while (e.hasMoreElements()) { KeyStroke k = (KeyStroke) e.nextElement(); if (map.get(k).equals(a)) ret[i++] = k; } return ret; } public String getName() { return name; } public Keymap getResolveParent() { return parent; } public boolean isLocallyDefined(KeyStroke key) { return map.containsKey(key); } public void removeBindings() { map.clear(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -