Java Code Examples for javax.swing.JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

The following examples show how to use javax.swing.JComponent#WHEN_ANCESTOR_OF_FOCUSED_COMPONENT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GuiUtil.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public static void removeKeyBinding(JComponent component, String key)
{
    int condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
    InputMap inputMap = component.getInputMap(condition);
    // According to the docs, null should remove the action, but it does
    // not seem to work with Sun Java 1.4.2, new Object() works
    inputMap.put(KeyStroke.getKeyStroke(key), new Object());
}
 
Example 2
Source File: CommitPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    boolean ret = super.processKeyBinding(ks, e, condition, pressed);

    // XXX #250546 Reason of overriding: to process global shortcut.
    if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) {

        Keymap km = Lookup.getDefault().lookup(Keymap.class);
        Action action = (km != null) ? km.getAction(ks) : null;

        if (action == null) {
            return false;
        }

        if (action instanceof CallbackSystemAction) {
            CallbackSystemAction csAction = (CallbackSystemAction) action;
            if (tabbedPane != null) {
                Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey());
                if (a != null) {
                    a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks)));
                    return true;
                }
            }
        }
        return false;
    } else {
        return ret;
    }
}
 
Example 3
Source File: VCSCommitPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    boolean ret = super.processKeyBinding(ks, e, condition, pressed);

    // XXX #250546 Reason of overriding: to process global shortcut.
    if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) {

        Keymap km = Lookup.getDefault().lookup(Keymap.class);
        Action action = (km != null) ? km.getAction(ks) : null;

        if (action == null) {
            return false;
        }

        if (action instanceof CallbackSystemAction) {
            CallbackSystemAction csAction = (CallbackSystemAction) action;
            if (tabbedPane != null) {
                Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey());
                if (a != null) {
                    a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks)));
                    return true;
                }
            }
        }
        return false;
    } else {
        return ret;
    }
}
 
Example 4
Source File: CommitPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
    boolean ret = super.processKeyBinding(ks, e, condition, pressed);

    // XXX #250546 Reason of overriding: to process global shortcut.
    if ((JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT == condition) && (ret == false) && !e.isConsumed()) {

        Keymap km = Lookup.getDefault().lookup(Keymap.class);
        Action action = (km != null) ? km.getAction(ks) : null;

        if (action == null) {
            return false;
        }

        if (action instanceof CallbackSystemAction) {
            CallbackSystemAction csAction = (CallbackSystemAction) action;
            if (tabbedPane != null) {
                Action a = tabbedPane.getActionMap().get(csAction.getActionMapKey());
                if (a != null) {
                    a.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Utilities.keyToString(ks)));
                    return true;
                }
            }
        }
        return false;
    } else {
        return ret;
    }
}
 
Example 5
Source File: CloseTabPaneUI.java    From iBioSim with Apache License 2.0 5 votes vote down vote up
static InputMap getMyInputMap(int condition) {
	if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
		return (InputMap) UIManager.get("TabbedPane.ancestorInputMap");
	}
	else if (condition == JComponent.WHEN_FOCUSED) {
		return (InputMap) UIManager.get("TabbedPane.focusInputMap");
	}
	return null;
}
 
Example 6
Source File: BasicLizziePaneUI.java    From lizzie with GNU General Public License v3.0 4 votes vote down vote up
InputMap getInputMap(int condition) {
  if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
    return (InputMap) UIManager.get("LizziePane.ancestorInputMap", lizziePane.getLocale());
  }
  return null;
}