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:me.mayo.telnetkek.MainPanel.java

public final void setupTablePopup() {
    this.tblPlayers.addMouseListener(new MouseAdapter() {
        @Override//from   w w w . j a v a2 s.c  om
        public void mouseReleased(final MouseEvent mouseEvent) {
            final JTable table = MainPanel.this.tblPlayers;

            final int r = table.rowAtPoint(mouseEvent.getPoint());
            if (r >= 0 && r < table.getRowCount()) {
                table.setRowSelectionInterval(r, r);
            } else {
                table.clearSelection();
            }

            final int rowindex = table.getSelectedRow();
            if (rowindex < 0) {
                return;
            }

            if ((SwingUtilities.isRightMouseButton(mouseEvent) || mouseEvent.isControlDown())
                    && mouseEvent.getComponent() instanceof JTable) {
                final PlayerInfo player = getSelectedPlayer();
                if (player != null) {
                    final JPopupMenu popup = new JPopupMenu(player.getName());

                    final JMenuItem header = new JMenuItem("Apply action to " + player.getName() + ":");
                    header.setEnabled(false);
                    popup.add(header);

                    popup.addSeparator();

                    final ActionListener popupAction = (ActionEvent actionEvent) -> {
                        Object _source = actionEvent.getSource();
                        if (_source instanceof PlayerListPopupItem_Command) {
                            final PlayerListPopupItem_Command source = (PlayerListPopupItem_Command) _source;
                            final String output = source.getCommand().buildOutput(source.getPlayer(), true);
                            MainPanel.this.getConnectionManager().sendDelayedCommand(output, true, 100);
                        } else if (_source instanceof PlayerListPopupItem) {
                            final PlayerListPopupItem source = (PlayerListPopupItem) _source;

                            final PlayerInfo _player = source.getPlayer();

                            switch (actionEvent.getActionCommand()) {
                            case "Copy IP": {
                                copyToClipboard(_player.getIp());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied IP to clipboard: " + _player.getIp()));
                                break;
                            }
                            case "Copy Name": {
                                copyToClipboard(_player.getName());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied name to clipboard: " + _player.getName()));
                                break;
                            }
                            case "Copy UUID": {
                                copyToClipboard(_player.getUuid());
                                MainPanel.this.writeToConsole(
                                        new ConsoleMessage("Copied UUID to clipboard: " + _player.getUuid()));
                                break;
                            }
                            }
                        }
                    };

                    TelnetKek.config.getCommands().stream().map(
                            (command) -> new PlayerListPopupItem_Command(command.getName(), player, command))
                            .map((item) -> {
                                item.addActionListener(popupAction);
                                return item;
                            }).forEach((item) -> {
                                popup.add(item);
                            });

                    popup.addSeparator();

                    JMenuItem item;

                    item = new PlayerListPopupItem("Copy Name", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy IP", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    item = new PlayerListPopupItem("Copy UUID", player);
                    item.addActionListener(popupAction);
                    popup.add(item);

                    popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                }
            }
        }
    });
}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java

/**
 * /*w ww.j  a  va 2  s . co  m*/
 */
protected void buildUI() {
    SchemaLocalizerXMLHelper slxh = new SchemaLocalizerXMLHelper(schemaType, tableMgr);
    localizableIO = slxh;
    localizableIO.load(false);

    //stripToSingleLocale("pt", slxh);

    LocalizableStrFactory localizableStrFactory = new LocalizableStrFactory() {
        public LocalizableStrIFace create() {
            SpLocaleItemStr str = new SpLocaleItemStr();
            str.initialize();
            return str;
        }

        public LocalizableStrIFace create(String text, Locale locale) {
            return new SpLocaleItemStr(text, locale); // no initialize needed for this constructor
        }
    };

    LocalizerBasePanel.setLocalizableStrFactory(localizableStrFactory);
    SchemaLocalizerXMLHelper.setLocalizableStrFactory(localizableStrFactory);

    schemaLocPanel = new SchemaLocalizerPanel(null, dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache,
            webLinkMgrCache, schemaType);
    schemaLocPanel.setLocalizableIO(localizableIO);
    schemaLocPanel.setStatusBar(statusBar);

    boolean useDisciplines = AppPreferences.getLocalPrefs().getBoolean("SCHEMA_DISP", false);
    schemaLocPanel.setUseDisciplines(useDisciplines);

    // rods - for now 
    //schemaLocPanel.setIncludeHiddenUI(true);
    schemaLocPanel.buildUI();
    schemaLocPanel.setHasChanged(localizableIO.didModelChangeDuringLoad());

    statusBar.setSectionText(1,
            schemaType == SpLocaleContainer.CORE_SCHEMA ? getResourceString("SchemaLocalizerFrame.FULL_SCHEMA") //$NON-NLS-1$
                    : getResourceString("SchemaLocalizerFrame.WB_SCHEMA")); //$NON-NLS-1$

    UIRegistry.setStatusBar(statusBar);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    String title = "File"; //$NON-NLS-1$
    String mneu = "F"; //$NON-NLS-1$
    JMenu fileMenu = UIHelper.createLocalizedMenu(menuBar, title, mneu);

    title = "Save"; //$NON-NLS-1$
    mneu = "S"; //$NON-NLS-1$
    JMenuItem saveMenuItem = UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", false, //$NON-NLS-1$
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    write();
                }
            });
    saveMenuItem.setEnabled(false);

    title = "Export"; //$NON-NLS-1$
    mneu = "E"; //$NON-NLS-1$
    UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
    {
        public void actionPerformed(ActionEvent e) {
            export();
        }
    });

    title = "SchemaLocalizerFrame.ExportLOCALE"; //$NON-NLS-1$
    mneu = "SchemaLocalizerFrame.ExportLOCALEMnu"; //$NON-NLS-1$
    UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
    {
        public void actionPerformed(ActionEvent e) {
            exportSingleLocale();
        }
    });

    title = "Exit"; //$NON-NLS-1$
    mneu = "x"; //$NON-NLS-1$
    if (!UIHelper.isMacOS()) {
        fileMenu.addSeparator();

        UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
        {
            public void actionPerformed(ActionEvent e) {
                shutdown();
            }
        });
    }
    /*
    JMenu toolMenu = UIHelper.createMenu(menuBar, "Tools", "T");
    UIHelper.createMenuItem(toolMenu, "Create Resource Files", "C", "", true, new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
        createResourceFiles();
    }
    });
    */

    menuBar.add(SchemaI18NService.getInstance().createLocaleMenu(this, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("locale")) //$NON-NLS-1$
            {
                schemaLocPanel.localeChanged((Locale) evt.getNewValue());
                statusBar.setSectionText(0, SchemaI18NService.getCurrentLocale().getDisplayName());
            }
        }
    }));

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    setSize(800, 600);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(schemaLocPanel, BorderLayout.CENTER);
    mainPanel.add(statusBar, BorderLayout.SOUTH);

    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    setContentPane(mainPanel);

    statusBar.setSectionText(0, SchemaI18NService.getCurrentLocale().getDisplayName());

    schemaLocPanel.setSaveMenuItem(saveMenuItem);

    schemaLocPanel.getContainerList().setEnabled(true);

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    ImageIcon helpIcon = IconManager.getIcon("AppIcon", IconSize.Std16); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    AppPrefsCache.setUseLocalOnly(true);
    SpecifyAppPrefs.loadColorAndFormatPrefs();

    if (localizableIO.didModelChangeDuringLoad()) {
        saveMenuItem.setEnabled(true);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame(getResourceString("SchemaLocalizerFrame.CHG_TO_SCHEMA")); //$NON-NLS-1$
                frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

                JTextPane tp = new JTextPane();
                JScrollPane js = new JScrollPane();
                js.getViewport().add(tp);

                tp.setContentType("text/html");
                tp.setText(((SchemaLocalizerXMLHelper) localizableIO).getChangesBuffer());

                frame.setContentPane(js);
                frame.pack();
                frame.setSize(400, 500);
                frame.setVisible(true);
            }
        });
    }
}

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

