Example usage for javax.swing JMenuItem setActionCommand

List of usage examples for javax.swing JMenuItem setActionCommand

Introduction

In this page you can find the example usage for javax.swing JMenuItem setActionCommand.

Prototype

public void setActionCommand(String actionCommand) 

Source Link

Document

Sets the action command for this button.

Usage

From source file:org.executequery.gui.editor.QueryEditorPopupMenu.java

private JMenuItem createExecuteMenuItem() {
    JMenuItem menuItem = MenuItemFactory.createMenuItem(action());
    menuItem.setText("Execute");
    menuItem.setActionCommand("execute");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
    executeActionButtons().add(menuItem);
    return menuItem;
}

From source file:org.executequery.gui.ReadOnlyTextPanePopUpMenu.java

protected JMenuItem createMenuItem(String text, String actionCommand, String toolTip) {

    JMenuItem menuItem = MenuItemFactory.createMenuItem(text);
    menuItem.setActionCommand(actionCommand);
    menuItem.addActionListener(reflectiveAction);

    if (StringUtils.isNotBlank(toolTip)) {

        menuItem.setToolTipText(toolTip);
    }//from   ww  w .  j  a  v a 2s  . c  o  m

    return menuItem;
}

From source file:org.geopublishing.atlasViewer.swing.AtlasViewerGUI.java

/**
 * Change the {@link JMenu} languageSubMenu that allows changing the
 * displayed language Attention, not to replace the object in the
 * {@link JMenu} structure Call this after changes to atlasConfig.langages.
 * //  w w  w  .  j a  v a 2s.  c  om
 * @author <a href="mailto:skpublic@wikisquare.de">Stefan Alfons Tzeggai</a>
 * 
 *         Note: This method is double in {@link AtlasViewerGUI} and
 *         Geopublisher
 */
private void updateLangMenu() {
    if (getAtlasConfig() == null)
        return;

    // Assuming that the language was changed, update the windows title
    // getJFrame().setTitle("Loaded ace.getName().toString());

    SwingUtil.checkOnEDT();

    if (languageSubMenu == null) {

        languageSubMenu = new JMenu(GpCoreUtil.R("AtlasViewer.FileMenu.LanguageSubMenu.change_language"));

        languageSubMenu.setFont(AtlasMenuItem.BIGFONT);

        languageSubMenu.setToolTipText(GpCoreUtil.R("AtlasViewer.FileMenu.LanguageSubMenu.change_language_tt"));
        languageSubMenu.setIcon(Icons.ICON_FLAGS_SMALL);
    } else {
        // Remove all old MenuItems
        languageSubMenu.removeAll();
    }

    // If there is only one language, the whole menu is disabled and a
    // different tooltip appears.
    if (getAtlasConfig().getLanguages().size() == 1) {
        getLanguageSubMenu().setToolTipText(
                GpCoreUtil.R("AtlasViewer.FileMenu.LanguageSubMenu.change_language_notAvailable_tt",
                        getAtlasConfig().getLanguages().get(0)));
        getLanguageSubMenu().setEnabled(false);
        return;
    }

    for (String langCode : getAtlasConfig().getLanguages()) {

        // Not show the option to switch to actual language...
        if (langCode.equals(Translation.getActiveLang()))
            continue;

        JMenuItem langMenuItem = new AtlasMenuItem(
                new AbstractAction(I18NUtil.getMultilanguageString(langCode)) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            Translation.setActiveLang(e.getActionCommand());

                            // To force the recreation of the Menus, we have
                            // to null some of the elements
                            // updateMenu();

                            // Update the GUI
                            updateLangMenu();

                            setMap(map, true);
                        } catch (Throwable ex) {
                            ExceptionDialog.show(getJFrame(), ex);
                        }
                    }

                });
        langMenuItem.setActionCommand(langCode);
        getLanguageSubMenu().add(langMenuItem);
    }
}

From source file:org.jab.docsearch.DocSearch.java

/**
 * Creates menu bar/*from  www .  j av a  2  s.  c o  m*/
 *
 * @param menuBar  Menu bar
 */
