Search in sources :

Example 6 with AWTKeyStroke

use of java.awt.AWTKeyStroke in project jsql-injection by ron190.

the class ActionHandler method addShortcut.

/**
 * Add action to a single tabbedpane (ctrl-tab, ctrl-shift-tab).
 */
public static void addShortcut(JTabbedPane tabbedPane) {
    KeyStroke ctrlTab = KeyStroke.getKeyStroke("ctrl TAB");
    KeyStroke ctrlShiftTab = KeyStroke.getKeyStroke("ctrl shift TAB");
    // Remove ctrl-tab from normal focus traversal
    Set<AWTKeyStroke> forwardKeys = new HashSet<>(tabbedPane.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    forwardKeys.remove(ctrlTab);
    tabbedPane.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forwardKeys);
    // Remove ctrl-shift-tab from normal focus traversal
    Set<AWTKeyStroke> backwardKeys = new HashSet<>(tabbedPane.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    backwardKeys.remove(ctrlShiftTab);
    tabbedPane.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardKeys);
    // Add keys to the tab's input map
    InputMap inputMap = tabbedPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(ctrlTab, "navigateNext");
    inputMap.put(ctrlShiftTab, "navigatePrevious");
}
Also used : AWTKeyStroke(java.awt.AWTKeyStroke) KeyStroke(javax.swing.KeyStroke) AWTKeyStroke(java.awt.AWTKeyStroke) InputMap(javax.swing.InputMap) HashSet(java.util.HashSet)

Example 7 with AWTKeyStroke

use of java.awt.AWTKeyStroke in project sulky by huxi.

the class SwingLogging method logTraversal.

public static void logTraversal(JComponent component) {
    final Logger logger = LoggerFactory.getLogger(SwingLogging.class);
    final int[] ids = { KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS };
    final String[] names = { "FORWARD_TRAVERSAL_KEYS", "BACKWARD_TRAVERSAL_KEYS", "UP_CYCLE_TRAVERSAL_KEYS", "DOWN_CYCLE_TRAVERSAL_KEYS" };
    if (logger.isDebugEnabled()) {
        for (int i = 0; i < ids.length; i++) {
            Set<AWTKeyStroke> keys = component.getFocusTraversalKeys(ids[i]);
            logger.debug("ID: {}\nKeys:{}", names[i], keys);
        }
    }
}
Also used : AWTKeyStroke(java.awt.AWTKeyStroke) Logger(org.slf4j.Logger)

Aggregations

AWTKeyStroke (java.awt.AWTKeyStroke)7 HashSet (java.util.HashSet)5 InputMap (javax.swing.InputMap)3 ActionMap (javax.swing.ActionMap)2 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 KeyStroke (javax.swing.KeyStroke)1 DefaultEditorKit (javax.swing.text.DefaultEditorKit)1 EditorKit (javax.swing.text.EditorKit)1 Logger (org.slf4j.Logger)1