@Override public KeyStroke[] keys() { return inputMap.keys(); }
@Override public KeyStroke[] keys() { return inputMap.keys(); }
public KeyStroke[] keys() { KeyStroke[] sKeys = super.keys(); KeyStroke[] keymapKeys = keymap.getBoundKeyStrokes(); int sCount = (sKeys == null) ? 0 : sKeys.length; int keymapCount = (keymapKeys == null) ? 0 : keymapKeys.length; if (sCount == 0) { return keymapKeys; } if (keymapCount == 0) { return sKeys; } KeyStroke[] retValue = new KeyStroke[sCount + keymapCount]; // There may be some duplication here... System.arraycopy(sKeys, 0, retValue, 0, sCount); System.arraycopy(keymapKeys, 0, retValue, sCount, keymapCount); return retValue; }
private void printKeys() { System.out.println("Keys"); for( KeyStroke keyStroke : inputMap.keys()){ System.out.println(keyStroke.toString()); } Thread.dumpStack(); }
private KeyStroke removeEntry(InputMap inputMap, String keyToBeRemoved) { KeyStroke removedEntry = null; for (KeyStroke ks : inputMap.keys()) { String key = (String) inputMap.get(ks); if (key.equals(keyToBeRemoved)) { inputMap.remove(ks); removedEntry = ks; break; } } return removedEntry; }
for (KeyStroke keyStroke: im.keys())
/** * Returns the key combination mapping. * * @return Key combination mapping: key is the description, and value is the key combination * @since 0.3.0 */ public Map<String, KeyStroke> getKeyCombinations(int focusLevel) { Map<String, KeyStroke> keyCombinationMap = new TreeMap<>(); InputMap inputMap = getInputMap(focusLevel); KeyStroke[] currentKeyCombinationArray = inputMap.keys(); if (currentKeyCombinationArray != null) { Set<KeyStroke> currentKeyCombinationSet = new LinkedHashSet<>(Arrays.asList(currentKeyCombinationArray)); for(KeyStroke i : currentKeyCombinationSet) { String description = inputMap.get(i).toString(); keyCombinationMap.put(description, i); } } return keyCombinationMap; }
/** * Adds a key combination triggering some action. * * @param description Description of the action * @param keyCombination Key combination (it must not be already defined) * @param action Action to be triggered by {@code keyCombination} * @since 0.3.0 */ public final void addKeyCombinationAction(int focusLevel, String description, Action action, KeyStroke... keyCombination) { InputMap inputMap = getInputMap(focusLevel); KeyStroke[] currentKeyCombinationArray = inputMap.keys(); if (currentKeyCombinationArray != null) { Set<KeyStroke> currentKeyCombinationSet = new LinkedHashSet<KeyStroke>(Arrays.asList(currentKeyCombinationArray)); for(KeyStroke i : keyCombination) if (currentKeyCombinationSet.contains(i)) throw new RuntimeException("Cannot override previous action for " + i); } ActionMap actionMap = getActionMap(); for(KeyStroke i : keyCombination) { inputMap.put(i, description); actionMap.put(description, action); } }
System.out.println(Arrays.toString(im.keys())); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), NIL);
/** * Removes all entries from the InputMap that point to an action with the * prefix of this. * * @param pane The JRootPane to remove the hotkeys from */ private void removeHotkeys(JRootPane pane) { Set<KeyStroke> toBeRemoved = new HashSet<>(); InputMap input = pane.getInputMap(INPUT_MAP_KEY); ActionMap action = pane.getActionMap(); if (input.keys() == null) { return; } for (KeyStroke keyStroke : input.keys()) { Object key = input.get(keyStroke); if (key instanceof String && ((String)key).startsWith(PREFIX)) { toBeRemoved.add(keyStroke); action.remove(key); } } for (KeyStroke keyStroke : toBeRemoved) { input.remove(keyStroke); } }
/** * This Method registers a component at the TooltipManager, * to be able to set the initialDelay of the tooltip per componenent. * @param c the component to register */ public static void registerComponentAtTooltipManager(JComponent c) { InputMap imap = c.getInputMap(); boolean removeKeyStroke = false; KeyStroke[] ks = imap.keys(); if(ks == null || ks.length == 0) { imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, 0), "backSlash"); // dummy removeKeyStroke = true; } ToolTipManager.sharedInstance().registerComponent(c); // ToolTipManager.sharedInstance().setDismissDelay(99000); // set showing time to 99 seconds if(removeKeyStroke) { imap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, 0)); } c.addMouseListener(MOUSE_HANDLER); }
private static void appendStrokes(StringBuilder builder, SComponent component, int condition, InputMap inputMap) { KeyStroke[] keyStrokes = inputMap.keys(); if (keyStrokes != null) { for (KeyStroke keyStroke : keyStrokes) {
for(;;) KeyStroke[] keyStrokes = inputMap.keys(); if(keyStrokes != null)
if ( !clearAll ) final KeyStroke[] inputs = inputMap.keys(); if ( inputs != null )
for(;;) KeyStroke[] keyStrokes = inputMap.keys(); if(keyStrokes != null)
private static void removeMenuModifierBindings( InputMap imap, int primary, Set keySet ) { if( imap == null ) return; final KeyStroke[] keys = imap.keys(); if( keys != null ) { for( int i = 0; i < keys.length; i++ ) { final KeyStroke k = keys[ i ]; if( (k.getModifiers() != primary) && keySet.contains( k )) { imap.remove( k ); } } } removeMenuModifierBindings( imap.getParent(), primary, keySet ); } }
private ActionListener getEscapeAction(JComponent rootPane) { // Search the operatorDescriptor InputMap to see if a binding for the ESCAPE key // exists. This binding is added when a popup menu is made visible // (and removed when the popup menu is hidden). InputMap im = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if (im == null || (im = im.getParent()) == null) { return null; } Object[] keys = im.keys(); if (keys == null) { return null; } for (Object keyStroke : keys) { if (keyStroke.equals(ESCAPE_KEY_STROKE)) { Object key = im.get(ESCAPE_KEY_STROKE); return rootPane.getActionMap().get(key); } } return null; }
KeyStroke[] results = inputMap.keys(); assertArrayEquals(expResults, results);