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:SciTK.PlotXYZBlock.java

private void init(String x_label, String y_label, String window_title) {
    chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);/*ww  w  .  ja  v  a 2s  .  co  m*/

    // turn off borders of the plot:
    XYPlot p = chart.getXYPlot();
    p.getDomainAxis().setLowerMargin(0.0);
    p.getDomainAxis().setUpperMargin(0.0);
    p.getRangeAxis().setLowerMargin(0.0);
    p.getRangeAxis().setUpperMargin(0.0);

    // --------------------------------------------
    //          set up a lookup table
    // --------------------------------------------
    // this is how we render the block plots:
    XYBlockRenderer renderer = new XYBlockRenderer();
    // need to find max and min z of the data set:
    double min = 0;
    double max = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets
    {
        for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset
        {
            if (data.getZValue(i, j) < min)
                min = data.getZValue(i, j);
            else if (data.getZValue(i, j) > max)
                max = data.getZValue(i, j);
        }
    }
    // create paint scale using min and max values, default color black:
    LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black);
    // set up the LUT:
    double step_size = (max - min) / 255.; // step size for LUT
    for (int i = 0; i < 256; i++) {
        paintScale.add(min + i * step_size, new Color(i, i, i, 255));
    }
    renderer.setPaintScale(paintScale);
    // set this renderer to the plot:
    p.setRenderer(renderer);

    // --------------------------------------------
    //          set up a color bar
    // --------------------------------------------
    // create an array of display labels:
    num_labels = 10; // default to 10 labels on color bar
    double display_step_size = (max - min) / ((double) num_labels);
    String[] scale_bar_labels = new String[num_labels + 1];
    // to format numbers in scientific notation:
    DecimalFormat formater = new DecimalFormat("0.#E0");
    // create list of labesl:
    for (int i = 0; i <= num_labels; i++) {
        scale_bar_labels[i] = formater.format(min + i * display_step_size);
    }
    // create axis:
    SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels);
    scaleAxis.setRange(min, max);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);
    // set up the paint scale:
    psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background
    // set up frame with buffer region to allow text display
    psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0),
            new RectangleInsets(15, 10, 15, 10)));
    psl.setAxisOffset(5.0);
    // display on right side:
    psl.setPosition(RectangleEdge.RIGHT);
    // margin around color scale:
    psl.setMargin(new RectangleInsets(20, 15, 20, 15));
    // add to the chart so it will be displayed by default:
    chart.addSubtitle(psl);

    // --------------------------------------------
    //          WINDOW-RELATED UI
    // --------------------------------------------
    // set up the generic plot UI:
    super.window_title = window_title;
    super.initUI();

    // add another menu item
    JMenuBar mb = super.getJMenuBar(); // get the menu bar
    // find menu named "Plot"
    JMenu menu_plot = null;
    for (int i = 0; i < mb.getMenuCount(); i++) {
        if (mb.getMenu(i).getText() == "Plot")
            menu_plot = mb.getMenu(i);
    }
    // Add a new checkbox for the color scale bar
    JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale");
    menu_plot_scalebar.setToolTipText("Show color scale bar?");
    menu_plot_scalebar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            AbstractButton aButton = (AbstractButton) event.getSource();
            boolean selected = aButton.getModel().isSelected();
            setScaleBar(selected);
        }
    });
    // set appropirate checkbox state:
    menu_plot_scalebar.setState(true);
    if (menu_plot != null) // sanity check
        menu_plot.add(menu_plot_scalebar);

}

From source file:ca.phon.app.project.ProjectWindow.java

