Java Code Examples for javax.swing.InputMap#remove()

The following examples show how to use javax.swing.InputMap#remove() . 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: FlatInputMaps.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
@Override
public Object createValue( UIDefaults table ) {
	// get base input map
	InputMap inputMap = (baseInputMap instanceof LazyValue)
		? (InputMap) ((LazyValue)baseInputMap).createValue( table )
		: (InputMap) baseInputMap;

	// modify input map (replace or remove)
	for( int i = 0; i < bindings.length; i += 2 ) {
		KeyStroke keyStroke = KeyStroke.getKeyStroke( (String) bindings[i] );
		if( bindings[i + 1] != null )
			inputMap.put( keyStroke, bindings[i + 1] );
		else
			inputMap.remove( keyStroke );
	}

	return inputMap;
}
 
Example 2
Source File: CheckTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of CheckTreeView */
public CheckTreeView() {
    
    setFocusable( false );
    
    CheckListener l = new CheckListener();
    tree.addMouseListener( l );
    tree.addKeyListener( l );

    CheckRenderer check = new CheckRenderer();
    tree.setCellRenderer( check );
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    tree.setShowsRootHandles(false);
    
    InputMap input = tree.getInputMap( JTree.WHEN_FOCUSED );
    if( null != input )
        input.remove( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) );
    
    setBorder( UIManager.getBorder("ScrollPane.border") );
}
 
Example 3
Source File: CheckTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Creates a new instance of CheckTreeView */
public CheckTreeView() {
    
    setFocusable( false );
    
    CheckListener l = new CheckListener();
    tree.addMouseListener( l );
    tree.addKeyListener( l );

    CheckRenderer check = new CheckRenderer();
    tree.setCellRenderer( check );
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    tree.setShowsRootHandles(false);
    
    InputMap input = tree.getInputMap( JTree.WHEN_FOCUSED );
    if( null != input )
        input.remove( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0) );
    
    setBorder( UIManager.getBorder("ScrollPane.border") );
}
 
Example 4
Source File: FlatLFCustoms.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Object createValue(UIDefaults table) {
    // get base input map from look and feel defaults (resolves lazy base input map)
    InputMap inputMap = (InputMap) UIManager.getLookAndFeelDefaults().get(baseKey);

    // modify input map (replace or remove)
    for (int i = 0; i < bindings.length; i += 2) {
        KeyStroke keyStroke = KeyStroke.getKeyStroke((String) bindings[i]);
        if (bindings[i + 1] != null) {
            inputMap.put(keyStroke, bindings[i + 1]);
        } else {
            inputMap.remove(keyStroke);
        }
    }

    return inputMap;
}
 
Example 5
Source File: TranslationTree.java    From i18n-editor with MIT License 6 votes vote down vote up
private void setupUI() {
	UIManager.put("Tree.repaintWholeRow", Boolean.TRUE);
	
	// Remove all key strokes
	InputMap inputMap = getInputMap().getParent();
	for (KeyStroke k : getRegisteredKeyStrokes()) {
		inputMap.remove(k);
	}
	
       setUI(new TranslationTreeUI());
	setCellRenderer(new TranslationTreeCellRenderer());
	addTreeWillExpandListener(new TranslationTreeExpandListener());
	addMouseListener(new TranslationTreeMouseListener());
	setEditable(false);
	setOpaque(false);
}
 
Example 6
Source File: mxCellEditor.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * Installs the keyListener in the textArea and editorPane
 * for handling the enter keystroke and updating the modified state.
 */
