Example usage for java.awt AWTKeyStroke getAWTKeyStroke

List of usage examples for java.awt AWTKeyStroke getAWTKeyStroke

Introduction

In this page you can find the example usage for java.awt AWTKeyStroke getAWTKeyStroke.

Prototype

@SuppressWarnings("deprecation")
public static AWTKeyStroke getAWTKeyStroke(String s) 

Source Link

Document

Parses a string and returns an AWTKeyStroke .

Usage

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

/**
 * Make JTable handle TAB key as all other components - move focus to next/previous components.
 * <p>Default Swing behaviour for table is to move focus to next/previous cell inside the table.</p>
 * @param table table instance//from ww  w.  j a  v  a2  s . co m
 */
public static void correctTableFocusTraversal(JTable table) {
    table.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
            Collections.singleton(AWTKeyStroke.getAWTKeyStroke("TAB")));
    table.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
            Collections.singleton(AWTKeyStroke.getAWTKeyStroke("shift TAB")));
}

From source file:net.sf.jabref.EntryEditor.java

/**
 * NOTE: This method is only used for the source panel, not for the
 * other tabs. Look at EntryEditorTab for the setup of text components
 * in the other tabs.//from   ww  w.j a va 2  s. c  o  m
 */
private void setupJTextFieldForSourceArea(JTextComponent ta) {
    setupSwingComponentKeyBindings(ta);

    // HashSet<AWTKeyStroke> keys = new HashSet<AWTKeyStroke>(ta.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));          
    HashSet<AWTKeyStroke> keys = new HashSet<AWTKeyStroke>();
    keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB"));
    ta.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);

    // keys = new HashSet<AWTKeyStroke>(ta.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    keys = new HashSet<AWTKeyStroke>();
    keys.add(KeyStroke.getKeyStroke("shift pressed TAB"));
    ta.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);

    ta.addFocusListener(new FieldListener());
}

From source file:net.sf.jabref.gui.entryeditor.EntryEditor.java

/**
 * NOTE: This method is only used for the source panel, not for the
 * other tabs. Look at EntryEditorTab for the setup of text components
 * in the other tabs.//from   w w  w  . j  a  v  a  2s .c  o  m
 */
private void setupJTextComponent(JTextComponent textComponent) {
    // Set up key bindings and focus listener for the FieldEditor.
    InputMap inputMap = textComponent.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = textComponent.getActionMap();

    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store");
    actionMap.put("store", getStoreFieldAction());

    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right");
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right");
    actionMap.put("right", getSwitchRightAction());

    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left");
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left");
    actionMap.put("left", getSwitchLeftAction());

    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help");
    actionMap.put("help", getHelpAction());
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.SAVE_DATABASE), "save");
    actionMap.put("save", getSaveDatabaseAction());

    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab");
    actionMap.put("nexttab", frame.nextTab);
    inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.PREVIOUS_TAB), "prevtab");
    actionMap.put("prevtab", frame.prevTab);

    Set<AWTKeyStroke> keys = new HashSet<>(
            textComponent.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    keys.clear();
    keys.add(AWTKeyStroke.getAWTKeyStroke("pressed TAB"));
    textComponent.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, keys);
    keys = new HashSet<>(textComponent.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    keys.clear();
    keys.add(KeyStroke.getKeyStroke("shift pressed TAB"));
    textComponent.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, keys);

    textComponent.addFocusListener(new FieldListener());
}