Search in sources :

Example 1 with MenuItemPager

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;
        }
    };
}
Also used : IExternalFinderItemMenuGenerator(org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator) ExternalFinderItemMenuGenerator(org.omegat.externalfinder.item.ExternalFinderItemMenuGenerator) IExternalFinderItemMenuGenerator(org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator) ArrayList(java.util.ArrayList) List(java.util.List) MenuItemPager(org.omegat.util.gui.MenuItemPager) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) IProjectEventListener(org.omegat.core.events.IProjectEventListener) JMenu(javax.swing.JMenu)

Example 2 with MenuItemPager

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();
}
Also used : MenuItemPager(org.omegat.util.gui.MenuItemPager) JMenuItem(javax.swing.JMenuItem)

Aggregations

JMenuItem (javax.swing.JMenuItem)2 MenuItemPager (org.omegat.util.gui.MenuItemPager)2 Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JMenu (javax.swing.JMenu)1 IProjectEventListener (org.omegat.core.events.IProjectEventListener)1 ExternalFinderItemMenuGenerator (org.omegat.externalfinder.item.ExternalFinderItemMenuGenerator)1 IExternalFinderItemMenuGenerator (org.omegat.externalfinder.item.IExternalFinderItemMenuGenerator)1