@Override
public void setJMenuBar(JMenuBar menu) {
    super.setJMenuBar(menu);

    JMenu projectMenu = new JMenu("Project");

    int projectMenuIndex = -1;
    // get the edit menu and add view commands
    for (int i = 0; i < menu.getMenuCount(); i++) {
        JMenu currentBar = menu.getMenu(i);

        if (currentBar != null && currentBar.getText() != null && currentBar.getText().equals("Workspace")) {
            projectMenuIndex = i + 1;/* ww  w .j  a va2 s. c o m*/
        }
    }

    if (projectMenuIndex > 0) {
        menu.add(projectMenu, projectMenuIndex);
    }

    // refresh lists 
    final RefreshAction refreshItem = new RefreshAction(this);
    projectMenu.add(refreshItem);
    projectMenu.addSeparator();

    // create corpus item
    final NewCorpusAction newCorpusItem = new NewCorpusAction(this);
    projectMenu.add(newCorpusItem);

    //       create corpus item
    final NewSessionAction newSessionItem = new NewSessionAction(this);
    projectMenu.add(newSessionItem);

    projectMenu.addSeparator();

    final AnonymizeAction anonymizeParticipantInfoItem = new AnonymizeAction(this);
    projectMenu.add(anonymizeParticipantInfoItem);

    final CheckTranscriptionsAction repairItem = new CheckTranscriptionsAction(this);
    projectMenu.add(repairItem);

    // merge/split sessions
    final DeriveSessionAction deriveItem = new DeriveSessionAction(this);
    projectMenu.add(deriveItem);

    final JMenu teamMenu = new JMenu("Team");
    teamMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            teamMenu.removeAll();
            if (getProject() != null) {
                final ProjectGitController gitController = new ProjectGitController(getProject());
                if (gitController.hasGitFolder()) {
                    teamMenu.add(new CommitAction(ProjectWindow.this));

                    teamMenu.addSeparator();

                    teamMenu.add(new PullAction(ProjectWindow.this));
                    teamMenu.add(new PushAction(ProjectWindow.this));

                } else {
                    final InitAction initRepoAct = new InitAction(ProjectWindow.this);
                    teamMenu.add(initRepoAct);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {

        }

        @Override
        public void menuCanceled(MenuEvent e) {

        }
    });
    projectMenu.addSeparator();
    projectMenu.add(teamMenu);
}

From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java

/**
 * Re maps help links for a couple items on iReport Help menu
 *//*from   w  w w. j ava2s .  c om*/
public void fixUpHelpLinks() {
    int helpMenuIdx = 9;
    int homePageItemIdx = 0;
    int helpItemIdx = 1;
    final String jasperHomePage = "http://jasperforge.org/";

    JMenuBar mb = getJMenuBar();
    JMenu hm = mb.getMenu(helpMenuIdx);
    homePageItem = hm.getItem(homePageItemIdx);
    //remove original listener linked to bad url
    ActionListener[] als = homePageItem.getActionListeners();
    for (int l = 0; l < als.length; l++) {
        homePageItem.removeActionListener(als[l]);
    }
    //add new listener
    homePageItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            openUrl(jasperHomePage);
        }

    });

    JMenuItem helpPageItem = hm.getItem(helpItemIdx);
    als = helpPageItem.getActionListeners();
    //remove original listener linked to bad url
    for (int l = 0; l < als.length; l++) {
        helpPageItem.removeActionListener(als[l]);
    }
    HelpMgr.registerComponent(helpPageItem, "iReport");

    setIconImage(IconManager.getIcon("SPIReports", IconManager.IconSize.NonStd).getImage());

}

From source file:org.fhcrc.cpl.viewer.gui.ProteinMatcherFrame.java

/**
 * initial setup of UI and class variables
 *//*from w  w w  .  j  a va 2 s.  com*/
