use of javax.swing.KeyStroke in project freeplane by freeplane.
the class ActionAcceleratorManager method processKeyBinding.
public boolean processKeyBinding(KeyStroke ks, KeyEvent event) {
AFreeplaneAction action = actionForAccelerator(ks);
if (action == null) {
final KeyStroke derivedKeyStroke = FreeplaneMenuBar.derive(ks, event.getKeyChar());
action = actionForAccelerator(derivedKeyStroke);
}
if (action != null && action.isEnabled()) {
if (action != null && SwingUtilities.notifyAction(action, ks, event, event.getComponent(), event.getModifiers())) {
return true;
}
}
return false;
}
use of javax.swing.KeyStroke in project freeplane by freeplane.
the class IconSelectionPopupDialog method findIndexByKeyEvent.
private int findIndexByKeyEvent(final KeyEvent keyEvent) {
for (int i = 0; i < icons.size(); i++) {
final IIconInformation info = icons.get(i);
final KeyStroke iconKeyStroke = info.getKeyStroke();
if (iconKeyStroke != null && (keyEvent.getKeyCode() == iconKeyStroke.getKeyCode() && keyEvent.getKeyCode() != 0 && (iconKeyStroke.getModifiers() & InputEvent.SHIFT_MASK) == (keyEvent.getModifiers() & InputEvent.SHIFT_MASK) || keyEvent.getKeyChar() == iconKeyStroke.getKeyChar()) && keyEvent.getKeyChar() != 0 && keyEvent.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
return i;
}
}
return -1;
}
use of javax.swing.KeyStroke in project freeplane by freeplane.
the class MenuAcceleratorChangeListenerTest method setsKeystroke.
@Test
public void setsKeystroke() throws Exception {
final EntriesForAction entriesForAction = new EntriesForAction();
final MenuAcceleratorChangeListener menuAcceleratorChangeListener = new MenuAcceleratorChangeListener(entriesForAction);
final AFreeplaneAction action = mock(AFreeplaneAction.class);
Entry actionEntry = new Entry();
final JMenuItem menu = new JMenuItem();
new EntryAccessor().setComponent(actionEntry, menu);
entriesForAction.registerEntry(action, actionEntry);
final KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0);
menuAcceleratorChangeListener.acceleratorChanged(action, null, keyStroke);
Assert.assertThat(menu.getAccelerator(), equalTo(keyStroke));
}
use of javax.swing.KeyStroke in project freeplane by freeplane.
the class UITools method getKeyStroke.
/**
* returns a KeyStroke if possible and null otherwise.
*/
public static KeyStroke getKeyStroke(final String keyStrokeDescription) {
if (keyStrokeDescription == null) {
return null;
}
final KeyStroke keyStroke = KeyStroke.getKeyStroke(keyStrokeDescription);
if (keyStroke != null) {
return keyStroke;
}
final int lastSpacePos = keyStrokeDescription.lastIndexOf(' ') + 1;
final String modifiedDescription = keyStrokeDescription.substring(0, lastSpacePos) + "typed " + keyStrokeDescription.substring(lastSpacePos);
return KeyStroke.getKeyStroke(modifiedDescription);
}
use of javax.swing.KeyStroke in project freeplane by freeplane.
the class MenuActionComponentProvider method createComponent.
/* (non-Javadoc)
* @see org.freeplane.core.ui.menubuilders.menu.ComponentProvider#createComponent(org.freeplane.core.ui.menubuilders.generic.Entry)
*/
@Override
public Component createComponent(Entry entry) {
final AFreeplaneAction action = entryAccessor.getAction(entry);
if (action != null) {
final JMenuItem actionComponent;
IFreeplaneAction wrappedAction = acceleratebleActionProvider.wrap(action);
if (action.isSelectable()) {
actionComponent = new JAutoCheckBoxMenuItem(wrappedAction);
} else {
actionComponent = new JFreeplaneMenuItem(wrappedAction);
}
final KeyStroke accelerator = accelerators.getAccelerator(action);
actionComponent.setAccelerator(accelerator);
MenuIconScaling.scaleIcon(actionComponent);
return actionComponent;
} else if (entry.builders().contains("separator")) {
return new JPopupMenu.Separator();
} else
return null;
}
Aggregations