private JMenuBar createMenuBar() {

    // menu bar
    JMenuBar menuBar = new JMenuBar();

    // ----- menu file

    // menu item print
    JMenuItem menuItemPrint = new JMenuItem(I18n.getString("menuitem.print"));
    menuItemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
    menuItemPrint.setActionCommand("ac_print");
    menuItemPrint.addActionListener(this);

    // scale X
    JRadioButtonMenuItem scaleXRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_width"));
    scaleXRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
    scaleXRadioBut.addActionListener(new ScaleXListener());
    // scale Y
    JRadioButtonMenuItem scaleYRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_length"));
    scaleYRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.CTRL_MASK));
    scaleYRadioBut.addActionListener(new ScaleYListener());
    // scale fit
    JRadioButtonMenuItem scaleFitRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_to_fit"));
    scaleFitRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK));
    scaleFitRadioBut.addActionListener(new ScaleFitListener());
    // scale half
    JRadioButtonMenuItem scaleHalfRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_half"));
    scaleHalfRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK));
    scaleHalfRadioBut.addActionListener(new ScaleHalfListener());
    // scale double
    JRadioButtonMenuItem scale2RadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_2x"));
    scale2RadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
    scale2RadioBut.addActionListener(new Scale2Listener());
    // scale off
    JRadioButtonMenuItem scaleOffRadioBut = new JRadioButtonMenuItem(I18n.getString("print_scale_off"), true);
    scaleOffRadioBut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));

    ButtonGroup scaleSetGroup = new ButtonGroup();
    scaleSetGroup.add(scale2RadioBut);
    scaleSetGroup.add(scaleFitRadioBut);
    scaleSetGroup.add(scaleHalfRadioBut);
    scaleSetGroup.add(scaleOffRadioBut);
    scaleSetGroup.add(scaleXRadioBut);
    scaleSetGroup.add(scaleYRadioBut);

    // build complete menu print preferences
    JMenu menuPrintPref = new JMenu(I18n.getString("menuitem.print_preferences"), true);
    menuPrintPref.add(scaleXRadioBut);
    menuPrintPref.add(scaleYRadioBut);
    menuPrintPref.add(scaleFitRadioBut);
    menuPrintPref.add(scaleHalfRadioBut);
    menuPrintPref.add(scale2RadioBut);
    menuPrintPref.addSeparator();
    menuPrintPref.add(scaleOffRadioBut);

    // menu item exit
    JMenuItem menuItemExit = new JMenuItem(I18n.getString("menuitem.exit"));
    menuItemExit.setActionCommand("ac_exit");
    menuItemExit.addActionListener(this);

    // build complete menu file
    JMenu menuFile = new JMenu(I18n.getString("menu.file"));
    menuFile.add(menuItemPrint);
    menuFile.add(menuPrintPref);
    menuFile.addSeparator();
    menuFile.add(menuItemExit);

    // add menu to menu bar
    menuBar.add(menuFile);

    // ----- menu index

    // menu item new
    JMenuItem menuItemNewIndex = new JMenuItem(I18n.getString("menuitem.new_index"));
    menuItemNewIndex.setActionCommand("ac_newindex");
    menuItemNewIndex.addActionListener(this);
    // menu item new spider
    JMenuItem menuItemNewSpiderIndex = new JMenuItem(I18n.getString("menuitem.new_spider_index"));
    menuItemNewSpiderIndex.setActionCommand("ac_newspiderindex");
    menuItemNewSpiderIndex.addActionListener(this);
    // menu item manage
    JMenuItem menuItemManageIndex = new JMenuItem(I18n.getString("menuitem.manage_indexes"));
    menuItemManageIndex.setActionCommand("ac_manageindex");
    menuItemManageIndex.addActionListener(this);
    // menu item rebuild
    JMenuItem menuItemRebuildIndex = new JMenuItem(I18n.getString("menuitem.rebuild_all_indexes"));
    menuItemRebuildIndex.setActionCommand("ac_rebuildindexes");
    menuItemRebuildIndex.addActionListener(this);
    // menu item import
    JMenuItem menuItemImportIndex = new JMenuItem(I18n.getString("menuitem.import_index"));
    menuItemImportIndex.setActionCommand("ac_importindex");
    menuItemImportIndex.addActionListener(this);

    // build complete menu index
    JMenu indexMenu = new JMenu(I18n.getString("menu.index"));
    indexMenu.add(menuItemNewIndex);
    indexMenu.add(menuItemNewSpiderIndex);
    indexMenu.add(menuItemManageIndex);
    indexMenu.add(menuItemRebuildIndex);
    indexMenu.addSeparator();
    indexMenu.add(menuItemImportIndex);

    // add menu to menu bar
    menuBar.add(indexMenu);

    // ----- menu bookmark

    // menu item add
    JMenuItem menuItemAddBookmark = new JMenuItem(I18n.getString("menuitem.add_bookmark"));
    menuItemAddBookmark.setActionCommand("ac_addbookmark");
    menuItemAddBookmark.addActionListener(this);
    // menu item delete all
    JMenuItem menuItemDeleteAll = new JMenuItem(I18n.getString("menuitem.delete_all_bookmarks"));
    menuItemDeleteAll.setActionCommand("ac_deleteallbookmarks");
    menuItemDeleteAll.addActionListener(this);

    // build complete menu index
    bookMarkMenu = new JMenu(I18n.getString("menu.bookmarks"));
    bookMarkMenu.add(menuItemAddBookmark);
    bookMarkMenu.add(menuItemDeleteAll);
    bookMarkMenu.addSeparator();

    // add menu to menu bar
    menuBar.add(bookMarkMenu);

    // ----- menu report

    // menu item metadata report
    JMenuItem menuItemMetadataReport = new JMenuItem(I18n.getString("menuitem.metadata_report"));
    menuItemMetadataReport.setActionCommand("ac_metadata_report");
    menuItemMetadataReport.addActionListener(this);
    // menu item servlet report
    JMenuItem menuItemServletReport = new JMenuItem(I18n.getString("menuitem.servlet_log_report"));
    menuItemServletReport.setActionCommand("ac_servlet_log_report");
    menuItemServletReport.addActionListener(this);

    // build complete menu report
    JMenu reportMenu = new JMenu(I18n.getString("menu.reports"));
    reportMenu.add(menuItemMetadataReport);
    reportMenu.add(menuItemServletReport);

    // add menu to menu bar
    menuBar.add(reportMenu);

    // ----- menu tools

    // menu item makr cd
    JMenuItem menuItemMakeCD = new JMenuItem(I18n.getString("menuitem.make_cd"));
    menuItemMakeCD.setActionCommand("ac_makecd");
    menuItemMakeCD.addActionListener(this);
    // menu item setting
    JMenuItem menuItemSetting = new JMenuItem(I18n.getString("menuitem.settings"));
    menuItemSetting.setActionCommand("ac_settings");
    menuItemSetting.addActionListener(this);

    // build complete menu report
    JMenu menuTool = new JMenu(I18n.getString("menu.tools"));
    menuTool.add(menuItemMakeCD);
    menuTool.addSeparator();
    menuTool.add(menuItemSetting);

    // add menu to menu bar
    menuBar.add(menuTool);

    // ----- menu help

    // menu item search tip
    JMenuItem menuItemSearchTip = new JMenuItem(I18n.getString("menuitem.search_tips"));
    menuItemSearchTip.setActionCommand("ac_search_tips");
    menuItemSearchTip.addActionListener(this);
    // menu item about
    JMenuItem menuItemAbout = new JMenuItem(I18n.getString("menuitem.about"));
    menuItemAbout.setActionCommand("ac_about");
    menuItemAbout.addActionListener(this);

    // build complete menu help
    JMenu menuHelp = new JMenu(I18n.getString("menu.help"));
    menuHelp.add(menuItemSearchTip);
    menuHelp.add(menuItemAbout);

    // add menu to menu bar
    menuBar.add(menuHelp);

    // finished
    return menuBar;
}

