Search in sources :

Example 1 with JAutoCheckBoxMenuItem

use of org.freeplane.core.ui.components.JAutoCheckBoxMenuItem 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)

Example 2 with JAutoCheckBoxMenuItem

use of org.freeplane.core.ui.components.JAutoCheckBoxMenuItem in project freeplane by freeplane.

the class JMenuItemBuilderTest method createsMenuItemWithSelectableAction.

@Test
public void createsMenuItemWithSelectableAction() {
    menuEntry.addChild(actionEntry);
    when(action.isSelectable()).thenReturn(true);
    new EntryAccessor().setComponent(menuEntry, menu);
    menuActionGroupBuilder.visit(actionEntry);
    JAutoCheckBoxMenuItem item = (JAutoCheckBoxMenuItem) new EntryAccessor().getComponent(actionEntry);
    final AccelerateableAction itemAction = (AccelerateableAction) item.getAction();
    assertThat(itemAction.getOriginalAction(), CoreMatchers.<Action>equalTo(action));
    assertThat(item.getParent(), CoreMatchers.<Container>equalTo(menu.getPopupMenu()));
}
Also used : EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JAutoCheckBoxMenuItem(org.freeplane.core.ui.components.JAutoCheckBoxMenuItem) AccelerateableAction(org.freeplane.core.ui.AccelerateableAction) Test(org.junit.Test)

Aggregations

JAutoCheckBoxMenuItem (org.freeplane.core.ui.components.JAutoCheckBoxMenuItem)2 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 KeyStroke (javax.swing.KeyStroke)1 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)1 AccelerateableAction (org.freeplane.core.ui.AccelerateableAction)1 IFreeplaneAction (org.freeplane.core.ui.IFreeplaneAction)1 JFreeplaneMenuItem (org.freeplane.core.ui.components.JFreeplaneMenuItem)1 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)1 Test (org.junit.Test)1