Search in sources :

Example 46 with AFreeplaneAction

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

the class EntriesForActionTest method returnsListWithTwoRegisteredActions.

@Test
public void returnsListWithTwoRegisteredActions() throws Exception {
    final EntriesForAction entriesForAction = new EntriesForAction();
    AFreeplaneAction action = mock(AFreeplaneAction.class);
    final Entry actionEntry1 = new Entry();
    final Entry actionEntry2 = new Entry();
    entriesForAction.registerEntry(action, actionEntry1);
    entriesForAction.registerEntry(action, actionEntry2);
    Collection<Entry> entries = entriesForAction.entries(action);
    assertThat(entries, equalTo((Collection<Entry>) asList(actionEntry1, actionEntry2)));
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) Collection(java.util.Collection) Test(org.junit.Test)

Example 47 with AFreeplaneAction

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

the class UserInputListenerFactory method createModeActions.

private void createModeActions(final Entry modesMenuEntry) {
    rebuildMenuOnMapChange(modesMenuEntry);
    Controller controller = Controller.getCurrentController();
    EntryAccessor entryAccessor = new EntryAccessor();
    for (final String key : new LinkedList<String>(controller.getModes())) {
        final AFreeplaneAction modesMenuAction = new ModesMenuAction(key, controller);
        modeController.addActionIfNotAlreadySet(modesMenuAction);
        Entry actionEntry = new Entry();
        entryAccessor.setAction(actionEntry, modesMenuAction);
        actionEntry.setName(modesMenuAction.getKey());
        final ModeController modeController = controller.getModeController();
        if (modeController != null && modeController.getModeName().equals(key)) {
            actionEntry.setAttribute("selected", true);
        }
        modesMenuEntry.addChild(actionEntry);
        ResourceController.getResourceController().getProperty(("keystroke_mode_" + key));
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) ModeController(org.freeplane.features.mode.ModeController) Controller(org.freeplane.features.mode.Controller) ResourceController(org.freeplane.core.resources.ResourceController) ViewController(org.freeplane.features.ui.ViewController) ModeController(org.freeplane.features.mode.ModeController) LinkedList(java.util.LinkedList)

Example 48 with AFreeplaneAction

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

the class EntryAccessorTest method addsChildAction.

@Test
public void addsChildAction() throws Exception {
    final AFreeplaneAction action = mock(AFreeplaneAction.class);
    when(action.getKey()).thenReturn("key");
    entryAccessor.addChildAction(entry, action);
    final Entry actionEntry = entry.getChild(0);
    final AFreeplaneAction entryAction = entryAccessor.getAction(actionEntry);
    Assert.assertThat(actionEntry.getName(), equalTo("key"));
    Assert.assertThat(entryAction, equalTo(action));
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Test(org.junit.Test)

Example 49 with AFreeplaneAction

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

the class JToolbarComponentBuilderTest method createsToolbarButtonWithSelectableAction.

@Test
public void createsToolbarButtonWithSelectableAction() {
    Entry actionEntry = new Entry();
    final AFreeplaneAction action = Mockito.mock(AFreeplaneAction.class);
    when(action.isSelectable()).thenReturn(true);
    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);
    JAutoToggleButton button = (JAutoToggleButton) new EntryAccessor().getComponent(actionEntry);
    assertThat(button.getAction(), CoreMatchers.<Action>equalTo(action));
    assertThat(button.getParent(), CoreMatchers.equalTo((Container) toolbar));
}
Also used : JAutoToggleButton(org.freeplane.core.ui.components.JAutoToggleButton) 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) JToolbarComponentBuilder(org.freeplane.core.ui.menubuilders.menu.JToolbarComponentBuilder) Test(org.junit.Test)

Example 50 with AFreeplaneAction

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

the class LastOpenedMapsRibbonContributorFactory method getContributor.

public ARibbonContributor getContributor(final Properties attributes) {
    return new ARibbonContributor() {

        @Override
        public String getKey() {
            return "lastOpenedMaps";
        }

        private final String menuName = TextUtils.getText(attributes.getProperty("name_ref"));

        @Override
        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            RibbonApplicationMenuEntryPrimary primeEntry = new RibbonApplicationMenuEntryPrimary(null, menuName, null, CommandButtonKind.POPUP_ONLY);
            primeEntry.setRolloverCallback(getCallback(primeEntry));
            parent.addChild(primeEntry, new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", ""))));
        }

        @Override
        public void addChild(Object child, ChildProperties properties) {
        }

        private PrimaryRolloverCallback getCallback(final RibbonApplicationMenuEntryPrimary primeEntry) {
            if (rolloverCallback == null) {
                rolloverCallback = new PrimaryRolloverCallback() {

                    public void menuEntryActivated(JPanel targetPanel) {
                        targetPanel.removeAll();
                        targetPanel.setLayout(new BorderLayout());
                        JCommandButtonPanel secondary = new JRibbonApplicationMenuPopupPanelSecondary(primeEntry);
                        secondary.setToShowGroupLabels(false);
                        String groupDesc = menuName;
                        secondary.addButtonGroup(groupDesc);
                        List<AFreeplaneAction> openActions = lastOpenedList.createOpenLastMapActionList();
                        for (AFreeplaneAction action : openActions) {
                            String restoreable = (String) action.getValue(Action.DEFAULT);
                            StringTokenizer tokens = new StringTokenizer(restoreable, ";");
                            File file = lastOpenedList.createFileFromRestorable(tokens);
                            JCommandButton menuButton = new JCommandButton(file.getName());
                            menuButton.addActionListener(action);
                            menuButton.setCommandButtonKind(CommandButtonKind.ACTION_ONLY);
                            menuButton.setHorizontalAlignment(SwingUtilities.LEADING);
                            menuButton.setPopupOrientationKind(CommandButtonPopupOrientationKind.SIDEWARD);
                            menuButton.setEnabled(true);
                            menuButton.setActionRichTooltip(new RichTooltip((String) action.getValue(Action.SHORT_DESCRIPTION), file.toString()));
                            secondary.addButtonToLastGroup(menuButton);
                        }
                        JScrollablePanel<JCommandButtonPanel> scrollPanel = new JScrollablePanel<JCommandButtonPanel>(secondary, ScrollType.VERTICALLY);
                        targetPanel.add(scrollPanel, BorderLayout.CENTER);
                    }
                };
            }
            return rolloverCallback;
        }
    };
}
Also used : ARibbonContributor(org.freeplane.core.ui.ribbon.ARibbonContributor) JPanel(javax.swing.JPanel) JRibbonApplicationMenuPopupPanelSecondary(org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.JRibbonApplicationMenuPopupPanelSecondary) PrimaryRolloverCallback(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary.PrimaryRolloverCallback) JScrollablePanel(org.pushingpixels.flamingo.api.common.JScrollablePanel) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) RibbonApplicationMenuEntryPrimary(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary) RichTooltip(org.pushingpixels.flamingo.api.common.RichTooltip) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) StringTokenizer(java.util.StringTokenizer) BorderLayout(java.awt.BorderLayout) JCommandButtonPanel(org.pushingpixels.flamingo.api.common.JCommandButtonPanel) List(java.util.List) File(java.io.File) RibbonBuildContext(org.freeplane.core.ui.ribbon.RibbonBuildContext)

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