本文整理汇总了Java中javax.swing.text.Keymap.addActionForKeyStroke方法的典型用法代码示例。如果您正苦于以下问题:Java Keymap.addActionForKeyStroke方法的具体用法?Java Keymap.addActionForKeyStroke怎么用?Java Keymap.addActionForKeyStroke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Keymap
的用法示例。
在下文中一共展示了Keymap.addActionForKeyStroke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBackup
import javax.swing.text.Keymap; //导入方法依赖的package包/类
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());
}
}
示例2: unload
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/**
* 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());
}
}
}
示例3: EditField
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/**
* 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);
}
示例4: load
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/***
* 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();
}
示例5: unload
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/***
* 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());
}
}
}
示例6: 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);
}
}
}
}
}
示例7: setUp
import javax.swing.text.Keymap; //导入方法依赖的package包/类
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;
}
示例8: TestNimbusOverride
import javax.swing.text.Keymap; //导入方法依赖的package包/类
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);
}
示例9: removeTabBinding
import javax.swing.text.Keymap; //导入方法依赖的package包/类
/** Removes the Tab Key Binding */
private void removeTabBinding() {
// Remove the binding for the TAB Key.
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
Keymap noTabMap = getKeymap();
noTabMap.removeKeyStrokeBinding(tab);
noTabMap.addActionForKeyStroke(tab, new DefaultEditorKit.DefaultKeyTypedAction());
addKeymap("NoTabbingMap", noTabMap);
}
示例10: updateKeymap
import javax.swing.text.Keymap; //导入方法依赖的package包/类
protected void updateKeymap() {
// KeyStroke key = KeyStroke.getKeyStroke('\n'); didn't work.
KeyStroke key = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,
0,false);
Action action = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
((IOTextArea) e.getSource()).handleNewline(); }};
Keymap newKeymap = JTextComponent.addKeymap
("IOTextAreaKeymap", this.area.getKeymap());
newKeymap.addActionForKeyStroke(key, action);
this.area.setKeymap(newKeymap); }
示例11: 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));
}
示例12: registerAccelerators
import javax.swing.text.Keymap; //导入方法依赖的package包/类
public void registerAccelerators() {
CommandManager commandManager = getCommandManager();
Keymap keymap = new DefaultKeymap(getClass().getName(), textComponent.getKeymap());
for (int i = 0; i < COMMANDS.length; i++) {
ActionCommand command = commandManager.getActionCommand(COMMANDS[i]);
keymap.addActionForKeyStroke(command.getAccelerator(), command.getActionAdapter());
}
if (COMMANDS.length > 0) {
textComponent.setKeymap(keymap);
}
}
示例13: initKeyMap
import javax.swing.text.Keymap; //导入方法依赖的package包/类
public void initKeyMap(JTextArea text) {
Keymap keyMap = JTextArea.addKeymap("EnterSubmit", text.getKeymap());
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
keyMap.addActionForKeyStroke(key, new SubmitAction());
text.setKeymap(keyMap);
}
示例14: initKeyMap
import javax.swing.text.Keymap; //导入方法依赖的package包/类
public void initKeyMap(JTextArea text) {
Keymap keyMap = JTextArea.addKeymap("EnterSubmit", text.getKeymap());
KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
keyMap.addActionForKeyStroke(key, new RefreshAction());
text.setKeymap(keyMap);
}
示例15: init
import javax.swing.text.Keymap; //导入方法依赖的package包/类
public void init() {
Keymap parent = m_TCPane.getActiveTextPane().getKeymap();
Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent);
KeyStroke shiftF5key = KeyStroke.getKeyStroke(KeyEvent.VK_F5, InputEvent.SHIFT_MASK);
newmap.addActionForKeyStroke(shiftF5key, new ShiftF5Action());
KeyStroke F5key = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
newmap.addActionForKeyStroke(F5key, new F5Action());
KeyStroke F6Key = KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0);
newmap.addActionForKeyStroke(F6Key, new F6Action());
KeyStroke F8Key = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
newmap.addActionForKeyStroke(F8Key, new ShiftF5Action());
KeyStroke CTRLF2Key = KeyStroke.getKeyStroke(KeyEvent.VK_F2, InputEvent.CTRL_DOWN_MASK);
newmap.addActionForKeyStroke(CTRLF2Key, new CTRLF2Action());
m_TCPane.getActiveTextPane().setKeymap(newmap);
}