Search in sources :

Example 1 with MenuSplitter

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

the class JComponentRemoverTest method removesExtraSubmenusFromParents.

@Test
public void removesExtraSubmenusFromParents() throws Exception {
    final JComponentRemover componentRemover = new JComponentRemover();
    final Entry entry = new Entry();
    JMenu parent = new JMenu();
    JComponent entryComponent = new JMenu();
    final MenuSplitter menuSplitter = new MenuSplitter(1);
    menuSplitter.addMenuComponent(parent, new JMenu());
    menuSplitter.addMenuComponent(parent, entryComponent);
    new EntryAccessor().setComponent(entry, entryComponent);
    componentRemover.visit(entry);
    Assert.assertThat(parent.getPopupMenu().getComponentCount(), equalTo(1));
}
Also used : Entry(org.freeplane.core.ui.menubuilders.generic.Entry) MenuSplitter(org.freeplane.core.ui.MenuSplitter) EntryAccessor(org.freeplane.core.ui.menubuilders.generic.EntryAccessor) JComponent(javax.swing.JComponent) JMenu(javax.swing.JMenu) Test(org.junit.Test)

Example 2 with MenuSplitter

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

the class MIconController method addActionToIconSubmenu.

private void addActionToIconSubmenu(final JMenu menu, final MindIcon icon, final String fileName) {
    final AFreeplaneAction myAction = iconActions.get(icon);
    final int separatorPosition = fileName.indexOf('/');
    if (separatorPosition == -1) {
        new MenuSplitter().addMenuComponent(menu, new JMenuItem(myAction), menu.getItemCount());
        return;
    }
    final String submenuName = fileName.substring(0, separatorPosition);
    final int componentCount = menu.getItemCount();
    if (componentCount != 0) {
        final Component lastComponent = menu.getMenuComponent(componentCount - 1);
        if (lastComponent instanceof JMenu) {
            final JMenu lastSubmenu = (JMenu) lastComponent;
            if (lastSubmenu.getText().equals(submenuName)) {
                addActionToIconSubmenu(lastSubmenu, icon, fileName.substring(separatorPosition + 1));
                return;
            }
        }
    }
    final JMenu submenu = new JMenu(submenuName);
    menu.add(submenu);
    addActionToIconSubmenu(submenu, icon, fileName.substring(separatorPosition + 1));
}
Also used : AFreeplaneAction(org.freeplane.core.ui.AFreeplaneAction) MenuSplitter(org.freeplane.core.ui.MenuSplitter) JMenuItem(javax.swing.JMenuItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) Point(java.awt.Point) JMenu(javax.swing.JMenu)

Aggregations

JComponent (javax.swing.JComponent)2 JMenu (javax.swing.JMenu)2 MenuSplitter (org.freeplane.core.ui.MenuSplitter)2 Component (java.awt.Component)1 Point (java.awt.Point)1 JMenuItem (javax.swing.JMenuItem)1 AFreeplaneAction (org.freeplane.core.ui.AFreeplaneAction)1 Entry (org.freeplane.core.ui.menubuilders.generic.Entry)1 EntryAccessor (org.freeplane.core.ui.menubuilders.generic.EntryAccessor)1 Test (org.junit.Test)1