本文整理匯總了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();
}