Search in sources :

Example 51 with EntryAccessor

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

the class JMenuItemBuilderTest method createsMenuButtonWithAcceleratedAction.

@Test
public void createsMenuButtonWithAcceleratedAction() {
    final EntryAccessor entryAccessor = new EntryAccessor();
    entryAccessor.setComponent(menuEntry, menu);
    menuEntry.addChild(actionEntry);
    final KeyStroke keyStroke = KeyStroke.getKeyStroke('A');
    when(accelerators.getAccelerator(action)).thenReturn(keyStroke);
    menuActionGroupBuilder.visit(actionEntry);
    JMenuItem item = (JMenuItem) new EntryAccessor().getComponent(actionEntry);
    Assert.assertThat(item.getAccelerator(), equalTo(keyStroke));
}
Also used : EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) KeyStroke(javax.swing.KeyStroke) JMenuItem(javax.swing.JMenuItem) Test(org.junit.Test)

Example 52 with EntryAccessor

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

the class JMenuItemBuilderTest method createsMenuSeparator.

@Test
public void createsMenuSeparator() {
    new EntryAccessor().setComponent(menuEntry, menu);
    Entry separatorEntry = new Entry();
    separatorEntry.setBuilders(asList("separator"));
    menuEntry.addChild(separatorEntry);
    menuActionGroupBuilder.visit(separatorEntry);
    JPopupMenu.Separator separator = (JPopupMenu.Separator) new EntryAccessor().getComponent(separatorEntry);
    assertThat(separator.getParent(), CoreMatchers.<Container>equalTo(menu.getPopupMenu()));
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JPopupMenu(javax.swing.JPopupMenu) Test(org.junit.Test)

Example 53 with EntryAccessor

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

the class JMenuItemBuilderTest method setup.

@Before
public void setup() {
    actionEntry = new Entry();
    action = Mockito.mock(AFreeplaneAction.class);
    actionEntry.setName("action");
    when(action.getKey()).thenReturn("action");
    when(action.getRawText()).thenReturn("action");
    new EntryAccessor().setAction(actionEntry, action);
    menuEntry = new Entry();
    menuEntry.setName("menu");
    groupEntry = new Entry();
    menu = new JMenu();
    popupListener = mock(EntryPopupListener.class);
    resourceAccessorMock = mock(ResourceAccessor.class);
    when(resourceAccessorMock.getRawText(anyString())).thenReturn("");
    when(resourceAccessorMock.getRawText("menu")).thenReturn("menu");
    accelerators = mock(IAcceleratorMap.class);
    acceleratebleActionProvider = new AcceleratebleActionProvider() {

        @Override
        protected boolean isApplet() {
            return false;
        }
    };
    menuActionGroupBuilder = new JMenuItemBuilder(popupListener, accelerators, acceleratebleActionProvider, resourceAccessorMock);
}
Also used : ResourceAccessor(org.freeplane.core.ui.menubuilders.generic.ResourceAccessor) IAcceleratorMap(org.freeplane.core.ui.menubuilders.action.IAcceleratorMap) AcceleratebleActionProvider(org.freeplane.core.ui.menubuilders.action.AcceleratebleActionProvider) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JMenu(javax.swing.JMenu) EntryPopupListener(org.freeplane.core.ui.menubuilders.generic.EntryPopupListener) Before(org.junit.Before)

Example 54 with EntryAccessor

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

the class JMenuItemBuilderTest method createsSubmenuWithAction.

@Test
public void createsSubmenuWithAction() {
    Entry parentMenuEntry = new Entry();
    final JMenu parentMenu = new JMenu();
    new EntryAccessor().setComponent(parentMenuEntry, parentMenu);
    parentMenuEntry.addChild(menuEntry);
    menuEntry.addChild(actionEntry);
    new EntryAccessor().setAction(menuEntry, action);
    menuActionGroupBuilder.visit(menuEntry);
    final JMenuItem menuItem = getFirstSubMenuItem(menuEntry);
    assertThatMenuItemHasCorrectAction(menuItem);
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) Test(org.junit.Test)

Example 55 with EntryAccessor

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

the class JMenubarBuilderTest method createsEmptyToolbarComponent.

@Test
public void createsEmptyToolbarComponent() {
    Entry toolbarEntry = new Entry();
    final IUserInputListenerFactory userInputListenerFactory = mock(IUserInputListenerFactory.class);
    final FreeplaneMenuBar menubar = TestMenuBarFactory.createFreeplaneMenuBar();
    when(userInputListenerFactory.getMenuBar()).thenReturn(menubar);
    final JMenubarBuilder toolbarBuilder = new JMenubarBuilder(userInputListenerFactory);
    toolbarBuilder.visit(toolbarEntry);
    assertThat(new EntryAccessor().getComponent(toolbarEntry), CoreMatchers.<Object>is(menubar));
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) IUserInputListenerFactory(org.freeplane.core.ui.IUserInputListenerFactory) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) FreeplaneMenuBar(org.freeplane.core.ui.components.FreeplaneMenuBar) Test(org.junit.Test)

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