public void initialize() {
    _ms1Features = getMS1Features();
    if (_ms1Features == null) {
        ApplicationContext.infoMessage(TextProvider.getText("AMT_REQUIRES_DISPLAYED_FEATURES"));
        this.setVisible(false);
        this.dispose();
        return;
    }
    this.setVisible(true);

    //graphical stuff
    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/gui/ProteinMatcherMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    Container contentPanel;
    try {
        contentPanel = Localizer.renderSwixml("org/fhcrc/cpl/viewer/gui/ProteinMatcherFrame.xml", this);
        setContentPane(contentPanel);
        pack();
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_CREATING_DIALOG"), x);
        throw new RuntimeException(x);
    }

    Dimension d = contentPanel.getPreferredSize();
    setBounds(600, 100, (int) d.getWidth(), (int) d.getHeight());

    ListenerHelper helper = new ListenerHelper(this);
    helper.addListener(tblProteins.getSelectionModel(), "tblProteinsModel_valueChanged");
    helper.addListener(buttonFilterProteins, "buttonFilterProteins_actionPerformed");
    //hitting enter in the text field should act the same as hitting the filter button.  Hack, focus, whatever
    helper.addListener(textProteinPrefix, "buttonFilterProteins_actionPerformed");
    helper.addListener(tblFeatures.getSelectionModel(), "tblFeaturesModel_valueChanged");

    _proteinTableModel = new ProteinTableModel();
    tblProteins.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tblProteins.setAutoCreateColumnsFromModel(false);
    tblProteins.setModel(_proteinTableModel);
    tblProteins.setColumnModel(_proteinTableModel.columnModel);

    if (null != displayMatchedUnmatchedComboBox) {
        //TODO: should really use TextProvider here, and use an internal value for determining state
        displayMatchedUnmatchedComboBox.addItem("matched");
        displayMatchedUnmatchedComboBox.addItem("unmatched peptides");
        displayMatchedUnmatchedComboBox.addItem("unmatched ms2");
        helper.addListener(displayMatchedUnmatchedComboBox, "displayMatchedUnmatchedComboBox_actionPerformed");
    }

    _featureTableModel = new FeatureTableModel();
    tblFeatures.setModel(_featureTableModel);

    tblFeatures.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tblFeatures.setAutoCreateColumnsFromModel(false);

    ProteinTablePopupMenu proteinPopup = new ProteinTablePopupMenu();

    tblProteins.setComponentPopupMenu(proteinPopup);
    proteinLabel.setComponentPopupMenu(proteinPopup);
}

From source file:org.fhcrc.cpl.viewer.quant.gui.QuantitationReviewer.java

/**
 * Initialize all GUI components and display the UI
 *//*www .  j a  v a2 s  . c om*/
