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:corelyzer.ui.CorelyzerApp.java

private JPopupMenu sectionListPopupMenu(final int[] rows) {
    // section popup
    JPopupMenu menu = new JPopupMenu("Sections");

    // Section/Image property
    JMenuItem propertiesMenuItem = new JMenuItem("Properties...");
    propertiesMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, MENU_MASK));
    propertiesMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.sectionProperties(rows);
        }//from ww  w . j a v a 2s. c o m
    });

    JMenuItem splitMenuItem = new JMenuItem("Split...");
    if (rows.length > 1) {
        splitMenuItem.setEnabled(false);
    }
    splitMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            controller.sectionSplit();
        }
    });

    JMenuItem deleteMenuItem = new JMenuItem("Delete");
    deleteMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            onDeleteSelectedSections(rows);
        }
    });

    JMenuItem locateMenuItem = new JMenuItem("Locate");
    locateMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            onLocateSelectedSection();
        }
    });

    menu.add(locateMenuItem);
    menu.add(splitMenuItem);
    menu.add(propertiesMenuItem);
    menu.add(deleteMenuItem);

    return menu;
}

From source file:net.cantab.hayward.george.OCS.Statics.java

/**
 * Display the command menu// w ww.j  a  v  a2 s .  c om
 */
public void launchCommandMenu() {
    if (curCommander == null) {
        return;
    }
    int i;
    JMenu theMenu = new JMenu();
    JMenuItem mi;
    for (i = 0; i < 2; i++) {
        int j;
        int k = 0;
        for (j = 0; j < theCommanders.length; j++) {
            if (theCommanders[j].sidesCommanded[i]) {
                k++;
            }
        }
        if (k != 0) {
            JMenu com = new JMenu("Commanders of the " + theSides[i].name + " side");
            for (j = 0; j < theCommanders.length; j++) {
                if (theCommanders[j].sidesCommanded[i]) {
                    mi = new JMenuItem(theCommanders[j].name);
                    mi.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                        }
                    });
                    mi.setEnabled(true);
                    com.add(mi);
                }
            }
            theMenu.add(com);
        }
        if (curCommander.sidesCommanded[i]) {
            final int m = i;
            mi = new JMenuItem("Resign from " + theSides[i].name + " side");
            mi.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    resignSide(m);
                }
            });
            mi.setEnabled(true);
            theMenu.add(mi);
            int n = 0;
            for (j = 0; j < theCommanders.length; j++) {
                if (theCommanders[j].sidesRequested[i]) {
                    n++;
                }
            }
            if (n != 0) {
                JMenu app = new JMenu("Approve to join " + theSides[i].name + " side");
                JMenu rej = new JMenu("Reject to join " + theSides[i].name + " side");
                for (j = 0; j < theCommanders.length; j++) {
                    if (theCommanders[j].sidesRequested[i]) {
                        mi = new JMenuItem(theCommanders[j].name);
                        final int p = j;
                        mi.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                acceptSide(m, p);
                            }
                        });
                        mi.setEnabled(true);
                        app.add(mi);
                        mi = new JMenuItem(theCommanders[j].name);
                        mi.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                rejectSide(m, p);
                            }
                        });
                        mi.setEnabled(true);
                        rej.add(mi);
                    }
                }
                theMenu.add(app);
                theMenu.add(rej);
            }
        } else {
            final int m = i;
            if (k != 0) {
                mi = new JMenuItem("Join " + theSides[i].name + " side");
                mi.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        joinSide(m);
                    }
                });
                mi.setEnabled(true);
                theMenu.add(mi);
            } else {
                mi = new JMenuItem("Command " + theSides[i].name + " side");
                mi.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        commandSide(m);
                    }
                });
                mi.setEnabled(true);
                theMenu.add(mi);
            }
        }
    }
    for (i = 0; i < 2; i++) {
        final int m = i;
        mi = new JMenuItem((showPZs[i] ? "Hide " : "Show ") + theSides[i].name + " PZs");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                displayPZs(m);
            }
        });
        mi.setEnabled(true);
        theMenu.add(mi);
        mi = new JMenuItem((showZOCs[i] ? "Hide " : "Show ") + theSides[i].name + " ZOCs");
        mi.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                displayZOCs(m);
            }
        });
        mi.setEnabled(true);
        theMenu.add(mi);
        if (curCommander.sidesCommanded[i]) {
            mi = new JMenuItem((showHQs[i] ? "Hide " : "Show ") + theSides[i].name + " HQs");
            mi.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    displayHQs(m);
                }
            });
            mi.setEnabled(true);
            theMenu.add(mi);
        }
    }
    theMenu.getPopupMenu().show(commandLaunch, 0, commandLaunch.getHeight());
}

