下面列出了javax.swing.JPopupMenu#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addRestActions(JPopupMenu menu, WorldObject worldObject) {
if (Game.canActionExecute(playerCharacter, Actions.SLEEP_ACTION, Args.EMPTY, world, worldObject)) {
JMenuItem restMultipleTurnsMenuItem = MenuFactory.createJMenuItem(new GuiRestMultipleTurnsAction(playerCharacter, imageInfoReader, soundIdReader, world, container, dungeonMaster, worldObject, parentFrame), soundIdReader);
restMultipleTurnsMenuItem.setText("Sleep multiple turns...");
setMenuIcon(restMultipleTurnsMenuItem, ImageIds.SLEEPING_INDICATOR);
restMultipleTurnsMenuItem.setToolTipText(Actions.SLEEP_ACTION.getDescription());
menu.add(restMultipleTurnsMenuItem);
GuiRestUntilRestedAction guiRestUntilRestedAction = new GuiRestUntilRestedAction(playerCharacter, imageInfoReader, soundIdReader, world, container, dungeonMaster, worldObject, parentFrame);
JMenuItem restUntilRestedMenuItem = MenuFactory.createJMenuItem(guiRestUntilRestedAction, soundIdReader);
restUntilRestedMenuItem.setText("Sleep " + guiRestUntilRestedAction.getTurns() + " turns until energy is recovered");
setMenuIcon(restUntilRestedMenuItem, ImageIds.SLEEPING_INDICATOR);
restUntilRestedMenuItem.setEnabled(guiRestUntilRestedAction.getTurns() > 0);
restUntilRestedMenuItem.setToolTipText(Actions.SLEEP_ACTION.getDescription());
menu.add(restUntilRestedMenuItem);
}
}
private void addVoteActions(JPopupMenu menu, WorldObject worldObject) {
if (canPlayerCharacterPerformAction(worldObject, Actions.VOTE_FOR_LEADER_ACTION)) {
JMenuItem guiVoteMenuItem = MenuFactory.createJMenuItem(new GuiVoteAction(playerCharacter, imageInfoReader, soundIdReader, world, container, dungeonMaster, worldObject, parentFrame), soundIdReader);
guiVoteMenuItem.setText("Vote...");
setMenuIcon(guiVoteMenuItem, Actions.VOTE_FOR_LEADER_ACTION.getImageIds(playerCharacter));
guiVoteMenuItem.setToolTipText(Actions.VOTE_FOR_LEADER_ACTION.getDescription());
menu.add(guiVoteMenuItem);
}
if (VotingPropertyUtils.isVotingBox(worldObject)) {
JMenuItem guiViewCandidatesMenuItem = MenuFactory.createJMenuItem(new GuiViewCandidatesAction(playerCharacter, imageInfoReader, soundIdReader, world, container, dungeonMaster, worldObject, parentFrame), soundIdReader);
guiViewCandidatesMenuItem.setText("View Candidates...");
setMenuIcon(guiViewCandidatesMenuItem, Actions.VOTE_FOR_LEADER_ACTION.getImageIds(playerCharacter));
guiViewCandidatesMenuItem.setToolTipText("View list of candidates for the election");
menu.add(guiViewCandidatesMenuItem);
}
}
@Override
public void showPopup(MouseEvent e)
{
List<EquipNode> targets = getMenuTargets(equipmentSetTable, e);
if (targets.isEmpty())
{
return;
}
JPopupMenu popupMenu = new JPopupMenu();
popupMenu.add(new MoveEquipUpMenuItem(character, targets));
popupMenu.add(new MoveEquipDownMenuItem(character, targets));
popupMenu.addSeparator();
popupMenu.add(new SortEquipMenuItem(character, targets));
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
public DockableResultDisplay() {
this.dockKey.setDockGroup(MainFrame.DOCK_GROUP_RESULTS);
DockableActionCustomizer customizer = new DockableActionCustomizer() {
@Override
public void visitTabSelectorPopUp(JPopupMenu popUpMenu, Dockable dockable) {
popUpMenu.add(new JMenuItem(new CloseAllResultsAction(RapidMinerGUI.getMainFrame())));
}
};
customizer.setTabSelectorPopUpCustomizer(true); // enable tabbed dock custom popup menu
// entries
this.dockKey.setActionCustomizer(customizer);
setLayout(new BorderLayout());
ExtendedJScrollPane overviewScrollpane = new ExtendedJScrollPane(overview);
overviewScrollpane.setBorder(null);
overviewScrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
overviewScrollpane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(overviewScrollpane, BorderLayout.CENTER);
tableUpdateQueue.start();
}
/** Creates new form RefactoringPanelContainer */
private RefactoringPanelContainer(String name, boolean isRefactoring) {
setName(name);
setToolTipText(name);
setFocusable(true);
setLayout(new java.awt.BorderLayout());
setMinimumSize(new Dimension(1,1));
getAccessibleContext().setAccessibleDescription(
NbBundle.getMessage(RefactoringPanelContainer.class, "ACSD_usagesPanel")
);
pop = new JPopupMenu();
pop.add(new Close());
pop.add(new CloseAll());
pop.add(new CloseAllButCurrent());
listener = new PopupListener();
closeL = new CloseListener();
this.isRefactoring = isRefactoring;
setFocusCycleRoot(true);
JLabel label = new JLabel(NbBundle.getMessage(RefactoringPanelContainer.class, "LBL_NoUsages"));
label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
label.setEnabled(false);
this.add(label, BorderLayout.CENTER);
initActions();
}
private void customizeTemplatesLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_customizeTemplatesLabelMouseClicked
if (collection) {
new OpenTemplateAction(this, NbBundle.getMessage(ManagedBeanCustomizer.class, "ManagedBeanCustomizer.tableTemplate"),
JsfTemplateUtils.getTemplatePath(TemplateType.SNIPPETS, getTemplatesStyle(), TABLE_TEMPLATE)).actionPerformed(null);
} else {
JPopupMenu menu = new JPopupMenu();
String viewTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.SNIPPETS, getTemplatesStyle(), VIEW_TEMPLATE);
String editTemplatePath = JsfTemplateUtils.getTemplatePath(TemplateType.SNIPPETS, getTemplatesStyle(), EDIT_TEMPLATE);
menu.add(new OpenTemplateAction(this, NbBundle.getMessage(ManagedBeanCustomizer.class, "ManagedBeanCustomizer.allTemplates"), viewTemplatePath, editTemplatePath));
menu.add(new OpenTemplateAction(this, NbBundle.getMessage(ManagedBeanCustomizer.class, "ManagedBeanCustomizer.viewTemplate"), viewTemplatePath));
menu.add(new OpenTemplateAction(this, NbBundle.getMessage(ManagedBeanCustomizer.class, "ManagedBeanCustomizer.editTemplate"), editTemplatePath));
menu.show(customizeTemplatesLabel, evt.getX(), evt.getY());
}
}
private static JPopupMenu createPopupMenu(MergePanel panel) {
JPopupMenu popup = new JPopupMenuPlus();
SystemAction[] actions = panel.getSystemActions();
for (int i = 0; i < actions.length; i++) {
if (actions[i] == null) {
popup.addSeparator();
} else if (actions[i] instanceof CallableSystemAction) {
popup.add(((CallableSystemAction)actions[i]).getPopupPresenter());
//add FileSystemAction to pop-up menu
} else if (actions[i] instanceof FileSystemAction) {
popup.add(((FileSystemAction)actions[i]).getPopupPresenter());
}
}
return popup;
}
/**
* Add an item to the generate lists menu.
*
* @param menu Menu.
* @param mode List to be generated.
*/
private void addItemInInternalLinks(JPopupMenu menu, PageListWorker.Mode mode) {
JMenuItem item = Utilities.createJMenuItem(mode.getTitle(), true);
item.setActionCommand(mode.name());
item.addActionListener(EventHandler.create(
ActionListener.class, this, "actionInternalLinks", "actionCommand"));
menu.add(item);
}
private void addPlayerCharacterMenuActions(JPopupMenu popupMenu, InventoryItem inventoryItem, InventoryDialogModel inventoryDialogModel, InventoryActionFactory inventoryActionFactory) {
for(Action inventoryDialogAction : inventoryActionFactory.getPlayerCharacterInventoryActions(inventoryItem.getId())) {
JMenuItem actionMenuItem = MenuFactory.createJMenuItem(inventoryDialogAction, soundIdReader);
actionMenuItem.setToolTipText((String) inventoryDialogAction.getValue(Action.LONG_DESCRIPTION));
popupMenu.add(actionMenuItem);
}
}
/**
* Adds menus related to node selection to a given node context menu.
*
* @param menu The node context menu to extend.
* @param graph The graph the clicked node belongs to.
* @param node The clicked node.
*/
public static void addSelectionMenus(
final JPopupMenu menu, final ZyGraph graph, final NaviNode node) {
Preconditions.checkNotNull(menu, "IE02144: Menu argument can not be null");
Preconditions.checkNotNull(graph, "IE02145: Graph argument can not be null");
Preconditions.checkNotNull(node, "IE02146: Node argument can not be null");
final JMenu selectionMenu = new JMenu("Selection");
selectionMenu.add(CActionProxy.proxy(new CActionSelectNodePredecessors(graph, node)));
selectionMenu.add(CActionProxy.proxy(new CActionSelectNodeSuccessors(graph, node)));
if (graph.getSelectedNodes().size() > 0) {
selectionMenu.add(CActionProxy.proxy(new CGroupAction(graph)));
}
if (node.getRawNode() instanceof INaviCodeNode) {
try {
final INaviFunction parentFunction =
((INaviCodeNode) node.getRawNode()).getParentFunction();
selectionMenu.add(CActionProxy.proxy(
new CActionSelectSameParentFunction(graph, parentFunction)));
} catch (final MaybeNullException exception) {
// Obviously we can not select nodes of the same parent function if there
// is no parent function.
}
} else if (node.getRawNode() instanceof INaviFunctionNode) {
final INaviFunction function = ((INaviFunctionNode) node.getRawNode()).getFunction();
selectionMenu.add(CActionProxy.proxy(
new CActionSelectSameFunctionType(graph, function.getType())));
}
menu.add(selectionMenu);
menu.addSeparator();
}
@Override
public void configureMenu(JPopupMenu menu, Project proj) {
this.circState = proj.getCircuitState();
boolean enabled = circState != null;
this.edit = createItem(enabled, Strings.get("ramEditMenuItem"));
this.clear = createItem(enabled, Strings.get("ramClearMenuItem"));
menu.addSeparator();
menu.add(this.edit);
menu.add(this.clear);
}
/**
* Action called when Load Selection button is pressed.
*/
public void actionLoadSelection() {
// Retrieve possible selections
Configuration config = Configuration.getConfiguration();
Properties properties = config.getProperties(null, Configuration.ARRAY_CHECK_BOT_SELECTION);
if ((properties == null) || (properties.isEmpty())) {
return;
}
Set<Object> keySet = properties.keySet();
List<String> keyList = new ArrayList<String>();
for (Object key : keySet) {
keyList.add(key.toString());
}
Collections.sort(keyList);
// Create menu
JPopupMenu menu = new JPopupMenu();
for (String name : keyList) {
JMenuItem item = Utilities.createJMenuItem(name, true);
item.setActionCommand(properties.getProperty(name));
item.addActionListener(EventHandler.create(
ActionListener.class, this, "actionLoadSelection", "actionCommand"));
menu.add(item);
}
menu.show(
buttonLoadSelection,
0,
buttonLoadSelection.getHeight());
}
private void showPopup(final MouseEvent event) {
final JPopupMenu popupMenu = new JPopupMenu();
popupMenu.add(new AddMemberAction());
final int selectedRow = table.getSelectedRow();
if (selectedRow != -1) {
final MemberTableRowData row = table.getModel().getRow(selectedRow);
popupMenu.add(new InsertMemberBeforeAction(selectedRow, row.getName()));
popupMenu.add(new InsertMemberAfterAction(selectedRow, row.getName()));
popupMenu.add(new DeleteMemberAction(selectedRow, row.getName()));
}
popupMenu.show(event.getComponent(), event.getX(), event.getY());
}
private void addAction(JPopupMenu popup, Action action) {
if (action == null) {
popup.addSeparator();
} else {
Class cls = (Class)action.getValue(KEY_CLASS);
if (Boolean.class.equals(cls)) {
Boolean boolvalue = (Boolean)action.getValue(KEY_BOOLVALUE);
JCheckBoxMenuItem item = new JCheckBoxMenuItem(action);
item.setSelected(boolvalue);
popup.add(item);
} else {
popup.add(action);
}
}
}
/**
* Creates a popup menu for the panel.
*
* @param properties include a menu item for the chart property editor.
* @param save include a menu item for saving the chart.
* @param print include a menu item for printing the chart.
* @param zoom include menu items for zooming.
*
* @return The popup menu.
*/
@Override
protected JPopupMenu createPopupMenu(boolean properties, boolean save,
boolean print, boolean zoom) {
JPopupMenu result = super.createPopupMenu(properties, save, print, zoom);
int zoomInIndex = getPopupMenuItem(result,
localizationResources.getString("Zoom_In"));
int zoomOutIndex = getPopupMenuItem(result,
localizationResources.getString("Zoom_Out"));
int autoIndex = getPopupMenuItem(result,
localizationResources.getString("Auto_Range"));
if (zoom) {
JMenuItem zoomIn = new JMenuItem(
localizationResources.getString("Zoom_In"));
zoomIn.setActionCommand(POLAR_ZOOM_IN_ACTION_COMMAND);
zoomIn.addActionListener(this);
JMenuItem zoomOut = new JMenuItem(
localizationResources.getString("Zoom_Out"));
zoomOut.setActionCommand(POLAR_ZOOM_OUT_ACTION_COMMAND);
zoomOut.addActionListener(this);
JMenuItem auto = new JMenuItem(
localizationResources.getString("Auto_Range"));
auto.setActionCommand(POLAR_AUTO_RANGE_ACTION_COMMAND);
auto.addActionListener(this);
if (zoomInIndex != -1) {
result.remove(zoomInIndex);
}
else {
zoomInIndex = result.getComponentCount() - 1;
}
result.add(zoomIn, zoomInIndex);
if (zoomOutIndex != -1) {
result.remove(zoomOutIndex);
}
else {
zoomOutIndex = zoomInIndex + 1;
}
result.add(zoomOut, zoomOutIndex);
if (autoIndex != -1) {
result.remove(autoIndex);
}
else {
autoIndex = zoomOutIndex + 1;
}
result.add(auto, autoIndex);
}
return result;
}
@Override
public void configureMenu(JPopupMenu menu, Project proj) {
menu.addSeparator();
menu.add(new SplitterDistributeItem(proj, this, 1));
menu.add(new SplitterDistributeItem(proj, this, -1));
}
private void selectionChart(DBBrowserNode selectedNode, MouseEvent e, boolean pressed) {
OpenChartAction openAction = new OpenChartAction();
openAction.setChartName(selectedNode.getDBObject().getName());
openAction.setChartPath(selectedNode.getDBObject().getAbsolutePath());
if (e.getClickCount() == 2) {
if (pressed) {
openAction.actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
}
} else {
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem(openAction);
popupMenu.add(menuItem);
DeleteChartAction deleteAction = new DeleteChartAction(instance, selectedNode);
JMenuItem menuItem2 = new JMenuItem(deleteAction);
popupMenu.add(menuItem2);
RenameChartAction renameAction = new RenameChartAction(instance, selectedNode);
JMenuItem menuItem3 = new JMenuItem(renameAction);
popupMenu.add(menuItem3);
ExportChartAction exportAction = new ExportChartAction(instance, selectedNode);
JMenuItem menuItem4 = new JMenuItem(exportAction);
popupMenu.add(menuItem4);
Chart chart = ChartUtil.loadChart(selectedNode.getDBObject().getAbsolutePath());
PreviewChartAction previewHTML5Action = new PreviewChartAction(ChartRunner.GRAPHIC_FORMAT,
ChartRunner.HTML5_TYPE, I18NSupport.getString("preview.html5"));
previewHTML5Action.setChart(chart);
popupMenu.add(previewHTML5Action);
PreviewChartAction previewFlashAction = new PreviewChartAction(ChartRunner.GRAPHIC_FORMAT,
ChartRunner.FLASH_TYPE, I18NSupport.getString("preview.flash"));
previewFlashAction.setChart(chart);
popupMenu.add(previewFlashAction);
previewFlashAction.setEnabled(!ChartType.hasNoFlashSupport(chart.getType().getType()));
PreviewChartAction previewImageAction = new PreviewChartAction(ChartRunner.IMAGE_FORMAT,
ChartRunner.NO_TYPE, I18NSupport.getString("preview.image"));
previewImageAction.setChart(chart);
popupMenu.add(previewImageAction);
PublishChartAction publishAction = new PublishChartAction(selectedNode.getDBObject().getAbsolutePath());
JMenuItem menuItem5 = new JMenuItem(publishAction);
popupMenu.add(menuItem5);
JMenuItem menuItem6 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject()));
popupMenu.add(menuItem6);
JMenuItem menuItem7 = new JMenuItem(new AddToFavoritesAction(selectedNode.getDBObject()));
popupMenu.add(menuItem7);
popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
}
}
private void initKeyStoreTabPopupMenu() {
jpmKeyStoreTab = new JPopupMenu();
jmiKeyStoreTabSave = new JMenuItem(saveAction);
jmiKeyStoreTabSave.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabSave, (String) saveAction.getValue(Action.LONG_DESCRIPTION), this);
jpmKeyStoreTab.add(jmiKeyStoreTabSave);
jmiKeyStoreTabSaveAll = new JMenuItem(saveAllAction);
jmiKeyStoreTabSaveAll.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabSaveAll, (String) saveAllAction.getValue(Action.LONG_DESCRIPTION),
this);
jpmKeyStoreTab.add(jmiKeyStoreTabSaveAll);
jpmKeyStoreTab.addSeparator();
jmiKeyStoreTabPaste = new JMenuItem(pasteAction);
jmiKeyStoreTabPaste.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabPaste, (String) pasteAction.getValue(Action.LONG_DESCRIPTION), this);
jpmKeyStoreTab.add(jmiKeyStoreTabPaste);
jpmKeyStoreTab.addSeparator();
jmiKeyStoreTabClose = new JMenuItem(closeAction);
jmiKeyStoreTabClose.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabClose, (String) closeAction.getValue(Action.LONG_DESCRIPTION), this);
jpmKeyStoreTab.add(jmiKeyStoreTabClose);
jmiKeyStoreTabCloseOthers = new JMenuItem(closeOthersAction);
jmiKeyStoreTabCloseOthers.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabCloseOthers,
(String) closeOthersAction.getValue(Action.LONG_DESCRIPTION), this);
jpmKeyStoreTab.add(jmiKeyStoreTabCloseOthers);
jmiKeyStoreTabCloseAll = new JMenuItem(closeAllAction);
jmiKeyStoreTabCloseAll.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabCloseAll, (String) closeAllAction.getValue(Action.LONG_DESCRIPTION),
this);
jpmKeyStoreTab.add(jmiKeyStoreTabCloseAll);
jpmKeyStoreTab.addSeparator();
jmiKeyStoreTabProperties = new JMenuItem(propertiesAction);
jmiKeyStoreTabProperties.setToolTipText(null);
new StatusBarChangeHandler(jmiKeyStoreTabProperties,
(String) propertiesAction.getValue(Action.LONG_DESCRIPTION), this);
jpmKeyStoreTab.add(jmiKeyStoreTabProperties);
}
public ResultView() {
setLayout(contentCards = new CardLayout());
setName("Search Results"); //NOI18N
setDisplayName(NbBundle.getMessage(ResultView.class, "TITLE_SEARCH_RESULTS")); //NOI18N
initAccessibility();
pop = new JPopupMenu();
pop.add(new Close());
pop.add(new CloseAll());
pop.add(new CloseAllButCurrent());
popL = new PopupListener();
closeL = new CloseListener();
emptyPanel = new JPanel();
singlePanel = new JPanel();
singlePanel.setLayout(new BoxLayout(singlePanel, BoxLayout.PAGE_AXIS));
emptyPanel.setOpaque(true);
tabs = TabbedPaneFactory.createCloseButtonTabbedPane();
tabs.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
updateLookup();
}
});
tabs.setMinimumSize(new Dimension(0, 0));
tabs.addMouseListener(popL);
tabs.addPropertyChangeListener(closeL);
add(emptyPanel, CARD_NAME_EMPTY);
add(tabs, CARD_NAME_TABS);
add(singlePanel, CARD_NAME_SINGLE);
if (isMacLaf) {
emptyPanel.setBackground(macBackground);
tabs.setBackground(macBackground);
tabs.setOpaque(true);
setBackground(macBackground);
setOpaque(true);
} else {
emptyPanel.setBackground(
UIManager.getColor("Tree.background")); //NOI18N
}
contentCards.show(this, CARD_NAME_EMPTY);
associateLookup(Lookups.proxy(lookupProvider));
}
/**
* Responsible for popping up the menu items.
*
* @param e the MouseEvent that triggered it.
* @param jid the JID to handle.
*/
private void showPopup(MouseEvent e, String jid) {
final JPopupMenu popup = new JPopupMenu();
popup.add(unBanMenuItem);
popup.show(this, e.getX(), e.getY());
}