Search in sources :

Example 1 with RibbonApplicationMenuEntryPrimary

use of org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary in project freeplane by freeplane.

the class RibbonMenuPrimaryContributorFactory method getContributor.

/**
 *********************************************************************************
 * REQUIRED METHODS FOR INTERFACES
 *********************************************************************************
 */
public ARibbonContributor getContributor(final Properties attributes) {
    String accel = attributes.getProperty("accelerator", null);
    final String actionKey = attributes.getProperty("action");
    if (actionKey != null) {
        if (accel != null) {
            if (Compat.isMacOsX()) {
                accel = accel.replaceFirst("CONTROL", "META").replaceFirst("control", "meta");
            }
            builder.getAcceleratorManager().setDefaultAccelerator(actionKey, accel);
        }
    }
    return new ARibbonContributor() {

        RibbonApplicationMenuEntryPrimary entry;

        public String getKey() {
            String key = attributes.getProperty("action", null);
            if (key == null) {
                key = attributes.getProperty("name", null);
            }
            return key;
        }

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            entry = null;
            if (context.hasChildren(context.getCurrentPath())) {
                if (attributes.get("action") == null) {
                    AFreeplaneAction action = ActionUtils.getDummyAction(getKey());
                    entry = createMenuEntry(action, CommandButtonKind.POPUP_ONLY);
                } else {
                    AFreeplaneAction action = context.getBuilder().getMode().getAction(getKey());
                    if (action == null) {
                        action = ActionUtils.getDummyAction(getKey());
                    }
                    entry = createMenuEntry(action, CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION);
                }
                context.processChildren(context.getCurrentPath(), this);
            } else {
                if (attributes.get("action") == null) {
                    return;
                }
                AFreeplaneAction action = context.getBuilder().getMode().getAction(getKey());
                if (action == null) {
                    return;
                }
                entry = createMenuEntry(action, CommandButtonKind.ACTION_ONLY);
            }
            KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(getKey());
            if (ks != null) {
                AFreeplaneAction action = context.getBuilder().getMode().getAction(getKey());
                if (action != null) {
                    RichTooltip tip = RibbonActionContributorFactory.getRichTooltip(action, ks);
                    if (tip != null) {
                        entry.setActionRichTooltip(tip);
                    }
                }
            }
            parent.addChild(entry, new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", ""))));
        }

        public void addChild(Object child, ChildProperties properties) {
            if (child instanceof SecondaryEntryGroup) {
                SecondaryEntryGroup group = (SecondaryEntryGroup) child;
                entry.addSecondaryMenuGroup(group.getTitle(), group.getEntries().toArray(new RibbonApplicationMenuEntrySecondary[0]));
            }
        }
    };
}
Also used : RichTooltip(org.pushingpixels.flamingo.api.common.RichTooltip) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) KeyStroke(javax.swing.KeyStroke) RibbonApplicationMenuEntryPrimary(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary) RibbonApplicationMenuEntrySecondary(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary)

Example 2 with RibbonApplicationMenuEntryPrimary

use of org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary 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)

Example 3 with RibbonApplicationMenuEntryPrimary

use of org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary in project freeplane by freeplane.

the class RibbonMenuPrimaryContributorFactory method createMenuEntry.

/**
 *********************************************************************************
 * METHODS
 *********************************************************************************
 */
public static RibbonApplicationMenuEntryPrimary createMenuEntry(final AFreeplaneAction action, CommandButtonKind kind) {
    String title = ActionUtils.getActionTitle(action);
    ResizableIcon icon = ActionUtils.getActionIcon(action);
    RibbonApplicationMenuEntryPrimary entry = new RibbonApplicationMenuEntryPrimary(icon, title, new RibbonActionContributorFactory.RibbonActionListener(action), kind);
    return entry;
}
Also used : ResizableIcon(org.pushingpixels.flamingo.api.common.icon.ResizableIcon) RibbonApplicationMenuEntryPrimary(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary)

Example 4 with RibbonApplicationMenuEntryPrimary

use of org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary in project freeplane by freeplane.

the class RibbonMenuContributorFactory method getContributor.

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

        private RibbonApplicationMenu menu;

        public String getKey() {
            return "app_menu";
        }

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            menu = new RibbonApplicationMenu();
            context.processChildren(context.getCurrentPath(), this);
            parent.addChild(menu, null);
        }

        public void addChild(Object child, ChildProperties properties) {
            if (child instanceof RibbonApplicationMenuEntryFooter) {
                menu.addFooterEntry((RibbonApplicationMenuEntryFooter) child);
            } else if (child instanceof RibbonApplicationMenuEntryPrimary) {
                menu.addMenuEntry((RibbonApplicationMenuEntryPrimary) child);
            }
        }
    };
}
Also used : RibbonApplicationMenu(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenu) RibbonApplicationMenuEntryFooter(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryFooter) RibbonApplicationMenuEntryPrimary(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary)

Aggregations

RibbonApplicationMenuEntryPrimary (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary)4 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)2 RichTooltip (org.pushingpixels.flamingo.api.common.RichTooltip)2 BorderLayout (java.awt.BorderLayout)1 File (java.io.File)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 JPanel (javax.swing.JPanel)1 KeyStroke (javax.swing.KeyStroke)1 ARibbonContributor (org.freeplane.core.ui.ribbon.ARibbonContributor)1 RibbonBuildContext (org.freeplane.core.ui.ribbon.RibbonBuildContext)1 JCommandButton (org.pushingpixels.flamingo.api.common.JCommandButton)1 JCommandButtonPanel (org.pushingpixels.flamingo.api.common.JCommandButtonPanel)1 JScrollablePanel (org.pushingpixels.flamingo.api.common.JScrollablePanel)1 ResizableIcon (org.pushingpixels.flamingo.api.common.icon.ResizableIcon)1 RibbonApplicationMenu (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenu)1 RibbonApplicationMenuEntryFooter (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryFooter)1 PrimaryRolloverCallback (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary.PrimaryRolloverCallback)1 RibbonApplicationMenuEntrySecondary (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary)1 JRibbonApplicationMenuPopupPanelSecondary (org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.JRibbonApplicationMenuPopupPanelSecondary)1