Search in sources :

Example 1 with JCommandToggleMenuButton

use of org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton in project freeplane by freeplane.

the class EdgeStyleContributorFactory method getContributor.

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

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

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            if (parent == null) {
                return;
            }
            JRibbonBand band = new JRibbonBand(TextUtils.removeTranslateComment(TextUtils.getText("ribbon.band.edgeStyles")), null, null);
            band.setExpandButtonKeyTip("ES");
            band.setCollapsedStateKeyTip("ZE");
            JCommandButton styleGroupButton = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("edgeStyleGroupAction.text")));
            styleGroupButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            AFreeplaneAction action = context.getBuilder().getMode().getAction("EdgeStyleAsParentAction");
            final JCommandToggleMenuButton styleAsParent = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleAsParent);
            action = context.getBuilder().getMode().getAction("EdgeStyleAction.linear");
            final JCommandToggleMenuButton styleLinear = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleLinear);
            action = context.getBuilder().getMode().getAction("EdgeStyleAction.bezier");
            final JCommandToggleMenuButton styleBezier = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleBezier);
            action = context.getBuilder().getMode().getAction("EdgeStyleAction.sharp_linear");
            final JCommandToggleMenuButton styleSharpLinear = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleSharpLinear);
            action = context.getBuilder().getMode().getAction("EdgeStyleAction.sharp_bezier");
            final JCommandToggleMenuButton styleSharpBezier = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleSharpBezier);
            action = context.getBuilder().getMode().getAction("EdgeStyleAction.horizontal");
            final JCommandToggleMenuButton styleHorizontal = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleHorizontal);
            action = context.getBuilder().getMode().getAction("EdgeStyleAction.hide_edge");
            final JCommandToggleMenuButton styleHideEdge = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, styleHideEdge);
            ButtonGroup group = new ButtonGroup();
            styleAsParent.getActionModel().setGroup(group);
            styleLinear.getActionModel().setGroup(group);
            styleAsParent.getActionModel().setGroup(group);
            styleBezier.getActionModel().setGroup(group);
            styleAsParent.getActionModel().setGroup(group);
            styleSharpLinear.getActionModel().setGroup(group);
            styleAsParent.getActionModel().setGroup(group);
            styleSharpBezier.getActionModel().setGroup(group);
            styleAsParent.getActionModel().setGroup(group);
            styleHorizontal.getActionModel().setGroup(group);
            styleAsParent.getActionModel().setGroup(group);
            styleHideEdge.getActionModel().setGroup(group);
            styleAsParent.getActionModel().setGroup(group);
            styleGroupButton.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    popupmenu.addMenuButton(styleAsParent);
                    popupmenu.addMenuButton(styleLinear);
                    popupmenu.addMenuButton(styleBezier);
                    popupmenu.addMenuButton(styleSharpLinear);
                    popupmenu.addMenuButton(styleSharpBezier);
                    popupmenu.addMenuButton(styleHorizontal);
                    popupmenu.addMenuButton(styleHideEdge);
                    return popupmenu;
                }
            });
            band.addCommandButton(styleGroupButton, RibbonElementPriority.MEDIUM);
            JCommandButton lineWidthGroupButton = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("edgeLineWidthGroupAction.text")));
            lineWidthGroupButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            action = context.getBuilder().getMode().getAction("EdgeWidthAction_width_parent");
            final JCommandToggleMenuButton widthParent = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, widthParent);
            action = context.getBuilder().getMode().getAction("EdgeWidthAction_width_thin");
            final JCommandToggleMenuButton widthThin = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, widthThin);
            action = context.getBuilder().getMode().getAction("EdgeWidthAction_1");
            final JCommandToggleMenuButton width1 = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, width1);
            action = context.getBuilder().getMode().getAction("EdgeWidthAction_2");
            final JCommandToggleMenuButton width2 = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, width2);
            action = context.getBuilder().getMode().getAction("EdgeWidthAction_4");
            final JCommandToggleMenuButton width4 = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, width4);
            action = context.getBuilder().getMode().getAction("EdgeWidthAction_8");
            final JCommandToggleMenuButton width8 = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
            addDefaultToggleHandler(context, action, width8);
            lineWidthGroupButton.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    popupmenu.addMenuButton(widthParent);
                    popupmenu.addMenuButton(widthThin);
                    popupmenu.addMenuButton(width1);
                    popupmenu.addMenuButton(width2);
                    popupmenu.addMenuButton(width4);
                    popupmenu.addMenuButton(width8);
                    return popupmenu;
                }
            });
            band.addCommandButton(lineWidthGroupButton, RibbonElementPriority.MEDIUM);
            action = context.getBuilder().getMode().getAction("EdgeColorAction");
            final JCommandButton edgeColorButton = RibbonActionContributorFactory.createCommandButton(action);
            band.addCommandButton(edgeColorButton, RibbonElementPriority.MEDIUM);
            action = context.getBuilder().getMode().getAction("AutomaticEdgeColorHookAction");
            // RIBBONS
            // KeyStroke ks =RibbonAcceleratorManager.parseKeyStroke("j2ef2");
            // context.getBuilder().getAcceleratorManager().setAccelerator(action, ks);
            // RibbonActionContributorFactory.updateRichTooltip(button, action, ks);
            final JCommandButton automaticColorButton = RibbonActionContributorFactory.createCommandButton(action);
            band.addCommandButton(automaticColorButton, RibbonElementPriority.MEDIUM);
            List<RibbonBandResizePolicy> policies = new ArrayList<RibbonBandResizePolicy>();
            policies.add(new CoreRibbonResizePolicies.Mirror(band.getControlPanel()));
            policies.add(new CoreRibbonResizePolicies.High2Mid(band.getControlPanel()));
            band.setResizePolicies(policies);
            parent.addChild(band, new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", ""))));
        }

        public void addChild(Object child, ChildProperties properties) {
        }
    };
}
Also used : ARibbonContributor(org.freeplane.core.ui.ribbon.ARibbonContributor) CoreRibbonResizePolicies(org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies) JCommandToggleMenuButton(org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton) ArrayList(java.util.ArrayList) PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) JPopupPanel(org.pushingpixels.flamingo.api.common.popup.JPopupPanel) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) RibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.RibbonBandResizePolicy) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) JRibbonBand(org.pushingpixels.flamingo.api.ribbon.JRibbonBand) ButtonGroup(javax.swing.ButtonGroup) JCommandPopupMenu(org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu) RibbonBuildContext(org.freeplane.core.ui.ribbon.RibbonBuildContext)

Example 2 with JCommandToggleMenuButton

use of org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton in project freeplane by freeplane.

the class RibbonActionContributorFactory method createCommandToggleMenuButton.

public static JCommandToggleMenuButton createCommandToggleMenuButton(final AFreeplaneAction action) {
    String title = ActionUtils.getActionTitle(action);
    ResizableIcon icon = ActionUtils.getActionIcon(action);
    final JCommandToggleMenuButton button = new JCommandToggleMenuButton(title, icon);
    updateRichTooltip(button, action, null);
    button.addActionListener(new RibbonActionListener(action));
    button.setFocusable(false);
    return button;
}
Also used : JCommandToggleMenuButton(org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton) ImageWrapperResizableIcon(org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon) ResizableIcon(org.pushingpixels.flamingo.api.common.icon.ResizableIcon)

Example 3 with JCommandToggleMenuButton

use of org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton in project freeplane by freeplane.

the class RibbonActionContributorFactory method getContributor.

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

        private List<Component> childButtons = new ArrayList<Component>();

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

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            final String actionKey = attributes.getProperty("action");
            final boolean mandatory = Boolean.parseBoolean(attributes.getProperty("mandatory", "false").toLowerCase());
            ChildProperties childProps = new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", "")));
            childProps.set(RibbonElementPriority.class, getPriority(attributes.getProperty("priority", "medium")));
            if (actionKey != null) {
                AFreeplaneAction action = context.getBuilder().getMode().getAction(actionKey);
                if (action != null) {
                    if (mandatory) {
                        action.putValue(MANDATORY_PROPERTY, mandatory);
                    }
                    AbstractCommandButton button;
                    if (isSelectionListener(action)) {
                        button = createCommandToggleButton(action);
                        if (context.hasChildren(context.getCurrentPath())) {
                            LogUtils.severe("RibbonActionContributorFactory.getContributor(): can't add popup menu to toggle button for action: " + context.getCurrentPath().toString());
                        }
                    } else {
                        button = createCommandButton(action);
                        if (context.hasChildren(context.getCurrentPath())) {
                            StructurePath path = context.getCurrentPath();
                            ((JCommandButton) button).setPopupCallback(getPopupPanelCallBack(path, context));
                            ((JCommandButton) button).setCommandButtonKind(CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION);
                            KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(actionKey);
                            updateRichTooltip(button, action, ks);
                            updateActionState(action, button);
                        }
                    }
                    button.putClientProperty(ACTION_KEY_PROPERTY, action);
                    KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(actionKey);
                    if (ks != null) {
                        button.putClientProperty(ACTION_ACCELERATOR, ks);
                        updateRichTooltip(button, action, ks);
                    }
                    getAccelChangeListener().addAction(actionKey, button);
                    builder.getMapChangeAdapter().addListener(new ActionChangeListener(action, button));
                    parent.addChild(button, childProps);
                }
            } else {
                final String name = attributes.getProperty("name");
                if (name != null) {
                    AFreeplaneAction action = ActionUtils.getDummyAction(name);
                    final JCommandButton button = new JCommandButton(ActionUtils.getActionTitle(action), ActionUtils.getActionIcon(action));
                    button.putClientProperty(ACTION_NAME_PROPERTY, action);
                    updateRichTooltip(button, action, null);
                    if (context.hasChildren(context.getCurrentPath())) {
                        StructurePath path = context.getCurrentPath();
                        button.setPopupCallback(getPopupPanelCallBack(path, context));
                        button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
                    }
                    button.setFocusable(false);
                    parent.addChild(button, childProps);
                }
            }
        }

        private PopupPanelCallback getPopupPanelCallBack(StructurePath path, final RibbonBuildContext context) {
            childButtons.clear();
            context.processChildren(path, this);
            return new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    for (Component comp : childButtons) {
                        if (comp instanceof JSeparator) {
                            popupmenu.addMenuSeparator();
                        } else if (comp instanceof AbstractCommandButton) {
                            AbstractCommandButton button = (AbstractCommandButton) comp;
                            AbstractCommandButton menuButton = null;
                            AFreeplaneAction action = (AFreeplaneAction) button.getClientProperty(ACTION_KEY_PROPERTY);
                            if (action != null) {
                                if (isSelectionListener(action)) {
                                    menuButton = createCommandToggleMenuButton(action);
                                    popupmenu.addMenuButton((JCommandToggleMenuButton) menuButton);
                                } else {
                                    menuButton = createCommandMenuButton(action);
                                    popupmenu.addMenuButton((JCommandMenuButton) menuButton);
                                }
                                menuButton.setEnabled(button.isEnabled());
                                menuButton.putClientProperty(ACTION_KEY_PROPERTY, action);
                                KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(action.getKey());
                                updateRichTooltip(menuButton, action, ks);
                                updateActionState(action, menuButton);
                            } else {
                                action = (AFreeplaneAction) button.getClientProperty(ACTION_NAME_PROPERTY);
                                menuButton = createCommandMenuButton(action);
                                if (action != null) {
                                    menuButton.putClientProperty(ACTION_NAME_PROPERTY, action);
                                    updateRichTooltip(menuButton, action, null);
                                }
                            }
                            if (button instanceof JCommandButton) {
                                if (((JCommandButton) button).getPopupCallback() != null) {
                                    ((JCommandMenuButton) menuButton).setPopupCallback(((JCommandButton) button).getPopupCallback());
                                    ((JCommandMenuButton) menuButton).setCommandButtonKind(((JCommandButton) button).getCommandButtonKind());
                                }
                            }
                            // clear all RibbonActionListeners from the menuButton
                            for (ActionListener listener : menuButton.getListeners(ActionListener.class)) {
                                if (listener instanceof RibbonActionListener) {
                                    menuButton.removeActionListener(listener);
                                }
                            }
                            // add
                            for (ActionListener listener : button.getListeners(ActionListener.class)) {
                                if (listener instanceof RibbonActionListener) {
                                    menuButton.addActionListener(listener);
                                }
                            }
                        }
                    }
                    return popupmenu;
                }
            };
        }

        public void addChild(Object child, ChildProperties properties) {
            if (child instanceof AbstractCommandButton) {
                childButtons.add((AbstractCommandButton) child);
                Object obj = ((AbstractCommandButton) child).getClientProperty(ACTION_KEY_PROPERTY);
                if (obj != null) {
                    try {
                        builder.getMapChangeAdapter().removeListener((IChangeObserver) ((AFreeplaneAction) obj).getValue(ACTION_CHANGE_LISTENER));
                        getAccelChangeListener().removeAction(((AFreeplaneAction) obj).getKey());
                    } catch (Exception e) {
                        LogUtils.info("RibbonActionContributorFactory.getContributor(...).new ARibbonContributor() {...}.addChild(): " + e.getMessage());
                    }
                }
            }
            if (child instanceof RibbonSeparator) {
                childButtons.add(new JSeparator(JSeparator.HORIZONTAL));
            }
        }
    };
}
Also used : StructurePath(org.freeplane.core.ui.ribbon.StructureTree.StructurePath) JCommandToggleMenuButton(org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton) PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) JSeparator(javax.swing.JSeparator) JCommandMenuButton(org.pushingpixels.flamingo.api.common.JCommandMenuButton) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) RibbonSeparator(org.freeplane.core.ui.ribbon.RibbonSeparatorContributorFactory.RibbonSeparator) ActionListener(java.awt.event.ActionListener) AbstractCommandButton(org.pushingpixels.flamingo.api.common.AbstractCommandButton) JCommandPopupMenu(org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu) KeyStroke(javax.swing.KeyStroke) ArrayList(java.util.ArrayList) List(java.util.List) Component(java.awt.Component)

Example 4 with JCommandToggleMenuButton

use of org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton in project freeplane by freeplane.

the class FilterConditionsContributorFactory method getContributor.

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

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

        public void contribute(final RibbonBuildContext context, ARibbonContributor parent) {
            if (parent == null) {
                return;
            }
            JCommandButton button = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("FilterCondition")));
            button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            button.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    AFreeplaneAction action = context.getBuilder().getMode().getAction("ApplyToVisibleAction");
                    JCommandToggleMenuButton toggleButton = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
                    action.setSelected();
                    toggleButton.getActionModel().setSelected(action.isSelected());
                    popupmenu.addMenuButton(toggleButton);
                    action = context.getBuilder().getMode().getAction("ShowAncestorsAction");
                    toggleButton = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
                    action.setSelected();
                    toggleButton.getActionModel().setSelected(action.isSelected());
                    popupmenu.addMenuButton(toggleButton);
                    action = context.getBuilder().getMode().getAction("ShowDescendantsAction");
                    toggleButton = RibbonActionContributorFactory.createCommandToggleMenuButton(action);
                    action.setSelected();
                    toggleButton.getActionModel().setSelected(action.isSelected());
                    popupmenu.addMenuButton(toggleButton);
                    return popupmenu;
                }
            });
            ChildProperties props = new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", "")));
            props.set(RibbonElementPriority.class, RibbonElementPriority.MEDIUM);
            parent.addChild(button, props);
        }

        public void addChild(Object child, ChildProperties properties) {
        }
    };
}
Also used : ARibbonContributor(org.freeplane.core.ui.ribbon.ARibbonContributor) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) JCommandToggleMenuButton(org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton) JCommandPopupMenu(org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu) PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) JPopupPanel(org.pushingpixels.flamingo.api.common.popup.JPopupPanel) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) RibbonBuildContext(org.freeplane.core.ui.ribbon.RibbonBuildContext)

