Java 类javax.swing.text.Keymap 实例源码
项目:incubator-netbeans
文件:ScrollCompletionPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
Action a = component.getActionMap().get(editorActionName);
Keymap km = component.getKeymap();
if (a != null && km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
return ret;
}
项目:incubator-netbeans
文件:CslEditorKit.java
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target) {
// Try to get the accelerator
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if ((keys != null) && (keys.length > 0)) {
item.setAccelerator(keys[0]);
} else if (a != null) {
KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
if (ks != null) {
item.setAccelerator(ks);
}
}
}
}
项目:incubator-netbeans
文件:CompletionScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null && editorActionName != null) {
Action a = component.getActionMap().get(editorActionName);
Keymap km = component.getKeymap();
if (a != null && km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
return ret;
}
项目:incubator-netbeans
文件:DocumentationScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
TextUI componentUI = component.getUI();
Keymap km = component.getKeymap();
if (componentUI != null && km != null) {
EditorKit kit = componentUI.getEditorKit(component);
if (kit instanceof BaseKit) {
Action a = ((BaseKit)kit).getActionByName(editorActionName);
if (a != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
}
}
return ret;
}
项目:incubator-netbeans
文件:DocumentationScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
TextUI componentUI = component.getUI();
Keymap km = component.getKeymap();
if (componentUI != null && km != null) {
EditorKit kit = componentUI.getEditorKit(component);
if (kit instanceof BaseKit) {
Action a = ((BaseKit)kit).getActionByName(editorActionName);
if (a != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
}
}
return ret;
}
项目:incubator-netbeans
文件:Terminal.java
private void applyShortcuts() {
if (!termOptions.getIgnoreKeymap()) {
Set<String> actions = new HashSet<String>();
for (FileObject def : shortcutsDir.getChildren()) {
try {
DataObject dobj = DataObject.find(def);
InstanceCookie ic = dobj.getLookup().lookup(InstanceCookie.class);
if (ic != null) {
// put class names in the map,
// otherwise we may end with several instances of the action
actions.add(ic.instanceCreate().getClass().getName());
}
} catch (Exception e) {
Exceptions.printStackTrace(e);
}
}
term.setKeymap(Lookup.getDefault().lookup(Keymap.class), actions);
// needed for Ctrl+Tab, Ctrl+Shift+Tab switching
term.getScreen().setFocusTraversalKeysEnabled(false);
} else {
term.setKeymap(null, null);
term.getScreen().setFocusTraversalKeysEnabled(true);
}
}
项目:incubator-netbeans
文件:CompletionScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null && editorActionName != null) {
Action a = component.getActionMap().get(editorActionName);
Keymap km = component.getKeymap();
if (a != null && km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
return ret;
}
项目:incubator-netbeans
文件:DocumentationScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
TextUI componentUI = component.getUI();
Keymap km = component.getKeymap();
if (componentUI != null && km != null) {
EditorKit kit = componentUI.getEditorKit(component);
if (kit instanceof BaseKit) {
Action a = ((BaseKit)kit).getActionByName(editorActionName);
if (a != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
}
}
return ret;
}
项目:incubator-netbeans
文件:NbEditorKit.java
private static void assignAccelerator(Keymap km, Action action, JMenuItem item) {
if (item.getAccelerator() == null){
KeyStroke ks = (KeyStroke)action.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setMnemonic(ks.getKeyCode());
} else {
// Try to get the accelerator from keymap
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(action);
if (keys != null && keys.length > 0) {
item.setMnemonic(keys[0].getKeyCode());
}
}
}
}
}
项目:incubator-netbeans
文件:NbEditorKit.java
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target){
// Try to get the accelerator
Keymap km = (target == null) ? BaseKit.getKit(BaseKit.class).getKeymap() :
target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
boolean added = false;
for (int i = 0; i<keys.length; i++){
if ((keys[i].getKeyCode() == KeyEvent.VK_MULTIPLY) ||
keys[i].getKeyCode() == KeyEvent.VK_ADD){
item.setMnemonic(keys[i].getKeyCode());
added = true;
break;
}
}
if (added == false) item.setMnemonic(keys[0].getKeyCode());
}
}
}
项目:incubator-netbeans
文件:ScrollCompletionPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(JTextComponent component, String editorActionName, KeyStroke defaultKey) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
Action a = component.getActionMap().get(editorActionName);
Keymap km = component.getKeymap();
if (a != null && km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
return ret;
}
项目:incubator-netbeans
文件:MainMenuAction.java
/** Adds accelerators to given JMenuItem taken from the action */
protected static void addAccelerators(Action a, JMenuItem item, JTextComponent target){
if (target == null || a==null || item==null) return;
// get accelerators from kitAction
Action kitAction = getActionByName((String)a.getValue(Action.NAME));
if (kitAction!=null) a = kitAction;
// Try to get the accelerator, TopComponent action could be obsoleted
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
KeyStroke itemAccelerator = item.getAccelerator();
if (keys != null && keys.length > 0) {
if (itemAccelerator==null || !itemAccelerator.equals(keys[0])){
item.setAccelerator(keys[0]);
}
}else{
if (itemAccelerator!=null && kitAction!=null){
item.setAccelerator(null);
}
}
}
}
项目:javify
文件:BasicTextUI.java
/**
* Creates the {@link Keymap} that is installed on the text component.
*
* @return the {@link Keymap} that is installed on the text component
*/
protected Keymap createKeymap()
{
String keymapName = getKeymapName();
Keymap keymap = JTextComponent.getKeymap(keymapName);
if (keymap == null)
{
Keymap parentMap =
JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
keymap = JTextComponent.addKeymap(keymapName, parentMap);
Object val = UIManager.get(getPropertyPrefix() + ".keyBindings");
if (val != null && val instanceof JTextComponent.KeyBinding[])
{
JTextComponent.KeyBinding[] bindings =
(JTextComponent.KeyBinding[]) val;
JTextComponent.loadKeymap(keymap, bindings,
getComponent().getActions());
}
}
return keymap;
}
项目:jvm-stm
文件:BasicTextUI.java
/**
* Creates the {@link Keymap} that is installed on the text component.
*
* @return the {@link Keymap} that is installed on the text component
*/
protected Keymap createKeymap()
{
String keymapName = getKeymapName();
Keymap keymap = JTextComponent.getKeymap(keymapName);
if (keymap == null)
{
Keymap parentMap =
JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
keymap = JTextComponent.addKeymap(keymapName, parentMap);
Object val = UIManager.get(getPropertyPrefix() + ".keyBindings");
if (val != null && val instanceof JTextComponent.KeyBinding[])
{
JTextComponent.KeyBinding[] bindings =
(JTextComponent.KeyBinding[]) val;
JTextComponent.loadKeymap(keymap, bindings,
getComponent().getActions());
}
}
return keymap;
}
项目:goworks
文件:GrammarEditorKit.java
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target){
// Try to get the accelerator
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
item.setAccelerator(keys[0]);
}else if (a!=null){
KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setAccelerator(ks);
}
}
}
}
项目:goworks
文件:GoEditorKit.java
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target){
// Try to get the accelerator
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
item.setAccelerator(keys[0]);
}else if (a!=null){
KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setAccelerator(ks);
}
}
}
}
项目:goworks
文件:CompletionScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
Action a = component.getActionMap().get(editorActionName);
Keymap km = component.getKeymap();
if (a != null && km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
return ret;
}
项目:goworks
文件:DocumentationScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
TextUI componentUI = component.getUI();
Keymap km = component.getKeymap();
if (componentUI != null && km != null) {
EditorKit kit = componentUI.getEditorKit(component);
if (kit instanceof BaseKit) {
Action a = ((BaseKit)kit).getActionByName(editorActionName);
if (a != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
}
}
return ret;
}
项目:JamVM-PH
文件:BasicTextUI.java
/**
* Creates the {@link Keymap} that is installed on the text component.
*
* @return the {@link Keymap} that is installed on the text component
*/
protected Keymap createKeymap()
{
String keymapName = getKeymapName();
Keymap keymap = JTextComponent.getKeymap(keymapName);
if (keymap == null)
{
Keymap parentMap =
JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
keymap = JTextComponent.addKeymap(keymapName, parentMap);
Object val = UIManager.get(getPropertyPrefix() + ".keyBindings");
if (val != null && val instanceof JTextComponent.KeyBinding[])
{
JTextComponent.KeyBinding[] bindings =
(JTextComponent.KeyBinding[]) val;
JTextComponent.loadKeymap(keymap, bindings,
getComponent().getActions());
}
}
return keymap;
}
项目:jabref
文件:EmacsKeyBindings.java
private static void createBackup() {
Keymap oldBackup = JTextComponent.getKeymap(EmacsKeyBindings.JTCS[0].getClass().getName());
if (oldBackup != null) {
// if there is already a backup, do not create a new backup
return;
}
for (JTextComponent jtc : EmacsKeyBindings.JTCS) {
Keymap orig = jtc.getKeymap();
Keymap backup = JTextComponent.addKeymap
(jtc.getClass().getName(), null);
Action[] bound = orig.getBoundActions();
for (Action aBound : bound) {
KeyStroke[] strokes = orig.getKeyStrokesForAction(aBound);
for (KeyStroke stroke : strokes) {
backup.addActionForKeyStroke(stroke, aBound);
}
}
backup.setDefaultAction(orig.getDefaultAction());
}
}
项目:jabref
文件:EmacsKeyBindings.java
/**
* Restores the original keybindings for the concrete subclasses of
* {@link JTextComponent}.
*/
public static void unload() {
for (int i = 0; i < EmacsKeyBindings.JTCS.length; i++) {
Keymap backup = JTextComponent.getKeymap
(EmacsKeyBindings.JTCS[i].getClass().getName());
if (backup != null) {
Keymap current = EmacsKeyBindings.JTCS[i].getKeymap();
current.removeBindings();
Action[] bound = backup.getBoundActions();
for (Action aBound : bound) {
KeyStroke[] strokes =
backup.getKeyStrokesForAction(bound[i]);
for (KeyStroke stroke : strokes) {
current.addActionForKeyStroke(stroke, aBound);
}
}
current.setDefaultAction(backup.getDefaultAction());
}
}
}
项目:classpath
文件:BasicTextUI.java
/**
* Creates the {@link Keymap} that is installed on the text component.
*
* @return the {@link Keymap} that is installed on the text component
*/
protected Keymap createKeymap()
{
String keymapName = getKeymapName();
Keymap keymap = JTextComponent.getKeymap(keymapName);
if (keymap == null)
{
Keymap parentMap =
JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);
keymap = JTextComponent.addKeymap(keymapName, parentMap);
Object val = UIManager.get(getPropertyPrefix() + ".keyBindings");
if (val != null && val instanceof JTextComponent.KeyBinding[])
{
JTextComponent.KeyBinding[] bindings =
(JTextComponent.KeyBinding[]) val;
JTextComponent.loadKeymap(keymap, bindings,
getComponent().getActions());
}
}
return keymap;
}
项目:antlrworks2
文件:GrammarEditorKit.java
private void addAcceleretors(Action a, JMenuItem item, JTextComponent target){
// Try to get the accelerator
Keymap km = target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
item.setAccelerator(keys[0]);
}else if (a!=null){
KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setAccelerator(ks);
}
}
}
}
项目:antlrworks2
文件:CompletionScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
Action a = component.getActionMap().get(editorActionName);
Keymap km = component.getKeymap();
if (a != null && km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
return ret;
}
项目:antlrworks2
文件:DocumentationScrollPane.java
/** Attempt to find the editor keystroke for the given editor action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey, JTextComponent component) {
// This method is implemented due to the issue
// #25715 - Attempt to search keymap for the keybinding that logically corresponds to the action
KeyStroke[] ret = new KeyStroke[] { defaultKey };
if (component != null) {
TextUI componentUI = component.getUI();
Keymap km = component.getKeymap();
if (componentUI != null && km != null) {
EditorKit kit = componentUI.getEditorKit(component);
if (kit instanceof BaseKit) {
Action a = ((BaseKit)kit).getActionByName(editorActionName);
if (a != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
}
}
}
}
}
return ret;
}
项目:TechScore
文件:EditField.java
/**
* Creates a new <code>EditField</code> instance.
*
*/
public EditField(String value, int cols) {
super(value, cols);
Keymap km = this.getKeymap();
km.addActionForKeyStroke(KeyStroke.getKeyStroke("ESCAPE"),
new AbstractAction() {
public void actionPerformed(ActionEvent ev) {
EditField.this.rollBack();
}
});
km.addActionForKeyStroke(KeyStroke.getKeyStroke("ENTER"),
new AbstractAction() {
public void actionPerformed(ActionEvent evt) {
EditField.this.commitEdit();
}
});
this.previous = value;
this.addFocusListener(this);
}
项目:wombat-ide
文件:EmacsKeyBindings.java
/***
* Loads the emacs keybindings for all common <code>JTextComponent</code>s.
*
* The shared keymap instances of the concrete subclasses of
* {@link JTextComponent} are fed with the keybindings.
*
* The original keybindings are stored in a backup array.
*/
public static void load() {
JTextComponent[] jtcs = new JTextComponent[] { new JTextArea(),
new JTextPane(), new JTextField(), new JEditorPane(), };
for (int i = 0; i < jtcs.length; i++) {
Keymap orig = jtcs[i].getKeymap();
Keymap backup = JTextComponent.addKeymap(jtcs[i].getClass()
.getName(), null);
Action[] bound = orig.getBoundActions();
for (int j = 0; j < bound.length; j++) {
KeyStroke[] strokes = orig.getKeyStrokesForAction(bound[j]);
for (int k = 0; k < strokes.length; k++) {
backup.addActionForKeyStroke(strokes[k], bound[j]);
}
}
backup.setDefaultAction(orig.getDefaultAction());
}
loadEmacsKeyBindings();
}
项目:wombat-ide
文件:EmacsKeyBindings.java
/***
* Restores the original keybindings for the concrete subclasses of
* {@link JTextComponent}.
*
*/
public static void unload() {
JTextComponent[] jtcs = new JTextComponent[] { new JTextArea(),
new JTextPane(), new JTextField(), new JEditorPane(), };
for (int i = 0; i < jtcs.length; i++) {
Keymap backup = JTextComponent.getKeymap(jtcs[i].getClass()
.getName());
if (backup != null) {
Keymap current = jtcs[i].getKeymap();
current.removeBindings();
Action[] bound = backup.getBoundActions();
for (int j = 0; j < bound.length; j++) {
KeyStroke[] strokes = backup
.getKeyStrokesForAction(bound[i]);
for (int k = 0; k < strokes.length; k++) {
current.addActionForKeyStroke(strokes[k], bound[j]);
}
}
current.setDefaultAction(backup.getDefaultAction());
}
}
}
项目:incubator-netbeans
文件:MultiKeymap.java
/** Loads key to action mappings into this keymap
* @param bindings array of bindings
* @param actions map of [action_name, action] pairs
*/
public void load(JTextComponent.KeyBinding[] bindings, Map actions) {
// now create bindings in keymap(s)
for (int i = 0; i < bindings.length; i++) {
Action a = (Action)actions.get(bindings[i].actionName);
if (a != null) {
boolean added = false;
if (bindings[i] instanceof MultiKeyBinding) {
MultiKeyBinding mb = (MultiKeyBinding)bindings[i];
if (mb.keys != null) {
Keymap cur = delegate;
for (int j = 0; j < mb.keys.length; j++) {
if (j == mb.keys.length - 1) { // last keystroke in sequence
cur.addActionForKeyStroke(mb.keys[j], a);
} else { // not the last keystroke
Action sca = cur.getAction(mb.keys[j]);
if (!(sca instanceof KeymapSetContextAction)) {
sca = new KeymapSetContextAction(JTextComponent.addKeymap(null, null));
cur.addActionForKeyStroke(mb.keys[j], sca);
}
cur = ((KeymapSetContextAction)sca).contextKeymap;
}
}
added = true;
}
}
if (!added) {
if (bindings[i].key != null) {
delegate.addActionForKeyStroke(bindings[i].key, a);
} else { // key is null -> set default action
setDefaultAction(a);
}
}
}
}
}
项目:incubator-netbeans
文件:MultiKeymap.java
public void setResolveParent(Keymap parent) {
if (context != null) {
context.setResolveParent(parent);
} else {
delegate.setResolveParent(parent);
}
}
项目:incubator-netbeans
文件:CommitPanel.java
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
boolean ret = super.processKeyBinding(ks, e, condition, pressed);
// XXX #250546 Reason of overriding: to process global shortcut.
if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) {
Keymap km = Lookup.getDefault().lookup(Keymap.class);
Action action = (km != null) ? km.getAction(ks) : null;
if (action == null) {
return false;
}
if (action instanceof CallbackSystemAction) {
CallbackSystemAction csAction = (CallbackSystemAction) action;
if (tabbedPane != null) {
Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey());
if (a != null) {
a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks)));
return true;
}
}
}
return false;
} else {
return ret;
}
}
项目:incubator-netbeans
文件:VCSCommitPanel.java
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
boolean ret = super.processKeyBinding(ks, e, condition, pressed);
// XXX #250546 Reason of overriding: to process global shortcut.
if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) {
Keymap km = Lookup.getDefault().lookup(Keymap.class);
Action action = (km != null) ? km.getAction(ks) : null;
if (action == null) {
return false;
}
if (action instanceof CallbackSystemAction) {
CallbackSystemAction csAction = (CallbackSystemAction) action;
if (tabbedPane != null) {
Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey());
if (a != null) {
a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks)));
return true;
}
}
}
return false;
} else {
return ret;
}
}
项目:incubator-netbeans
文件:NbKeymap.java
protected @Override KeyStroke keyStrokeForAction(Action action, FileObject definingFile) {
Keymap km = Lookup.getDefault().lookup(Keymap.class);
if (km instanceof NbKeymap) {
return ((NbKeymap) km).keyStrokeForAction(action, definingFile);
} else {
LOG.log(Level.WARNING, "unexpected keymap: {0}", km);
return null;
}
}
项目:incubator-netbeans
文件:ShortcutAndMenuKeyEventProcessor.java
private boolean processShortcut(KeyEvent ev) {
//ignore shortcut keys when the IDE is shutting down
if (NbLifecycleManager.isExiting()) {
ev.consume();
return true;
}
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(ev);
Window w = SwingUtilities.windowForComponent(ev.getComponent());
// don't process shortcuts if this is a help frame
if ((w instanceof JFrame) && ((JFrame)w).getRootPane().getClientProperty("netbeans.helpframe") != null) // NOI18N
return true;
// don't let action keystrokes to propagate from both
// modal and nonmodal dialogs, but propagate from separate floating windows,
// even if they are backed by JDialog
if ((w instanceof Dialog) &&
!WindowManagerImpl.isSeparateWindow(w) &&
!isTransmodalAction(ks)) {
return false;
}
// Provide a reasonably useful action event that identifies what was focused
// when the key was pressed, as well as what keystroke ran the action.
ActionEvent aev = new ActionEvent(
ev.getSource(), ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks));
Keymap root = Lookup.getDefault().lookup(Keymap.class);
Action a = root.getAction (ks);
if (a != null && a.isEnabled()) {
ActionManager am = Lookup.getDefault().lookup(ActionManager.class);
am.invokeAction(a, aev);
ev.consume();
return true;
}
return false;
}
项目:incubator-netbeans
文件:ContextAwareActionInTopComponentTest.java
protected void setUp () throws Exception {
tc = new TopComponent ();
tc.requestActive();
MockServices.setServices( MyKeymap.class );
Keymap km = Lookup.getDefault().lookup(Keymap.class);
km.addActionForKeyStroke( KEY_STROKE, myGlobalAction );
MyContextAwareAction.globalActionWasPerformed = false;
MyContextAwareAction.contextActionWasPerformed = false;
}
项目:incubator-netbeans
文件:ToolTipView.java
@Override
public void setKeymap(Keymap map) {
//#181722: keymaps are shared among components with the same UI
//a default action will be set to the Keymap of this component below,
//so it is necessary to use a Keymap that is not shared with other JTextAreas
super.setKeymap(addKeymap(null, map));
}
项目:incubator-netbeans
文件:NbEditorKit.java
private static void addAcceleretors(Action a, JMenuItem item, JTextComponent target) {
// Try to get the accelerator
Keymap km = (target == null) ? BaseKit.getKit(BaseKit.class).getKeymap() :
target.getKeymap();
if (km != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
boolean added = false;
for (int i = 0; i<keys.length; i++){
if ((keys[i].getKeyCode() == KeyEvent.VK_MULTIPLY) ||
keys[i].getKeyCode() == KeyEvent.VK_ADD){
item.setMnemonic(keys[i].getKeyCode());
added = true;
break;
}
}
if (added == false) {
item.setMnemonic(keys[0].getKeyCode());
}
}else if (a!=null){
KeyStroke ks = (KeyStroke)a.getValue(Action.ACCELERATOR_KEY);
if (ks!=null) {
item.setMnemonic(ks.getKeyCode());
}
}
}
}
项目:incubator-netbeans
文件:NbEditorToolBar.java
/** Attempt to find the editor keystroke for the given action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
KeyStroke[] ret = new KeyStroke[] { defaultKey };
JTextComponent comp = getComponent();
if (editorActionName != null && comp != null) {
TextUI textUI = comp.getUI();
Keymap km = comp.getKeymap();
if (textUI != null && km != null) {
EditorKit kit = textUI.getEditorKit(comp);
if (kit instanceof BaseKit) {
Action a = ((BaseKit)kit).getActionByName(editorActionName);
if (a != null) {
KeyStroke[] keys = km.getKeyStrokesForAction(a);
if (keys != null && keys.length > 0) {
ret = keys;
} else {
// try kit's keymap
Keymap km2 = ((BaseKit)kit).getKeymap();
KeyStroke[] keys2 = km2.getKeyStrokesForAction(a);
if (keys2 != null && keys2.length > 0) {
ret = keys2;
}
}
}
}
}
}
return ret;
}
项目:incubator-netbeans
文件:CommitPanel.java
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
boolean ret = super.processKeyBinding(ks, e, condition, pressed);
// XXX #250546 Reason of overriding: to process global shortcut.
if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) {
Keymap km = Lookup.getDefault().lookup(Keymap.class);
Action action = (km != null) ? km.getAction(ks) : null;
if (action == null) {
return false;
}
if (action instanceof CallbackSystemAction) {
CallbackSystemAction csAction = (CallbackSystemAction) action;
if (tabbedPane != null) {
Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey());
if (a != null) {
a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks)));
return true;
}
}
}
return false;
} else {
return ret;
}
}
项目:openjdk-jdk10
文件:TestNimbusOverride.java
public TestNimbusOverride()
{
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
/*
* Create a frame containing a JEditorPane, and override the action for the space bar to show
* a dialog.
*/
JEditorPane pp = new JEditorPane();
UIDefaults defaults = new UIDefaults();
pp.putClientProperty("Nimbus.Overrides", defaults);
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BorderLayout());
setContentPane(contentPanel);
contentPanel.setPreferredSize(new Dimension(400, 300));
contentPanel.add(pp, BorderLayout.CENTER);
Keymap origKeymap = pp.getKeymap();
Keymap km = JEditorPane.addKeymap("Test keymap", origKeymap);
km.addActionForKeyStroke(KeyStroke.getKeyStroke(' '), new AbstractAction("SHOW_SPACE") {
@Override
public void actionPerformed(ActionEvent e)
{
passed = true;
}
});
pp.setKeymap(km);
}