protected void initAction(final Action action, final JMenuItem menuItem) {
    if (initializedActions.contains(action))
        return;//from   ww w. ja  va  2  s .  c  o m

    action.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (Action.PROP_CAPTION.equals(evt.getPropertyName())) {
                menuItem.setText(action.getCaption());
            } else if (Action.PROP_ENABLED.equals(evt.getPropertyName())) {
                menuItem.setEnabled(action.isEnabled());
            } else if (Action.PROP_VISIBLE.equals(evt.getPropertyName())) {
                menuItem.setVisible(action.isVisible());
            }
        }
    });

    initializedActions.add(action);
}

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Disables most menu items//from w  w  w  .  j a v  a2s. co m
 */
public void disableMost() {
    //      for (Component component : getComponents()) {
    //         if (component instanceof JMenu && ((JMenu) component).getText().equals("Settings")) {
    //            for (Component menuComponent : ((JMenu) component).getMenuComponents()) {
    //               if (!(menuComponent instanceof JMenuItem) || (!((JMenuItem) menuComponent).getText().equals("Toggle Gridlines") && !((JMenuItem) menuComponent).getText().equals("Toggle Dot Names")))
    //                  menuComponent.setEnabled(false);
    //            }
    //         } else {
    //            component.setEnabled(false);
    //         }
    //      }
    for (Component component : getComponents()) {
        if (component instanceof JMenu) {
            boolean enabled = false;
            for (Component menuComponent : ((JMenu) component).getMenuComponents()) {
                JMenuItem menuItem = (JMenuItem) menuComponent;
                switch (menuItem.getText()) {
                case "Quit":
                case "Toggle Gridlines":
                case "Toggle Dot Names":
                case "Help":
                case "About":
                    enabled = true;
                    break;
                default:
                    menuItem.setEnabled(false);
                }
            }
            if (!enabled)
                component.setEnabled(false);
        } else
            component.setEnabled(false);
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing.CFAsteriskSwingClusterFinderJInternalFrame.java

public void adjustFinderMenuBar() {
    JMenuItem menuItem;
    Action act;/*from ww w.  ja  v  a2  s  .  c  o  m*/
    String itemLabel;
    ICFSecurityClusterObj selectedObj = getSwingFocusAsCluster();
    boolean enableState;
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(enableState);
    }

    if (menuFile != null) {
        int itemCount = menuFile.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuFile.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(enableState);
                }
            }
        }
    }
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JMenu createMenuExtra() {
    final JMenu menuExtra = new JMenu(Messages.getString("Menu.extra")); //$NON-NLS-1$

    final JMenuItem menuExtraOpenExternalEditor = new JMenuItem(Messages.getString("Menu.openExternal")); //$NON-NLS-1$
    menuExtraOpenExternalEditor.addActionListener(new ActionListener() {
        @Override/*from   www.  ja  va  2  s  . c  om*/
        public void actionPerformed(final ActionEvent event) {
            showExternalEditor();
        }
    });
    menuExtra.add(menuExtraOpenExternalEditor);

    menuExtra.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuExtraOpenExternalEditor.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });

    return menuExtra;
}

