Search in sources :

Example 1 with MenuElement

use of javax.swing.MenuElement in project zaproxy by zaproxy.

the class MainPopupMenu method setVisible.

/**
	 * {@inheritDoc}
	 * <p>
	 * Overridden to call the method {@code ExtensionPopupMenuComponent#dismissed(ExtensionPopupMenuComponent)} of child
	 * {@code ExtensionPopupMenuComponent}s when the pop up menu is hidden.
	 * 
	 * @see ExtensionPopupMenuComponent#dismissed(ExtensionPopupMenuComponent)
	 */
@Override
public void setVisible(boolean b) {
    super.setVisible(b);
    if (!b) {
        ExtensionPopupMenuComponent selectedMenuComponent = null;
        if (pathSelectedMenu != null) {
            MenuElement selectedMenuElement = pathSelectedMenu[pathSelectedMenu.length - 1];
            if (PopupMenuUtils.isExtensionPopupMenuComponent(selectedMenuElement)) {
                selectedMenuComponent = (ExtensionPopupMenuComponent) selectedMenuElement;
            }
            pathSelectedMenu = null;
        }
        for (int i = 0; i < getComponentCount(); i++) {
            Component component = getComponent(i);
            if (PopupMenuUtils.isExtensionPopupMenuComponent(component)) {
                ((ExtensionPopupMenuComponent) component).dismissed(selectedMenuComponent);
            }
        }
    }
}
Also used : Component(java.awt.Component) ExtensionPopupMenuComponent(org.zaproxy.zap.view.popup.ExtensionPopupMenuComponent) MenuElement(javax.swing.MenuElement) ExtensionPopupMenuComponent(org.zaproxy.zap.view.popup.ExtensionPopupMenuComponent)

Example 2 with MenuElement

use of javax.swing.MenuElement in project JMRI by JMRI.

the class AudioTableAction method setMenuBar.

@Override
public void setMenuBar(BeanTableFrame f) {
    JMenuBar menuBar = f.getJMenuBar();
    ResourceBundle rbapps = ResourceBundle.getBundle("apps.AppsBundle");
    MenuElement[] subElements;
    JMenu fileMenu = null;
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
        if (menuBar.getComponent(i) instanceof JMenu) {
            if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuFile"))) {
                fileMenu = menuBar.getMenu(i);
            }
        }
    }
    if (fileMenu == null) {
        return;
    }
    subElements = fileMenu.getSubElements();
    for (MenuElement subElement : subElements) {
        MenuElement[] popsubElements = subElement.getSubElements();
        for (MenuElement popsubElement : popsubElements) {
            if (popsubElement instanceof JMenuItem) {
                if (((JMenuItem) popsubElement).getText().equals(rbapps.getString("PrintTable"))) {
                    JMenuItem printMenu = (JMenuItem) popsubElement;
                    fileMenu.remove(printMenu);
                    break;
                }
            }
        }
    }
    fileMenu.add(atp.getPrintItem());
}
Also used : ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem) MenuElement(javax.swing.MenuElement) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 3 with MenuElement

use of javax.swing.MenuElement in project jmeter by apache.

the class MainFrame method closeMenu.

/**
     * Close the currently selected menu.
     */
public void closeMenu() {
    if (menuBar.isSelected()) {
        MenuElement[] menuElement = menuBar.getSubElements();
        if (menuElement != null) {
            for (MenuElement element : menuElement) {
                JMenu menu = (JMenu) element;
                if (menu.isSelected()) {
                    menu.setPopupMenuVisible(false);
                    menu.setSelected(false);
                    break;
                }
            }
        }
    }
}
Also used : MenuElement(javax.swing.MenuElement) JMenu(javax.swing.JMenu)

Example 4 with MenuElement

use of javax.swing.MenuElement in project jmeter by apache.

the class JMeterMenuBar method updateMenuElement.

/**
     * <p>Refreshes all texts in the menu and all submenus to a new locale.</p>
     *
     * <p>Assumes that the item name is set to the resource key, so the resource can be retrieved.
     * Certain action types do not follow this rule, @see JMeterMenuBar#isNotResource(String)</p>
     *
     * The Language Change event assumes that the name is the same as the locale name,
     * so this additionally means that all supported locales must be defined as resources.
     *
     */
private void updateMenuElement(MenuElement menu) {
    Component component = menu.getComponent();
    final String compName = component.getName();
    if (compName != null) {
        for (MenuCreator menuCreator : menuCreators) {
            if (menuCreator.localeChanged(menu)) {
                return;
            }
        }
        if (component instanceof JMenu) {
            final JMenu jMenu = (JMenu) component;
            if (isResource(jMenu.getActionCommand())) {
                jMenu.setText(JMeterUtils.getResString(compName));
            }
        } else {
            final JMenuItem jMenuItem = (JMenuItem) component;
            if (isResource(jMenuItem.getActionCommand())) {
                jMenuItem.setText(JMeterUtils.getResString(compName));
            } else if (ActionNames.CHANGE_LANGUAGE.equals(jMenuItem.getActionCommand())) {
                jMenuItem.setText(JMeterUtils.getLocaleString(compName));
            }
        }
    }
    for (MenuElement subElement : menu.getSubElements()) {
        updateMenuElement(subElement);
    }
}
Also used : MenuCreator(org.apache.jmeter.gui.plugin.MenuCreator) JComponent(javax.swing.JComponent) Component(java.awt.Component) JMenuItem(javax.swing.JMenuItem) MenuElement(javax.swing.MenuElement) JMenu(javax.swing.JMenu)

Aggregations

MenuElement (javax.swing.MenuElement)4 JMenu (javax.swing.JMenu)3 Component (java.awt.Component)2 JMenuItem (javax.swing.JMenuItem)2 ResourceBundle (java.util.ResourceBundle)1 JComponent (javax.swing.JComponent)1 JMenuBar (javax.swing.JMenuBar)1 MenuCreator (org.apache.jmeter.gui.plugin.MenuCreator)1 ExtensionPopupMenuComponent (org.zaproxy.zap.view.popup.ExtensionPopupMenuComponent)1