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:org.executequery.gui.editor.QueryEditorPopupMenu.java
private void setExecutingButtonsEnabled(boolean enable) { for (JMenuItem menuItem : executingButtons()) { menuItem.setEnabled(enable); }/*from w w w . j a v a 2s .c om*/ }
From source file:org.executequery.gui.editor.QueryEditorPopupMenu.java
private void setExecuteActionButtonsEnabled(boolean enable) { for (JMenuItem menuItem : executeActionButtons()) { menuItem.setEnabled(enable); }/*w w w.ja v a 2 s.c om*/ }
From source file:org.n52.ifgicopter.spf.gui.SPFMainFrame.java
/** * this method creates a default UI for an input plugin that does not provide its own. * /*from www. ja v a 2 s.c o m*/ * @param ip * the input plugin * @return a simple gui */ private ModuleGUI createDefaultInputUI(IInputPlugin ip) { ModuleGUI ipgui = new ModuleGUI(); SimpleInputPluginGUI panel = ipgui.new SimpleInputPluginGUI(ip); JMenu newMen = new JMenu(ip.getName()); JMenuItem newItem = new JMenuItem("(no actions)"); newMen.add(newItem); newItem.setEnabled(false); ipgui.setMenu(newMen); ipgui.setGui(panel); return ipgui; }
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup Menu Bar/* w ww . ja v a 2 s . co m*/ * @return JMenu Bar */ private JMenuBar setupMenu() { JMenuBar menuBar = new JMenuBar(); /* -- GridNode Menu -- */ JMenu gridNodeMenu = new JMenu("GridNode"); gridNodeMenu.setMnemonic(KeyEvent.VK_N); menuBar.add(gridNodeMenu); // Discover JMenuItem clusterDiscoverItem = new JMenuItem("Disover and Connect Clusters"); clusterDiscoverItem.setMnemonic(KeyEvent.VK_D); clusterDiscoverItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)); gridNodeMenu.add(clusterDiscoverItem); clusterDiscoverItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doDiscover(false); ((JCheckBoxMenuItem) getUIElement("menu.node.autodiscover")).setSelected(false); } }); addUIElement("menu.node.discover", clusterDiscoverItem); // Add to components map // Auto-Discovery final JCheckBoxMenuItem autodiscoveryItem = new JCheckBoxMenuItem("Auto Discover"); autodiscoveryItem.setMnemonic(KeyEvent.VK_A); autodiscoveryItem.setSelected(true); gridNodeMenu.add(autodiscoveryItem); autodiscoveryItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { autodiscover = autodiscoveryItem.isSelected(); } }); addUIElement("menu.node.autodiscover", autodiscoveryItem); // Add to components map gridNodeMenu.addSeparator(); // Cluster-> Shutdown JMenuItem nodeShutdownItem = new JMenuItem("Shutdown", 'u'); nodeShutdownItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0)); nodeShutdownItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doShutdownNode(); } }); gridNodeMenu.add(nodeShutdownItem); addUIElement("menu.node.shutdown", nodeShutdownItem); // Add to components map /* -- Options Menu -- */ JMenu optionsMenu = new JMenu("Options"); optionsMenu.setMnemonic(KeyEvent.VK_O); menuBar.add(optionsMenu); // Configuration JMenuItem optionsConfigItem = new JMenuItem("Configuration...", 'C'); optionsConfigItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showConfiguration(); } }); optionsMenu.add(optionsConfigItem); optionsConfigItem.setEnabled(false); // TODO Create Configuration Options /* -- Help Menu -- */ JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic(KeyEvent.VK_H); menuBar.add(helpMenu); // Help Contents JMenuItem helpContentsItem = new JMenuItem("Help Contents", 'H'); helpContentsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); helpContentsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showHelp(); } }); helpMenu.add(helpContentsItem); helpMenu.addSeparator(); JMenuItem helpAboutItem = new JMenuItem("About", 'A'); helpAboutItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showAbout(); } }); helpMenu.add(helpAboutItem); return menuBar; }
From source file:org.nuclos.client.customcomp.resplan.ResPlanPanel.java
private void initJResPlan() { resPlan = new JResPlanComponent<Collectable, Date, Collectable, Collectable>(resPlanModel, timeModel); resPlan.getTimelineHeader().setCategoryModel(timeGranularityModel.getSelectedItem()); resPlan.addMouseListener(new AbstractJPopupMenuListener() { @Override// www . ja v a 2 s. c o m protected JPopupMenu getJPopupMenu(MouseEvent evt) { JPopupMenu popupMenu = new JPopupMenu(); Point pt = evt.getPoint(); Area<Collectable, Date> blankSelection = resPlan.getSelectedBlankArea(); if (blankSelection != null) { popupMenu.add(new AddAction(blankSelection.getResource(), blankSelection.getInterval())); } else { popupMenu.add(new AddAction(resPlan.getResourceAt(pt), resPlan.getTimeIntervalAt(pt))); } List<Collectable> selectedEntries = selectEntriesForEvent(pt); List<Collectable> selectedRelations = selectRelationsForEvent(pt); if (resPlan.isEditable() && (!selectedEntries.isEmpty() || !selectedRelations.isEmpty())) { JMenuItem menuItem = popupMenu.add(removeAction); boolean enabled = true; for (Collectable clct : selectedEntries) { if (!resPlanModel.isRemoveEntryAllowed(clct)) { enabled = false; break; } } for (Collectable clct : selectedRelations) { if (!resPlanModel.isRemoveRelationAllowed(clct)) { enabled = false; break; } } // Note: just change the state of the menu item (and leave the action as is) menuItem.setEnabled(enabled); } if (!selectedEntries.isEmpty() || !selectedRelations.isEmpty()) { popupMenu.add(detailsAction); } if (selectedEntries.size() == 1 && resPlanModel.getRelationEntity() != null && resPlanModel.isCreateRelationAllowed()) { popupMenu.addSeparator(); if (resPlan.getRelateBegin() != null) { Collectable to = selectedEntries.get(0); if (to != resPlan.getRelateBegin()) { popupMenu.add(relateFinishAction); } } popupMenu.add(relateBeginAction); } return popupMenu; } private List<Collectable> selectEntriesForEvent(Point pt) { List<Collectable> selection = resPlan.getSelectedEntries(); Collectable entryAt = resPlan.getEntryAt(pt); if (entryAt != null && (selection.isEmpty() || !selection.contains(entryAt))) { selection = Collections.singletonList(entryAt); resPlan.setSelectedEntries(selection); } return selection; } private List<Collectable> selectRelationsForEvent(Point pt) { List<Collectable> selection = resPlan.getSelectedRelations(); Collectable relAt = resPlan.getRelationAt(pt); if (relAt != null && (selection.isEmpty() || !selection.contains(relAt))) { selection = Collections.singletonList(relAt); resPlan.setSelectedRelations(selection); } return selection; } @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Collectable clct = resPlan.getEntryAt(evt.getPoint()); if (clct == null) { clct = resPlan.getRelationAt(evt.getPoint()); if (clct != null) { runDetailsCollectable(resPlanModel.getRelationEntity().getEntityName(), clct); } } else { runDetailsCollectable(resPlanModel.getEntryEntity().getEntityName(), clct); } evt.consume(); } } }); resPlan.getResourceHeader().addMouseListener(new AbstractJPopupMenuListener() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { Collectable clct = resPlan.getResourceHeader().getValueAt(evt.getPoint()); runDetailsCollectable(resPlanModel.getResourceEntity().getEntityName(), clct); evt.consume(); } } @Override protected JPopupMenu getJPopupMenu(MouseEvent evt) { final Collectable clct = resPlan.getResourceHeader().getValueAt(evt.getPoint()); if (clct != null) { JPopupMenu popupMenu = new JPopupMenu(); popupMenu.add(new AbstractAction( SpringLocaleDelegate.getInstance().getText("nuclos.resplan.action.showDetails")) { @Override public void actionPerformed(ActionEvent e) { runDetailsCollectable(resPlanModel.getResourceEntity().getEntityName(), clct); } }); return popupMenu; } return null; } }); Date start = DateUtils.addDays(DateUtils.getPureDate(new Date()), -5); Date end = DateUtils.addDays(start, 30); resPlan.setTimeHorizon(new Interval<Date>(start, end)); }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @precondition getEntityField().isReferencing() * @return a new "show details" entry for the context menu in edit mode *//*from w w w.j a v a 2 s.co m*/ protected final JMenuItem newShowDetailsEntry() { if (!getEntityField().isReferencing()) { throw new IllegalStateException(); } final JMenuItem result = new JMenuItem(TEXT_SHOWDETAILS); boolean bShowDetailsEnabled; try { bShowDetailsEnabled = isReferencedEntityDisplayable() && getField().getValueId() != null; } catch (CollectableFieldFormatException ex) { bShowDetailsEnabled = false; } if (bShowDetailsEnabled) { bShowDetailsEnabled = SecurityCache.getInstance() .isReadAllowedForEntity(getEntityField().getReferencedEntityName()); } result.setEnabled(bShowDetailsEnabled); result.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { fireShowDetails(); } }); return result; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @precondition getEntityField().isReferencing() * @return a new "new" entry for the context menu in edit mode *//*from w w w . j ava2 s. c o m*/ protected final JMenuItem newInsertEntry() { if (!getEntityField().isReferencing()) { throw new IllegalStateException(); } final JMenuItem result = new JMenuItem(TEXT_NEW); String referencedEntity = getEntityField().getReferencedEntityName(); boolean bInsertEnabled = isReferencedEntityDisplayable(); if (bInsertEnabled) { if (Modules.getInstance().existModule(referencedEntity)) { bInsertEnabled = SecurityCache.getInstance().isNewAllowedForModule(referencedEntity); } else { bInsertEnabled = SecurityCache.getInstance().isWriteAllowedForMasterData(referencedEntity); } boolean blnEntityIsEditable = MetaDataClientProvider.getInstance().getEntity(referencedEntity) .isEditable(); if (!blnEntityIsEditable) bInsertEnabled = blnEntityIsEditable; } if (this instanceof CollectableComboBox) result.setEnabled(bInsertEnabled && ((CollectableComboBox) this).getLabeledComponent().isEnabled()); else result.setEnabled(bInsertEnabled && getControlComponent().isEnabled()); result.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { fireCreateNew(); } }); return result; }
From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java
/** * @precondition getEntityField().isReferencing() * @return a new "refresh" entry for the context menu in edit mode *///w w w . j a v a 2 s . co m protected final JMenuItem newRefreshEntry() { if (!getEntityField().isReferencing()) { throw new IllegalStateException(); } final JMenuItem result = new JMenuItem(TEXT_REFRESH); result.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { refreshCacheAndValueList(false); } }); } }); result.setEnabled(getJComponent().isEnabled()); return result; }
From source file:org.nuclos.client.ui.collect.component.CollectableListOfValues.java
/** * adds a "Clear" entry to the popup menu, for a non-searchable component. *//*from ww w . ja v a2 s. co m*/ @Override public JPopupMenu newJPopupMenu() { final JPopupMenu result = super.newJPopupMenu(); if (!this.isSearchComponent()) { final JMenuItem miClear = new JMenuItem(SpringLocaleDelegate.getInstance() .getMessage("CollectableFileNameChooserBase.1", "Zur\u00fccksetzen")); boolean bClearEnabled; try { bClearEnabled = this.getBrowseButton().isEnabled() && (this.getField().getValueId() != null); } catch (CollectableFieldFormatException ex) { bClearEnabled = false; } miClear.setEnabled(bClearEnabled); miClear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { CollectableListOfValues.this.clearListOfValues(); } }); result.add(miClear); } return result; }
From source file:org.omegat.gui.scripting.ScriptingWindow.java
private void setupRunButtons(JPanel panel) { m_btnRunScript = new JButton(); Mnemonics.setLocalizedText(m_btnRunScript, OStrings.getString("SCW_RUN_SCRIPT")); m_btnRunScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnRunScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnRunScript.addActionListener(new ActionListener() { @Override/*from w ww . j a v a 2s . c o m*/ public void actionPerformed(ActionEvent a) { runScript(); } }); panel.add(m_btnRunScript); m_btnCancelScript = new JButton(); Mnemonics.setLocalizedText(m_btnCancelScript, OStrings.getString("SCW_CANCEL_SCRIPT")); m_btnCancelScript.setToolTipText(OStrings.getString("SCW_CANCEL_BUTTON_TOOLTIP")); m_btnCancelScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnCancelScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnCancelScript.addActionListener(e -> cancelCurrentScript()); panel.add(m_btnCancelScript); for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) { final int index = i; final int scriptKey = scriptKey(index); m_quickScriptButtons[i] = new JButton(String.valueOf(scriptKey)); // Run a script from the quick button bar m_quickScriptButtons[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent a) { if (Preferences.existsPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey)) { runQuickScript(index); } else { logResult(StringUtil.format(OStrings.getString("SCW_NO_SCRIPT_BOUND"), scriptKey)); } } }); JPopupMenu quickScriptPopup = new JPopupMenu(); // Add a script to the quick script button bar final JMenuItem addQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_ADD_SCRIPT")); addQuickScriptMenuItem.addActionListener(new QuickScriptUpdater(index)); quickScriptPopup.add(addQuickScriptMenuItem); // Remove a script from the button bar final JMenuItem removeQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_REMOVE_SCRIPT")); removeQuickScriptMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String scriptName = Preferences .getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, "(unknown)"); logResult(StringUtil.format(OStrings.getString("SCW_REMOVED_QUICK_SCRIPT"), scriptName, scriptKey)); Preferences.setPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, ""); m_quickScriptButtons[index].setToolTipText(OStrings.getString("SCW_NO_SCRIPT_SET")); m_quickScriptButtons[index].setText(" " + scriptKey + " "); unsetQuickScriptMenu(index); } }); quickScriptPopup.add(removeQuickScriptMenuItem); quickScriptPopup.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // Disable add a script command if script selection empty addQuickScriptMenuItem.setEnabled(!m_scriptList.isSelectionEmpty()); // Disable remove a script command if the quick run button is not bounded String scriptName = Preferences .getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, null); removeQuickScriptMenuItem.setEnabled(!StringUtil.isEmpty(scriptName)); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // do nothing } @Override public void popupMenuCanceled(PopupMenuEvent e) { // do nothing } }); m_quickScriptButtons[i].setComponentPopupMenu(quickScriptPopup); panel.add(m_quickScriptButtons[i]); } }