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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations