use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.
the class JToolbarComponentBuilderTest method createsToolbarButtonWithAction.
@Test
public void createsToolbarButtonWithAction() {
Entry actionEntry = new Entry();
final AFreeplaneAction action = Mockito.mock(AFreeplaneAction.class);
new EntryAccessor().setAction(actionEntry, action);
Entry toolbarEntry = new Entry();
final FreeplaneToolBar toolbar = new FreeplaneToolBar("toolbar", SwingConstants.HORIZONTAL);
new EntryAccessor().setComponent(toolbarEntry, toolbar);
toolbarEntry.addChild(actionEntry);
final JToolbarComponentBuilder toolbarActionGroupBuilder = new JToolbarComponentBuilder();
toolbarActionGroupBuilder.visit(actionEntry);
JButton button = (JButton) new EntryAccessor().getComponent(actionEntry);
assertThat(button.getAction(), CoreMatchers.<Action>equalTo(action));
assertThat(button.getParent(), CoreMatchers.equalTo((Container) toolbar));
}
use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.
the class MenuAcceleratorChangeListenerTest method setsKeystroke.
@Test
public void setsKeystroke() throws Exception {
final EntriesForAction entriesForAction = new EntriesForAction();
final MenuAcceleratorChangeListener menuAcceleratorChangeListener = new MenuAcceleratorChangeListener(entriesForAction);
final AFreeplaneAction action = mock(AFreeplaneAction.class);
Entry actionEntry = new Entry();
final JMenuItem menu = new JMenuItem();
new EntryAccessor().setComponent(actionEntry, menu);
entriesForAction.registerEntry(action, actionEntry);
final KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0);
menuAcceleratorChangeListener.acceleratorChanged(action, null, keyStroke);
Assert.assertThat(menu.getAccelerator(), equalTo(keyStroke));
}
use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.
the class ToolbarComponentProvider 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 EntryAccessor entryAccessor = new EntryAccessor();
final Object existingComponent = entryAccessor.getComponent(entry);
if (existingComponent != null)
return (Component) existingComponent;
final AFreeplaneAction action = entryAccessor.getAction(entry);
Component component;
if (action != null) {
if (action.isSelectable()) {
component = new JAutoToggleButton(action);
} else {
component = new JButton(action);
}
} else if (entry.builders().contains("separator")) {
component = new Separator();
} else
component = null;
return component;
}
use of org.freeplane.core.ui.AFreeplaneAction in project freeplane by freeplane.
the class MenuActionComponentProvider 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 JAutoCheckBoxMenuItem(wrappedAction);
} else {
actionComponent = new JFreeplaneMenuItem(wrappedAction);
}
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;
}
use of org.freeplane.core.ui.AFreeplaneAction 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;
}
Aggregations