Example usage for javax.swing JMenuBar getMenu

List of usage examples for javax.swing JMenuBar getMenu

Introduction

In this page you can find the example usage for javax.swing JMenuBar getMenu.

Prototype

public JMenu getMenu(int index) 

Source Link

Document

Returns the menu at the specified position in the menu bar.

Usage

From source file:org.pmedv.core.commands.OpenPerspectiveCommand.java

@Override
public void execute(ActionEvent e) {

    final ApplicationContext ctx = AppContext.getContext();
    final ApplicationWindow win = ctx.getBean(ApplicationWindow.class);
    final ApplicationWindowAdvisor advisor = ctx.getBean(ApplicationWindowAdvisor.class);

    final AbstractPerspective perspective = (AbstractPerspective) ctx.getBean(id);

    JMenuBar appMenuBar = win.getAppMenuBar();

    for (int i = 0; i < appMenuBar.getMenuCount(); i++) {

        JMenuWithId menu = (JMenuWithId) appMenuBar.getMenu(i);

        if (menu.getId() != null && (menu.getId().equals("common") || menu.getId().equals(perspective.ID)
                || menu.getId().equals("languages")))
            menu.setVisible(true);/*w w  w. j a  v a 2  s . c o m*/
        else
            menu.setVisible(false);
    }

    JToolBar appToolbar = win.getToolBar();

    for (int i = 0; i < appToolbar.getComponentCount(); i++) {

        if (appToolbar.getComponent(i) instanceof CmdJButton) {

            CmdJButton button = (CmdJButton) appToolbar.getComponent(i);

            if (button.getId().equals("common") || button.getId().equals(perspective.ID))
                button.setVisible(true);
            else
                button.setVisible(false);

        }

    }

    log.info("Setting current editor area to " + perspective.getEditorArea());

    advisor.setCurrentEditorArea(perspective.getEditorArea());
    advisor.setCurrentPerspective(perspective);

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {

            InputStream is = getClass().getClassLoader().getResourceAsStream("application.properties");
            Properties properties = new Properties();
            try {
                properties.load(is);
            } catch (IOException e1) {
                properties.setProperty("version", "not set");
            }

            // String title = resources.getResourceByKey(perspective.ID+".title");            
            // win.setTitle(configProvider.getConfig().getTitle()+" - "+title+" Version "+Constants.VERSION);      
            win.setTitle(AppContext.getName() + " " + properties.getProperty("version"));
            win.getLayoutPane().removeAll();
            win.getLayoutPane().add(perspective, BorderLayout.CENTER);
            win.getLayoutPane().revalidate();
            win.getLayoutPane().repaint();
        }

    });

}