Example usage for javax.swing InputMap InputMap

List of usage examples for javax.swing InputMap InputMap

Introduction

In this page you can find the example usage for javax.swing InputMap InputMap.

Prototype

public InputMap() 

Source Link

Document

Creates an InputMap with no parent and no mappings.

Usage

From source file:org.docx4all.swing.text.WordMLEditorKit.java

private void initKeyBindings(JEditorPane editor) {
    ActionMap myActionMap = new ActionMap();
    InputMap myInputMap = new InputMap();

    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK);
    myActionMap.put(insertSoftBreakAction, new InsertSoftBreakAction(insertSoftBreakAction));
    myInputMap.put(ks, insertSoftBreakAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    myActionMap.put(enterKeyTypedAction, new EnterKeyTypedAction(enterKeyTypedAction));
    myInputMap.put(ks, enterKeyTypedAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    myActionMap.put(deleteNextCharAction, new DeleteNextCharAction(deleteNextCharAction));
    myInputMap.put(ks, deleteNextCharAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
    myActionMap.put(deletePrevCharAction, new DeletePrevCharAction(deletePrevCharAction));
    myInputMap.put(ks, deletePrevCharAction);

    myActionMap.setParent(editor.getActionMap());
    myInputMap.setParent(editor.getInputMap());
    editor.setActionMap(myActionMap);//w w  w.  j  a v a2  s.  co m
    editor.setInputMap(JComponent.WHEN_FOCUSED, myInputMap);
}

From source file:org.freeplane.main.application.MapViewDockingWindows.java

private void removeDesktopPaneAccelerators() {
    final InputMap map = new InputMap();
    rootWindow.setInputMap(JDesktopPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, map);
}

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *///ww  w  .  j  av a2s  . c  o  m
@Test
public void testBindKeyStrokes_InputMap_ObjectArr() {
    // bind
    InputMap inputMap = new InputMap();
    shotcuts.bindKeyStrokes(inputMap, TEST_SAVE, TEST_CUT, TEST_USER_1);

    // test map size
    long expSize = 3;
    long size = inputMap.size();
    assertEquals(expSize, size);

    // test keys
    KeyStroke[] expResults = new KeyStroke[] { CTRL_S, CTRL_X, CTRL_P };
    KeyStroke[] results = inputMap.keys();
    assertArrayEquals(expResults, results);

    // test entry1 exists
    Object expResult = TEST_SAVE;
    Object result = inputMap.get(CTRL_S);
    assertEquals(expResult, result);

    // test entry2 exists
    expResult = TEST_CUT;
    result = inputMap.get(CTRL_X);
    assertEquals(expResult, result);

    // test entry3 exists
    expResult = TEST_USER_1;
    result = inputMap.get(CTRL_P);
    assertEquals(expResult, result);

    // test remove entry with null shortcut
    inputMap.put(CTRL_D, TEST_DELETE); // put target
    expResult = TEST_DELETE;
    result = inputMap.get(CTRL_D);
    assertEquals(expResult, result); // target exists before remove
    shotcuts.bindKeyStrokes(inputMap, TEST_DELETE); // key to be removed as null
    result = inputMap.get(CTRL_D);
    assertNull(result); // target will be null after removed

    // test map size again
    expSize = 3;
    size = inputMap.size();
    assertEquals(expSize, size);

    // ensure no affect for entry1 after removing
    expResult = TEST_SAVE;
    result = inputMap.get(CTRL_S);
    assertEquals(expResult, result);

    // ensure no affect for entry2 after removing
    expResult = TEST_CUT;
    result = inputMap.get(CTRL_X);
    assertEquals(expResult, result);

    // ensure no affect for entry3 after removing
    expResult = TEST_USER_1;
    result = inputMap.get(CTRL_P);
    assertEquals(expResult, result);
}

From source file:org.wings.SComponent.java

/**
 * @param condition Either {@link #WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT} or {@link #WHEN_IN_FOCUSED_FRAME}
 * @return The input map for the given condition.
 * @see #setInputMap(int, javax.swing.InputMap)
 *///from   w w  w  . j  a v a 2  s  . co  m
public InputMap getInputMap(int condition) {
    initInputMaps();
    InputMap result = inputMaps[condition];
    if (result == null) {
        inputMaps[condition] = new InputMap();
        result = inputMaps[condition];
    }
    registerGlobalInputMapWithFrame();
    return result;
}

From source file:org.wings.SFrame.java

public InputMap getInputMap(int condition) {
    // SFrame has only one inputMap
    if (myInputMap == null) {
        myInputMap = new InputMap();
    }// w w  w.  j  a  v a  2 s  .  c om
    return myInputMap;
}

From source file:pcgen.gui2.PCGenFrame.java

private static InputMap createInputMap(ActionMap actionMap) {
    InputMap inputMap = new InputMap();
    for (Object obj : actionMap.keys()) {
        KeyStroke key = (KeyStroke) actionMap.get(obj).getValue(Action.ACCELERATOR_KEY);
        if (key != null) {
            inputMap.put(key, obj);/*from w  ww  . jav a 2 s. co  m*/
        }
    }
    return inputMap;
}