From source file:net.sourceforge.msscodefactory.cfcrm.v2_1.CFCrmSwing.CFCrmSwingTldListJPanel.java

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;//  www . ja  v a  2s. c o m
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFCrmTldObj selectedObj = getSwingFocusAsTld();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

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

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

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

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;/*from   w  w w.j a v a 2 s.c o m*/
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFSecuritySysClusterObj selectedObj = getSwingFocusAsSysCluster();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(inEditState && enableState);
    }
    if (actionDeleteSelected != null) {
        actionDeleteSelected.setEnabled(inEditState && enableState);
    }
    if (actionAddSysCluster != null) {
        actionAddSysCluster.setEnabled(allowAdds);
    }

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

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

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;/*from w ww .  j a va2 s  .  c o  m*/
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFInternetTldObj selectedObj = getSwingFocusAsTld();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

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

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingTldListJPanel.java

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;//  w  w w  . j a  v a 2 s . c  o  m
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFAccTldObj selectedObj = getSwingFocusAsTld();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

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

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfasterisk.v2_0.CFAstSwing.CFAstSwingTldListJPanel.java

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;//from w  ww.ja  va2  s  . c o  m
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFAstTldObj selectedObj = getSwingFocusAsTld();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

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

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetSwing.CFInternetSwingSecUserListJPanel.java

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;//from  w w  w.  j  ava  2  s  .co  m
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFInternetSecUserObj selectedObj = getSwingFocusAsSecUser();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(inEditState && enableState);
    }
    if (actionDeleteSelected != null) {
        actionDeleteSelected.setEnabled(inEditState && enableState);
    }
    if (actionAddSecUser != null) {
        actionAddSecUser.setEnabled(allowAdds);
    }

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

From source file:net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetSwing.CFInternetSwingTenantListJPanel.java

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;/*from w w  w. j a v  a  2  s .c  o m*/
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFInternetTenantObj selectedObj = getSwingFocusAsTenant();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(inEditState && enableState);
    }
    if (actionDeleteSelected != null) {
        actionDeleteSelected.setEnabled(inEditState && enableState);
    }
    if (actionAddTenant != null) {
        actionAddTenant.setEnabled(allowAdds);
    }

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}

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

public void adjustListMenuBar() {
    JMenuItem menuItem;
    Action act;//from w  w  w  . ja  v a  2s .c o  m
    String itemLabel;
    boolean enableState;
    boolean inEditState;
    boolean allowAdds;
    ICFSecuritySecAppObj selectedObj = getSwingFocusAsSecApp();
    CFJPanel.PanelMode mode = getPanelMode();
    if (mode == CFJPanel.PanelMode.Edit) {
        inEditState = true;
        if (getSwingContainer() != null) {
            allowAdds = true;
        } else {
            allowAdds = false;
        }
    } else {
        inEditState = false;
        allowAdds = false;
    }
    if (selectedObj == null) {
        enableState = false;
    } else {
        enableState = true;
    }

    if (actionViewSelected != null) {
        actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
        actionEditSelected.setEnabled(inEditState && enableState);
    }
    if (actionDeleteSelected != null) {
        actionDeleteSelected.setEnabled(inEditState && enableState);
    }
    if (actionAddSecApp != null) {
        actionAddSecApp.setEnabled(allowAdds);
    }

    if (menuAdd != null) {
        menuAdd.setEnabled(allowAdds);
    }
    if (menuSelected != null) {
        menuSelected.setEnabled(enableState);
        int itemCount = menuSelected.getItemCount();
        for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
            menuItem = menuSelected.getItem(itemIdx);
            act = menuItem.getAction();
            if (act != null) {
                if (act == actionViewSelected) {
                    menuItem.setEnabled(enableState);
                } else if (act == actionEditSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                } else if (act == actionDeleteSelected) {
                    menuItem.setEnabled(inEditState && enableState);
                }
            }
        }
    }
}