From source file:org.jab.docsearch.DocSearch.java

private void addNewBookmark(SimpleBookmark sbm) {
    bookmarksList.add(sbm);/* w  w  w  . j  a  v  a2  s  .c o  m*/
    JMenuItem bmi = new JMenuItem(sbm.getDescription());
    bmi.setActionCommand(sbm.getURL());
    bmi.addActionListener(this);
    bookMarkMenu.add(bmi);
}

From source file:org.kepler.gui.MenuMapper.java

public static JMenuItem addMenuFor(String key, Action action, JComponent topLvlContainer,
        Map<String, JMenuItem> keplerMenuMap) {

    if (topLvlContainer == null) {
        if (isDebugging) {
            log.debug("NULL container received (eg JMenuBar) - returning NULL");
        }/*from www  .  j a  v a 2  s  .  c  o  m*/
        return null;
    }
    if (key == null) {
        if (isDebugging) {
            log.debug("NULL key received");
        }
        return null;
    }
    key = key.trim();

    if (key.length() < 1) {
        if (isDebugging) {
            log.debug("BLANK key received");
        }
        return null;
    }
    if (action == null && key.indexOf(MENU_SEPARATOR_KEY) < 0) {
        if (isDebugging) {
            log.debug("NULL action received, but was not a separator: " + key);
        }
        return null;
    }

    if (keplerMenuMap.containsKey(key)) {
        if (isDebugging) {
            log.debug("Menu already added; skipping: " + key);
        }
        return null;
    }

    // split delimited parts and ensure menus all exist
    String[] menuLevel = key.split(MENU_PATH_DELIMITER);

    int totLevels = menuLevel.length;

    // create a menu for each "menuLevel" if it doesn't already exist
    final StringBuffer nextLevelBuff = new StringBuffer();
    String prevLevelStr = null;
    JMenuItem leafMenuItem = null;

    for (int levelIdx = 0; levelIdx < totLevels; levelIdx++) {

        // save previous value
        prevLevelStr = nextLevelBuff.toString();

        String nextLevelStr = menuLevel[levelIdx];
        // get the index of the first MNEMONIC_SYMBOL
        int mnemonicIdx = nextLevelStr.indexOf(MNEMONIC_SYMBOL);
        char mnemonicChar = 0;

        // if an MNEMONIC_SYMBOL exists, remove all underscores. Then, idx
        // of
        // first underscore becomes idx of letter it used to precede - this
        // is the mnemonic letter
        if (mnemonicIdx > -1) {
            nextLevelStr = nextLevelStr.replaceAll(MNEMONIC_SYMBOL, "");
            mnemonicChar = nextLevelStr.charAt(mnemonicIdx);
        }
        if (levelIdx != 0) {
            nextLevelBuff.append(MENU_PATH_DELIMITER);
        }
        nextLevelBuff.append(nextLevelStr);

        // don't add multiple separators together...
        if (nextLevelStr.indexOf(MENU_SEPARATOR_KEY) > -1) {
            if (separatorJustAdded == false) {

                // Check if we're at the top level, since this makes sense
                // only for
                // context menu - we can't add a separator to a JMenuBar
                if (levelIdx == 0) {
                    if (topLvlContainer instanceof JContextMenu) {
                        ((JContextMenu) topLvlContainer).addSeparator();
                    }
                } else {
                    JMenu parent = (JMenu) keplerMenuMap.get(prevLevelStr);

                    if (parent != null) {
                        if (parent.getMenuComponentCount() < 1) {
                            if (isDebugging) {
                                log.debug("------ NOT adding separator to parent " + parent.getText()
                                        + ", since it does not contain any menu items");
                            }
                        } else {
                            if (isDebugging) {
                                log.debug("------ adding separator to parent " + parent.getText());
                            }
                            // add separator to parent
                            parent.addSeparator();
                            separatorJustAdded = true;
                        }
                    }
                }
            }
        } else if (!keplerMenuMap.containsKey(nextLevelBuff.toString())) {
            // If menu has not already been created, we need
            // to create it and then add it to the parent level...

            JMenuItem menuItem = null;

            // if we're at a "leaf node" - need to create a JMenuItem
            if (levelIdx == totLevels - 1) {

                // save old display name to use as actionCommand on
                // menuitem,
                // since some parts of PTII still
                // use "if (actionCommand.equals("SaveAs")) {..." etc
                String oldDisplayName = (String) action.getValue(Action.NAME);

                // action.putValue(Action.NAME, nextLevelStr);

                if (mnemonicChar > 0) {
                    action.putValue(GUIUtilities.MNEMONIC_KEY, new Integer(mnemonicChar));
                }

                // Now we look to see if it's a checkbox
                // menu item, or just a regular one
                String menuItemType = (String) (action.getValue(MENUITEM_TYPE));

                if (menuItemType != null && menuItemType == CHECKBOX_MENUITEM_TYPE) {
                    menuItem = new JCheckBoxMenuItem(action);
                } else {
                    menuItem = new JMenuItem(action);
                }

                // --------------------------------------------------------------
                /** @todo - setting menu names - TEMPORARY FIX - FIXME */
                // Currently, if we use the "proper" way of setting menu
                // names -
                // ie by using action.putValue(Action.NAME, "somename");,
                // then
                // the name appears on the port buttons on the toolbar,
                // making
                // them huge. As a temporary stop-gap, I am just setting the
                // new
                // display name using setText() instead of
                // action.putValue(..,
                // but this needs to be fixed elsewhere - we want to be able
                // to
                // use action.putValue(Action.NAME (ie uncomment the line
                // above
                // that reads:
                // action.putValue(Action.NAME, nextLevelStr);
                // and delete the line below that reads:
                // menuItem.setText(nextLevelStr);
                // otherwise this may bite us in future...
                menuItem.setText(nextLevelStr);
                // --------------------------------------------------------------

                // set old display name as actionCommand on
                // menuitem, for ptii backward-compatibility
                menuItem.setActionCommand(oldDisplayName);

                // add JMenuItem to the Action, so it can be accessed by
                // Action code
                action.putValue(NEW_JMENUITEM_KEY, menuItem);
                leafMenuItem = menuItem;
            } else {
                // if we're *not* at a "leaf node" - need to create a JMenu
                menuItem = new JMenu(nextLevelStr);
                if (mnemonicChar > 0) {
                    menuItem.setMnemonic(mnemonicChar);
                }
            }
            // level 0 is a special case, since the container (JMenuBar or
            // JContextMenu) is not a JMenu or a JMenuItem, so we can't
            // use the same code to add child to parent...
            if (levelIdx == 0) {
                if (topLvlContainer instanceof JMenuBar) {
                    // this handles JMenuBar menus
                    ((JMenuBar) topLvlContainer).add(menuItem);
                } else if (topLvlContainer instanceof JContextMenu) {
                    // this handles popup context menus
                    ((JContextMenu) topLvlContainer).add(menuItem);
                }
                // add to Map
                keplerMenuMap.put(nextLevelBuff.toString(), menuItem);
                separatorJustAdded = false;
            } else {
                JMenu parent = (JMenu) keplerMenuMap.get(prevLevelStr);
                if (parent != null) {
                    // add to parent
                    parent.add(menuItem);
                    // add to Map
                    keplerMenuMap.put(nextLevelBuff.toString(), menuItem);
                    separatorJustAdded = false;
                } else {
                    if (isDebugging) {
                        log.debug("Parent menu is NULL" + prevLevelStr);
                    }
                }
            }
        }
    }
    return leafMenuItem;
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @return//from   ww w .  j  a v a2 s  . c o m
 * @precondition hasComparisonOperator()
 */
public JPopupMenu newComparisonOperatorPopupMenu() {
    if (!hasComparisonOperator()) {
        throw new IllegalStateException();
    }
    final JPopupMenu result = new JPopupMenu(
            getSpringLocaleDelegate().getMessage("AbstractCollectableComponent.16", "Vergleichsoperator"));

    // 1. comparison operators:
    final ButtonGroup btngrpComparisonOperators = new ButtonGroup();

    final ItemListener itemlistener = new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent ev) {
            if (ev.getStateChange() == ItemEvent.SELECTED) {
                final String sOperatorName = ((AbstractButton) ev.getItem()).getActionCommand();
                setComparisonOperator(ComparisonOperator.getInstance(sOperatorName));
                runLocked(new Runnable() {
                    @Override
                    public void run() {
                        updateSearchConditionInModel();
                    }
                });
            }
        }
    };

    ComparisonOperator[] supportedComparisonOperators = getSupportedComparisonOperators();
    if (supportedComparisonOperators == null)
        return null;

    for (ComparisonOperator compop : supportedComparisonOperators) {
        JMenuItem mi = new JRadioButtonMenuItem(
                getSpringLocaleDelegate().getMessage(compop.getResourceIdForLabel(), null));
        mi.setActionCommand(compop.name());
        mi.setToolTipText(getSpringLocaleDelegate().getMessage(compop.getResourceIdForDescription(), null));
        result.add(mi);
        btngrpComparisonOperators.add(mi);
        mi.addItemListener(itemlistener);
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            for (int i = 0, n = result.getComponentCount(); i < n; i++) {
                Component c = result.getComponent(i);
                if (c instanceof JMenuItem && StringUtils.emptyIfNull(((JMenuItem) c).getActionCommand())
                        .equals(getComparisonOperator().name()))
                    ((JMenuItem) c).setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });

    // 2. right operand (value or other field):
    if (canDisplayComparisonWithOtherField()) {
        addRightOperandToPopupMenu(result, this);
    }

    return result;
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);//from  w w  w .j  a  v  a 2s .  com
    JMenuItem helpItem = new JMenuItem(ACTION_CMD_HELP);
    helpItem.addActionListener(this);
    helpItem.setActionCommand(ACTION_CMD_HELP);
    helpMenu.add(helpItem);

    return menuBar;
}

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *//*from  w  ww .j a v a  2  s. c  o  m*/
@Test
public void testBindKeyStrokes_JMenuBar() {
    JMenuBar menu = new JMenuBar();
    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);
    menu.add(parent);
    parent.add(child1);
    parent.add(child2);
    child1.add(grandchild1);
    child1.add(grandchild2);

    // bind
    shotcuts.bindKeyStrokes(menu);

    KeyStroke result = parent.getAccelerator();
    assertNull(result);

    result = child1.getAccelerator();
    assertNull(result);

    result = child2.getAccelerator();
    assertNull(result);

    KeyStroke expected = CTRL_P;
    result = grandchild1.getAccelerator();
    assertEquals(expected, result);

    expected = CTRL_X;
    result = grandchild2.getAccelerator();
    assertEquals(expected, result);
}

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *//*from  w  ww.  ja v  a 2  s.c  o m*/
@Test
public void testBindKeyStrokes_JMenuItem() {
    // case JMenuItem with no children
    JMenuItem item = new JMenuItem();
    item.setActionCommand(TEST_SAVE);
    KeyStroke expected = CTRL_S;
    KeyStroke result = item.getAccelerator();
    assertNull(result); // before binding
    shotcuts.bindKeyStrokes(item); // bind
    result = item.getAccelerator();
    assertEquals(expected, result); // after binding(1)

    item.setActionCommand(TEST_DELETE);
    shotcuts.bindKeyStrokes(item); // bind
    result = item.getAccelerator();
    assertNull(result); // after binding(2)

    item.setActionCommand(OUT_OF_LIST);
    item.setAccelerator(CTRL_D);
    shotcuts.bindKeyStrokes(item); // bind
    expected = CTRL_D;
    result = item.getAccelerator();
    assertEquals(expected, result); // after binding(3) - nothing has changed
}