use of org.omegat.util.gui.MenuItemPager in project omegat by omegat-org.
the class ExternalFinder method generateIProjectEventListener.
private static IProjectEventListener generateIProjectEventListener() {
return new IProjectEventListener() {
private final List<Component> menuItems = new ArrayList<Component>();
@Override
public void onProjectChanged(final IProjectEventListener.PROJECT_CHANGE_TYPE eventType) {
switch(eventType) {
case LOAD:
onLoad();
break;
case CLOSE:
onClose();
break;
default:
}
}
private void onLoad() {
// clear old items
menuItems.clear();
// add finder items to menuItems
IExternalFinderItemMenuGenerator generator = new ExternalFinderItemMenuGenerator(ExternalFinderItem.TARGET.BOTH, false);
List<JMenuItem> newMenuItems = generator.generate();
JMenu toolsMenu = Core.getMainWindow().getMainMenu().getToolsMenu();
// Separator
Component separator = new JPopupMenu.Separator();
toolsMenu.add(separator);
menuItems.add(separator);
// add menuItems to menu
MenuItemPager pager = new MenuItemPager(toolsMenu);
for (JMenuItem component : newMenuItems) {
pager.add(component);
}
menuItems.addAll(pager.getFirstPage());
}
private void onClose() {
// remove menu items
final JMenu menu = Core.getMainWindow().getMainMenu().getToolsMenu();
menuItems.forEach(menu::remove);
menuItems.clear();
projectConfig = null;
}
};
}
use of org.omegat.util.gui.MenuItemPager in project omegat by omegat-org.
the class ExternalFinderItemPopupMenuConstructor method addItems.
public void addItems(JPopupMenu menu, JTextComponent comp, int mousepos, boolean isInActiveEntry, boolean isInActiveTranslation, SegmentBuilder sb) {
final String selection = Core.getEditor().getSelectedText();
if (selection == null) {
return;
}
ExternalFinderItem.TARGET target;
if (ExternalFinderItem.isASCII(selection)) {
target = ExternalFinderItem.TARGET.ASCII_ONLY;
} else {
target = ExternalFinderItem.TARGET.NON_ASCII_ONLY;
}
IExternalFinderItemMenuGenerator generator = new ExternalFinderItemMenuGenerator(target, true);
List<JMenuItem> newMenuItems = generator.generate();
menu.addSeparator();
MenuItemPager pager = new MenuItemPager(menu);
for (JMenuItem component : newMenuItems) {
pager.add(component);
}
menu.addSeparator();
}
Aggregations