Java Code Examples for javax.swing.text.JTextComponent#getActionMap()

The following examples show how to use javax.swing.text.JTextComponent#getActionMap() . 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: NbEditorUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void detachSystemActionPerformer(JTextComponent c){
    if (c == null) return;

    Action action = getEditorAction(c);
    if (action == null) return;

    Action globalSystemAction = getSystemAction(c);
    if (globalSystemAction == null) return;

    if (globalSystemAction instanceof CallbackSystemAction){
        Object key = ((CallbackSystemAction)globalSystemAction).getActionMapKey();
        ActionMap am = c.getActionMap();
        if (am != null) {
            Object ea = am.get(key);
            if (action.equals(ea)) {
                am.remove(key);
            }
        }
    }                        
                        
}
 
Example 2
Source File: TextRegionManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static ActionMap [] installOverrideActionMap(JTextComponent component) {
    ActionMap origActionMap = component.getActionMap();
    ActionMap actionMap = new ActionMap();
    OverrideAction[] actions = new OverrideAction[]{
        new OverrideAction(TAB),
        new OverrideAction(SHIFT_TAB),
        new OverrideAction(ENTER),
    };

    // Install the actions into new action map
    for (OverrideAction action : actions) {
        Object actionKey = (String) action.getValue(Action.NAME);
        assert (actionKey != null);
        // Translate to the real key in the action map
        actionKey = action.findActionKey(component);
        if (actionKey != null) { // == null may happen during unit tests
            Action origAction = origActionMap.get(actionKey);
            action.putValue(ORIGINAL_ACTION_PROPERTY, origAction);
            actionMap.put(actionKey, action);
        }
    }
    actionMap.setParent(origActionMap);
    // Install the new action map and return the original action map
    component.setActionMap(actionMap);
    return new ActionMap [] { origActionMap, actionMap };
}
 
Example 3
Source File: TextRegionManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void removeGroupsUpdate() {
    if (editGroups.size() == 0) {
        JTextComponent component = component();
        if (doc instanceof BaseDocument) {
            BaseDocument bdoc = (BaseDocument) doc;
            // Add the listener to allow doc syncing modifications
            // The listener is never removed (since this object is a property of the document)
            bdoc.removePostModificationDocumentListener(DocListener.INSTANCE);
            bdoc.removeUpdateDocumentListener(UpdateDocListener.INSTANCE);
        }
        activeTextSync = null;
        componentRef = null;

        if (overridingKeys) {
            overridingKeys = false;
            component.removeKeyListener(OverrideKeysListener.INSTANCE);

            // check if the action map is still our overrideActionMap
            if (overrideActionMap != component.getActionMap()) {
                LOG.warning("The action map got tampered with! component=" //NOI18
                    + component.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(component)) //NOI18N
                    + "; doc=" + component.getDocument()); //NOI18N
            } else {
                component.setActionMap(origActionMap);
            }

            overrideActionMap.clear();
            origActionMap = null;
            overrideActionMap = null;
        }
    }
}
 
Example 4
Source File: AnimationAutoCompletion.java    From 3Dscript with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Installs this auto-completion on a text component. If this
 * {@link AnimationAutoCompletion} is already installed on another text component,
 * it is uninstalled first.
 *
 * @param c The text component.
 * @see #uninstall()
 */
@Override
public void install(JTextComponent c) {

	if (textComponent != null) {
		uninstall();
	}

	this.textComponent = c;
	installTriggerKey(getTriggerKey());

	// Install the function completion key, if there is one.
	// NOTE: We cannot do this if the start char is ' ' (e.g. just a space
	// between the function name and parameters) because it overrides
	// RSTA's special space action. It seems KeyStorke.getKeyStroke(' ')
	// hoses ctrl+space, shift+space, etc., even though I think it
	// shouldn't...
	char start = provider.getParameterListStart();
	if (start != 0 && start != ' ') {
		InputMap im = c.getInputMap();
		ActionMap am = c.getActionMap();
		KeyStroke ks = KeyStroke.getKeyStroke(start);
		oldParenKey = im.get(ks);
		im.put(ks, PARAM_COMPLETE_KEY);
		oldParenAction = am.get(PARAM_COMPLETE_KEY);
		am.put(PARAM_COMPLETE_KEY, new ParameterizedCompletionStartAction(
				start));
	}

	textComponentListener.addTo(this.textComponent);
	// In case textComponent is already in a window...
	textComponentListener.hierarchyChanged(null);

	if (isAutoActivationEnabled()) {
		autoActivationListener.addTo(this.textComponent);
	}

	UIManager.addPropertyChangeListener(lafListener);
	updateUI(); // In case there have been changes since we uninstalled

}