Example usage for javax.swing JMenuItem setEnabled

List of usage examples for javax.swing JMenuItem setEnabled

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The enabled state of the component.")
public void setEnabled(boolean b) 

Source Link

Document

Enables or disables the menu item.

Usage

From source file:com.projity.menu.MenuManager.java

public void setActionEnabled(String id, boolean enable) {
    Collection buttons = toolBarFactory.getButtonsFromId(id);
    if (buttons != null) {
        Iterator i = buttons.iterator();
        while (i.hasNext()) {
            AbstractButton button = (AbstractButton) i.next();
            if (button != null)
                button.setEnabled(enable);
        }//from  ww  w . java2s. co  m
    }
    JMenuItem menuItem = menuFactory.getMenuItemFromId(id);
    if (menuItem != null)
        menuItem.setEnabled(enable);
}

From source file:be.fedict.eid.tsl.tool.TslTool.java

private JMenuItem addActionMenuItem(String text, int mnemonic, String actionCommand, JMenu menu,
        boolean enabled) {
    JMenuItem menuItem = new JMenuItem(text);
    menuItem.setMnemonic(mnemonic);// www  . j a  v a 2s .  c  o  m
    menuItem.setActionCommand(actionCommand);
    menuItem.addActionListener(this);
    menuItem.setEnabled(enabled);
    menu.add(menuItem);
    return menuItem;
}

From source file:de.codesourcery.eve.skills.ui.utils.PopupMenuBuilder.java

protected int populateMenu() {

    int itemCount = 0;
    for (Object obj : this.entries) {
        if (obj == SEPARATOR) {
            popupMenu.addSeparator();/*from ww w .  j ava 2  s  .  c  o  m*/
        } else {
            final MyMenuItem item = (MyMenuItem) obj;

            final Action action = item.getAction();

            final boolean isEnabled = action.isEnabled();

            if (isEnabled || action instanceof IActionWithDisabledText) {
                final JMenuItem menuItem = new JMenuItem(action);

                final String text;
                if (isEnabled) {
                    text = item.getLabel();
                } else {
                    text = ((IActionWithDisabledText) action).getDisabledText();
                    // do not render action that returns a blank/empty label
                    if (StringUtils.isBlank(text)) {
                        continue;
                    }
                    menuItem.setEnabled(false);
                }
                menuItem.setText(text);
                popupMenu.add(menuItem);
                itemCount++;
            }
        }
    }
    return itemCount;
}

From source file:com.digitalgeneralists.assurance.ui.MainWindow.java

private void setMenuState(int menuIndex, Boolean enabled, Boolean ignoreExceptions) {
    JMenu relevantMenu = this.menuBar.getMenu(menuIndex);

    if (relevantMenu != null) {
        for (int i = 0; i < relevantMenu.getItemCount(); i++) {
            JMenuItem item = relevantMenu.getItem(i);
            // NOTE: I don't like how Swing manages menus.
            if (item != null) {
                if (ignoreExceptions
                        || (!AssuranceActions.newScanDefinitonAction.equals(item.getActionCommand()))) {
                    item.setEnabled(enabled);
                }/*w  w w  .  ja v  a2s. c om*/
            }
        }
    }
}

From source file:es.emergya.ui.gis.FleetControlMapViewer.java

@Override
protected JPopupMenu getContextMenu() {
    JPopupMenu menu = new JPopupMenu();

    menu.setBackground(Color.decode("#E8EDF6"));

    // Ttulo/*from   ww  w.  j  ava  2 s .  co m*/
    final JMenuItem titulo = new JMenuItem(i18n.getString("map.menu.titulo.puntoGenerico"));
    titulo.setFont(LogicConstants.deriveBoldFont(10.0f));
    titulo.setBackground(Color.decode("#A4A4A4"));
    titulo.setFocusable(false);

    menu.add(titulo);

    menu.addSeparator();

    // Actualizar posicin
    final JMenuItem gps = new JMenuItem(i18n.getString("map.menu.gps"), KeyEvent.VK_P);
    gps.setIcon(LogicConstants.getIcon("menucontextual_icon_actualizargps"));
    menu.add(gps);
    gps.addActionListener(this);
    gps.setEnabled(false);

    menu.addSeparator();

    // Mostrar ms cercanos
    final JMenuItem mmc = new JMenuItem(i18n.getString("map.menu.showNearest"), KeyEvent.VK_M);
    mmc.setIcon(LogicConstants.getIcon("menucontextual_icon_mascercano"));
    mmc.addActionListener(this);
    menu.add(mmc);
    // Centrar aqui
    final JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C);
    cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar"));
    cent.addActionListener(this);
    menu.add(cent);
    // Nueva Incidencia
    final JMenuItem newIncidence = new JMenuItem(i18n.getString("map.menu.newIncidence"), KeyEvent.VK_I);
    newIncidence.setIcon(LogicConstants.getIcon("menucontextual_icon_newIncidence"));
    newIncidence.addActionListener(this);
    menu.add(newIncidence);
    // Calcular ruta desde aqui
    final JMenuItem from = new JMenuItem(i18n.getString("map.menu.route.from"), KeyEvent.VK_D);
    from.setIcon(LogicConstants.getIcon("menucontextual_icon_origenruta"));
    from.addActionListener(this);
    menu.add(from);
    // Calcular ruta hasta aqui
    final JMenuItem to = new JMenuItem(i18n.getString("map.menu.route.to"), KeyEvent.VK_H);
    to.setIcon(LogicConstants.getIcon("menucontextual_icon_destinoruta"));
    to.addActionListener(this);
    menu.add(to);

    menu.addSeparator();

    // Ver ficha [recurso / incidencia]
    final JMenuItem summary = new JMenuItem(i18n.getString("map.menu.summary"), KeyEvent.VK_F);
    summary.setIcon(LogicConstants.getIcon("menucontextual_icon_ficha"));
    summary.addActionListener(this);
    menu.add(summary);
    summary.setEnabled(false);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            eventOriginal = FleetControlMapViewer.this.mapView.lastMEvent;
            gps.setEnabled(false);
            summary.setEnabled(false);
            titulo.setText(i18n.getString("map.menu.titulo.puntoGenerico"));
            menuObjective = null;
            Point p = new Point(mapView.lastMEvent.getX(), mapView.lastMEvent.getY());
            for (Layer l : mapView.getAllLayers()) { // por cada capa...
                if (l instanceof MarkerLayer) { // ...de marcadores
                    for (Marker marker : ((MarkerLayer) l).data) { // miramos
                        // los
                        // marcadores
                        if ((marker instanceof CustomMarker) && marker.containsPoint(p)) { // y si
                            // estamos
                            // pinchando
                            // en uno
                            CustomMarker m = (CustomMarker) marker;
                            log.trace("Hemos pinchado en " + marker);

                            switch (m.getType()) {
                            case RESOURCE:
                                Recurso r = (Recurso) m.getObject();
                                log.trace("Es un recurso: " + r);
                                if (r != null) {
                                    menuObjective = r;
                                    if (r.getPatrullas() != null) {
                                        titulo.setText(
                                                i18n.getString(Locale.ROOT, "map.menu.titulo.recursoPatrulla",
                                                        r.getIdentificador(), r.getPatrullas()));
                                    } else {
                                        titulo.setText(r.getIdentificador());
                                    }
                                    gps.setEnabled(true);
                                    summary.setEnabled(true);
                                }
                                break;
                            case INCIDENCE:
                                Incidencia i = (Incidencia) m.getObject();
                                log.trace("Es una incidencia: " + i);
                                if (i != null) {
                                    menuObjective = i;
                                    titulo.setText(i.getTitulo());
                                    gps.setEnabled(false);
                                    summary.setEnabled(true);
                                }
                                break;
                            case UNKNOWN:
                                log.trace("Hemos pinchado en un marcador desconocido");
                                break;
                            }

                        }
                    }
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

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

    return menu;
}

From source file:de.hshannover.f4.trust.visitmeta.gui.GraphConnection.java

private JPopupMenu createContextMenu(final GraphicWrapper node) {
    JPopupMenu result = new JPopupMenu();

    for (final ContextMenuItem item : mContextMenuItems) {
        JMenuItem menuItem = new JMenuItem(item.getItemTitle());
        menuItem.addActionListener(new ActionListener() {
            @Override//w w  w  . j av a 2s . c o m
            public void actionPerformed(ActionEvent e) {
                item.actionPerformed(node);
            }
        });

        if (!item.canHandle(node.getData())) {
            menuItem.setEnabled(false);
        }

        result.add(menuItem);
    }

    return result;
}

From source file:edu.clemson.cs.nestbed.client.gui.NetworkMonitorFrame.java

private final JMenu buildNetworkMenu() {
    final JMenu menu = new JMenu("Network");
    final JMenuItem install = new JMenuItem("Install Programs");
    final JMenuItem vizMenu = new JMenuItem("Visualizations");

    install.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new Thread() {
                public void run() {
                    try {
                        install.setEnabled(false);
                        progDeployMgr.deployConfiguration(config.getID());
                    } catch (Exception ex) {
                        log.error("Exception occured while installing " + "programs.", ex);
                        ClientUtils.displayErrorMessage(NetworkMonitorFrame.this, ex);
                    } finally {
                        install.setEnabled(true);
                    }//from   w  ww  .  j av a 2  s  .  c  o  m
                }
            }.start();
        }
    });
    menu.add(install);
    menu.add(new JSeparator());

    vizMenu.addActionListener(new VisualizationMenuListener());
    menu.add(vizMenu);

    return menu;
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java

