Search in sources :

Example 56 with JMenuItem

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

the class MainWindowMenu method onProjectStatusChanged.

/**
 * Enable or disable items depend of project open or close.
 *
 * @param isProjectOpened
 *            project open status: true if opened, false if closed
 */
private void onProjectStatusChanged(final boolean isProjectOpened) {
    JMenuItem[] itemsToSwitchOff = new JMenuItem[] { projectNewMenuItem, projectTeamNewMenuItem, projectOpenMenuItem, projectMedOpenMenuItem };
    JMenuItem[] itemsToSwitchOn = new JMenuItem[] { projectImportMenuItem, projectWikiImportMenuItem, projectReloadMenuItem, projectCloseMenuItem, projectSaveMenuItem, projectEditMenuItem, projectCompileMenuItem, projectSingleCompileMenuItem, projectAccessProjectFilesMenu, projectMedCreateMenuItem, editMenu, editFindInProjectMenuItem, editReplaceInProjectMenuItem, editInsertSourceMenuItem, editInsertTranslationMenuItem, editTagPainterMenuItem, editOverwriteSourceMenuItem, editOverwriteTranslationMenuItem, editRedoMenuItem, editSelectFuzzy1MenuItem, editSelectFuzzy2MenuItem, editSelectFuzzy3MenuItem, editSelectFuzzy4MenuItem, editSelectFuzzy5MenuItem, editUndoMenuItem, switchCaseSubMenu, editOverwriteMachineTranslationMenuItem, editRegisterUntranslatedMenuItem, editRegisterEmptyMenuItem, editRegisterIdenticalMenuItem, gotoMenu, gotoNextSegmentMenuItem, gotoNextUntranslatedMenuItem, gotoPreviousSegmentMenuItem, gotoSegmentMenuItem, gotoNextNoteMenuItem, gotoPreviousNoteMenuItem, gotoMatchSourceSegment, viewFileListMenuItem, toolsCheckIssuesMenuItem, toolsCheckIssuesCurrentFileMenuItem, toolsShowStatisticsStandardMenuItem, toolsShowStatisticsMatchesMenuItem, toolsShowStatisticsMatchesPerFileMenuItem };
    for (JMenuItem item : itemsToSwitchOff) {
        item.setEnabled(!isProjectOpened);
    }
    for (JMenuItem item : itemsToSwitchOn) {
        item.setEnabled(isProjectOpened);
    }
    if (Core.getParams().containsKey(CLIParameters.NO_TEAM)) {
        projectTeamNewMenuItem.setEnabled(false);
    }
    if (isProjectOpened && Core.getProject().isRemoteProject() && Core.getProject().getProjectProperties().getSourceDir().isUnderRoot()) {
        projectCommitSourceFiles.setEnabled(true);
    } else {
        projectCommitSourceFiles.setEnabled(false);
    }
    if (isProjectOpened && Core.getProject().isRemoteProject() && Core.getProject().getProjectProperties().getTargetDir().isUnderRoot()) {
        projectCommitTargetFiles.setEnabled(true);
    } else {
        projectCommitTargetFiles.setEnabled(false);
    }
}
Also used : JMenuItem(javax.swing.JMenuItem)

Example 57 with JMenuItem

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

the class ScriptingWindow method createMenuBar.

