Search in sources :

Example 31 with AFreeplaneAction

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

the class ConditionalActionBuilder method visit.

@Override
public void visit(Entry target) {
    final String property = (String) target.getAttribute("property");
    if (ResourceController.getResourceController().getBooleanProperty(property, false)) {
        try {
            final String keyName = (String) target.getAttribute("actionKey");
            final AFreeplaneAction existingAction = freeplaneActions.getAction(keyName);
            final AFreeplaneAction action;
            if (existingAction != null)
                action = existingAction;
            else {
                final String className = (String) target.getAttribute("actionClass");
                final Class<?> classDefinition = getClass().getClassLoader().loadClass(className);
                action = (AFreeplaneAction) classDefinition.newInstance();
                freeplaneActions.addAction(action);
            }
            new EntryAccessor().setAction(target, action);
            return;
        } catch (Exception e) {
            LogUtils.severe(e);
        }
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor)

Example 32 with AFreeplaneAction

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

the class JMenuItemBuilder method createActionComponent.

private Component createActionComponent(Entry entry) {
    // FIXME actually not possible
    final Object alreadyExistingComponent = entryAccessor.getComponent(entry);
    if (alreadyExistingComponent != null) {
        LogUtils.severe("BUG : component already exists at " + entry.getPath());
        return null;
    }
    final Component component = menuActionComponentProvider.createComponent(entry);
    final AFreeplaneAction action = entryAccessor.getAction(entry);
    if (action != null) {
        final ActionEnabler actionEnabler = new ActionEnabler(component);
        action.addPropertyChangeListener(actionEnabler);
        entry.setAttribute(actionEnabler.getClass(), actionEnabler);
    }
    return component;
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) ActionEnabler(org.freeplane.core.ui.ActionEnabler) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 33 with AFreeplaneAction

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

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

the class EntryAccessor method getText.

public String getText(final Entry entry) {
    if (entry.getAttribute(TEXT) != null)
        return (String) entry.getAttribute(TEXT);
    else {
        final String textKey = (String) entry.getAttribute(TEXT_KEY);
        if (textKey != null)
            return (String) resourceAccessor.getRawText(textKey);
        else {
            final AFreeplaneAction action = getAction(entry);
            if (action != null)
                return action.getRawText();
            String name = entry.getName();
            if (name.isEmpty())
                return "";
            else {
                final String rawText = resourceAccessor.getRawText(name);
                if (rawText != null)
                    return rawText;
                else
                    return "";
            }
        }
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction)

Example 35 with AFreeplaneAction

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

the class EntryAccessor method getTextKey.

public String getTextKey(final Entry entry) {
    if (entry.getAttribute(TEXT) != null)
        return null;
    final String textKey = (String) entry.getAttribute(TEXT_KEY);
    if (textKey != null)
        return textKey;
    final AFreeplaneAction action = getAction(entry);
    if (action != null) {
        final String actionTextKey = action.getTextKey();
        if (TextUtils.getRawText(actionTextKey, null) != null)
            return actionTextKey;
        else
            return null;
    }
    String name = entry.getName();
    if (name.isEmpty())
        return null;
    else
        return name;
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction)

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