protected void initGUI() {
    settingsCLM = new ProteinQuantChartsCLM(false);

    setTitle("Qurate");
    try {
        setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewer.xml", this);
        assert null != contentPanel;
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    //Menu
    openFileAction = new OpenFileAction(this);
    createChartsAction = new CreateChartsAction();
    filterPepXMLAction = new FilterPepXMLAction(this);
    proteinSummaryAction = new ProteinSummaryAction(this);

    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewerMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    //Global stuff
    setSize(fullWidth, fullHeight);
    setContentPane(contentPanel);
    ListenerHelper helper = new ListenerHelper(this);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    leftPanel.setLayout(new GridBagLayout());
    leftPanel.setBorder(BorderFactory.createLineBorder(Color.gray));

    //Properties panel stuff
    propertiesTable = new QuantEvent.QuantEventPropertiesTable();
    propertiesScrollPane = new JScrollPane();
    propertiesScrollPane.setViewportView(propertiesTable);
    propertiesScrollPane.setMinimumSize(new Dimension(propertiesWidth, propertiesHeight));

    //event summary table; disembodied
    eventSummaryTable = new QuantEventsSummaryTable();
    eventSummaryTable.setVisible(true);
    ListSelectionModel tableSelectionModel = eventSummaryTable.getSelectionModel();
    tableSelectionModel.addListSelectionListener(new EventSummaryTableListSelectionHandler());
    JScrollPane eventSummaryScrollPane = new JScrollPane();
    eventSummaryScrollPane.setViewportView(eventSummaryTable);
    eventSummaryScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventSummaryFrame = new Frame("All Events");
    eventSummaryFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            eventSummaryFrame.setVisible(false);
        }
    });
    eventSummaryFrame.setSize(950, 450);
    eventSummaryFrame.add(eventSummaryScrollPane);

    //fields related to navigation
    navigationPanel = new JPanel();
    backButton = new JButton("<");
    backButton.setToolTipText("Previous Event");
    backButton.setMaximumSize(new Dimension(50, 30));
    backButton.setEnabled(false);
    forwardButton = new JButton(">");
    forwardButton.setToolTipText("Next Event");
    forwardButton.setMaximumSize(new Dimension(50, 30));
    forwardButton.setEnabled(false);
    showEventSummaryButton = new JButton("Show All");
    showEventSummaryButton.setToolTipText("Show all events in a table");
    showEventSummaryButton.setEnabled(false);

    helper.addListener(backButton, "buttonBack_actionPerformed");
    helper.addListener(forwardButton, "buttonForward_actionPerformed");
    helper.addListener(showEventSummaryButton, "buttonShowEventSummary_actionPerformed");

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    gbc.anchor = GridBagConstraints.WEST;
    navigationPanel.add(backButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    navigationPanel.add(forwardButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    navigationPanel.add(showEventSummaryButton, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    navigationPanel.setBorder(BorderFactory.createTitledBorder("Event"));
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Fields related to curation of events
    curationPanel = new JPanel();
    curationPanel.setLayout(new GridBagLayout());
    curationPanel.setBorder(BorderFactory.createTitledBorder("Curation"));
    //Quantitation curation
    JPanel quantCurationPanel = new JPanel();
    quantCurationPanel.setLayout(new GridBagLayout());
    quantCurationPanel.setBorder(BorderFactory.createTitledBorder("Quantitation"));
    quantCurationButtonGroup = new ButtonGroup();
    JRadioButton unknownRadioButton = new JRadioButton("?");
    JRadioButton goodRadioButton = new JRadioButton("Good");
    JRadioButton badRadioButton = new JRadioButton("Bad");
    onePeakRatioRadioButton = new JRadioButton("1-Peak");

    unknownRadioButton.setEnabled(false);
    goodRadioButton.setEnabled(false);
    badRadioButton.setEnabled(false);
    onePeakRatioRadioButton.setEnabled(false);

    quantCurationButtonGroup.add(unknownRadioButton);
    quantCurationButtonGroup.add(goodRadioButton);
    quantCurationButtonGroup.add(badRadioButton);
    quantCurationButtonGroup.add(onePeakRatioRadioButton);

    unknownRadioButtonModel = unknownRadioButton.getModel();
    goodRadioButtonModel = goodRadioButton.getModel();
    badRadioButtonModel = badRadioButton.getModel();
    onePeakRadioButtonModel = onePeakRatioRadioButton.getModel();

    helper.addListener(unknownRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(goodRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(badRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(onePeakRadioButtonModel, "buttonCuration_actionPerformed");

    gbc.anchor = GridBagConstraints.WEST;
    quantCurationPanel.add(unknownRadioButton, gbc);
    quantCurationPanel.add(badRadioButton, gbc);
    quantCurationPanel.add(goodRadioButton, gbc);
    quantCurationPanel.add(onePeakRatioRadioButton, gbc);

    gbc.anchor = GridBagConstraints.PAGE_START;
    //ID curation
    JPanel idCurationPanel = new JPanel();
    idCurationPanel.setLayout(new GridBagLayout());
    idCurationPanel.setBorder(BorderFactory.createTitledBorder("ID"));
    idCurationButtonGroup = new ButtonGroup();
    JRadioButton idUnknownRadioButton = new JRadioButton("?");
    JRadioButton idGoodRadioButton = new JRadioButton("Good");
    JRadioButton idBadRadioButton = new JRadioButton("Bad");
    idUnknownRadioButton.setEnabled(false);
    idGoodRadioButton.setEnabled(false);
    idBadRadioButton.setEnabled(false);

    idCurationButtonGroup.add(idUnknownRadioButton);
    idCurationButtonGroup.add(idGoodRadioButton);
    idCurationButtonGroup.add(idBadRadioButton);
    idUnknownRadioButtonModel = idUnknownRadioButton.getModel();
    idGoodRadioButtonModel = idGoodRadioButton.getModel();
    idBadRadioButtonModel = idBadRadioButton.getModel();
    helper.addListener(idUnknownRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idGoodRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idBadRadioButton, "buttonIDCuration_actionPerformed");
    gbc.anchor = GridBagConstraints.WEST;
    idCurationPanel.add(idUnknownRadioButton, gbc);
    idCurationPanel.add(idBadRadioButton, gbc);
    idCurationPanel.add(idGoodRadioButton, gbc);

    gbc.gridwidth = GridBagConstraints.RELATIVE;
    curationPanel.add(quantCurationPanel, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    curationPanel.add(idCurationPanel, gbc);

    //curation comment
    commentTextField = new JTextField();
    commentTextField.setToolTipText("Comment on this event");
    //saves after every keypress.  Would be more efficient to save when navigating away or saving to file
    commentTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (quantEvents == null)
                return;
            QuantEvent quantEvent = quantEvents.get(displayedEventIndex);
            //save the comment, being careful about tabs and new lines
            quantEvent.setComment(commentTextField.getText().replace("\t", " ").replace("\n", " "));
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });
    curationPanel.add(commentTextField, gbc);

    assessmentPanel = new JPanel();
    assessmentPanel.setLayout(new GridBagLayout());
    assessmentPanel.setBorder(BorderFactory.createTitledBorder("Algorithmic Assessment"));
    assessmentTypeTextField = new JTextField();
    assessmentTypeTextField.setEditable(false);
    assessmentPanel.add(assessmentTypeTextField, gbc);
    assessmentDescTextField = new JTextField();
    assessmentDescTextField.setEditable(false);
    assessmentPanel.add(assessmentDescTextField, gbc);

    //Theoretical peak distribution
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    theoreticalPeaksPanel = new JPanel();
    theoreticalPeaksPanel.setBorder(BorderFactory.createTitledBorder("Theoretical Peaks"));
    theoreticalPeaksPanel.setLayout(new GridBagLayout());
    theoreticalPeaksPanel.setMinimumSize(new Dimension(leftPanelWidth - 10, theoreticalPeaksPanelHeight));
    theoreticalPeaksPanel.setMaximumSize(new Dimension(1200, theoreticalPeaksPanelHeight));
    showTheoreticalPeaks();

    //Add everything to the left panel
    gbc.insets = new Insets(0, 5, 0, 5);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    leftPanel.addComponentListener(new LeftPanelResizeListener());
    gbc.weighty = 10;
    gbc.fill = GridBagConstraints.VERTICAL;
    leftPanel.add(propertiesScrollPane, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_END;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(assessmentPanel, gbc);
    leftPanel.add(theoreticalPeaksPanel, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(curationPanel, gbc);
    leftPanel.add(navigationPanel, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Chart display
    multiChartDisplay = new TabbedMultiChartDisplayPanel();
    multiChartDisplay.setResizeDelayMS(0);

    rightPanel.addComponentListener(new RightPanelResizeListener());
    rightPanel.add(multiChartDisplay, gbc);

    //status message
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    //paranoia.  Sometimes it seems Qurate doesn't exit when you close every window
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == WindowEvent.WINDOW_CLOSED) {
                dispose();
                System.exit(0);
            }
        }
    });

}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java

protected static void setAppLock(final boolean lock) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JMenuBar menuBar = (JMenuBar) UIRegistry.get(UIRegistry.MENUBAR);
            for (int m = 0; m < menuBar.getMenuCount(); m++) {
                if (isSystemMenu(menuBar, m)) {
                    menuBar.getMenu(m).setEnabled(!lock);
                } else if (isTabsMenu(menuBar, m)) {
                    menuBar.getMenu(m).setEnabled(!lock);
                }//from  ww w  . ja v a  2  s  .c o m
            }
        }
    });
}