private JMenu getHelpMenu() {
    final JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);

    // Pick a random message to display in the help menu
    final String messages[] = { "(You won't find any help here)", "(Nobody can help you)",
            "(Keep on lookin' if you need help)", "(Heeeeelp!)", "(You might want to try google for help)",
            "(Try yelling loudly if you need help)" };

    final Random generator = new Random(System.currentTimeMillis());

    final JMenuItem noHelpItem = new JMenuItem(messages[generator.nextInt(messages.length)]);
    noHelpItem.setEnabled(false);
    helpMenu.add(noHelpItem);//from ww  w .ja v a 2s.  c  o  m

    return helpMenu;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopPopupButton.java

protected void showPopup() {
    popup.removeAll();//w w w.  j  a va  2  s . co  m

    for (final Action action : actionList) {
        if (action.isVisible()) {
            final JMenuItem menuItem = new JMenuItem(action.getCaption());
            menuItem.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    action.actionPerform((Component) action.getOwner());
                }
            });
            menuItem.setEnabled(action.isEnabled());
            menuItem.setName(action.getId());

            initAction(action, menuItem);

            popup.add(menuItem);
        }
    }

    int popupHeight = popup.getComponentCount() * 25;

    Point pt = new Point();
    SwingUtilities.convertPointToScreen(pt, impl);

    int y;
    if (pt.getY() + impl.getHeight() + popupHeight < Toolkit.getDefaultToolkit().getScreenSize().getHeight()) {
        y = impl.getHeight();
    } else {
        y = -popupHeight;
    }

    // do not show ugly empty popup
    if (popup.getComponentCount() > 0) {
        popup.show(impl, 0, y);
    }
}

From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java

