Search in sources :

Example 51 with KeyStroke

use of javax.swing.KeyStroke in project chatty by chatty.

the class HotkeyManager method removeHotkeys.

/**
 * Removes all entries from the InputMap that point to an action with the
 * prefix of this.
 *
 * @param pane The JRootPane to remove the hotkeys from
 */
private void removeHotkeys(JRootPane pane) {
    Set<KeyStroke> toBeRemoved = new HashSet<>();
    InputMap input = pane.getInputMap(INPUT_MAP_KEY);
    ActionMap action = pane.getActionMap();
    if (input.keys() == null) {
        return;
    }
    for (KeyStroke keyStroke : input.keys()) {
        Object key = input.get(keyStroke);
        if (key instanceof String && ((String) key).startsWith(PREFIX)) {
            toBeRemoved.add(keyStroke);
            action.remove(key);
        }
    }
    for (KeyStroke keyStroke : toBeRemoved) {
        input.remove(keyStroke);
    }
}
Also used : ActionMap(javax.swing.ActionMap) KeyStroke(javax.swing.KeyStroke) InputMap(javax.swing.InputMap) HashSet(java.util.HashSet)

Example 52 with KeyStroke

use of javax.swing.KeyStroke in project freeplane by freeplane.

the class ActionAcceleratorManager method setDefaultAccelerator.

public void setDefaultAccelerator(final AFreeplaneAction action, String accelerator) {
    final String shortcutKey = getPropertyKey(action.getKey());
    if (null == getShortcut(shortcutKey)) {
        if (overwritttenDefaultProps.containsKey(shortcutKey))
            accelerator = overwritttenDefaultProps.getProperty(shortcutKey);
        accelerator = replaceModifiersForMac(accelerator);
        defaultProps.setProperty(shortcutKey, accelerator);
        KeyStroke ks = KeyStroke.getKeyStroke(accelerator);
        setAccelerator(action, ks);
    }
}
Also used : KeyStroke(javax.swing.KeyStroke)

Example 53 with KeyStroke

use of javax.swing.KeyStroke in project freeplane by freeplane.

the class ActionAcceleratorManager method setAccelerator.

private void setAccelerator(ModeController modeController, final AFreeplaneAction action, final KeyStroke keyStroke) {
    final AFreeplaneAction oldAction = accelerators.get(key(modeController, keyStroke));
    if (action == oldAction) {
        return;
    }
    if (keyStroke != null && oldAction != null) {
        if (acceleratorIsDefinedByUserProperties(oldAction, modeController, keysetProps))
            return;
        else {
            actionMap.remove(key(modeController, oldAction.getKey()));
            fireAcceleratorChanged(modeController, oldAction, keyStroke, null);
        }
    }
    if (action == null) {
        return;
    }
    if (keyStroke != null) {
        accelerators.put(key(modeController, keyStroke), action);
    }
    final KeyStroke removedAccelerator = removeAccelerator(modeController, action);
    final String actionKey = action.getKey();
    if (keyStroke != null) {
        actionMap.put(key(modeController, actionKey), keyStroke);
    }
    fireAcceleratorChanged(modeController, action, removedAccelerator, keyStroke);
}
Also used : KeyStroke(javax.swing.KeyStroke)

Example 54 with KeyStroke

use of javax.swing.KeyStroke in project freeplane by freeplane.

the class ActionAcceleratorManager method loadAcceleratorPreset.

private void loadAcceleratorPreset(final String shortcutKey, final String keystrokeString, Properties allPresets) {
    if (!shortcutKey.startsWith(SHORTCUT_PROPERTY_PREFIX)) {
        LogUtils.warn("wrong property key " + shortcutKey);
        return;
    }
    final int pos = shortcutKey.indexOf("/", SHORTCUT_PROPERTY_PREFIX.length());
    if (pos <= 0) {
        LogUtils.warn("wrong property key " + shortcutKey);
        return;
    }
    final String modeName = shortcutKey.substring(SHORTCUT_PROPERTY_PREFIX.length(), pos);
    final String itemKey = shortcutKey.substring(pos + 1);
    Controller controller = Controller.getCurrentController();
    final ModeController modeController = controller.getModeController(modeName);
    if (modeController != null) {
        final KeyStroke keyStroke;
        if (!keystrokeString.equals("")) {
            keyStroke = UITools.getKeyStroke(keystrokeString);
            final AFreeplaneAction oldAction = accelerators.get(key(modeController, keyStroke));
            if (!acceleratorIsDefinedByUserProperties(oldAction, modeController, allPresets))
                setAccelerator(modeController, oldAction, null);
        } else {
            keyStroke = null;
        }
        final AFreeplaneAction action = modeController.getAction(itemKey);
        if (action != null) {
            setAccelerator(modeController, action, keyStroke);
        }
    }
    setKeysetProperty(shortcutKey, keystrokeString);
}
Also used : KeyStroke(javax.swing.KeyStroke) ModeController(org.freeplane.features.mode.ModeController) ResourceController(org.freeplane.core.resources.ResourceController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController)

Example 55 with KeyStroke

use of javax.swing.KeyStroke in project freeplane by freeplane.

the class ActionAcceleratorManager method removeAction.

@Override
public void removeAction(FreeplaneActions freeplaneActions, AFreeplaneAction action) {
    final KeyStroke oldKeystroke = removeAccelerator(action);
    fireAcceleratorChanged(freeplaneActions, action, oldKeystroke, null);
}
Also used : 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