Search in sources :

Example 91 with KeyStroke

use of javax.swing.KeyStroke in project binnavi by google.

the class JHexView method initHotkeys.

/**
 * Initializes the keys that can be used by the user inside the component.
 */
private void initHotkeys() {
    // Don't change focus on TAB
    setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<KeyStroke>());
    final InputMap inputMap = this.getInputMap();
    final ActionMap actionMap = getActionMap();
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "LEFT");
    actionMap.put("LEFT", m_leftAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.SHIFT_DOWN_MASK), "shift LEFT");
    actionMap.put("shift LEFT", m_leftAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "RIGHT");
    actionMap.put("RIGHT", m_rightAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.SHIFT_DOWN_MASK), "shift RIGHT");
    actionMap.put("shift RIGHT", m_rightAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "UP");
    actionMap.put("UP", m_upAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.SHIFT_DOWN_MASK), "shift UP");
    actionMap.put("shift UP", m_upAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "DOWN");
    actionMap.put("DOWN", m_downAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.SHIFT_DOWN_MASK), "shift DOWN");
    actionMap.put("shift DOWN", m_downAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PAGE_DOWN");
    actionMap.put("PAGE_DOWN", m_pageDownAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, InputEvent.SHIFT_DOWN_MASK), "shift PAGE_DOWN");
    actionMap.put("shift PAGE_DOWN", m_pageDownAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PAGE_UP");
    actionMap.put("PAGE_UP", m_pageUpAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, InputEvent.SHIFT_DOWN_MASK), "shift PAGE_UP");
    actionMap.put("shift PAGE_UP", m_pageUpAction);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "TAB");
    actionMap.put("TAB", m_tabAction);
}
Also used : ActionMap(javax.swing.ActionMap) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Example 92 with KeyStroke

use of javax.swing.KeyStroke in project jmeter by apache.

the class MainFrame method addQuickComponentHotkeys.

private void addQuickComponentHotkeys(JTree treevar) {
    Action quickComponent = new QuickComponent("Quick Component");
    InputMap inputMap = treevar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    KeyStroke[] keyStrokes = new KeyStroke[] { KeyStrokes.CTRL_0, KeyStrokes.CTRL_1, KeyStrokes.CTRL_2, KeyStrokes.CTRL_3, KeyStrokes.CTRL_4, KeyStrokes.CTRL_5, KeyStrokes.CTRL_6, KeyStrokes.CTRL_7, KeyStrokes.CTRL_8, KeyStrokes.CTRL_9 };
    for (int n = 0; n < keyStrokes.length; n++) {
        treevar.getActionMap().put(ActionNames.QUICK_COMPONENT + String.valueOf(n), quickComponent);
        inputMap.put(keyStrokes[n], ActionNames.QUICK_COMPONENT + String.valueOf(n));
    }
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap)

Example 93 with KeyStroke

use of javax.swing.KeyStroke in project jmeter by apache.

the class TextComponentUI method installUndo.

/**
 * Installs an undo manager and keyboard shortcuts to a text component
 * @param component JTextField or JTextArea
 */
@API(since = "5.3", status = API.Status.INTERNAL)
public void installUndo(JTextComponent component) {
    // JMeter reuses Swing JComponents, so when user switches to another component,
    // JComponent#name is updated. However, we don't want user to be able to "undo" that
    // So when tree selection is changed, we increase undoEpoch. That enables
    // UndoManagers to treat that as "end of undo history"
    UndoManager manager = new DefaultUndoManager(undoEpoch);
    manager.setLimit(200);
    component.addPropertyChangeListener("document", new AddUndoableEditListenerPropertyChangeListener(manager));
    component.getActionMap().put("undo", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (manager.canUndo()) {
                manager.undo();
            }
        }
    });
    component.getActionMap().put("redo", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (manager.canRedo()) {
                manager.redo();
            }
        }
    });
    KeyStroke commandZ = KeyStroke.getKeyStroke(KeyEvent.VK_Z, COMMAND_KEY);
    component.getInputMap().put(commandZ, "undo");
    KeyStroke shiftCommandZ = KeyStroke.getKeyStroke(KeyEvent.VK_Z, COMMAND_KEY | InputEvent.SHIFT_DOWN_MASK);
    component.getInputMap().put(shiftCommandZ, "redo");
}
Also used : UndoManager(javax.swing.undo.UndoManager) ActionEvent(java.awt.event.ActionEvent) KeyStroke(javax.swing.KeyStroke) AbstractAction(javax.swing.AbstractAction) API(org.apiguardian.api.API)

Example 94 with KeyStroke

use of javax.swing.KeyStroke in project GCViewer by chewiebug.

the class ScreenCenteredDialog method createRootPane.

protected JRootPane createRootPane() {
    KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    KeyStroke enterStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    JRootPane rootPane = new JRootPane();
    rootPane.registerKeyboardAction(this, escapeStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    rootPane.registerKeyboardAction(this, enterStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
    return rootPane;
}
Also used : KeyStroke(javax.swing.KeyStroke) JRootPane(javax.swing.JRootPane)

Example 95 with KeyStroke

use of javax.swing.KeyStroke in project GDSC-SMLM by aherbert.

the class TableColumnAdjuster method installToggleAction.

/*
   * Update the input and action maps with new ToggleAction
   */
private void installToggleAction(boolean isToggleDynamic, boolean isToggleLarger, String key, String keyStroke) {
    final Action action = new ToggleAction(isToggleDynamic, isToggleLarger);
    final KeyStroke ks = KeyStroke.getKeyStroke(keyStroke);
    table.getInputMap().put(ks, key);
    table.getActionMap().put(key, action);
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) KeyStroke(javax.swing.KeyStroke)

Aggregations

KeyStroke (javax.swing.KeyStroke)194 ActionEvent (java.awt.event.ActionEvent)77 AbstractAction (javax.swing.AbstractAction)56 InputMap (javax.swing.InputMap)46 Action (javax.swing.Action)44 JRootPane (javax.swing.JRootPane)36 ActionListener (java.awt.event.ActionListener)27 JPanel (javax.swing.JPanel)20 ActionMap (javax.swing.ActionMap)17 JComponent (javax.swing.JComponent)16 KeyEvent (java.awt.event.KeyEvent)15 JMenuItem (javax.swing.JMenuItem)14 JScrollPane (javax.swing.JScrollPane)14 Point (java.awt.Point)13 JFrame (javax.swing.JFrame)12 JPopupMenu (javax.swing.JPopupMenu)12 WindowEvent (java.awt.event.WindowEvent)10 Dimension (java.awt.Dimension)9 MouseAdapter (java.awt.event.MouseAdapter)9 MouseEvent (java.awt.event.MouseEvent)9