Example usage for javax.swing.text JTextComponent setFocusTraversalKeys

List of usage examples for javax.swing.text JTextComponent setFocusTraversalKeys

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent setFocusTraversalKeys.

Prototype

public void setFocusTraversalKeys(int id, Set<? extends AWTKeyStroke> keystrokes) 

Source Link

Document

Sets the focus traversal keys for a given traversal operation for this Component.

Usage

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.// www. j a  v a  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.//w  w  w.j a va  2  s . c  om
 */
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());
}