Java Code Examples for javax.swing.JComponent.getInputMap()

The following are Jave code examples for showing how to use getInputMap() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: AddModulePanel.java   View Source Code Vote up 6 votes
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);
            }
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: ToolTipManagerEx.java   View Source Code Vote up 6 votes
/**
    * Registers a component for tooltip management.
    * <p>
    * This will register key bindings to show and hide the tooltip text
    * only if <code>component</code> has focus bindings. This is done
    * so that components that are not normally focus traversable, such
    * as <code>JLabel</code>, are not made focus traversable as a result
    * of invoking this method.
    *
    * @param component  a <code>JComponent</code> object to add
    * @see JComponent#isFocusTraversable
    */
   protected void registerComponent(JComponent component) {
       component.removeMouseListener(this);
       component.addMouseListener(this);
       component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    // register our accessibility keybindings for this component
    // this will apply globally across L&F
    // Post Tip: Ctrl+F1
    // Unpost Tip: Esc and Ctrl+F1
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
Example 3
Project: pdfjumbler   File: PdfJumbler.java   View Source Code Vote up 5 votes
private static void registerAccelerators(JComponent component, Action... actions) {
	InputMap inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	ActionMap actionMap = component.getActionMap();
	for (Action action : actions) {
		inputMap.put((KeyStroke)action.getValue(Action.ACCELERATOR_KEY), action);
		actionMap.put(action, action);
	}
}
 
Example 4
Project: incubator-netbeans   File: ToolTipManagerEx.java   View Source Code Vote up 5 votes
/**
    * Removes a component from tooltip control.
    *
    * @param component  a <code>JComponent</code> object to remove
    */
   protected void unregisterComponent(JComponent component) {
       component.removeMouseListener(this);
component.removeMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
Example 5
Project: incubator-netbeans   File: OutlineTable.java   View Source Code Vote up 5 votes
private void filterInputMap(JComponent component, int condition) {
    InputMap imap = component.getInputMap(condition);
    if (imap instanceof ComponentInputMap) {
        imap = new F8FilterComponentInputMap(component, imap);
    } else {
        imap = new F8FilterInputMap(imap);
    }
    component.setInputMap(condition, imap);
}
 
Example 6
Project: incubator-netbeans   File: Terminal.java   View Source Code Vote up 5 votes
private void setupKeymap(Set<Action> actions) {
JComponent comp = term.getScreen();

ActionMap actionMap = comp.getActionMap();
ActionMap newActionMap = new ActionMap();
newActionMap.setParent(actionMap);

printActionMap(actionMap);

InputMap inputMap = comp.getInputMap();
InputMap newInputMap = new InputMap();
newInputMap.setParent(inputMap);

Set<KeyStroke> passKeystrokes = new HashSet<KeyStroke>();

for (Action a : actions) {
    String name = (String) a.getValue(Action.NAME);
           KeyStroke accelerator = (KeyStroke) a.getValue(Action.ACCELERATOR_KEY);
    System.out.printf("Registering %s for %s\n", accelerator, name);
    if (accelerator == null)
	continue;
    newInputMap.put(accelerator, name);
    newActionMap.put(name, a);
    passKeystrokes.add(accelerator);
}

comp.setActionMap(newActionMap);
comp.setInputMap(JComponent.WHEN_FOCUSED, newInputMap);

       term.setKeyStrokeSet((HashSet) passKeystrokes);
   }
 
Example 7
Project: rapidminer   File: OperatorTransferHandler.java   View Source Code Vote up 5 votes
public static void addToActionMap(JComponent component) {
	ActionMap actionMap = component.getActionMap();
	actionMap.put(TransferHandler.getCutAction().getValue(Action.NAME), TransferHandler.getCutAction());
	actionMap.put(TransferHandler.getCopyAction().getValue(Action.NAME), TransferHandler.getCopyAction());
	actionMap.put(TransferHandler.getPasteAction().getValue(Action.NAME), TransferHandler.getPasteAction());
	actionMap.put(DeleteOperatorAction.getActionName(), new DeleteOperatorAction());

	// only required if you have not set the menu accelerators
	InputMap inputMap = component.getInputMap();
	inputMap.put(KeyStroke.getKeyStroke("ctrl X"), TransferHandler.getCutAction().getValue(Action.NAME));
	inputMap.put(KeyStroke.getKeyStroke("ctrl C"), TransferHandler.getCopyAction().getValue(Action.NAME));
	inputMap.put(KeyStroke.getKeyStroke("ctrl V"), TransferHandler.getPasteAction().getValue(Action.NAME));
	inputMap.put(KeyStroke.getKeyStroke("del"), DeleteOperatorAction.getActionName());
}
 
Example 8
Project: JavaGraph   File: Simulator.java   View Source Code Vote up 5 votes
/**
 * Adds the accelerator key for a given action to the action and input maps
 * of the simulator frame's content pane.
 * @param action the action to be added
 * @require <tt>frame.getContentPane()</tt> should be initialised
 */
public void addAccelerator(Action action) {
    JComponent contentPane = (JComponent) getFrame().getContentPane();
    ActionMap am = contentPane.getActionMap();
    am.put(action.getValue(Action.NAME), action);
    InputMap im = contentPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    im.put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), action.getValue(Action.NAME));
}
 
Example 9
Project: incubator-netbeans   File: ToolTipManagerEx.java   View Source Code Vote up 3 votes
/**
    * Returns whether or not bindings should be registered on the given
    * <code>JComponent</code>. This is implemented to return true if the
    * tool tip manager has a binding in any one of the
    * <code>InputMaps</code> registered under the condition
    * <code>WHEN_FOCUSED</code>.
    * <p>
    * This does not use <code>isFocusTraversable</code> as
    * some components may override <code>isFocusTraversable</code> and
    * base the return value on something other than bindings. For example,
    * <code>JButton</code> bases its return value on its enabled state.
    *
    * @param component  the <code>JComponent</code> in question
    */
   private boolean shouldRegisterBindings(JComponent component) {
InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
while (inputMap != null && inputMap.size() == 0) {
    inputMap = inputMap.getParent();
}
return (inputMap != null);
   }
 
Example 10
Project: MapAnalyst   File: GUIUtil.java   View Source Code Vote up 2 votes
/**
 * Adds support for plus and minus menu commands, typically for zooming in
 * and out. This is designed for menu items with key accelerators using
 * KeyEvent.VK_ADD and KeyEvent.VK_SUBTRACT (which are typically on the
 * numerical key pad). It adds support for KeyEvent.VK_MINUS and
 * KeyEvent.VK_PLUS, and KeyEvent.VK_EQUALS for keyboard layouts with the
 * plus sign as secondary key for the equals.
 *
 * @param zoomInAction action to call when the + key and the menu shortcut
 * key are pressed
 * @param zoomOutAction action to call when the - key and the menu shortcut
 * key are pressed
 * @param component component that will receive events and store actions
 */
public static void zoomMenuCommands(Action zoomInAction, Action zoomOutAction, JComponent component) {
    InputMap inputMap = component.getInputMap();
    ActionMap actionMap = component.getActionMap();
    zoomMenuCommands(inputMap, actionMap, zoomInAction, zoomOutAction);
}