Search in sources :

Example 1 with EntriesForAction

use of org.freeplane.core.ui.menubuilders.action.EntriesForAction 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));
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntriesForAction(org.freeplane.core.ui.menubuilders.action.EntriesForAction) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) KeyStroke(javax.swing.KeyStroke) JMenuItem(javax.swing.JMenuItem) Test(org.junit.Test)

Example 2 with EntriesForAction

use of org.freeplane.core.ui.menubuilders.action.EntriesForAction in project freeplane by freeplane.

the class UserInputListenerFactory method updateMenus.

public void updateMenus(String menuStructureResource, Set<String> plugins) {
    mapsPopupMenu = new JPopupMenu();
    mapsPopupMenu.setName(TextUtils.getText("mindmaps"));
    final URL genericStructure = ResourceController.getResourceController().getResource(menuStructureResource);
    try {
        final FreeplaneResourceAccessor resourceAccessor = new FreeplaneResourceAccessor();
        final EntriesForAction entries = new EntriesForAction();
        final ActionAcceleratorManager acceleratorManager = ResourceController.getResourceController().getAcceleratorManager();
        final BuildProcessFactory buildProcessFactory = new MenuBuildProcessFactory(this, modeController, resourceAccessor, acceleratorManager, entries, buildPhaseListeners);
        final PhaseProcessor buildProcessor = buildProcessFactory.getBuildProcessor();
        subtreeBuilder = buildProcessFactory.getChildProcessor();
        acceleratorManager.addAcceleratorChangeListener(modeController, new MenuAcceleratorChangeListener(entries));
        for (final Phase phase : Phase.values()) for (java.util.Map.Entry<String, BuilderDestroyerPair> entry : customBuilders.get(phase.ordinal()).entrySet()) buildProcessor.phase(phase).addBuilderPair(entry.getKey(), entry.getValue());
        final InputStream resource = genericStructure.openStream();
        final BufferedReader reader = new BufferedReader(new InputStreamReader(resource));
        genericMenuStructure = XmlEntryStructureBuilder.buildMenuStructure(reader);
        filterPlugins(genericMenuStructure, plugins);
        buildProcessor.build(genericMenuStructure);
        if (Boolean.getBoolean("org.freeplane.outputUnusedActions"))
            outputUnusedActions();
    } catch (Exception e) {
        final boolean isUserDefined = isUserDefined(genericStructure);
        if (isUserDefined) {
            LogUtils.warn(e);
            String myMessage = TextUtils.format("menu_error", genericStructure.getPath(), e.getMessage());
            UITools.backOtherWindows();
            JOptionPane.showMessageDialog(UITools.getMenuComponent(), myMessage, "Freeplane", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
        }
        throw new RuntimeException("Error in menu resource " + menuStructureResource, e);
    }
}
Also used : Phase(org.freeplane.core.ui.menubuilders.generic.PhaseProcessor.Phase) InputStreamReader(java.io.InputStreamReader) FreeplaneResourceAccessor(org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor) InputStream(java.io.InputStream) JPopupMenu(javax.swing.JPopupMenu) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) BuildProcessFactory(org.freeplane.core.ui.menubuilders.generic.BuildProcessFactory) MenuBuildProcessFactory(org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory) MenuBuildProcessFactory(org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory) Entry(org.freeplane.core.ui.menubuilders.generic.Entry) EntriesForAction(org.freeplane.core.ui.menubuilders.action.EntriesForAction) PhaseProcessor(org.freeplane.core.ui.menubuilders.generic.PhaseProcessor) ActionAcceleratorManager(org.freeplane.core.ui.ActionAcceleratorManager) BufferedReader(java.io.BufferedReader) MenuAcceleratorChangeListener(org.freeplane.core.ui.menubuilders.menu.MenuAcceleratorChangeListener)

Example 3 with EntriesForAction

use of org.freeplane.core.ui.menubuilders.action.EntriesForAction in project freeplane by freeplane.

the class MenuBuilderAcceptanceTest method setup.