protected void configureActionMaps()
{
	InputMap editorInputMap = editorPane.getInputMap();
	InputMap textInputMap = textArea.getInputMap();

	// Adds handling for the escape key to cancel editing
	editorInputMap.put(escapeKeystroke, cancelEditingAction);
	textInputMap.put(escapeKeystroke, cancelEditingAction);

	// Adds handling for shift-enter and redirects enter to stop editing
	if (graphComponent.isEnterStopsCellEditing())
	{
		editorInputMap.put(shiftEnterKeystroke, editorEnterActionMapKey);
		textInputMap.put(shiftEnterKeystroke, textEnterActionMapKey);

		editorInputMap.put(enterKeystroke, SUBMIT_TEXT);
		textInputMap.put(enterKeystroke, SUBMIT_TEXT);
	}
	else
	{
		editorInputMap.put(enterKeystroke, editorEnterActionMapKey);
		textInputMap.put(enterKeystroke, textEnterActionMapKey);

		if (isShiftEnterSubmitsText())
		{
			editorInputMap.put(shiftEnterKeystroke, SUBMIT_TEXT);
			textInputMap.put(shiftEnterKeystroke, SUBMIT_TEXT);
		}
		else
		{
			editorInputMap.remove(shiftEnterKeystroke);
			textInputMap.remove(shiftEnterKeystroke);
		}
	}
}
 
Example 7
Source File: QuickSearchComboBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected JTextComponent createCommandField() {
    JTextArea res = new DynamicWidthTA();
    res.setRows(1);
    res.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 4, 1, 1));
    // disable default Swing's Ctrl+Shift+O binding to enable our global action
    InputMap curIm = res.getInputMap(JComponent.WHEN_FOCUSED);
    while (curIm != null) {
        curIm.remove(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK));
        curIm = curIm.getParent();
    }
    return res;
}
 
Example 8
Source File: TreeList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Right-arrow key expands a row, left-arrow collapses a row, enter invokes
 * row's default action (if any).
 */
private void initKeysAndActions() {
    unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
    unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
    unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.SHIFT_DOWN_MASK));

    expandAction = new ExpandAction();
    collapseAction = new CollapseAction();
    defaultAction = new DefaultAction();
    showPopupAction = new ShowPopupAction();

    InputMap imp = getInputMap();
    InputMap impAncestor = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap am = getActionMap();

    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), ACTION_EXPAND);
    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), ACTION_COLLAPSE);
    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), ACTION_DEFAULT);
    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.SHIFT_DOWN_MASK), ACTION_SHOW_POPUP);

    impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
    impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));
    impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.SHIFT_DOWN_MASK));

    am.put(ACTION_EXPAND, expandAction);
    am.put(ACTION_COLLAPSE, collapseAction);
    am.put(ACTION_DEFAULT, defaultAction);
    am.put(ACTION_SHOW_POPUP, showPopupAction);
}
 
Example 9
Source File: BasicDatePickerUI.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void uninstallKeyboardActions() {
	InputMap input = peer
			.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	input
			.remove(KeyStroke.getKeyStroke(KeyEvent.VK_C,
					InputEvent.ALT_MASK));
	input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0));

	peer.getActionMap().remove(POPUP_KEY);
}
 
Example 10
Source File: BasicCalendarPaneUI.java    From microba with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void uninstallKeyboardActions() {
	InputMap input = peer
			.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	ActionMap action = peer.getActionMap();

	input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
	input.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));

	action.remove(ENTER_KEY);
	action.remove(ESCAPE_KEY);

}
 
Example 11
Source File: SheetTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void initKeysAndActions() {
    super.initKeysAndActions();
    unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
    unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));

    expandAction = new ExpandAction();
    collapseAction = new CollapseAction();
    edClassAction = new EditorClassAction();

    InputMap imp = getInputMap();
    InputMap impAncestor = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap am = getActionMap();
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK);
    imp.put(ks, null);

    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), ACTION_EXPAND);

    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), ACTION_COLLAPSE);

    if (!GraphicsEnvironment.isHeadless()) {
    imp.put(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_HOME, KeyEvent.SHIFT_DOWN_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
        ), ACTION_EDCLASS
    );
    }

    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), ACTION_NEXT);

    imp.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK), ACTION_PREV);

    impAncestor.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_DOWN_MASK), ACTION_CUSTOM_EDITOR);

    impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0));
    impAncestor.remove(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0));

    am.put(ACTION_EXPAND, expandAction);
    am.put(ACTION_COLLAPSE, collapseAction);

    am.put(ACTION_CUSTOM_EDITOR, getCustomEditorAction());
    am.put(ACTION_EDCLASS, edClassAction);

    Action defaultAction = am.get( "selectNextRow" );
    if( null != defaultAction ) {
        am.put("selectNextRow", new IncrementAction(false, defaultAction));
}
    defaultAction = am.get( "selectPreviousRow" );
    if( null != defaultAction ) {
        am.put("selectPreviousRow", new IncrementAction(true, defaultAction));
    }
}
 
