Search in sources :

Example 51 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class ExternalFinderItemMenuGenerator method generate.

@Override
public List<JMenuItem> generate() {
    List<ExternalFinderItem> finderItems = ExternalFinder.getItems();
    if (finderItems.isEmpty()) {
        return Collections.emptyList();
    }
    List<JMenuItem> menuItems = new ArrayList<>();
    // generate menu
    for (ExternalFinderItem finderItem : finderItems) {
        if (popup && finderItem.isNopopup()) {
            continue;
        }
        if (target == ExternalFinderItem.TARGET.ASCII_ONLY && finderItem.isNonAsciiOnly()) {
            continue;
        } else if (target == ExternalFinderItem.TARGET.NON_ASCII_ONLY && finderItem.isAsciiOnly()) {
            continue;
        }
        JMenuItem item = new JMenuItem();
        Mnemonics.setLocalizedText(item, finderItem.getName());
        // set keyboard shortcut
        if (!popup) {
            item.setAccelerator(finderItem.getKeystroke());
        }
        item.addActionListener(new ExternalFinderItemActionListener(finderItem));
        menuItems.add(item);
    }
    return menuItems;
}
Also used : ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem)

Example 52 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class RecentProjects method updateMenu.

public static void updateMenu() {
    IMainWindow window = Core.getMainWindow();
    if (window == null) {
        return;
    }
    JMenuItem recentMenu = window.getMainMenu().getProjectRecentMenuItem();
    if (recentMenu == null) {
        return;
    }
    recentMenu.removeAll();
    synchronized (RECENT_PROJECTS) {
        for (final String project : RECENT_PROJECTS) {
            JMenuItem recentProjectMenuItem = new JMenuItem(project);
            recentProjectMenuItem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent event) {
                    ProjectUICommands.projectOpen(new File(project), true);
                }
            });
            recentMenu.add(recentProjectMenuItem);
        }
        recentMenu.setEnabled(!RECENT_PROJECTS.isEmpty());
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) IMainWindow(org.omegat.gui.main.IMainWindow) JMenuItem(javax.swing.JMenuItem) File(java.io.File)

Example 53 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class MachineTranslateTextArea method populatePaneMenu.

@Override
public void populatePaneMenu(JPopupMenu menu) {
    final JMenuItem prefs = new JMenuItem(OStrings.getString("GUI_MACHINETRANSLATESWINDOW_OPEN_PREFS"));
    prefs.addActionListener(e -> new PreferencesWindowController().show(Core.getMainWindow().getApplicationFrame(), MachineTranslationPreferencesController.class));
    menu.add(prefs);
}
Also used : MachineTranslationPreferencesController(org.omegat.gui.preferences.view.MachineTranslationPreferencesController) PreferencesWindowController(org.omegat.gui.preferences.PreferencesWindowController) JMenuItem(javax.swing.JMenuItem)

Example 54 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class ProjectFilesListController method addContextMenuItem.

private void addContextMenuItem(JPopupMenu menu, boolean isSource, List<File> files) {
    long presentFiles = files.stream().filter(File::isFile).count();
    String defaultTitle, modTitle;
    if (presentFiles > 1) {
        defaultTitle = StringUtil.format(OStrings.getString(isSource ? "PF_OPEN_SOURCE_FILES" : "PF_OPEN_TARGET_FILES"), presentFiles);
        modTitle = StringUtil.format(OStrings.getString(isSource ? "PF_OPEN_SOURCE_FILES" : "PF_OPEN_TARGET_FILES"), presentFiles);
    } else {
        defaultTitle = OStrings.getString(isSource ? "PF_OPEN_SOURCE_FILE" : "PF_OPEN_TARGET_FILE");
        modTitle = OStrings.getString(isSource ? "PF_REVEAL_SOURCE_FILE" : "PF_REVEAL_TARGET_FILE");
    }
    JMenuItem item = menu.add(defaultTitle);
    item.addActionListener(e -> {
        boolean openParent = (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
        Stream<File> stream;
        if (openParent) {
            stream = files.stream().map(File::getParentFile).distinct().filter(File::isDirectory);
        } else {
            stream = files.stream().filter(File::isFile);
        }
        stream.forEach(f -> {
            try {
                Desktop.getDesktop().open(f);
            } catch (IOException ex) {
                Log.log(ex);
            }
        });
    });
    item.setEnabled(presentFiles > 0);
    item.addMenuKeyListener(new MenuKeyListener() {

        @Override
        public void menuKeyTyped(MenuKeyEvent e) {
        }

        @Override
        public void menuKeyReleased(MenuKeyEvent e) {
            if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0 || e.getKeyCode() == KeyEvent.VK_META || e.getKeyCode() == KeyEvent.VK_CONTROL) {
                setText(defaultTitle);
            }
        }

        @Override
        public void menuKeyPressed(MenuKeyEvent e) {
            if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
                setText(modTitle);
            }
        }

        private void setText(String text) {
            item.setText(text);
            menu.pack();
        }
    });
}
Also used : MenuKeyEvent(javax.swing.event.MenuKeyEvent) MenuKeyListener(javax.swing.event.MenuKeyListener) IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) File(java.io.File)

Example 55 with JMenuItem

use of javax.swing.JMenuItem in project omegat by omegat-org.

the class TagIssue method getMenuComponents.

@Override
public List<? extends JMenuItem> getMenuComponents() {
    String fixText = TagValidationTool.fixErrors(report);
    if (fixText == null) {
        return Collections.emptyList();
    } else {
        JMenuItem doFix = new JMenuItem();
        org.openide.awt.Mnemonics.setLocalizedText(doFix, OStrings.getString("ISSUES_TAGS_BUTTON_APPLY_FIX"));
        doFix.addActionListener(getFixActionListener(fixText));
        return Arrays.asList(doFix);
    }
}
Also used : JMenuItem(javax.swing.JMenuItem)

Aggregations

JMenuItem (javax.swing.JMenuItem)1130 ActionEvent (java.awt.event.ActionEvent)559 ActionListener (java.awt.event.ActionListener)464 JMenu (javax.swing.JMenu)369 JPopupMenu (javax.swing.JPopupMenu)225 JMenuBar (javax.swing.JMenuBar)103 AbstractAction (javax.swing.AbstractAction)90 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)76 ArrayList (java.util.ArrayList)71 JPanel (javax.swing.JPanel)70 Point (java.awt.Point)65 JSeparator (javax.swing.JSeparator)63 File (java.io.File)61 JLabel (javax.swing.JLabel)61 BorderLayout (java.awt.BorderLayout)57 JButton (javax.swing.JButton)54 Component (java.awt.Component)53 ButtonGroup (javax.swing.ButtonGroup)50 Dimension (java.awt.Dimension)46 MouseEvent (java.awt.event.MouseEvent)45