From source file:no.java.ems.client.swing.EmsClient.java

private JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu();
    fileMenu.setName("menus.file");
    fileMenu.add(new DelegatingAction("new", tabs));
    fileMenu.addSeparator();// w w  w.  j  a  v a2s. co  m
    fileMenu.add(new DelegatingAction("open", tabs));
    fileMenu.addSeparator();
    fileMenu.add(new DelegatingAction("refresh", tabs));
    fileMenu.addSeparator();
    fileMenu.add(new CloseTabAction());
    fileMenu.addSeparator();
    fileMenu.add(saveAction);
    fileMenu.addSeparator();
    fileMenu.add(logInAction);
    fileMenu.add(logOutAction);
    if (!SystemUtils.IS_OS_MAC) {
        fileMenu.addSeparator();
        fileMenu.add(exitAction);
    }
    menuBar.add(fileMenu);
    JMenu editMenu = new JMenu();
    editMenu.setName("menus.edit");
    editMenu.add(undoAction);
    editMenu.add(redoAction);
    editMenu.addSeparator();
    editMenu.add(new DelegatingAction("cut", tabs));
    editMenu.add(new DelegatingAction("copy", tabs));
    editMenu.add(new DelegatingAction("paste", tabs));
    editMenu.add(new DelegatingAction("delete", tabs));
    editMenu.addSeparator();
    editMenu.add(new DelegatingAction("addTags", tabs));
    editMenu.add(new DelegatingAction("replaceTags", tabs));
    editMenu.add(new DelegatingAction("addKeywords", tabs));
    editMenu.add(new DelegatingAction("replaceKeywords", tabs));
    menuBar.add(editMenu);
    if (SystemUtils.IS_OS_MAC) {
        for (int index = 0; index < menuBar.getMenuCount(); index++) {
            removeIcons(menuBar.getMenu(index));
        }
    }
    return menuBar;
}

