Search in sources :

Example 1 with RibbonApplicationMenuEntrySecondary

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

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

the class RibbonMenuSecondaryGroupContributorFactory method getContributor.

/**
 *********************************************************************************
 * CONSTRUCTORS
 *********************************************************************************
 */
/**
 *********************************************************************************
 * METHODS
 *********************************************************************************
 */
/**
 *********************************************************************************
 * REQUIRED METHODS FOR INTERFACES
 *********************************************************************************
 */
public ARibbonContributor getContributor(final Properties attributes) {
    return new ARibbonContributor() {

        SecondaryEntryGroup group;

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

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            group = new SecondaryEntryGroup(TextUtils.removeTranslateComment(TextUtils.getRawText("ribbon.menu.group." + getKey())));
            context.processChildren(context.getCurrentPath(), this);
            parent.addChild(group, new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", ""))));
        }

        public void addChild(Object child, ChildProperties properties) {
            if (child instanceof RibbonApplicationMenuEntrySecondary) {
                group.addEntry((RibbonApplicationMenuEntrySecondary) child);
            } else if (child instanceof AbstractCommandButton) {
                group.addEntry(wrapButton((AbstractCommandButton) child));
            }
        }

        private RibbonApplicationMenuEntrySecondary wrapButton(AbstractCommandButton button) {
            ActionListener listener = null;
            PopupPanelCallback callback = null;
            CommandButtonKind kind = CommandButtonKind.ACTION_ONLY;
            if (button instanceof JCommandButton) {
                if (((JCommandButton) button).getPopupCallback() != null) {
                    kind = (((JCommandButton) button).getCommandButtonKind());
                    callback = ((JCommandButton) button).getPopupCallback();
                }
            }
            for (ActionListener l : button.getListeners(ActionListener.class)) {
                if (l instanceof RibbonActionListener) {
                    listener = l;
                    break;
                }
            }
            RibbonApplicationMenuEntrySecondary entry = new RibbonApplicationMenuEntrySecondary(button.getIcon(), button.getText(), listener, kind);
            if (callback != null) {
                entry.setPopupCallback(callback);
            }
            KeyStroke ks = (KeyStroke) button.getClientProperty(RibbonActionContributorFactory.ACTION_ACCELERATOR);
            if (ks != null) {
                AFreeplaneAction action = (AFreeplaneAction) button.getClientProperty(RibbonActionContributorFactory.ACTION_KEY_PROPERTY);
                if (action != null) {
                    RichTooltip tip = RibbonActionContributorFactory.getRichTooltip(action, ks);
                    if (tip != null) {
                        entry.setActionRichTooltip(tip);
                    }
                }
            }
            return entry;
        }
    };
}
Also used : PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) RichTooltip(org.pushingpixels.flamingo.api.common.RichTooltip) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) ActionListener(java.awt.event.ActionListener) RibbonActionListener(org.freeplane.core.ui.ribbon.RibbonActionContributorFactory.RibbonActionListener) AbstractCommandButton(org.pushingpixels.flamingo.api.common.AbstractCommandButton) KeyStroke(javax.swing.KeyStroke) SecondaryEntryGroup(org.freeplane.core.ui.ribbon.RibbonMenuPrimaryContributorFactory.SecondaryEntryGroup) CommandButtonKind(org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind) RibbonActionListener(org.freeplane.core.ui.ribbon.RibbonActionContributorFactory.RibbonActionListener) RibbonApplicationMenuEntrySecondary(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary)

Aggregations

KeyStroke (javax.swing.KeyStroke)2 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)2 RichTooltip (org.pushingpixels.flamingo.api.common.RichTooltip)2 RibbonApplicationMenuEntrySecondary (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntrySecondary)2 ActionListener (java.awt.event.ActionListener)1 RibbonActionListener (org.freeplane.core.ui.ribbon.RibbonActionContributorFactory.RibbonActionListener)1 SecondaryEntryGroup (org.freeplane.core.ui.ribbon.RibbonMenuPrimaryContributorFactory.SecondaryEntryGroup)1 AbstractCommandButton (org.pushingpixels.flamingo.api.common.AbstractCommandButton)1 JCommandButton (org.pushingpixels.flamingo.api.common.JCommandButton)1 CommandButtonKind (org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind)1 PopupPanelCallback (org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback)1 RibbonApplicationMenuEntryPrimary (org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryPrimary)1