Example 5 with JCommandToggleMenuButton

use of org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton in project freeplane by freeplane.

the class ViewSettingsContributorFactory method getContributor.

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

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

        public void contribute(final RibbonBuildContext context, ARibbonContributor parent) {
            if (parent == null) {
                return;
            }
            JRibbonBand band = new JRibbonBand(TextUtils.removeTranslateComment(TextUtils.getText("ribbon.band.viewsettings")), null, null);
            createAttributeViewMenu(context, band);
            createNoteViewMenu(context, band);
            createToolTipMenu(context, band);
            createToolbarsMenu(context, band);
            List<RibbonBandResizePolicy> policies = new ArrayList<RibbonBandResizePolicy>();
            policies.add(new CoreRibbonResizePolicies.Mirror(band.getControlPanel()));
            policies.add(new CoreRibbonResizePolicies.High2Low(band.getControlPanel()));
            band.setResizePolicies(policies);
            parent.addChild(band, new ChildProperties(parseOrderSettings(attributes.getProperty("orderPriority", ""))));
        }

        private void createToolbarsMenu(final RibbonBuildContext context, JRibbonBand band) {
            JCommandButton button = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("menu_toolbars")));
            button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            button.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    final AFreeplaneAction toggleFBarAction = context.getBuilder().getMode().getAction("ToggleFBarAction");
                    final JCommandToggleMenuButton toggleFBarButton = RibbonActionContributorFactory.createCommandToggleMenuButton(toggleFBarAction);
                    toggleFBarAction.setSelected();
                    toggleFBarButton.getActionModel().setSelected(toggleFBarAction.isSelected());
                    popupmenu.addMenuButton(toggleFBarButton);
                    final AFreeplaneAction toggleLeftToolbarAction = context.getBuilder().getMode().getAction("ToggleLeftToolbarAction");
                    final JCommandToggleMenuButton toggleLeftToolbarButton = RibbonActionContributorFactory.createCommandToggleMenuButton(toggleLeftToolbarAction);
                    toggleLeftToolbarAction.setSelected();
                    toggleLeftToolbarButton.getActionModel().setSelected(toggleLeftToolbarAction.isSelected());
                    popupmenu.addMenuButton(toggleLeftToolbarButton);
                    final AFreeplaneAction toggleStatusAction = context.getBuilder().getMode().getAction("ToggleStatusAction");
                    final JCommandToggleMenuButton toggleStatusButton = RibbonActionContributorFactory.createCommandToggleMenuButton(toggleStatusAction);
                    toggleStatusAction.setSelected();
                    toggleStatusButton.getActionModel().setSelected(toggleStatusAction.isSelected());
                    popupmenu.addMenuButton(toggleStatusButton);
                    final AFreeplaneAction toggleScrollbarsAction = context.getBuilder().getMode().getAction("ToggleScrollbarsAction");
                    final JCommandToggleMenuButton toggleScrollbarsButton = RibbonActionContributorFactory.createCommandToggleMenuButton(toggleScrollbarsAction);
                    toggleScrollbarsAction.setSelected();
                    toggleScrollbarsButton.getActionModel().setSelected(toggleScrollbarsAction.isSelected());
                    popupmenu.addMenuButton(toggleScrollbarsButton);
                    return popupmenu;
                }
            });
            band.addCommandButton(button, RibbonElementPriority.MEDIUM);
            AFreeplaneAction action = context.getBuilder().getMode().getAction("SetShortenerStateAction");
            button = RibbonActionContributorFactory.createCommandButton(action);
            band.addCommandButton(button, RibbonElementPriority.MEDIUM);
            action = context.getBuilder().getMode().getAction("ToggleDetailsAction");
            button = RibbonActionContributorFactory.createCommandButton(action);
            band.addCommandButton(button, RibbonElementPriority.MEDIUM);
        }

        private void createToolTipMenu(final RibbonBuildContext context, final JRibbonBand band) {
            JCommandButton button = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("menu_hoverView")));
            button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            button.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    final SetBooleanPropertyAction showAction = (SetBooleanPropertyAction) context.getBuilder().getMode().getAction("SetBooleanPropertyAction.show_node_tooltips");
                    final JCommandToggleMenuButton showButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showAction);
                    showAction.setSelected();
                    showButton.getActionModel().setSelected(showAction.isSelected());
                    popupmenu.addMenuButton(showButton);
                    final SetBooleanPropertyAction showStylesAction = (SetBooleanPropertyAction) context.getBuilder().getMode().getAction("SetBooleanPropertyAction.show_styles_in_tooltip");
                    final JCommandToggleMenuButton showStylesButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showStylesAction);
                    showStylesAction.setSelected();
                    showStylesButton.getActionModel().setSelected(showStylesAction.isSelected());
                    popupmenu.addMenuButton(showStylesButton);
                    final AFreeplaneAction modificationAction = context.getBuilder().getMode().getAction("CreationModificationPluginAction");
                    final JCommandToggleMenuButton modificationButton = RibbonActionContributorFactory.createCommandToggleMenuButton(modificationAction);
                    modificationAction.setSelected();
                    modificationButton.getActionModel().setSelected(modificationAction.isSelected());
                    popupmenu.addMenuButton(modificationButton);
                    return popupmenu;
                }
            });
            band.addCommandButton(button, RibbonElementPriority.MEDIUM);
        }

        private void createNoteViewMenu(final RibbonBuildContext context, final JRibbonBand band) {
            JCommandButton displayNotesButton = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("menu_noteView")));
            displayNotesButton.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            displayNotesButton.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    final ShowNotesInMapAction showNotesInMapAction = (ShowNotesInMapAction) context.getBuilder().getMode().getAction("ShowNotesInMapAction");
                    final JCommandToggleMenuButton showNotedsInMapButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showNotesInMapAction);
                    showNotesInMapAction.setSelected();
                    showNotedsInMapButton.getActionModel().setSelected(showNotesInMapAction.isSelected());
                    popupmenu.addMenuButton(showNotedsInMapButton);
                    final SetBooleanMapPropertyAction showIconAction = (SetBooleanMapPropertyAction) context.getBuilder().getMode().getAction("SetBooleanMapPropertyAction.show_note_icons");
                    final JCommandToggleMenuButton toggleButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showIconAction);
                    showIconAction.setSelected();
                    toggleButton.getActionModel().setSelected(showIconAction.isSelected());
                    popupmenu.addMenuButton(toggleButton);
                    JCommandMenuButton button = new JCommandMenuButton(TextUtils.removeTranslateComment(TextUtils.getText("note_window_location")), null);
                    button.setDisplayState(CommandButtonDisplayState.MEDIUM);
                    button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
                    button.setPopupCallback(new PopupPanelCallback() {

                        public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                            JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                            final SetNoteWindowPosition posTopAction = (SetNoteWindowPosition) context.getBuilder().getMode().getAction("SetNoteWindowPosition.top");
                            final JCommandToggleMenuButton posTopButton = RibbonActionContributorFactory.createCommandToggleMenuButton(posTopAction);
                            popupmenu.addMenuButton(posTopButton);
                            posTopAction.setSelected();
                            posTopButton.getActionModel().setSelected(posTopAction.isSelected());
                            final SetNoteWindowPosition posLeftAction = (SetNoteWindowPosition) context.getBuilder().getMode().getAction("SetNoteWindowPosition.left");
                            final JCommandToggleMenuButton posLeftButton = RibbonActionContributorFactory.createCommandToggleMenuButton(posLeftAction);
                            popupmenu.addMenuButton(posLeftButton);
                            posLeftAction.setSelected();
                            posLeftButton.getActionModel().setSelected(posLeftAction.isSelected());
                            final SetNoteWindowPosition posRightAction = (SetNoteWindowPosition) context.getBuilder().getMode().getAction("SetNoteWindowPosition.right");
                            final JCommandToggleMenuButton posRightButton = RibbonActionContributorFactory.createCommandToggleMenuButton(posRightAction);
                            popupmenu.addMenuButton(posRightButton);
                            posRightAction.setSelected();
                            posRightButton.getActionModel().setSelected(posRightAction.isSelected());
                            final SetNoteWindowPosition posBottomAction = (SetNoteWindowPosition) context.getBuilder().getMode().getAction("SetNoteWindowPosition.bottom");
                            final JCommandToggleMenuButton posBottomButton = RibbonActionContributorFactory.createCommandToggleMenuButton(posBottomAction);
                            popupmenu.addMenuButton(posBottomButton);
                            posBottomAction.setSelected();
                            posBottomButton.getActionModel().setSelected(posBottomAction.isSelected());
                            return popupmenu;
                        }
                    });
                    popupmenu.addMenuButton(button);
                    return popupmenu;
                }
            });
            band.addCommandButton(displayNotesButton, RibbonElementPriority.MEDIUM);
        }

        private void createAttributeViewMenu(final RibbonBuildContext context, JRibbonBand band) {
            JCommandButton button = new JCommandButton(TextUtils.removeTranslateComment(TextUtils.getText("menu_displayAttributes")));
            button.setDisplayState(CommandButtonDisplayState.MEDIUM);
            button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            button.setPopupCallback(new PopupPanelCallback() {

                public JPopupPanel getPopupPanel(JCommandButton commandButton) {
                    JCommandPopupMenu popupmenu = new JCommandPopupMenu();
                    final AttributeViewTypeAction showSelectedAttributesAction = (AttributeViewTypeAction) context.getBuilder().getMode().getAction("ShowSelectedAttributesAction");
                    final JCommandToggleMenuButton showSelectedAttributesButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showSelectedAttributesAction);
                    popupmenu.addMenuButton(showSelectedAttributesButton);
                    showSelectedAttributesAction.setSelected();
                    showSelectedAttributesButton.getActionModel().setSelected(showSelectedAttributesAction.isSelected());
                    final AttributeViewTypeAction showAllAttributesAction = (AttributeViewTypeAction) context.getBuilder().getMode().getAction("ShowAllAttributesAction");
                    final JCommandToggleMenuButton showAllAttributesButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showAllAttributesAction);
                    popupmenu.addMenuButton(showAllAttributesButton);
                    showAllAttributesAction.setSelected();
                    showAllAttributesButton.getActionModel().setSelected(showAllAttributesAction.isSelected());
                    final AttributeViewTypeAction hideAllAttributesAction = (AttributeViewTypeAction) context.getBuilder().getMode().getAction("HideAllAttributesAction");
                    final JCommandToggleMenuButton hideAllAttributesButton = RibbonActionContributorFactory.createCommandToggleMenuButton(hideAllAttributesAction);
                    popupmenu.addMenuButton(hideAllAttributesButton);
                    hideAllAttributesAction.setSelected();
                    hideAllAttributesButton.getActionModel().setSelected(hideAllAttributesAction.isSelected());
                    final SetBooleanMapPropertyAction showIconAction = (SetBooleanMapPropertyAction) context.getBuilder().getMode().getAction("SetBooleanMapPropertyAction.show_icon_for_attributes");
                    final JCommandToggleMenuButton toggleButton = RibbonActionContributorFactory.createCommandToggleMenuButton(showIconAction);
                    showIconAction.setSelected();
                    toggleButton.getActionModel().setSelected(showIconAction.isSelected());
                    popupmenu.addMenuButton(toggleButton);
                    context.getBuilder().getMapChangeAdapter().addListener(new IChangeObserver() {

                        public void updateState(CurrentState state) {
                            showSelectedAttributesAction.setSelected();
                            showSelectedAttributesButton.getActionModel().setSelected(showSelectedAttributesAction.isSelected());
                            showAllAttributesAction.setSelected();
                            showAllAttributesButton.getActionModel().setSelected(showAllAttributesAction.isSelected());
                            hideAllAttributesAction.setSelected();
                            hideAllAttributesButton.getActionModel().setSelected(hideAllAttributesAction.isSelected());
                            showIconAction.setSelected();
                            toggleButton.getActionModel().setSelected(showIconAction.isSelected());
                        }
                    });
                    JCommandMenuButton button = RibbonActionContributorFactory.createCommandMenuButton(context.getBuilder().getMode().getAction("ShowAttributeDialogAction"));
                    popupmenu.addMenuButton(button);
                    return popupmenu;
                }
            });
            band.addCommandButton(button, RibbonElementPriority.MEDIUM);
        }

        public void addChild(Object child, ChildProperties properties) {
        }
    };
}
Also used : CoreRibbonResizePolicies(org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies) ArrayList(java.util.ArrayList) JPopupPanel(org.pushingpixels.flamingo.api.common.popup.JPopupPanel) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) RibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.RibbonBandResizePolicy) JCommandMenuButton(org.pushingpixels.flamingo.api.common.JCommandMenuButton) IChangeObserver(org.freeplane.core.ui.ribbon.IChangeObserver) JCommandPopupMenu(org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu) CurrentState(org.freeplane.core.ui.ribbon.CurrentState) RibbonBuildContext(org.freeplane.core.ui.ribbon.RibbonBuildContext) ARibbonContributor(org.freeplane.core.ui.ribbon.ARibbonContributor) JCommandToggleMenuButton(org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton) SetBooleanMapPropertyAction(org.freeplane.features.styles.mindmapmode.SetBooleanMapPropertyAction) SetNoteWindowPosition(org.freeplane.features.note.mindmapmode.SetNoteWindowPosition) PopupPanelCallback(org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback) AttributeViewTypeAction(org.freeplane.features.attribute.AttributeViewTypeAction) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) SetBooleanPropertyAction(org.freeplane.core.resources.SetBooleanPropertyAction) JRibbonBand(org.pushingpixels.flamingo.api.ribbon.JRibbonBand) ShowNotesInMapAction(org.freeplane.view.swing.map.ShowNotesInMapAction)