@BeforeClass
public static void setup() {
    final IUserInputListenerFactory userInputListenerFactory = mock(IUserInputListenerFactory.class);
    when(userInputListenerFactory.getToolBar("/main_toolbar")).thenReturn(new JToolBar());
    when(userInputListenerFactory.getNodePopupMenu()).thenReturn(new JPopupMenu());
    when(userInputListenerFactory.getMapPopup()).thenReturn(new JPopupMenu());
    when(userInputListenerFactory.getMenuBar()).thenReturn(TestMenuBarFactory.createFreeplaneMenuBar());
    final PhaseProcessor buildProcessor = new MenuBuildProcessFactory(userInputListenerFactory, Controller.getCurrentModeController(), new FreeplaneResourceAccessor(), mock(IAcceleratorMap.class), new EntriesForAction(), Collections.<BuildPhaseListener>emptyList()).getBuildProcessor();
    final String menuResource = "/xml/mindmapmodemenu.xml";
    final InputStream resource = MenuBuilderAcceptanceTest.class.getResourceAsStream(menuResource);
    final BufferedReader reader = new BufferedReader(new InputStreamReader(resource));
    menuStructure = XmlEntryStructureBuilder.buildMenuStructure(reader);
    buildProcessor.build(menuStructure);
}
Also used : BuildPhaseListener(org.freeplane.core.ui.menubuilders.generic.BuildPhaseListener) InputStreamReader(java.io.InputStreamReader) IUserInputListenerFactory(org.freeplane.core.ui.IUserInputListenerFactory) EntriesForAction(org.freeplane.core.ui.menubuilders.action.EntriesForAction) InputStream(java.io.InputStream) PhaseProcessor(org.freeplane.core.ui.menubuilders.generic.PhaseProcessor) BufferedReader(java.io.BufferedReader) JToolBar(javax.swing.JToolBar) JPopupMenu(javax.swing.JPopupMenu) MenuBuildProcessFactory(org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory) BeforeClass(org.junit.BeforeClass)

Example 4 with EntriesForAction

use of org.freeplane.core.ui.menubuilders.action.EntriesForAction in project freeplane by freeplane.

the class MenuBuildProcessFactoryTest method setup.

@Before
public void setup() {
    freeplaneActions = mock(FreeplaneActions.class);
    final ResourceAccessor resourceAccessorMock = mock(ResourceAccessor.class);
    when(resourceAccessorMock.getRawText(Matchers.anyString())).thenReturn("text");
    final IUserInputListenerFactory userInputListenerFactory = mock(IUserInputListenerFactory.class);
    final FreeplaneMenuBar menubar = TestMenuBarFactory.createFreeplaneMenuBar();
    when(userInputListenerFactory.getMenuBar()).thenReturn(menubar);
    phaseProcessor = new MenuBuildProcessFactory(userInputListenerFactory, freeplaneActions, resourceAccessorMock, mock(IAcceleratorMap.class), new EntriesForAction(), Collections.<BuildPhaseListener>emptyList()).getBuildProcessor();
}
Also used : ResourceAccessor(org.freeplane.core.ui.menubuilders.generic.ResourceAccessor) IAcceleratorMap(org.freeplane.core.ui.menubuilders.action.IAcceleratorMap) FreeplaneActions(org.freeplane.features.mode.FreeplaneActions) IUserInputListenerFactory(org.freeplane.core.ui.IUserInputListenerFactory) EntriesForAction(org.freeplane.core.ui.menubuilders.action.EntriesForAction) FreeplaneMenuBar(org.freeplane.core.ui.components.FreeplaneMenuBar) Before(org.junit.Before)

Aggregations

EntriesForAction (org.freeplane.core.ui.menubuilders.action.EntriesForAction)4 BufferedReader (java.io.BufferedReader)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 JPopupMenu (javax.swing.JPopupMenu)2 IUserInputListenerFactory (org.freeplane.core.ui.IUserInputListenerFactory)2 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)2 PhaseProcessor (org.freeplane.core.ui.menubuilders.generic.PhaseProcessor)2 MenuBuildProcessFactory (org.freeplane.core.ui.menubuilders.menu.MenuBuildProcessFactory)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 JMenuItem (javax.swing.JMenuItem)1 JToolBar (javax.swing.JToolBar)1 KeyStroke (javax.swing.KeyStroke)1 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)1 ActionAcceleratorManager (org.freeplane.core.ui.ActionAcceleratorManager)1 FreeplaneMenuBar (org.freeplane.core.ui.components.FreeplaneMenuBar)1 FreeplaneResourceAccessor (org.freeplane.core.ui.menubuilders.FreeplaneResourceAccessor)1 IAcceleratorMap (org.freeplane.core.ui.menubuilders.action.IAcceleratorMap)1 BuildPhaseListener (org.freeplane.core.ui.menubuilders.generic.BuildPhaseListener)1