@Override public KeyStroke[] allKeys() { return inputMap.allKeys(); }
private static void appendInputMap(StringBuilder buffer, String mapName, InputMap inputMap) { buffer.append("\tmapName: ").append(mapName).append('\n'); KeyStroke[] keys = inputMap.allKeys(); if(keys != null) { for(KeyStroke ks : keys) { buffer.append("\t\tKey : ").append(ks) .append("\n\t\tValue: ").append(inputMap.get(ks)) .append("\n\t\t----------\n"); } } } }
private Vector getRegisteredKeyCodes(JRootPane root) { Vector v = new Vector(); InputMap im = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if(im == null) return v; KeyStroke[] keys = im.allKeys(); if(keys == null) return v; for(int i = 0; i < keys.length; i++) { v.add(new Integer(keys[i].getKeyCode())); } return v; }
@RunsInCurrentThread static @Nonnull KeyStroke[] findKeyStrokesForAction(@Nonnull String actionName, @Nonnull Object actionKey, @Nonnull InputMap inputMap) { List<KeyStroke> keyStrokes = newArrayList(); for (KeyStroke keyStroke : inputMap.allKeys()) { if (actionKey.equals(inputMap.get(keyStroke))) { keyStrokes.add(keyStroke); } } if (!keyStrokes.isEmpty()) { return keyStrokes.toArray(new KeyStroke[keyStrokes.size()]); } throw actionFailure(String.format("Unable to find valid input event for action with key '%s'", actionName)); }
/** * <p>Returns the map of keyboard shortcuts associated to this module.</p> * * @return Map of keyboard shortcurts, where the key is the description of the triggered action and the value is the keyboard shortcut * @since 0.3.0 */ public Map<String, KeyStroke> getKeyShortcutMap() { Map<String, KeyStroke> keyShortcutMap = new LinkedHashMap<String, KeyStroke>(); InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); KeyStroke[] keyStrokes = inputMap.allKeys(); for(KeyStroke keyStroke : keyStrokes) keyShortcutMap.put(inputMap.get(keyStroke).toString(), keyStroke); return keyShortcutMap; }
/** * Check each component to see if its using Key Bindings */ private Set<KeyStroke> getKeyStrokes(DisabledPanel panel) { Set<KeyStroke> keyStrokes = new HashSet<KeyStroke>(); // Only JComponents use Key Bindings Container container = ((Container) panel.getComponent(1)); List<JComponent> components = SwingUtils.getDescendantsOfType(JComponent.class, container); // We only care about the WHEN_IN_FOCUSED_WINDOW bindings for (JComponent component : components) { InputMap im = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); if (im != null && im.allKeys() != null) { for (KeyStroke keyStroke : im.allKeys()) keyStrokes.add(keyStroke); } } return keyStrokes; }
/** * Adds Net2Plan's global key combinations to a given input and action map. * The added actions correspond to the ones that are found on the top menu at the main window. * Useful for adding these actions to new windows that are not contained within GUINet2Plan. * @param iMap Input window input map. * @param aMap Input window action map. */ public static void addGlobalActions(InputMap iMap, ActionMap aMap) { assert inputMap != null; assert actionMap != null; if (inputMap.allKeys() == null) return; if (actionMap.allKeys() == null) return; for (KeyStroke keyStroke : inputMap.allKeys()) { final Object o = inputMap.get(keyStroke); iMap.put(keyStroke, inputMap.get(keyStroke)); aMap.put(o, actionMap.get(o)); } }
public static void main( String[] args ) { EventQueue.invokeLater( new Runnable() { @Override public void run() { JTextField textField = new JTextField(); InputMap inputMap = textField.getInputMap( JComponent.WHEN_FOCUSED ); KeyStroke[] keyStrokes = inputMap.allKeys(); for ( int i = 0; i < keyStrokes.length; i++ ) { KeyStroke keyStroke = keyStrokes[ i ]; Object value = inputMap.get( keyStroke ); System.out.println(keyStroke + "-\"" + value + "\""); } } } ); }
import javax.swing.InputMap; import javax.swing.JComponent; import javax.swing.JTree; import javax.swing.KeyStroke; import java.awt.EventQueue; public class TreeActionMap { public static void main( String[] args ) { EventQueue.invokeLater( new Runnable() { @Override public void run() { JTree tree = new JTree( ); InputMap inputMap = tree.getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); KeyStroke[] keyStrokes = inputMap.allKeys(); for ( KeyStroke keyStroke : keyStrokes ) { Object actionCommand = inputMap.get( keyStroke ); System.out.println( "keyStroke = " + keyStroke ); System.out.println( "actionCommand = " + actionCommand ); } } } ); } }
/** * Modifies the current {@link InputMap} of this component according to the actual preferences. * Within the preferences of the syntax plugin, the user can change the behavior of some key strokes. e.g. the copy action. * Because we have no access to the syntax preferences at the moment, the UI is created, we have to modify them after the creation. * @param prefs Preferences to use. */ private void modifiyKeystrokesFromPreferences(SyntaxPreferences prefs) { InputMap shared = getInputMap(); if(prefs.isUseCopyAsRtf()){ // Replace the default copy behavior for all key bindings KeyStroke[] allKeys = shared.allKeys(); for (KeyStroke keyStroke : allKeys) { Object object = shared.get(keyStroke); if(DefaultEditorKit.copyAction.equals(object)){ shared.put(keyStroke, RSyntaxTextAreaEditorKit.rstaCopyAsRtfAction); } } } }
void addMap( final InputMap map, final String context ) final KeyStroke[] keys = map.allKeys(); for ( final KeyStroke key : keys )
KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i];
private void uninstallTracking() { InputMap currMap = SwingUtilities.getUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED); if (currMap != null) { InputMap newMap = new InputMap(); KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i]; Object val = currMap.get(stroke); if (stroke .equals(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)) && "flipTextSelection".equals(val)) { continue; } newMap.put(stroke, val); } SwingUtilities.replaceUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED, newMap); } this.jcomp.getActionMap().remove("flipTextSelection"); }
KeyStroke[] keys = map.allKeys(); if (keys != null) { for (KeyStroke key : keys) {
KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i];
if (!(editorComponent instanceof JTextComponent)) return; final InputMap inputMap = ((JTextComponent) editorComponent).getInputMap(); for (KeyStroke keyStroke : inputMap.allKeys()) { if (DefaultEditorKit.copyAction.equals(inputMap.get(keyStroke))) { comboBox.getInputMap().put(keyStroke, DefaultEditorKit.copyAction);
KeyStroke[] events = im.allKeys(); for (int i=0;events != null && i < events.length;i++) { KeyStroke ks = events[i];
KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i];
/** * CONSTRUCTOR */ public GraphPane(Frame parent) { this.parentFrame = parent; addMouseListener(this); // listens for own mouse and addMouseMotionListener(this); // mouse-motion events //addKeyListener( this ); getInputMap().allKeys(); addMouseWheelListener(this); //trackToYRangeMap = new HashMap<Track, Range>(); popupThread = new Thread(new PopupThread(this), "PopupThread"); popupThread.start(); // GraphPaneController gpc = GraphPaneController.getInstance(); gpc.addListener(new Listener<GraphPaneEvent>() { @Override public void handleEvent(GraphPaneEvent event) { if (event.getType() == GraphPaneEvent.Type.HIGHLIGHTING) { repaint(); } } }); }