Search in sources :

Example 56 with KeyStroke

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;
}
Also used : KeyStroke(javax.swing.KeyStroke)

Example 57 with KeyStroke

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;
}
Also used : KeyStroke(javax.swing.KeyStroke) IIconInformation(org.freeplane.features.icon.IIconInformation)

Example 58 with KeyStroke

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));
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntriesForAction(org.freeplane.core.ui.menubuilders.action.EntriesForAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) KeyStroke(javax.swing.KeyStroke) JMenuItem(javax.swing.JMenuItem) Test(org.junit.Test)

Example 59 with 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);
}
Also used : KeyStroke(javax.swing.KeyStroke) Point(java.awt.Point)

Example 60 with KeyStroke

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;
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) IFreeplaneAction(org.freeplane.core.ui.IFreeplaneAction) JAutoCheckBoxMenuItem(org.freeplane.core.ui.components.JAutoCheckBoxMenuItem) KeyStroke(javax.swing.KeyStroke) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JFreeplaneMenuItem(org.freeplane.core.ui.components.JFreeplaneMenuItem)

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