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));
}
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));
}
Aggregations