Search in sources :

Example 1 with RibbonElementPriority

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

the class RibbonBandContributorFactory method getContributor.

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

        private JRibbonBand band;

        private boolean valid = false;

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

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            if (parent == null) {
                return;
            }
            band = new JRibbonBand(TextUtils.removeTranslateComment(TextUtils.getText("ribbon.band." + attributes.getProperty("name"))), null);
            // read policies and sub-contributions
            context.processChildren(context.getCurrentPath(), this);
            setResizePolicies(attributes.getProperty("resize_policies"));
            band.setFocusable(false);
            if (valid) {
                parent.addChild(band, new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", ""))));
            }
        }

        public void addChild(Object child, ChildProperties properties) {
            if (child instanceof AbstractCommandButton) {
                RibbonElementPriority priority = properties.get(RibbonElementPriority.class);
                if (priority == null) {
                    priority = RibbonElementPriority.TOP;
                }
                band.addCommandButton((AbstractCommandButton) child, priority);
                valid = true;
            }
        }

        private void setResizePolicies(String policiesString) {
            if (policiesString != null) {
                String[] tokens = policiesString.split(",");
                List<RibbonBandResizePolicy> policyList = new ArrayList<RibbonBandResizePolicy>();
                for (String policyStr : tokens) {
                    if ("none".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.None(band.getControlPanel()));
                    } else if ("mirror".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.Mirror(band.getControlPanel()));
                    } else if ("high2low".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.High2Low(band.getControlPanel()));
                    } else if ("high2mid".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.High2Mid(band.getControlPanel()));
                    } else if ("mid2low".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.Mid2Low(band.getControlPanel()));
                    } else if ("mid2mid".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.Mid2Mid(band.getControlPanel()));
                    } else if ("low2mid".equals(policyStr.toLowerCase().trim())) {
                        policyList.add(new CoreRibbonResizePolicies.Low2Mid(band.getControlPanel()));
                    }
                }
                policyList.add(new IconRibbonBandResizePolicy(band.getControlPanel()));
                band.setResizePolicies(policyList);
                try {
                    FlamingoUtilities.checkResizePoliciesConsistency(band);
                } catch (Exception ignore) {
                    reorganizePolicies(band, true);
                }
            }
        }
    };
}
Also used : CoreRibbonResizePolicies(org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies) ArrayList(java.util.ArrayList) IconRibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy) RibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.RibbonBandResizePolicy) IconRibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy) RibbonElementPriority(org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority) JRibbonBand(org.pushingpixels.flamingo.api.ribbon.JRibbonBand) AbstractCommandButton(org.pushingpixels.flamingo.api.common.AbstractCommandButton)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractCommandButton (org.pushingpixels.flamingo.api.common.AbstractCommandButton)1 JRibbonBand (org.pushingpixels.flamingo.api.ribbon.JRibbonBand)1 RibbonElementPriority (org.pushingpixels.flamingo.api.ribbon.RibbonElementPriority)1 CoreRibbonResizePolicies (org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies)1 IconRibbonBandResizePolicy (org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy)1 RibbonBandResizePolicy (org.pushingpixels.flamingo.api.ribbon.resize.RibbonBandResizePolicy)1