本文整理汇总了Java中javax.swing.text.Keymap.getAction方法的典型用法代码示例。如果您正苦于以下问题:Java Keymap.getAction方法的具体用法?Java Keymap.getAction怎么用?Java Keymap.getAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Keymap
的用法示例。
在下文中一共展示了Keymap.getAction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/** 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);
}
}
}
}
}
示例2: processKeyBinding
import javax.swing.text.Keymap; //导入方法依赖的package包/类
@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;
}
}
示例3: processShortcut
import javax.swing.text.Keymap; //导入方法依赖的package包/类
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;
}
示例4: keymapAddAlias
import javax.swing.text.Keymap; //导入方法依赖的package包/类
private void keymapAddAlias(Keymap km, int origEvent, int origMask,
int aliasEvent, int aliasMask) {
KeyStroke orig = KeyStroke.getKeyStroke(origEvent, origMask);
System.err.println(orig);
KeyStroke alias = KeyStroke.getKeyStroke(aliasEvent, aliasMask);
System.err.println(alias);
Action a = km.getAction(alias);
System.err.println(a);
km.addActionForKeyStroke(orig, km.getAction(alias));
}
示例5: CodePane
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/**
* Creates a new <code>NoWrapJTextPane</code> and sets it to use various
* versions of my EditorKit implementation based on a few mime types.
*
* The special mime types it will now know are text/Java, text/C++,
* text/C#, text/VB.
**/
public CodePane()
{
//This is a convenient way to do this :-)
doContentType("java", JavaView.class);
doContentType("cpp", CPPView.class);
doContentType("csharp", CSharpView.class);
doContentType("vb", VBView.class);
doContentType("py", PythonView.class);
undo = new UndoManager();
getStyledDocument().addUndoableEditListener(undo);
addMouseListener(this);
setDragEnabled(true);
resetPrefs();
Keymap defaultKeymap = getKeymap();
subdispatcher = Dispatcher.getGlobalDispatcher().createSubDispatcher(this);
findContext = new FindReplaceContext(subdispatcher);
Keymap myKeymap = new KawigiEditKeyMap(subdispatcher);
myKeymap.setResolveParent(defaultKeymap);
setKeymap(myKeymap);
ActionMap actionMap = getActionMap();
InputMap inputMap = getInputMap();
KeyStroke[] keystrokes = myKeymap.getBoundKeyStrokes();
for (int i=0; i<keystrokes.length; i++)
if ((keystrokes[i].getModifiers() & (InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) != 0)
{
DefaultAction act = (DefaultAction)myKeymap.getAction(keystrokes[i]);
inputMap.put(keystrokes[i], act.getID().toString());
actionMap.put(act.getID().toString(), act);
}
subdispatcher.getAction(ActID.actInsertSnippet);
}
示例6: processKeyBinding
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/** Overrides superclass method, adds possible additional handling of global keystrokes
* in case this <code>TopComoponent</code> is ancestor of focused component. */
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
int condition, boolean pressed) {
boolean ret = super.processKeyBinding(ks, e, condition, pressed);
// XXX #30189 Reason of overriding: to process global shortcut.
if(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition
&& ret == false && !e.isConsumed()
&& (Dependency.JAVA_SPEC.compareTo(new SpecificationVersion("1.4")) >= 0)) { // NOI18N
Keymap km = (Keymap)Lookup.getDefault().lookup(Keymap.class);
Action action = km.getAction(ks);
if(action == null) {
return false;
}
// If necessary create context aware instance.
if(action instanceof ContextAwareAction) {
action = ((ContextAwareAction)action).createContextAwareInstance(getLookup());
} else if(SwingUtilities.getWindowAncestor(e.getComponent())
instanceof java.awt.Dialog) {
// #30303 For 'old type' actions check the transmodal flag,
// if invoked in dialog. See ShorcutAndMenuKeyEventProcessor in core.
Object value = action.getValue("OpenIDE-Transmodal-Action"); // NOI18N
if(!Boolean.TRUE.equals(value)) {
return false;
}
}
// #30600 We have to use ActionManager, which replanes performation
// of action to another thread, since our actions rely on that.
// return SwingUtilities.notifyAction(
// action, ks, e, this, e.getModifiers());
ActionManager am = (ActionManager)Lookup.getDefault().lookup(ActionManager.class);
am.invokeAction(
action,
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks))
);
return true;
} else {
return ret;
}
}
示例7: isTransmodalAction
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/**
* Checks to see if a given keystroke is bound to an action which should
* function on all focused components. This includes the Main Window,
* dialogs, popup menus, etc. Otherwise only the Main Window and
* TopComponents will receive the keystroke. By default, off, unless the
* action has a property named <code>OpenIDE-Transmodal-Action</code> which
* is set to {@link Boolean#TRUE}.
* @param key the keystroke to check
* @return <code>true</code> if transmodal; <code>false</code> if a normal
* action, or the key is not bound to anything in the global keymap
*/
private static boolean isTransmodalAction (KeyStroke key) {
Keymap root = Lookup.getDefault().lookup(Keymap.class);
Action a = root.getAction (key);
if (a == null) return false;
Object val = a.getValue ("OpenIDE-Transmodal-Action"); // NOI18N
return val != null && val.equals (Boolean.TRUE);
}