private JMenuBar createMenuBar() {
    mb = new JMenuBar();
    JMenu menu = new JMenu();
    Mnemonics.setLocalizedText(menu, OStrings.getString("SCW_MENU_TITLE"));
    JMenuItem item;
    // https://sourceforge.net/p/omegat/feature-requests/1314/
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_LOAD_FILE"));
    item.addActionListener(new OpenScriptAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(item);
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_NEW_SCRIPT"));
    item.addActionListener(new NewScriptAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(item);
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_SAVE_SCRIPT"));
    item.addActionListener(new SaveScriptAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(item);
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_RUN_SCRIPT"));
    item.addActionListener(new RunScriptAction());
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    menu.add(item);
    menu.addSeparator();
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_MENU_SET_SCRIPTS_FOLDER"));
    item.addActionListener(new SelectScriptFolderAction());
    menu.add(item);
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_MENU_ACCESS_FOLDER"));
    item.addActionListener(new ExploreScriptFolderAction());
    menu.add(item);
    menu.addSeparator();
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_MENU_CLOSE"));
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(e -> {
        frame.setVisible(false);
        frame.dispose();
    });
    menu.add(item);
    PropertiesShortcuts.getMainMenuShortcuts().bindKeyStrokes(menu);
    mb.add(menu);
    // Edit Menu
    m_txtScriptEditor.enhanceMenu(mb);
    buildSetsMenu(mb);
    menu = new JMenu();
    Mnemonics.setLocalizedText(menu, OStrings.getString("SCW_MENU_HELP"));
    item = new JMenuItem();
    Mnemonics.setLocalizedText(item, OStrings.getString("SCW_MENU_JAVADOC"));
    item.addActionListener(e -> {
        try {
            Help.showJavadoc();
        } catch (IOException ex) {
            Log.log(ex);
        }
    });
    menu.add(item);
    mb.add(menu);
    return mb;
}
Also used : IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 58 with JMenuItem

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

the class ScriptingWindow method setupRunButtons.

private void setupRunButtons(JPanel panel) {
    m_btnRunScript = new JButton();
    Mnemonics.setLocalizedText(m_btnRunScript, OStrings.getString("SCW_RUN_SCRIPT"));
    m_btnRunScript.setAlignmentX(Component.LEFT_ALIGNMENT);
    m_btnRunScript.setHorizontalAlignment(SwingConstants.LEFT);
    m_btnRunScript.addActionListener(a -> runScript());
    panel.add(m_btnRunScript);
    m_btnCancelScript = new JButton();
    Mnemonics.setLocalizedText(m_btnCancelScript, OStrings.getString("SCW_CANCEL_SCRIPT"));
    m_btnCancelScript.setToolTipText(OStrings.getString("SCW_CANCEL_BUTTON_TOOLTIP"));
    m_btnCancelScript.setAlignmentX(Component.LEFT_ALIGNMENT);
    m_btnCancelScript.setHorizontalAlignment(SwingConstants.LEFT);
    m_btnCancelScript.addActionListener(e -> cancelCurrentScript());
    panel.add(m_btnCancelScript);
    for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) {
        final int index = i;
        final int scriptKey = scriptKey(index);
        m_quickScriptButtons[i] = new JButton(String.valueOf(scriptKey));
        // Run a script from the quick button bar
        m_quickScriptButtons[i].addActionListener(a -> {
            if (Preferences.existsPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey)) {
                runQuickScript(index);
            } else {
                logResult(StringUtil.format(OStrings.getString("SCW_NO_SCRIPT_BOUND"), scriptKey));
            }
        });
        JPopupMenu quickScriptPopup = new JPopupMenu();
        // Add a script to the quick script button bar
        final JMenuItem addQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_ADD_SCRIPT"));
        addQuickScriptMenuItem.addActionListener(new QuickScriptUpdater(index));
        quickScriptPopup.add(addQuickScriptMenuItem);
        // Remove a script from the button bar
        final JMenuItem removeQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_REMOVE_SCRIPT"));
        removeQuickScriptMenuItem.addActionListener(evt -> {
            String scriptName = Preferences.getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, "(unknown)");
            logResult(StringUtil.format(OStrings.getString("SCW_REMOVED_QUICK_SCRIPT"), scriptName, scriptKey));
            Preferences.setPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, "");
            m_quickScriptButtons[index].setToolTipText(OStrings.getString("SCW_NO_SCRIPT_SET"));
            m_quickScriptButtons[index].setText(" " + scriptKey + " ");
            unsetQuickScriptMenu(index);
        });
        quickScriptPopup.add(removeQuickScriptMenuItem);
        quickScriptPopup.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                // Disable add a script command if script selection empty
                addQuickScriptMenuItem.setEnabled(!m_scriptList.isSelectionEmpty());
                // Disable remove a script command if the quick run button is not bounded
                String scriptName = Preferences.getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, null);
                removeQuickScriptMenuItem.setEnabled(!StringUtil.isEmpty(scriptName));
            }

            @Override
            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // do nothing
            }

            @Override
            public void popupMenuCanceled(PopupMenuEvent e) {
            // do nothing
            }
        });
        m_quickScriptButtons[i].setComponentPopupMenu(quickScriptPopup);
        panel.add(m_quickScriptButtons[i]);
    }
}
Also used : PopupMenuListener(javax.swing.event.PopupMenuListener) JButton(javax.swing.JButton) JMenuItem(javax.swing.JMenuItem) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu)

