Search in sources :

Example 1 with AFreeplaneAction

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

the class IconSelectionPlugin method actionPerformed.

public void actionPerformed(final ActionEvent e) {
    final ModeController modeController = Controller.getCurrentModeController();
    ArrayList<IIconInformation> actions = new ArrayList<IIconInformation>();
    final Controller controller = Controller.getCurrentController();
    final MapModel map = controller.getMap();
    final IconRegistry iconRegistry = map.getIconRegistry();
    final ListModel usedIcons = iconRegistry.getIconsAsListModel();
    for (int i = 0; i < usedIcons.getSize(); i++) {
        final Object icon = usedIcons.getElementAt(i);
        if (icon instanceof MindIcon) {
            actions.add(new IconAction((MindIcon) icon));
        }
    }
    final MIconController mIconController = (MIconController) IconController.getController();
    for (AFreeplaneAction aFreeplaneAction : mIconController.getIconActions()) actions.add((IIconInformation) aFreeplaneAction);
    actions.add((IIconInformation) modeController.getAction("RemoveIcon_0_Action"));
    actions.add((IIconInformation) modeController.getAction("RemoveIconAction"));
    actions.add((IIconInformation) modeController.getAction("RemoveAllIconsAction"));
    final ViewController viewController = controller.getViewController();
    final IconSelectionPopupDialog selectionDialog = new IconSelectionPopupDialog(viewController.getJFrame(), actions);
    final NodeModel selected = controller.getSelection().getSelected();
    controller.getMapViewManager().scrollNodeToVisible(selected);
    selectionDialog.pack();
    UITools.setDialogLocationRelativeTo(selectionDialog, selected);
    selectionDialog.setModal(true);
    selectionDialog.show();
    final int result = selectionDialog.getResult();
    if (result >= 0) {
        final Action action = (Action) actions.get(result);
        action.actionPerformed(new ActionEvent(action, 0, NodeModel.NODE_ICON, selectionDialog.getModifiers()));
    }
}
Also used : Action(javax.swing.Action) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) MindIcon(org.freeplane.features.icon.MindIcon) ModeController(org.freeplane.features.mode.ModeController) MapModel(org.freeplane.features.map.MapModel) IconSelectionPopupDialog(org.freeplane.core.ui.components.IconSelectionPopupDialog) IconController(org.freeplane.features.icon.IconController) Controller(org.freeplane.features.mode.Controller) ModeController(org.freeplane.features.mode.ModeController) ViewController(org.freeplane.features.ui.ViewController) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) NodeModel(org.freeplane.features.map.NodeModel) ViewController(org.freeplane.features.ui.ViewController) ListModel(javax.swing.ListModel) IIconInformation(org.freeplane.features.icon.IIconInformation) IconRegistry(org.freeplane.features.icon.IconRegistry)

Example 2 with AFreeplaneAction

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

the class ZoomContributorFactory 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;
            }
            JFlowRibbonBand band = new JFlowRibbonBand(TextUtils.removeTranslateComment(TextUtils.getText("ribbon.band.zoom")), null, null);
            JComboBox zoomBox = ((MapViewController) Controller.getCurrentController().getMapViewManager()).createZoomBox();
            addDefaultToggleHandler(context, zoomBox);
            band.addFlowComponent(zoomBox);
            JCommandButtonStrip strip = new JCommandButtonStrip();
            AFreeplaneAction action = context.getBuilder().getMode().getAction("ZoomInAction");
            JCommandButton button = RibbonActionContributorFactory.createCommandButton(action);
            button.setDisplayState(CommandButtonDisplayState.SMALL);
            getAccelChangeListener().addAction(action.getKey(), button);
            addDefaultToggleHandler(context, action, button);
            strip.add(button);
            action = context.getBuilder().getMode().getAction("ZoomOutAction");
            button = RibbonActionContributorFactory.createCommandButton(action);
            button.setDisplayState(CommandButtonDisplayState.SMALL);
            getAccelChangeListener().addAction(action.getKey(), button);
            addDefaultToggleHandler(context, action, button);
            strip.add(button);
            action = context.getBuilder().getMode().getAction("FitToPage");
            button = RibbonActionContributorFactory.createCommandButton(action);
            button.setDisplayState(CommandButtonDisplayState.MEDIUM);
            getAccelChangeListener().addAction(action.getKey(), button);
            addDefaultToggleHandler(context, action, button);
            strip.add(button);
            band.addFlowComponent(strip);
            List<RibbonBandResizePolicy> policies = new ArrayList<RibbonBandResizePolicy>();
            policies.add(new CoreRibbonResizePolicies.FlowTwoRows(band.getControlPanel()));
            policies.add(new IconRibbonBandResizePolicy(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) JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) IconRibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy) JCommandButton(org.pushingpixels.flamingo.api.common.JCommandButton) MapViewController(org.freeplane.view.swing.map.MapViewController) JFlowRibbonBand(org.pushingpixels.flamingo.api.ribbon.JFlowRibbonBand) IconRibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.IconRibbonBandResizePolicy) RibbonBandResizePolicy(org.pushingpixels.flamingo.api.ribbon.resize.RibbonBandResizePolicy) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) RibbonBuildContext(org.freeplane.core.ui.ribbon.RibbonBuildContext) JCommandButtonStrip(org.pushingpixels.flamingo.api.common.JCommandButtonStrip)

Example 3 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction 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 4 with AFreeplaneAction

use of org.freeplane.core.ui.AFreeplaneAction 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 5 with AFreeplaneAction

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

the class RibbonMenuFooterContributorFactory method getContributor.

/**
 *********************************************************************************
 * METHODS
 *********************************************************************************
 */
/**
 *********************************************************************************
 * 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() {

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

        public void contribute(RibbonBuildContext context, ARibbonContributor parent) {
            final String key = attributes.getProperty("action");
            if (key != null) {
                AFreeplaneAction action = context.getBuilder().getMode().getAction(key);
                if (action != null) {
                    String title = ActionUtils.getActionTitle(action);
                    ResizableIcon icon = ActionUtils.getActionIcon(action);
                    ActionListener listener = new RibbonActionContributorFactory.RibbonActionListener(action);
                    final RibbonApplicationMenuEntryFooter entry = new RibbonApplicationMenuEntryFooter(icon, title, listener);
                    KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(key);
                    if (ks != 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) {
        }
    };
}
Also used : RichTooltip(org.pushingpixels.flamingo.api.common.RichTooltip) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) ActionListener(java.awt.event.ActionListener) KeyStroke(javax.swing.KeyStroke) RibbonApplicationMenuEntryFooter(org.pushingpixels.flamingo.api.ribbon.RibbonApplicationMenuEntryFooter) ResizableIcon(org.pushingpixels.flamingo.api.common.icon.ResizableIcon)

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