Example 12
Source File: GuiInitializer.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * This function unregisters the keys F6 and F8 from JSplitPane components because we would rather
 * uses these keys for debugger functions.
 */
private static void initializeHotkeys() {
  final InputMap map = (InputMap) UIManager.get("SplitPane.ancestorInputMap");
  map.remove(HotKeys.GUI_INITIALIZER_KEY_1.getKeyStroke());
  map.remove(HotKeys.GUI_INITIALIZER_KEY_2.getKeyStroke());
}
 
Example 13
Source File: ChatMessagePanel.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void cleanupKeyMap() {
  final InputMap nextMessageKeymap = nextMessage.getInputMap();
  nextMessageKeymap.remove(KeyStroke.getKeyStroke('\n'));
  nextMessageKeymap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false));
  nextMessageKeymap.remove(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false));
}
 
Example 14
Source File: TextEditor.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of TextEditor
 */
public TextEditor(boolean tabsAsSpaces, boolean multiLineTab, boolean unwrapped) {
    this.tabsAsSpaces = tabsAsSpaces;
    this.multiLineTab = multiLineTab;
    this.unwrapped = unwrapped;

    // remove and replace the delete action to another spot so ctrl H later
    // on is strictly for showing the find & replace dialog
    ActionMap aMap = getActionMap();
    Action action = null;
    do {
        action = action == null ? aMap.get(DefaultEditorKit.deletePrevCharAction) : null;
        aMap.remove(DefaultEditorKit.deletePrevCharAction);
        aMap = aMap.getParent();
    } while (aMap != null);
    aMap = getActionMap();
    InputMap iMap = getInputMap();
    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0, false);
    iMap.put(keyStroke, "delete");
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, KeyEvent.SHIFT_MASK, false);
    iMap.put(keyStroke, "delete");
    aMap.put("delete", action);

    // set all the actions
    action = new FindAction();
    aMap.put(FIND, action);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_MASK, false);
    iMap.put(keyStroke, FIND);

    aMap.put(FIND_NEXT, FindReplaceUtility.FIND_ACTION);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0, false);
    iMap.put(keyStroke, FIND_NEXT);

    aMap.put(FIND_PREVIOUS, FindReplaceUtility.FIND_ACTION);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_F3, KeyEvent.SHIFT_MASK, false);
    iMap.put(keyStroke, FIND_PREVIOUS);

    action = new TabAction();
    aMap.put("TextEditor-tabAction", action);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0, false);
    iMap.put(keyStroke, "TextEditor-tabAction");

    action = new ShiftTabAction();
    aMap.put("TextEditor-shiftTabAction", action);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK, false);
    iMap.put(keyStroke, "TextEditor-shiftTabAction");

    action = new ReplaceAction();
    getActionMap().put(REPLACE, action);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_MASK, false);
    do {
        iMap.remove(keyStroke);
        iMap = iMap.getParent();
    } while (iMap != null);
    getInputMap().put(keyStroke, REPLACE);

    action = new AutoIndentAction();
    getActionMap().put(AUTO_INDENT, action);
    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    getInputMap().put(keyStroke, AUTO_INDENT);

    setAutoscrolls(true);

    defaultCaret = getCaret();
    overtypeCaret = new OvertypeCaret();
    overtypeCaret.setBlinkRate(defaultCaret.getBlinkRate());
}