Aggregations

JCommandToggleMenuButton (org.pushingpixels.flamingo.api.common.JCommandToggleMenuButton)5 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)4 JCommandButton (org.pushingpixels.flamingo.api.common.JCommandButton)4 JCommandPopupMenu (org.pushingpixels.flamingo.api.common.popup.JCommandPopupMenu)4 PopupPanelCallback (org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback)4 ArrayList (java.util.ArrayList)3 ARibbonContributor (org.freeplane.core.ui.ribbon.ARibbonContributor)3 RibbonBuildContext (org.freeplane.core.ui.ribbon.RibbonBuildContext)3 JPopupPanel (org.pushingpixels.flamingo.api.common.popup.JPopupPanel)3 JCommandMenuButton (org.pushingpixels.flamingo.api.common.JCommandMenuButton)2 JRibbonBand (org.pushingpixels.flamingo.api.ribbon.JRibbonBand)2 CoreRibbonResizePolicies (org.pushingpixels.flamingo.api.ribbon.resize.CoreRibbonResizePolicies)2 RibbonBandResizePolicy (org.pushingpixels.flamingo.api.ribbon.resize.RibbonBandResizePolicy)2 Component (java.awt.Component)1 ActionListener (java.awt.event.ActionListener)1 List (java.util.List)1 ButtonGroup (javax.swing.ButtonGroup)1 JSeparator (javax.swing.JSeparator)1 KeyStroke (javax.swing.KeyStroke)1 SetBooleanPropertyAction (org.freeplane.core.resources.SetBooleanPropertyAction)1