Search in sources :

Example 16 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.

the class JToolbarComponentBuilderTest method createsToolbarButtonWithAction.

@Test
public void createsToolbarButtonWithAction() {
    Entry actionEntry = new Entry();
    final AFreeplaneAction action = Mockito.mock(AFreeplaneAction.class);
    new EntryAccessor().setAction(actionEntry, action);
    Entry toolbarEntry = new Entry();
    final FreeplaneToolBar toolbar = new FreeplaneToolBar("toolbar", SwingConstants.HORIZONTAL);
    new EntryAccessor().setComponent(toolbarEntry, toolbar);
    toolbarEntry.addChild(actionEntry);
    final JToolbarComponentBuilder toolbarActionGroupBuilder = new JToolbarComponentBuilder();
    toolbarActionGroupBuilder.visit(actionEntry);
    JButton button = (JButton) new EntryAccessor().getComponent(actionEntry);
    assertThat(button.getAction(), CoreMatchers.<Action>equalTo(action));
    assertThat(button.getParent(), CoreMatchers.equalTo((Container) toolbar));
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Container(java.awt.Container) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) FreeplaneToolBar(org.freeplane.core.ui.components.FreeplaneToolBar) JButton(javax.swing.JButton) JToolbarComponentBuilder(org.freeplane.core.ui.menubuilders.menu.JToolbarComponentBuilder) Test(org.junit.Test)

Example 17 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction 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 18 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.

the class ToolbarComponentProvider 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 EntryAccessor entryAccessor = new EntryAccessor();
    final Object existingComponent = entryAccessor.getComponent(entry);
    if (existingComponent != null)
        return (Component) existingComponent;
    final AFreeplaneAction action = entryAccessor.getAction(entry);
    Component component;
    if (action != null) {
        if (action.isSelectable()) {
            component = new JAutoToggleButton(action);
        } else {
            component = new JButton(action);
        }
    } else if (entry.builders().contains("separator")) {
        component = new Separator();
    } else
        component = null;
    return component;
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JButton(javax.swing.JButton) Component(java.awt.Component) Separator(javax.swing.JToolBar.Separator)

Example 19 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction 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 20 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.

the class MenuRadioActionComponentProvider 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 JAutoRadioButtonMenuItem(wrappedAction);
        } else {
            actionComponent = new JRadioButtonMenuItem(wrappedAction);
        }
        actionComponent.setSelected(Boolean.parseBoolean(String.valueOf(entry.getAttribute("selected"))) || entry.getName().equals(getSelectedActionName(entry)));
        buttonGroup.add(actionComponent);
        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) KeyStroke(javax.swing.KeyStroke) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JAutoRadioButtonMenuItem(org.freeplane.core.ui.components.JAutoRadioButtonMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)66 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)23 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)20 Test (org.junit.Test)20 Component (java.awt.Component)9 ArrayList (java.util.ArrayList)9 KeyStroke (javax.swing.KeyStroke)8 JCommandButton (org.pushingpixels.flamingo.api.common.JCommandButton)8 Container (java.awt.Container)6 ARibbonContributor (org.freeplane.core.ui.ribbon.ARibbonContributor)6 RibbonBuildContext (org.freeplane.core.ui.ribbon.RibbonBuildContext)6 Controller (org.freeplane.features.mode.Controller)6 ModeController (org.freeplane.features.mode.ModeController)6 ActionEvent (java.awt.event.ActionEvent)5 JMenuItem (javax.swing.JMenuItem)5 ResourceController (org.freeplane.core.resources.ResourceController)5 JComponent (javax.swing.JComponent)4 MModeController (org.freeplane.features.mode.mindmapmode.MModeController)4 RichTooltip (org.pushingpixels.flamingo.api.common.RichTooltip)4 PopupPanelCallback (org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback)4