Search in sources :

Example 31 with EntryAccessor

use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.

the class JToolbarComponentBuilder method visit.

@Override
public void visit(Entry entry) {
    Component component = componentProvider.createComponent(entry);
    if (component != null) {
        final EntryAccessor entryAccessor = new EntryAccessor();
        entryAccessor.setComponent(entry, component);
        final AFreeplaneAction action = entryAccessor.getAction(entry);
        if (action != null) {
            final ActionEnabler actionEnabler = new ActionEnabler(component);
            action.addPropertyChangeListener(actionEnabler);
            entry.setAttribute(actionEnabler.getClass(), actionEnabler);
        }
        final Container container = (Container) new EntryAccessor().getAncestorComponent(entry);
        if (container instanceof JToolBar)
            container.add(component);
        else
            SwingUtilities.getAncestorOfClass(JToolBar.class, container).add(component);
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Container(java.awt.Container) ActionEnabler(org.freeplane.core.ui.ActionEnabler) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JToolBar(javax.swing.JToolBar) Component(java.awt.Component)

Example 32 with EntryAccessor

use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.

the class MTextController method createActions.

private void createActions() {
    final ModeController modeController = Controller.getCurrentModeController();
    modeController.addAction(new EditAction());
    modeController.addAction(new UsePlainTextAction());
    modeController.addAction(new EditLongAction());
    modeController.addAction(new SetImageByFileChooserAction());
    modeController.addAction(new EditDetailsAction(false));
    modeController.addAction(new EditDetailsAction(true));
    modeController.addAction(new DeleteDetailsAction());
    modeController.addUiBuilder(Phase.ACTIONS, "splitToWordsActions", new EntryVisitor() {

        @Override
        public void visit(Entry target) {
            final String[] nodeNumbersInLine = ResourceController.getResourceController().getProperty("SplitToWordsAction.nodeNumbersInLine").split("[^\\d]+");
            for (String nodeNumberInLineAsString : nodeNumbersInLine) {
                try {
                    final int nodeNumberInLine = Integer.parseInt(nodeNumberInLineAsString);
                    if (nodeNumberInLine > 0) {
                        final SplitToWordsAction action = new SplitToWordsAction(nodeNumberInLine);
                        new EntryAccessor().addChildAction(target, action);
                        modeController.addAction(action);
                    }
                } catch (NumberFormatException e) {
                }
            }
        }

        @Override
        public boolean shouldSkipChildren(Entry entry) {
            return true;
        }
    });
    modeController.addUiBuilder(Phase.ACTIONS, "joinNodesActions", new EntryVisitor() {

        @Override
        public void visit(Entry target) {
            final String textSeparators = ResourceController.getResourceController().getProperty("JoinNodesAction.textSeparators");
            final Pattern JOIN_NODES_ACTION_SEPARATORS = Pattern.compile("\\{\\{.*?\\}\\}");
            final Matcher matcher = JOIN_NODES_ACTION_SEPARATORS.matcher(textSeparators);
            if (matcher.find()) {
                do {
                    String textSeparator = textSeparators.substring(matcher.start() + 2, matcher.end() - 2);
                    addAction(modeController, target, textSeparator);
                } while (matcher.find());
            } else {
                addAction(modeController, target, textSeparators);
            }
        }

        private void addAction(final ModeController modeController, Entry target, String textSeparator) {
            final JoinNodesAction action = new JoinNodesAction(textSeparator);
            new EntryAccessor().addChildAction(target, action);
            modeController.addAction(action);
            if (target.getChildCount() == 1)
                target.getChild(0).setAttribute(EntryAccessor.ACCELERATOR, target.getAttribute(EntryAccessor.ACCELERATOR));
        }

        @Override
        public boolean shouldSkipChildren(Entry entry) {
            return true;
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) ModeController(org.freeplane.features.mode.ModeController) MModeController(org.freeplane.features.mode.mindmapmode.MModeController) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntryVisitor(org.freeplane.core.ui.menubuilders.generic.EntryVisitor)

Example 33 with EntryAccessor

use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.

the class AcceleratorBuilder method visit.

public void visit(Entry entry) {
    final AFreeplaneAction action = new EntryAccessor().getAction(entry);
    if (action != null) {
        final EntryAccessor entryAccessor = new EntryAccessor();
        String accelerator = entryAccessor.getAccelerator(entry);
        if (accelerator != null) {
            map.setDefaultAccelerator(action, accelerator);
        } else
            map.setUserDefinedAccelerator(action);
        entries.registerEntry(action, entry);
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Example 34 with EntryAccessor

use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.

the class ActionFinder method visit.

@Override
public void visit(final Entry target) {
    final String actionName = target.getName();
    if (!actionName.isEmpty() && new EntryAccessor().getAction(target) == null) {
        AFreeplaneAction action = freeplaneActions.getAction(actionName);
        if (action == null) {
            for (final Class<? extends AFreeplaneAction> actionClass : Arrays.asList(SetBooleanPropertyAction.class, SetBooleanMapPropertyAction.class, SetBooleanMapViewPropertyAction.class, SetStringPropertyAction.class)) {
                final String setBooleanPropertyActionPrefix = actionClass.getSimpleName() + ".";
                if (actionName.startsWith(setBooleanPropertyActionPrefix)) {
                    String propertyName = actionName.substring(setBooleanPropertyActionPrefix.length());
                    action = createAction(actionClass, propertyName);
                    if (action != null) {
                        freeplaneActions.addAction(action);
                    }
                    break;
                }
            }
        }
        new EntryAccessor().setAction(target, action);
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Example 35 with EntryAccessor

use of org.freeplane.core.ui.menubuilders.generic.EntryAccessor in project freeplane by freeplane.

the class UpdateCheckAction method addUpdateButton.

private void addUpdateButton(final FreeplaneVersion lastVersion) {
    if (entry != null) {
        Controller controller = Controller.getCurrentController();
        final Component component = (Component) new EntryAccessor().getComponent(entry);
        if (component != null) {
            final Dimension preferredSize = component.getPreferredSize();
            if (lastVersion == null || lastVersion.compareTo(FreeplaneVersion.getVersion()) <= 0) {
                ResourceController.getResourceController().setProperty(LAST_UPDATE_VERSION, "");
                component.setPreferredSize(new Dimension(0, preferredSize.height));
                component.setVisible(false);
            } else {
                ResourceController.getResourceController().setProperty(LAST_UPDATE_VERSION, lastVersion.toString());
                final String updateAvailable = TextUtils.format("new_version_available", lastVersion.toString());
                controller.getViewController().out(updateAvailable);
                putValue(SHORT_DESCRIPTION, updateAvailable);
                putValue(LONG_DESCRIPTION, updateAvailable);
                component.setPreferredSize(new Dimension(preferredSize.height, preferredSize.height));
                component.setVisible(true);
            }
        }
    }
}
Also used : EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) Dimension(java.awt.Dimension) AddOnsController(org.freeplane.main.addons.AddOnsController) ResourceController(org.freeplane.core.resources.ResourceController) Controller(org.freeplane.features.mode.Controller) Component(java.awt.Component)

Aggregations

EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)58 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)40 Test (org.junit.Test)35 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)27 JMenu (javax.swing.JMenu)13 Component (java.awt.Component)6 Container (java.awt.Container)6 JMenuItem (javax.swing.JMenuItem)6 JToolBar (javax.swing.JToolBar)4 JButton (javax.swing.JButton)3 JComponent (javax.swing.JComponent)3 JPanel (javax.swing.JPanel)3 FreeplaneMenuBar (org.freeplane.core.ui.components.FreeplaneMenuBar)3 FreeplaneToolBar (org.freeplane.core.ui.components.FreeplaneToolBar)3 FreeplaneResourceAccessor (org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor)3 JToolbarComponentBuilder (org.freeplane.core.ui.menubuilders.menu.JToolbarComponentBuilder)3 ActionEvent (java.awt.event.ActionEvent)2 KeyStroke (javax.swing.KeyStroke)2 ResourceController (org.freeplane.core.resources.ResourceController)2 ActionEnabler (org.freeplane.core.ui.ActionEnabler)2