List of usage examples for javax.swing JMenuItem setEnabled
@BeanProperty(preferred = true, description = "The enabled state of the component.") public void setEnabled(boolean b)
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java
private JMenuItem getAddOption() { JMenuItem addItem = new JMenuItem("Add " + networkElementType); ;// ww w .j a va 2 s. c o m addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { AdvancedJTable_demand.createLinkDemandGUI(networkElementType, callback); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to add " + networkElementType); } } }); NetPlan netPlan = callback.getDesign(); int N = netPlan.getNumberOfNodes(); if (N < 2) addItem.setEnabled(false); return addItem; }
From source file:edu.ku.brc.specify.tasks.SystemSetupTask.java
/** * Adds the Context PopupMenu for the RecordSet. * @param roc the RolloverCommand btn to add the pop to *//*w w w .j av a 2s. co m*/ public void addPopMenu(final RolloverCommand roc, final PickList pickList) { if (roc.getLabelText() != null) { final JPopupMenu popupMenu = new JPopupMenu(); JMenuItem delMenuItem = new JMenuItem(getResourceString("Delete")); if (!pickList.getIsSystem()) { delMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { CommandDispatcher.dispatch(new CommandAction(SYSTEMSETUPTASK, DELETE_CMD_ACT, roc)); } }); } else { delMenuItem.setEnabled(false); } popupMenu.add(delMenuItem); JMenuItem viewMenuItem = new JMenuItem(getResourceString("EDIT")); viewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { startEditor(edu.ku.brc.specify.datamodel.PickList.class, "name", roc.getName(), roc.getName(), PICKLIST); } }); popupMenu.add(viewMenuItem); MouseListener mouseListener = new MouseAdapter() { private boolean showIfPopupTrigger(MouseEvent mouseEvent) { if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) { popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); return true; } return false; } @Override public void mousePressed(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } }; roc.addMouseListener(mouseListener); } }
From source file:corelyzer.ui.CorelyzerGLCanvas.java
void createPopupMenuUI() { JPopupMenu.setDefaultLightWeightPopupEnabled(false); this.scenePopupMenu = new JPopupMenu(); JMenuItem trackName = new JMenuItem("Track Name"); trackName.setEnabled(false); this.scenePopupMenu.add(trackName); JMenuItem sectionName = new JMenuItem("Section name"); sectionName.setEnabled(false);/*from w w w . jav a 2 s.co m*/ this.scenePopupMenu.add(sectionName); this.scenePopupMenu.addSeparator(); // Mode menu JMenu modeMenu = new JMenu("Mode"); ButtonGroup modeGroup = new ButtonGroup(); this.normalMode = new JRadioButtonMenuItem("Normal mode"); this.normalMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/normal.gif"))); this.normalMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(0); } }); this.normalMode.setSelected(true); modeGroup.add(this.normalMode); modeMenu.add(this.normalMode); this.clastMode = new JRadioButtonMenuItem("Create annotation mode"); this.clastMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/copyright.gif"))); this.clastMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(3); } }); modeGroup.add(this.clastMode); modeMenu.add(this.clastMode); this.markerMode = new JRadioButtonMenuItem("Modify annotation marker mode"); this.markerMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/marker.gif"))); this.markerMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(2); } }); modeGroup.add(this.markerMode); modeMenu.add(this.markerMode); this.measureMode = new JRadioButtonMenuItem("Measure mode"); this.measureMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/ruler.gif"))); this.measureMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(1); } }); modeGroup.add(this.measureMode); modeMenu.add(this.measureMode); this.cutMode = new JRadioButtonMenuItem("Cut mode"); this.cutMode.setIcon(new ImageIcon(getClass().getResource("/corelyzer/ui/resources/cut.gif"))); this.cutMode.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { CorelyzerApp.getApp().getToolFrame().setMode(4); } }); modeGroup.add(this.cutMode); modeMenu.add(this.cutMode); this.scenePopupMenu.add(modeMenu); JMenuItem hideTrackMenuItem = new JMenuItem("Hide track"); hideTrackMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { doHideTrack(); } }); this.scenePopupMenu.add(hideTrackMenuItem); JMenuItem exportTrackMenuItem = new JMenuItem("Export track"); exportTrackMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { doExportTrack(); } }); this.scenePopupMenu.add(exportTrackMenuItem); JMenuItem lockSectionMenuItem = new JCheckBoxMenuItem("Lock Section"); lockSectionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { AbstractButton b = (AbstractButton) actionEvent.getSource(); doLockSection(b.getModel().isSelected()); } }); JMenuItem lockSectionGraphMenuItem = new JCheckBoxMenuItem("Lock Section Graphs"); lockSectionGraphMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { AbstractButton b = (AbstractButton) actionEvent.getSource(); doLockSectionGraph(b.getModel().isSelected()); } }); JMenuItem graphMenuItem = new JMenuItem("Graph..."); graphMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { doGraphDialog(); } }); this.propertyMenuItem = new JMenuItem("Properties..."); this.propertyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { SectionImagePropertyDialog dialog = new SectionImagePropertyDialog(canvas); dialog.setProperties(selectedTrack, selectedTrackSection); dialog.pack(); dialog.setLocationRelativeTo(canvas); dialog.setVisible(true); dialog.dispose(); } }); splitMenuItem = new JMenuItem("Split..."); splitMenuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { CorelyzerApp app = CorelyzerApp.getApp(); if (app != null) { app.getController().sectionSplit(); } } }); JMenuItem deleteItem = new JMenuItem("Delete..."); deleteItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent actionEvent) { doDeleteSection(); } }); JMenuItem staggerSectionsItem = new JCheckBoxMenuItem("Stagger Sections", false); staggerSectionsItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { AbstractButton b = (AbstractButton) e.getSource(); doStaggerSections(b.getModel().isSelected()); } }); JMenuItem trimSectionsItem = new JMenuItem("Trim Sections..."); trimSectionsItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { doTrimSections(); } }); JMenuItem stackSectionsItem = new JMenuItem("Stack Sections"); stackSectionsItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { doStackSections(); } }); this.scenePopupMenu.addSeparator(); this.scenePopupMenu.add(lockSectionMenuItem); this.scenePopupMenu.add(lockSectionGraphMenuItem); this.scenePopupMenu.addSeparator(); this.scenePopupMenu.add(graphMenuItem); this.scenePopupMenu.add(splitMenuItem); this.scenePopupMenu.add(propertyMenuItem); this.scenePopupMenu.add(deleteItem); this.scenePopupMenu.add(staggerSectionsItem); this.scenePopupMenu.add(trimSectionsItem); this.scenePopupMenu.add(stackSectionsItem); CorelyzerApp.getApp().getPluginManager().addPluginPopupSubMenus(this.scenePopupMenu); }
From source file:edu.clemson.cs.nestbed.client.gui.ConfigManagerFrame.java
private final JMenu buildProfilingMenu() { final JMenu menu = new JMenu("Profiling"); final JMenuItem deleteProfilingSymbol = new JMenuItem("Delete " + "Profiling " + "Symbol"); final JMenuItem deleteProfilingMessage = new JMenuItem("Delete " + "Profiling " + "Message"); deleteProfilingSymbol.addActionListener(new DeleteProgramProfilingSymbolListener()); menu.add(deleteProfilingSymbol);//from www. j av a 2 s . c o m deleteProfilingMessage.addActionListener(new DeleteProgramProfilingMessageSymbolListener()); menu.add(deleteProfilingMessage); menu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent e) { setDeleteProfilingSymbolEnabled(); setDeleteProfilingMessageEnabled(); } private void setDeleteProfilingSymbolEnabled() { int row = profilingSymbolTable.getSelectedRow(); deleteProfilingSymbol.setEnabled((row != -1) && (row != (profilingSymbolTable.getRowCount() - 1))); } private void setDeleteProfilingMessageEnabled() { int row = profilingMsgTable.getSelectedRow(); deleteProfilingMessage.setEnabled((row != -1) && (row != (profilingMsgTable.getRowCount() - 1))); } public void menuCanceled(MenuEvent e) { } public void menuDeselected(MenuEvent e) { } }); return menu; }
From source file:com.AandR.beans.plotting.imagePlotPanel.CanvasPanel.java
/** * Access to the method used to create the popup menu items used in the Canvas Popup Menu. * @param label/* w w w . ja va 2s . co m*/ * @param icon * @param keyStroke * @return */ public JMenuItem createPopupMenuItem(String label, Icon icon, KeyStroke keyStroke) { JMenuItem menuItem = new JMenuItem(label, icon); menuItem.setAccelerator(keyStroke); menuItem.addActionListener(this); menuItem.setBackground(Color.WHITE); menuItem.setEnabled(true); return menuItem; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * @param menu//from www. j a va 2s . c om */ private void makeSchemeMenu(JMenu menu) { menu.removeAll(); // Specification... JMenuItem menuItem = new JMenuItem(Menu.SPECIFICATION, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Extend menuItem = new JMenuItem(Menu.EXTEND_SPEC, KeyEvent.VK_E); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menu.add(new JSeparator()); // Run menuItem = new JMenuItem(Menu.RUN, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Propagate menuItem = new JCheckBoxMenuItem(Menu.PROPAGATE_VALUES, RuntimeProperties.isPropagateValues()); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Compute goal menuItem = new JCheckBoxMenuItem(Menu.COMPUTE_GOAL, RuntimeProperties.isComputeGoal()); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menu.add(new JSeparator()); // Values menuItem = new JMenuItem(Menu.SCHEME_VALUES, KeyEvent.VK_V); menuItem.addActionListener(getActionListener()); boolean enabled = getCurrentCanvas() != null && getCurrentCanvas().getLastProgramRunnerID() != 0; menuItem.setEnabled(enabled); if (!enabled) menuItem.setToolTipText("Run the scheme first"); menu.add(menuItem); menu.add(new JSeparator()); // Options menuItem = new JMenuItem(Menu.SCHEMEOPTIONS, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
protected JMenuItem createMenuItem(final String text, final IMenuAction r, final boolean enabled) { final JMenuItem item = new JMenuItem(new AbstractAction() { @Override/*from w w w . j a v a 2 s. c o m*/ public boolean isEnabled() { return enabled; } @Override public void actionPerformed(ActionEvent e) { submitTask(new UITask() { @Override public String getId() { return text; } @Override public void run() throws Exception { try { r.run(); } catch (PriceInfoUnavailableException e) { displayError("Found no price for " + e.getItemType().getName()); } catch (Exception e1) { displayError("Error: " + e1.getMessage(), e1); } } }); } }); item.setEnabled(enabled); item.setText(text); return item; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing.CFAsteriskSwingClusterListJPanel.java
public void adjustListMenuBar() { JMenuItem menuItem; Action act;/*from w w w.j a va2 s .c o m*/ String itemLabel; boolean enableState; boolean inEditState; boolean allowAdds; ICFSecurityClusterObj selectedObj = getSwingFocusAsCluster(); 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 (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); } } } } }
From source file:ca.phon.ipamap.IpaMap.java
/** * Create the context menu based on source component *//*from www . j ava2s.com*/ public void setupContextMenu(JPopupMenu menu, JComponent comp) { final CommonModuleFrame parentFrame = (CommonModuleFrame) SwingUtilities .getAncestorOfClass(CommonModuleFrame.class, comp); if (parentFrame != null) { final PhonUIAction toggleAlwaysOnTopAct = new PhonUIAction(parentFrame, "setAlwaysOnTop", !parentFrame.isAlwaysOnTop()); toggleAlwaysOnTopAct.putValue(PhonUIAction.NAME, "Always on top"); toggleAlwaysOnTopAct.putValue(PhonUIAction.SELECTED_KEY, parentFrame.isAlwaysOnTop()); final JCheckBoxMenuItem toggleAlwaysOnTopItem = new JCheckBoxMenuItem(toggleAlwaysOnTopAct); menu.add(toggleAlwaysOnTopItem); } // button options first if (comp instanceof CellButton) { CellButton btn = (CellButton) comp; Cell cell = btn.cell; // copy to clipboard options String cellData = cell.getText().replaceAll("" + (char) 0x25cc, ""); PhonUIAction copyToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", cellData); copyToClipboardAct.putValue(PhonUIAction.NAME, "Copy character (" + cell.getText() + ")"); JMenuItem copyToClipboardItem = new JMenuItem(copyToClipboardAct); menu.add(copyToClipboardItem); String htmlVal = new String(); for (Character c : cellData.toCharArray()) { htmlVal += "&#" + (int) c + ";"; } PhonUIAction copyHTMLToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", htmlVal); copyHTMLToClipboardAct.putValue(PhonUIAction.NAME, "Copy as HTML (" + htmlVal + ")"); JMenuItem copyHTMLToClipboardItem = new JMenuItem(copyHTMLToClipboardAct); menu.add(copyHTMLToClipboardItem); String hexVal = new String(); for (Character c : cellData.toCharArray()) { hexVal += (hexVal.length() > 0 ? " " : "") + Integer.toHexString((int) c); } hexVal = hexVal.toUpperCase(); PhonUIAction copyHEXToClipboardAct = new PhonUIAction(this, "onCopyToClipboard", hexVal); copyHEXToClipboardAct.putValue(PhonUIAction.NAME, "Copy as Unicode HEX (" + hexVal + ")"); JMenuItem copyHEXToClipboardItem = new JMenuItem(copyHEXToClipboardAct); menu.add(copyHEXToClipboardItem); menu.addSeparator(); if (isInFavorites(cell)) { PhonUIAction removeFromFavAct = new PhonUIAction(this, "onRemoveCellFromFavorites", cell); removeFromFavAct.putValue(Action.NAME, "Remove from favorites"); removeFromFavAct.putValue(Action.SHORT_DESCRIPTION, "Remove button from list of favorites"); JMenuItem removeFromFavItem = new JMenuItem(removeFromFavAct); menu.add(removeFromFavItem); } else { PhonUIAction addToFavAct = new PhonUIAction(this, "onAddCellToFavorites", cell); addToFavAct.putValue(Action.NAME, "Add to favorites"); addToFavAct.putValue(Action.SHORT_DESCRIPTION, "Add button to list of favorites"); JMenuItem addToFavItem = new JMenuItem(addToFavAct); menu.add(addToFavItem); } menu.addSeparator(); } // section scroll-tos JMenuItem gotoTitleItem = new JMenuItem("Scroll to:"); gotoTitleItem.setEnabled(false); menu.add(gotoTitleItem); for (JXButton toggleBtn : toggleButtons) { PhonUIAction gotoAct = new PhonUIAction(this, "onGoto", toggleBtn); gotoAct.putValue(Action.NAME, toggleBtn.getText()); gotoAct.putValue(Action.SHORT_DESCRIPTION, "Scroll to " + toggleBtn.getText()); JMenuItem gotoItem = new JMenuItem(gotoAct); menu.add(gotoItem); } menu.addSeparator(); // setup font scaler final JLabel smallLbl = new JLabel("A"); smallLbl.setFont(getFont().deriveFont(12.0f)); smallLbl.setHorizontalAlignment(SwingConstants.CENTER); JLabel largeLbl = new JLabel("A"); largeLbl.setFont(getFont().deriveFont(24.0f)); largeLbl.setHorizontalAlignment(SwingConstants.CENTER); final JSlider scaleSlider = new JSlider(1, 101); scaleSlider.setValue((int) (scale * 100)); scaleSlider.setMajorTickSpacing(20); scaleSlider.setMinorTickSpacing(10); scaleSlider.setSnapToTicks(true); scaleSlider.setPaintTicks(true); scaleSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { int sliderVal = scaleSlider.getValue(); float scale = (float) sliderVal / (float) 100; _cFont = null; setSavedScale(scale); setScale(scale); } }); FormLayout scaleLayout = new FormLayout("3dlu, center:pref, fill:pref:grow, center:pref, 3dlu", "pref"); CellConstraints cc = new CellConstraints(); JPanel scalePanel = new JPanel(scaleLayout) { @Override public Insets getInsets() { Insets retVal = super.getInsets(); retVal.left += UIManager.getIcon("Tree.collapsedIcon").getIconWidth(); return retVal; } }; scalePanel.add(smallLbl, cc.xy(2, 1)); scalePanel.add(scaleSlider, cc.xy(3, 1)); scalePanel.add(largeLbl, cc.xy(4, 1)); JMenuItem scaleItem = new JMenuItem("Font size"); scaleItem.setEnabled(false); menu.add(scaleItem); menu.add(scalePanel); menu.addSeparator(); // highlighting PhonUIAction onToggleHighlightAct = new PhonUIAction(this, "onToggleHighlightRecent"); onToggleHighlightAct.putValue(PhonUIAction.NAME, "Highlight recently used"); onToggleHighlightAct.putValue(PhonUIAction.SELECTED_KEY, isHighlightRecent()); JCheckBoxMenuItem onToggleHighlightItm = new JCheckBoxMenuItem(onToggleHighlightAct); menu.add(onToggleHighlightItm); }
From source file:net.chaosserver.timelord.swingui.TimelordMenu.java
/** * Creates the view menu./*from w ww . j av a 2 s. co m*/ * * @return the new view menu */ protected JMenu createViewMenu() { JMenuItem menuItem; JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); JMenu annoyanceModeMenu = new JMenu("Annoyance Mode"); annoyanceJordanCheckbox = new JCheckBoxMenuItem("Jordan Mode"); annoyanceJordanCheckbox.setToolTipText("For Cool People"); annoyanceJordanCheckbox.setActionCommand(ACTION_ANNOY_JORDAN); annoyanceJordanCheckbox.addActionListener(this); annoyanceModeMenu.add(annoyanceJordanCheckbox); annoyanceDougCheckbox = new JCheckBoxMenuItem("Doug Mode"); annoyanceDougCheckbox.setToolTipText("For Losers"); annoyanceJordanCheckbox.setActionCommand(ACTION_ANNOY_DOUG); annoyanceDougCheckbox.addActionListener(this); annoyanceModeMenu.add(annoyanceDougCheckbox); annoyanceNoneCheckbox = new JCheckBoxMenuItem("None"); annoyanceJordanCheckbox.setActionCommand(ACTION_ANNOY_NONE); annoyanceNoneCheckbox.addActionListener(this); annoyanceModeMenu.add(annoyanceNoneCheckbox); updateAnnoyanceButtons(); viewMenu.add(annoyanceModeMenu); menuItem = new JMenuItem("Refresh View", KeyEvent.VK_R); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItem.setActionCommand(ACTION_REFRESH_VIEW); menuItem.addActionListener(this); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JMenuItem("Change Start Time"); menuItem.setActionCommand(ACTION_CHANGE_START); menuItem.addActionListener(this); viewMenu.add(menuItem); menuItem = new JMenuItem("Change Annoy Time"); // currently disabled experimental functionality menuItem.setEnabled(false); menuItem.setActionCommand(ACTION_CHANGE_ANNOY); menuItem.addActionListener(this); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JMenuItem("Select Previous Tab", KeyEvent.VK_BRACELEFT); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BRACELEFT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItem.setActionCommand(ACTION_PREVIOUS_TAB); menuItem.addActionListener(this); viewMenu.add(menuItem); menuItem = new JMenuItem("Select Next Tab", KeyEvent.VK_BRACERIGHT); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BRACERIGHT, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItem.setActionCommand(ACTION_NEXT_TAB); menuItem.addActionListener(this); viewMenu.add(menuItem); return viewMenu; }