Example 59 with JMenuItem

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

the class SearchWindowMenu method init.

private void init() {
    JMenu fileMenu = add(new JMenu());
    Mnemonics.setLocalizedText(fileMenu, OStrings.getString("SW_FILE_MENU"));
    JMenuItem item;
    item = fileMenu.add(new JMenuItem());
    Mnemonics.setLocalizedText(item, OStrings.getString("SW_FILE_MENU_SELECT_SEARCH_FIELD"));
    item.setActionCommand("editFindInProjectMenuItem");
    item.addActionListener(e -> {
        String selection = controller.getViewerSelection();
        if (!StringUtil.isEmpty(selection)) {
            controller.setSearchText(selection);
        }
        controller.focusSearchField();
    });
    item = fileMenu.add(new JMenuItem());
    Mnemonics.setLocalizedText(item, OStrings.getString("SW_FILE_MENU_CLOSE"));
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(e -> controller.doCancel());
    JMenu editMenu = add(new JMenu());
    Mnemonics.setLocalizedText(editMenu, OStrings.getString("SW_EDIT_MENU"));
    // "Action Commands" must be the same as equivalent MainWindowMenu
    // members in order to get matching shortcuts.
    item = editMenu.add(new JMenuItem());
    Mnemonics.setLocalizedText(item, OStrings.getString("TF_MENU_EDIT_SOURCE_INSERT"));
    item.setActionCommand("editInsertSourceMenuItem");
    item.addActionListener(e -> controller.insertIntoActiveField(Core.getEditor().getCurrentEntry().getSrcText()));
    item = editMenu.add(new JMenuItem());
    Mnemonics.setLocalizedText(item, OStrings.getString("TF_MENU_EDIT_SOURCE_OVERWRITE"));
    item.setActionCommand("editOverwriteSourceMenuItem");
    item.addActionListener(e -> controller.replaceCurrentFieldText(Core.getEditor().getCurrentEntry().getSrcText()));
    editMenu.addSeparator();
    item = editMenu.add(new JMenuItem());
    Mnemonics.setLocalizedText(item, OStrings.getString("TF_MENU_EDIT_CREATE_GLOSSARY_ENTRY"));
    item.setActionCommand("editCreateGlossaryEntryMenuItem");
    item.addActionListener(e -> Core.getGlossary().showCreateGlossaryEntryDialog(controller.getWindow()));
    editMenu.addSeparator();
    item = editMenu.add(new JMenuItem());
    Mnemonics.setLocalizedText(item, OStrings.getString("SW_EDIT_MENU_RESET_OPTIONS"));
    item.addActionListener(e -> controller.resetOptions());
    PropertiesShortcuts.getMainMenuShortcuts().bindKeyStrokes(this);
}
Also used : JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 60 with JMenuItem

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

the class PropertiesShortcutsTest method testBindKeyStrokesJMenuItemRecursive.

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 */
@Test
public void testBindKeyStrokesJMenuItemRecursive() {
    // case JMenu with children
    JMenu parent = new JMenu();
    JMenuItem child1 = new JMenu();
    JMenuItem child2 = new JMenuItem();
    child2.setActionCommand(TEST_DELETE);
    child2.setAccelerator(CTRL_D);
    JMenuItem grandchild1 = new JMenuItem();
    grandchild1.setActionCommand(TEST_USER_1);
    JMenuItem grandchild2 = new JMenuItem();
    grandchild2.setActionCommand(OUT_OF_LIST);
    grandchild2.setAccelerator(CTRL_X);
    parent.add(child1);
    parent.add(child2);
    child1.add(grandchild1);
    child1.add(grandchild2);
    // bind
    shortcuts.bindKeyStrokes(parent);
    assertNull(parent.getAccelerator());
    assertNull(child1.getAccelerator());
    assertNull(child2.getAccelerator());
    assertEquals(CTRL_P, grandchild1.getAccelerator());
    assertEquals(CTRL_X, grandchild2.getAccelerator());
}
Also used : JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) Test(org.junit.Test)

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