Search in sources :

Example 1 with ActionEnabler

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

the class JComponentRemover method visit.

@Override
public void visit(Entry target) {
    final EntryAccessor entryAccessor = new EntryAccessor();
    final Component component = (Component) entryAccessor.removeComponent(target);
    if (component != null) {
        if (component instanceof AbstractButton)
            ((AbstractButton) component).setAction(null);
        removeMenuComponent(component);
        ActionEnabler actionEnabler = target.removeAttribute(ActionEnabler.class);
        if (actionEnabler != null) {
            final AFreeplaneAction action = entryAccessor.getAction(target);
            action.removePropertyChangeListener(actionEnabler);
        }
    }
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) AbstractButton(javax.swing.AbstractButton) ActionEnabler(org.freeplane.core.ui.ActionEnabler) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) Component(java.awt.Component)

Example 2 with ActionEnabler

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

use of org.freeplane.core.ui.ActionEnabler 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)

Aggregations

Component (java.awt.Component)3 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)3 ActionEnabler (org.freeplane.core.ui.ActionEnabler)3 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)2 Container (java.awt.Container)1 AbstractButton (javax.swing.AbstractButton)1 JComponent (javax.swing.JComponent)1 JToolBar (javax.swing.JToolBar)1