@SuppressWarnings("serial")
private JMenuBar createMenu() {
    JMenuBar menuBar = new JMenuBar();

    // the file menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.add(this.saveGraphImageAction);
    menuBar.add(fileMenu);/*w  w w .j  a  v  a  2s .c  o  m*/

    // the tools menu
    JMenu toolsMenu = new JMenu("Tools");
    JMenuItem configureGraphItem = new JMenuItem("Configure Graph...");
    configureGraphItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            VolcanoPlotPanel.this.chartConfigurationDialog.setVisible(true);
        }
    });
    toolsMenu.add(configureGraphItem);
    toolsMenu.addSeparator();

    toolsMenu.add(new AbstractAction("Clear Selections") {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            VolcanoPlotPanel.this.setSelectedIndices(new int[0]);
        }
    });
    toolsMenu.addSeparator();

    ButtonGroup dragButtonGroup = new ButtonGroup();
    JCheckBoxMenuItem selectModeCheckBox = new JCheckBoxMenuItem("Drag Cursor to Select");
    selectModeCheckBox.setSelected(true);
    this.dragToSelect = true;
    selectModeCheckBox.addItemListener(new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            VolcanoPlotPanel.this.dragToSelect = e.getStateChange() == ItemEvent.SELECTED;
        }
    });
    dragButtonGroup.add(selectModeCheckBox);
    toolsMenu.add(selectModeCheckBox);

    JCheckBoxMenuItem zoomModeCheckBox = new JCheckBoxMenuItem("Drag Cursor to Zoom");
    zoomModeCheckBox.addItemListener(new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            VolcanoPlotPanel.this.dragToZoom = e.getStateChange() == ItemEvent.SELECTED;
        }
    });
    dragButtonGroup.add(zoomModeCheckBox);
    toolsMenu.add(zoomModeCheckBox);
    toolsMenu.addSeparator();

    toolsMenu.add(new AbstractAction("Zoom Out") {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            VolcanoPlotPanel.this.autoRangeChart();
        }
    });
    toolsMenu.addSeparator();

    JCheckBoxMenuItem showTooltipCheckbox = new JCheckBoxMenuItem("Show Info Popup for Nearest Point");
    showTooltipCheckbox.setSelected(true);
    this.showTooltip = true;
    showTooltipCheckbox.addItemListener(new ItemListener() {
        /**
         * {@inheritDoc}
         */
        public void itemStateChanged(ItemEvent e) {
            VolcanoPlotPanel.this.showTooltip = e.getStateChange() == ItemEvent.SELECTED;
            VolcanoPlotPanel.this.clearProbePopup();
        }
    });
    toolsMenu.add(showTooltipCheckbox);
    toolsMenu.addSeparator();

    toolsMenu.add(this.displayTestResultsAction);
    toolsMenu.addSeparator();

    toolsMenu.add(this.saveSelectedPointsMenuItem);

    JMenu selectPointsFromLisMenu = new JMenu("Select Points From Gene List");
    List<String> geneListNames = this.maanovaTestResult.getParentExperiment().getGeneListNames();
    if (geneListNames.isEmpty()) {
        JMenuItem noListsMenuItem = new JMenuItem("No Gene Lists Available");
        noListsMenuItem.setEnabled(false);
        selectPointsFromLisMenu.add(noListsMenuItem);
    } else {
        for (final String geneListName : geneListNames) {
            JMenuItem currGeneListMenuItem = new JMenuItem(
                    RUtilities.fromRIdentifierToReadableName(geneListName));
            currGeneListMenuItem.addActionListener(new ActionListener() {
                /**
                 * {@inheritDoc}
                 */
                public void actionPerformed(ActionEvent e) {
                    VolcanoPlotPanel.this.selectedIndicesFromGeneList(geneListName);
                }
            });
            selectPointsFromLisMenu.add(currGeneListMenuItem);
        }
    }
    toolsMenu.add(selectPointsFromLisMenu);

    menuBar.add(toolsMenu);

    // the help menu
    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Help...");
    Icon helpIcon = new ImageIcon(VolcanoPlotPanel.class.getResource("/images/action/help-16x16.png"));
    helpMenuItem.setIcon(helpIcon);
    helpMenuItem.addActionListener(new ActionListener() {
        /**
         * {@inheritDoc}
         */
        public void actionPerformed(ActionEvent e) {
            Maanova.getInstance().showHelp("volcano-plot", VolcanoPlotPanel.this);
        }
    });
    helpMenu.add(helpMenuItem);
    menuBar.add(helpMenu);

    return menuBar;
}