From source file:net.chaosserver.timelord.swingui.TimelordMenu.java

/**
 * Creates a new instance of the help menu.
 *
 * @return the new help menu//from w w  w.  ja  v  a 2  s.  com
 */
protected JMenu createHelpMenu() {
    JMenuItem menuItem;
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    this.add(helpMenu);

    menuItem = new JMenuItem("Help Topics", KeyEvent.VK_H);
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_H, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    try {
        URL hsURL = HelpSet.findHelpSet(this.getClass().getClassLoader(),
                "net/chaosserver/timelord/help/TimelordHelp.hs");
        HelpSet hs = new HelpSet(null, hsURL);
        HelpBroker hb = hs.createHelpBroker();
        menuItem.addActionListener(new CSH.DisplayHelpFromSource(hb));
    } catch (HelpSetException e) {
        menuItem.setEnabled(false);
    }

    // menuItem.setActionCommand(ACTION_ABOUT);
    helpMenu.add(menuItem);

    menuItem = new JMenuItem("Log Window");
    menuItem.setActionCommand(ACTION_LOG);
    menuItem.addActionListener(this);
    menuItem.setEnabled(false);
    helpMenu.add(menuItem);

    menuItem = new JMenuItem("Cause Memory Leak");
    menuItem.setActionCommand(ACTION_LEAK);
    menuItem.addActionListener(this);
    menuItem.setEnabled(false);
    helpMenu.add(menuItem);

    if (!OsUtil.isMac()) {
        helpMenu.addSeparator();

        menuItem = new JMenuItem("About Timelord", KeyEvent.VK_A);
        menuItem.setActionCommand(ACTION_ABOUT);
        menuItem.addActionListener(this);
        helpMenu.add(menuItem);
    }

    return helpMenu;
}

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

protected JPopupMenu createPopupMenu() {
    JPopupMenu popup = new JPopupMenu();
    JMenuItem menuItem;
    for (final com.haulmont.cuba.gui.components.Action action : actionList) {
        if (StringUtils.isNotBlank(action.getCaption()) && action.isVisible()) {
            menuItem = new JMenuItem(action.getCaption());
            if (action.getIcon() != null) {
                menuItem.setIcon(AppBeans.get(IconResolver.class).getIconResource(action.getIcon()));
            }/*w  w  w  .  j a v a2  s.com*/
            if (action.getShortcutCombination() != null) {
                menuItem.setAccelerator(
                        DesktopComponentsHelper.convertKeyCombination(action.getShortcutCombination()));
            }
            menuItem.setEnabled(action.isEnabled());
            menuItem.addActionListener(e -> action.actionPerform(DesktopTree.this));
            popup.add(menuItem);
        }
    }
    return popup;
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmSwing.CFCrmSwingTldFinderJInternalFrame.java

public void adjustFinderMenuBar() {
    JMenuItem menuItem;
    Action act;//from  w  w  w.java 2s  .c  om
    String itemLabel;
    ICFCrmTldObj selectedObj = getSwingFocusAsTld();
    boolean enableState;
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(enableState);
    }
    if (actionDeleteSelected != null) {
        actionDeleteSelected.setEnabled(enableState);
    }
    if (actionAddTld != null) {
        actionAddTld.setEnabled(true);
    }

    if (menuFile != null) {
        int itemCount = menuFile.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuFile.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionAddTld) {
                    menuItem.setEnabled(true);
                }
            }
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing.CFAsteriskSwingTldFinderJInternalFrame.java

public void adjustFinderMenuBar() {
    JMenuItem menuItem;
    Action act;// w w w.j a  v a 2  s. c o m
    String itemLabel;
    ICFInternetTldObj selectedObj = getSwingFocusAsTld();
    boolean enableState;
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(enableState);
    }
    if (actionDeleteSelected != null) {
        actionDeleteSelected.setEnabled(enableState);
    }
    if (actionAddTld != null) {
        actionAddTld.setEnabled(true);
    }

    if (menuFile != null) {
        int itemCount = menuFile.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuFile.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionAddTld) {
                    menuItem.setEnabled(true);
                }
            }
        }
    }
}