From source file:org.jivesoftware.sparkimpl.plugin.viewer.PluginViewer.java

public void initialize() {
    // Add Plugins Menu
    JMenuBar menuBar = SparkManager.getMainWindow().getJMenuBar();

    // Get last menu which is help
    JMenu sparkMenu = menuBar.getMenu(0);

    JMenuItem viewPluginsMenu = new JMenuItem();

    Action viewAction = new AbstractAction() {
        private static final long serialVersionUID = 6518407602062984752L;

        public void actionPerformed(ActionEvent e) {
            invokeViewer();/*from w w w.  j  av  a  2s.  c om*/
        }
    };

    viewAction.putValue(Action.NAME, Res.getString("menuitem.plugins"));
    viewAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.PLUGIN_IMAGE));
    viewPluginsMenu.setAction(viewAction);

    sparkMenu.insert(viewPluginsMenu, 2);
}

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

public void init() {

    if (_tableauFrameInstance == null) {
        log.error(/*from  w w w.j  a  va2s . co m*/
                "MenuMapper cannot proceed, due to one or more NULL values:" + "\nptiiMenubar = " + _ptiiMenubar
                        + "\ntableauFrameInstance = " + _tableauFrameInstance + "\ndefaulting to PTII menus");

        return;
    }

    // First, we need to make sure PTII has finished constructing its menus.
    // Those menus are created and assembled in a thread that is started in
    // the
    // pack() method of ptolemy.gui.Top. As that thread finishes, it adds
    // the
    // new ptii JMenuBar to the frame - so we test for that here, and don't
    // proceed until the frame has the new JMenuBar added
    // For safety, so we don't have an infinite loop, we also set a safety
    // counter:
    // maxWaitMS is the longest the app waits for the ptii
    // menus to be added, before it continues anyway.
    final int maxWaitMS = 500;
    // sleepTimeMS is the amount of time it sleeps per loop:
    final int sleepTimeMS = 5;
    // ////
    final int maxLoops = maxWaitMS / sleepTimeMS;
    int safetyCounter = 0;

    while (safetyCounter++ < maxLoops && !_tableauFrameInstance.isMenuPopulated()) {

        if (isDebugging) {
            log.debug("Waiting for PTII menus to be created... " + safetyCounter);
        }
        try {
            Thread.sleep(sleepTimeMS);
        } catch (Exception e) {
            // ignore
        }
    }

    JMenuBar _keplerMenubar = null;
    if (_ptiiMenubar == null) {
        _ptiiMenubar = _tableauFrameInstance.getJMenuBar();
    }

    if (_ptiiMenubar != null) {

        // gets here if a PTII menubar has been added to frame...

        // 1) Now PTII has finished constructing its menus, get all
        // menu items and put them in a Map for easier access later...
        _ptiiMenuActionsMap = getPTIIMenuActionsMap();
        Map<String, Action> ptiiMenuActionsMap = _ptiiMenuActionsMap;

        // 2) Now we have all the PTII menu items, get the
        // Kepler-specific menu mappings from the preferences file,
        // then go thru the Kepler menu mappings and
        // populate the new menubar with Kepler menus,
        // creating any new menu items that don't exist yet

        // this is a Map that will be used to keep track of
        // what we have added to the menus, and in what order
        _keplerMenubar = createKeplerMenuBar(ptiiMenuActionsMap);

        if (_keplerMenubar != null) {

            // First, look to see if any menus are empty. If
            // they are, remove the top-level menu from the menubar...
            // ** NOTE - do these by counting *down* to zero, otherwise the
            // menus'
            // indices change dynamically as we remove menus, causing
            // errors!
            for (int m = _keplerMenubar.getMenuCount() - 1; m >= 0; m--) {
                JMenu nextMenu = _keplerMenubar.getMenu(m);
                if (nextMenu.getMenuComponentCount() < 1) {
                    if (isDebugging) {
                        log.debug("deleting empty menu: " + nextMenu.getText());
                    }
                    _keplerMenubar.remove(nextMenu);
                }
            }
            // hide the ptii menubar
            _tableauFrameInstance.hideMenuBar();

            // add the new menu bar
            _tableauFrameInstance.setJMenuBar(_keplerMenubar);
        } else {
            log.error("Problem creating Kepler menus - defaulting to PTII menus");
        }

    } else {
        // gets here if a PTII menubar has *NOT* been added to frame...
        // Therefore, this frame doesn't have a menubar by default,
        // so we probably shouldn't add one, for now, at least

        // hide the ptii menubar (may not be necessary)
        _tableauFrameInstance.hideMenuBar();

        // add the new menu bar (may not be necessary)
        _tableauFrameInstance.setJMenuBar(null);
    }
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java

/**
  * Creates the menu bar.// w  ww  . ja  v  a  2s . co  m
  * 
  * @return The menu bar.
  */
private JMenuBar createMenuBar() {
    TaskBar tb = ImporterAgent.getRegistry().getTaskBar();
    JMenuBar bar = tb.getTaskBarMenuBar();
    if (!model.isMaster())
        return bar;
    JMenu[] existingMenus = new JMenu[bar.getMenuCount()];
    for (int i = 0; i < existingMenus.length; i++) {
        existingMenus[i] = bar.getMenu(i);
    }

    bar.removeAll();
    bar.add(createFileMenu());
    for (int i = 0; i < existingMenus.length; i++) {
        if (i != TaskBar.FILE_MENU)
            bar.add(existingMenus[i]);
    }
    return bar;
}