Search in sources :

Example 1 with JAutoRadioButtonMenuItem

use of org.freeplane.core.ui.components.JAutoRadioButtonMenuItem in project freeplane by freeplane.

the class MenuRadioActionComponentProvider method createComponent.

/* (non-Javadoc)
	 * @see org.freeplane.core.ui.menubuilders.menu.ComponentProvider#createComponent(org.freeplane.core.ui.menubuilders.generic.Entry)
	 */
@Override
public Component createComponent(Entry entry) {
    final AFreeplaneAction action = entryAccessor.getAction(entry);
    if (action != null) {
        final JMenuItem actionComponent;
        IFreeplaneAction wrappedAction = acceleratebleActionProvider.wrap(action);
        if (action.isSelectable()) {
            actionComponent = new JAutoRadioButtonMenuItem(wrappedAction);
        } else {
            actionComponent = new JRadioButtonMenuItem(wrappedAction);
        }
        actionComponent.setSelected(Boolean.parseBoolean(String.valueOf(entry.getAttribute("selected"))) || entry.getName().equals(getSelectedActionName(entry)));
        buttonGroup.add(actionComponent);
        final KeyStroke accelerator = accelerators.getAccelerator(action);
        actionComponent.setAccelerator(accelerator);
        MenuIconScaling.scaleIcon(actionComponent);
        return actionComponent;
    } else if (entry.builders().contains("separator")) {
        return new JPopupMenu.Separator();
    } else
        return null;
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) IFreeplaneAction(org.freeplane.core.ui.IFreeplaneAction) KeyStroke(javax.swing.KeyStroke) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JMenuItem(javax.swing.JMenuItem) JAutoRadioButtonMenuItem(org.freeplane.core.ui.components.JAutoRadioButtonMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 2 with JAutoRadioButtonMenuItem

use of org.freeplane.core.ui.components.JAutoRadioButtonMenuItem in project freeplane by freeplane.

the class MenuBuilder method addRadioItem.

public JMenuItem addRadioItem(final String category, final String key, final AFreeplaneAction action, final boolean isSelected) {
    assert key != null;
    final JRadioButtonMenuItem item;
    if (action.getClass().getAnnotation(SelectableAction.class) != null) {
        item = new JAutoRadioButtonMenuItem(decorateAction(category, action));
    } else {
        item = new JRadioButtonMenuItem(decorateAction(category, action));
    }
    addMenuItem(category, item, key, MenuBuilder.AS_CHILD);
    item.setSelected(isSelected);
    addListeners(key, action);
    return item;
}
Also used : JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JAutoRadioButtonMenuItem(org.freeplane.core.ui.components.JAutoRadioButtonMenuItem)

Aggregations

JRadioButtonMenuItem (javax.swing.JRadioButtonMenuItem)2 JAutoRadioButtonMenuItem (org.freeplane.core.ui.components.JAutoRadioButtonMenuItem)2 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 KeyStroke (javax.swing.KeyStroke)1 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)1 IFreeplaneAction (org.freeplane.core.ui.IFreeplaneAction)1