List of utility methods to do Swing Key Action
void | escapeKeyAction(JComponent component, javax.swing.AbstractAction abstractAction) escape Key Action component.getRootPane().getActionMap().put(ESC_ACTION_KEY, abstractAction); component.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESC_ACTION_KEY); |
String | formatKeyStroke(final KeyStroke keyStroke) pretty print a keystroke. final String keyModifiersText = KeyEvent.getKeyModifiersText(keyStroke.getModifiers()); final String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode()); return keyModifiersText.length() == 0 ? keyText : keyModifiersText + "+" + keyText; |
String | getActionID(final Action a) Tries to find an ID for the passed action from its Action#getValue(String) properties . Object actionID = a.getValue(Action.ACTION_COMMAND_KEY); if (actionID == null) actionID = a.getValue(Action.NAME); return actionID == null ? null : actionID.toString(); |
String | getActionInstanceName(Action delegate) get Action Instance Name Object commandKey = delegate.getValue(Action.ACTION_COMMAND_KEY); String id; if (commandKey != null && !commandKey.toString().isEmpty()) { id = commandKey.toString(); } else { id = delegate.getClass().getName(); id = id.replace('/', '-').replace('.', '-').replace('$', '-'); ... |
KeyStroke | getEscapeKeystroke() get Escape Keystroke return KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
|
KeyStroke | getKeyStroke(int i0, int i1) get Key Stroke if ((i1 & KeyEvent.META_MASK) != 0) { if (!onMac) { i1 = i1 - KeyEvent.META_MASK + KeyEvent.CTRL_MASK; KeyStroke ks = KeyStroke.getKeyStroke(i0, i1); if (debug) { Exception ex = new Exception(); ... |
KeyStroke | getKeystroke(int keyevent) Returns a cross-platform keystroke that enables the platform behave natively. return KeyStroke.getKeyStroke(keyevent, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
|
KeyStroke | getKeyStrokeCopy() get Key Stroke Copy return KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
|
String | getKeyStrokeRepresentation(KeyStroke ks) Returns a String representation for the given KeyStroke for display, in the following format: modifier+modifier+...+key For example, return ks.toString().replaceFirst("(released )|(pressed )|(typed )", ""); |
String | getKeyStrokeText(KeyStroke ks) get Key Stroke Text StringBuilder sb = new StringBuilder(); String modifierText = KeyEvent.getKeyModifiersText(ks.getModifiers()); sb.append(modifierText); String keyText = KeyEvent.getKeyText(ks.getKeyCode()); if (!keyText.isEmpty() && !modifierText.contains(keyText)) { if (sb.length() > 0) { sb.append('+'); sb.append(keyText); return sb.toString(); |