本文整理汇总了Java中javax.swing.InputMap.allKeys方法的典型用法代码示例。如果您正苦于以下问题:Java InputMap.allKeys方法的具体用法?Java InputMap.allKeys怎么用?Java InputMap.allKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.InputMap
的用法示例。
在下文中一共展示了InputMap.allKeys方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exchangeCommands
import javax.swing.InputMap; //导入方法依赖的package包/类
private static void exchangeCommands(String[][] commandsToExchange,
final JComponent target, final JComponent source) {
InputMap targetBindings = target.getInputMap();
KeyStroke[] targetBindingKeys = targetBindings.allKeys();
ActionMap targetActions = target.getActionMap();
InputMap sourceBindings = source.getInputMap();
ActionMap sourceActions = source.getActionMap();
for (int i = 0; i < commandsToExchange.length; i++) {
String commandFrom = commandsToExchange[i][0];
String commandTo = commandsToExchange[i][1];
final Action orig = targetActions.get(commandTo);
if (orig == null) {
continue;
}
sourceActions.put(commandTo, new AbstractAction() {
public void actionPerformed(ActionEvent e) {
orig.actionPerformed(new ActionEvent(target, e.getID(), e.getActionCommand(), e.getWhen(), e.getModifiers()));
}
});
for (int j = 0; j < targetBindingKeys.length; j++) {
if (targetBindings.get(targetBindingKeys[j]).equals(commandFrom)) {
sourceBindings.put(targetBindingKeys[j], commandTo);
}
}
}
}
示例2: getKeyStrokeFor
import javax.swing.InputMap; //导入方法依赖的package包/类
private String getKeyStrokeFor(String action) {
JSONArray r = new JSONArray();
if (component instanceof JComponent) {
InputMap inputMap = ((JComponent) component).getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (KeyStroke ks : allKeys) {
if (action.equals(inputMap.get(ks))) {
r.put(ks.toString());
}
}
}
if (r.length() > 0) {
return r.toString();
}
return null;
}
示例3: getOSKey
import javax.swing.InputMap; //导入方法依赖的package包/类
private JavaAgentKeys getOSKey() {
KeyStroke selectall = null;
InputMap inputMap = new JTextField().getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (KeyStroke keyStroke : allKeys) {
Object object = inputMap.get(keyStroke);
if (object.equals("select-all")) {
selectall = keyStroke;
break;
}
}
if ((selectall.getModifiers() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
return JavaAgentKeys.CONTROL;
}
if ((selectall.getModifiers() & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) {
return JavaAgentKeys.META;
}
throw new RuntimeException("Which key?");
}
示例4: checkKeystrokesForActions
import javax.swing.InputMap; //导入方法依赖的package包/类
public void checkKeystrokesForActions() throws Throwable {
StringBuilder sb = new StringBuilder();
driver = new JavaDriver();
WebElement textField = driver.findElement(By.cssSelector("text-field"));
JTextField f = new JTextField();
InputMap inputMap = f.getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (KeyStroke keyStroke : allKeys) {
Object object = inputMap.get(keyStroke);
try {
OSUtils.getKeysFor(textField, object.toString());
} catch (Throwable t) {
sb.append("failed for(" + object + "): " + keyStroke);
}
}
AssertJUnit.assertEquals("", sb.toString());
}
示例5: toString
import javax.swing.InputMap; //导入方法依赖的package包/类
/** Converts an action map to a string representation. */
static public String toString(InputMap im) {
StringBuilder result = new StringBuilder();
LinkedHashMap<Object,Object> map = new LinkedHashMap<>();
for (KeyStroke key : im.allKeys()) {
map.put(key, im.get(key));
}
result.append(map);
result.append('\n');
InputMap parent = im.getParent();
if (parent != null) {
result.append("Parent: ");
result.append(toString(parent));
}
return result.toString();
}