List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:de.erdesignerng.visual.common.OutlineComponent.java
/** * Create the PopupMenu actions correlating to a specific tree node. * * @param aNode - the node//from w w w . ja v a 2 s . c o m * @param aMenu - the menu to add the actions to * @param aRecursive - recursive */ private void initializeActionsFor(final DefaultMutableTreeNode aNode, JPopupMenu aMenu, boolean aRecursive) { Object theUserObject = aNode.getUserObject(); if (!aRecursive) { JMenuItem theExpandAllItem = new JMenuItem(); theExpandAllItem.setText(getResourceHelper().getFormattedText(ERDesignerBundle.EXPANDALL)); theExpandAllItem .addActionListener(e -> expandOrCollapseAllChildrenOfNode(new TreePath(aNode.getPath()), true)); aMenu.add(theExpandAllItem); JMenuItem theCollapseAllItem = new JMenuItem(); theCollapseAllItem.setText(getResourceHelper().getFormattedText(ERDesignerBundle.COLLAPSEALL)); theCollapseAllItem.addActionListener( e -> expandOrCollapseAllChildrenOfNode(new TreePath(aNode.getPath()), false)); aMenu.add(theCollapseAllItem); aMenu.addSeparator(); } List<ModelItem> theItemList = new ArrayList<>(); if (theUserObject instanceof ModelItem) { theItemList.add((ModelItem) theUserObject); ContextMenuFactory.addActionsToMenu(ERDesignerComponent.getDefault().getEditor(), aMenu, theItemList); } if (aNode.getParent() != null) { initializeActionsFor((DefaultMutableTreeNode) aNode.getParent(), aMenu, true); } }
From source file:ca.phon.app.project.ProjectWindow.java
/** * Displays the corpus list menu//from w w w . ja v a 2 s.co m * * @param clickPoint */ private void showCorpusListContextMenu(Point clickPoint) { List<String> corpora = getSelectedCorpora(); JPopupMenu contextMenu = new JPopupMenu(); if (corpora.size() == 1) { // new session item JMenuItem newSessionItem = new JMenuItem(new NewSessionAction(this)); contextMenu.add(newSessionItem); contextMenu.addSeparator(); JMenuItem templateItem = new JMenuItem(new OpenCorpusTemplateAction(this)); contextMenu.add(templateItem); contextMenu.addSeparator(); } JMenuItem dupItem = new JMenuItem(new DuplicateCorpusAction(this)); if (corpora.size() > 1) { dupItem.setText("Duplicate Corpora"); } contextMenu.add(dupItem); if (corpora.size() == 1) { // rename JMenuItem renameItem = new JMenuItem(new RenameCorpusAction(this)); contextMenu.add(renameItem); } // delete JMenuItem deleteItem = new JMenuItem(new DeleteCorpusAction(this)); if (corpora.size() > 1) { deleteItem.setText("Delete Corpora"); } contextMenu.add(deleteItem); contextMenu.show(corpusList, clickPoint.x, clickPoint.y); }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initTablePopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteMenuItem = new JMenuItem("(D)", new ImageIcon(getClass().getResource("edit-delete-6.png"))); deleteMenuItem.setMnemonic('D'); popupMenu.add(deleteMenuItem); deleteMenuItem.addActionListener(new ActionListener() { @Override// ww w . j av a2 s .co m public void actionPerformed(ActionEvent e) { deleteRecord(); } }); popupMenu.addSeparator(); JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png"))); editMenuItem.setMnemonic('E'); popupMenu.add(editMenuItem); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow())); showUpdateRecordDialog(record); } }); // ??popup menu table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (disable) return; JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(e.getPoint()); if (SwingUtilities.isRightMouseButton(e)) { if (row >= 0 && col >= 0) { table.setRowSelectionInterval(row, row); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } else if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 2) { if (row >= 0 && col >= 0) { // Record record = model.getRecord(table.convertRowIndexToModel(row)); // showUpdateRecordDialog(record); } } } } }); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table.getActionMap().put("Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { if (disable) return; //do something on JTable enter pressed int row = table.getSelectedRow(); if (row >= 0) { Record record = model.getRecord(table.convertRowIndexToModel(row)); showUpdateRecordDialog(record); } } }); }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void displayAddPopup(JButton src) { JPopupMenu p = new JPopupMenu(); Map<String, List<Series<?>>> series = sampler.getCategories(); for (Map.Entry<String, List<Series<?>>> e1 : series.entrySet()) { JMenu sm = new JMenu(e1.getKey()); for (final Series<?> s : e1.getValue()) { if (!enabled.contains(s.getKey())) { JMenuItem mi = new JMenuItem(s.getLabel()); mi.addActionListener(new ActionListener() { @Override//ww w .j a v a 2 s. c o m public void actionPerformed(ActionEvent e) { enable(s); } }); sm.add(mi); } } p.add(sm); } p.show(src, 4, 4); }
From source file:brainflow.app.toplevel.BrainFlow.java
private JPopupMenu createPopup(java.util.List<Action> actionList) { JPopupMenu menu = new JPopupMenu(); for (Action action : actionList) { menu.add(action); }//from w ww .jav a 2 s .c o m return menu; }
From source file:medsavant.enrichment.app.RegionListAggregatePanel.java
private JPopupMenu createPopup() { JPopupMenu menu = new JPopupMenu(); TableModel model = tablePanel.getTable().getModel(); final int[] selRows = tablePanel.getTable().getSelectedRows(); if (selRows.length == 1) { JMenuItem browseItem = new JMenuItem(String.format("<html>Look at %s in genome browser</html>", "<i>" + model.getValueAt(selRows[0], 0) + "</i>")); browseItem.addActionListener(new ActionListener() { @Override/* w w w . j av a 2s . co m*/ public void actionPerformed(ActionEvent ae) { TableModel model = tablePanel.getTable().getModel(); int r = selRows[0]; LocationController.getInstance().setLocation((String) model.getValueAt(r, 1), new Range((Integer) model.getValueAt(r, 2), (Integer) model.getValueAt(r, 3))); ViewController.getInstance().getMenu().switchToSubSection(BrowserPage.getInstance()); } }); menu.add(browseItem); } JMenuItem posItem = new JMenuItem(String.format("<html>Filter by %s</html>", selRows.length == 1 ? "Region <i>" + model.getValueAt(selRows[0], 0) + "</i>" : "Selected Regions")); posItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { ThreadController.getInstance().cancelWorkers(pageName); List<GenomicRegion> regions = new ArrayList<GenomicRegion>(); TableModel model = tablePanel.getTable().getModel(); for (int r : selRows) { String geneName = (String) model.getValueAt(r, 0); String chrom = (String) model.getValueAt(r, 1); Integer start = (Integer) model.getValueAt(r, 2); Integer end = (Integer) model.getValueAt(r, 3); regions.add(new GenomicRegion(geneName, chrom, start, end)); } QueryUtils.addQueryOnRegions(regions, Arrays.asList(new RegionSet[] { (RegionSet) regionSetCombo.getSelectedItem() })); } }); menu.add(posItem); return menu; }
From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java
protected JPopupMenu createPopupMenu() { if (TABLE.getSelectionModel().isSelectionEmpty()) { return null; }/*from w w w . j ava 2s. co m*/ JPopupMenu menu = new SkinPopupMenu(); menu.add(new SkinMenuItem(LAUNCH_ACTION)); if (getMediaType().equals(MediaType.getAudioMediaType())) { menu.add(new SkinMenuItem(LAUNCH_OS_ACTION)); } if (hasExploreAction()) { menu.add(new SkinMenuItem(OPEN_IN_FOLDER_ACTION)); } if (areAllSelectedFilesMP4s()) { menu.add(DEMUX_MP4_AUDIO_ACTION); DEMUX_MP4_AUDIO_ACTION.setEnabled(!((DemuxMP4AudioAction) DEMUX_MP4_AUDIO_ACTION).isDemuxing()); } menu.add(new SkinMenuItem(CREATE_TORRENT_ACTION)); if (areAllSelectedFilesPlayable()) { menu.add(createAddToPlaylistSubMenu()); } //sharing takes a while... //there's an in between state while the file is changing from //unshare to shared, this is "being shared" boolean noneSharing = !isAnyBeingShared(); boolean allShared = areAllSelectedFilesShared(); WIFI_SHARE_ACTION.setEnabled(noneSharing && !allShared); //unsharing is immediate. WIFI_UNSHARE_ACTION.setEnabled(noneSharing && allShared); //menu.add(new SkinMenuItem(areAllSelectedFilesShared() ? WIFI_UNSHARE_ACTION : WIFI_SHARE_ACTION)); if (WIFI_SHARE_ACTION.isEnabled()) { menu.add(WIFI_SHARE_ACTION); } if (WIFI_UNSHARE_ACTION.isEnabled()) { menu.add(WIFI_UNSHARE_ACTION); } menu.add(new SkinMenuItem(SEND_TO_FRIEND_ACTION)); menu.add(new SkinMenuItem(SEND_TO_ITUNES_ACTION)); menu.addSeparator(); menu.add(new SkinMenuItem(DELETE_ACTION)); menu.add(new SkinMenuItem(RENAME_ACTION)); menu.addSeparator(); int[] rows = TABLE.getSelectedRows(); boolean dirSelected = false; boolean fileSelected = false; for (int i = 0; i < rows.length; i++) { File f = DATA_MODEL.get(rows[i]).getFile(); if (f.isDirectory()) { dirSelected = true; // if (IncompleteFileManager.isTorrentFolder(f)) // torrentSelected = true; } else fileSelected = true; if (dirSelected && fileSelected) break; } if (dirSelected) { DELETE_ACTION.setEnabled(true); RENAME_ACTION.setEnabled(false); } else { DELETE_ACTION.setEnabled(true); } LibraryFilesTableDataLine line = DATA_MODEL.get(rows[0]); menu.add(createSearchSubMenu(line)); return menu; }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
private JPopupMenu createPopupMenu(boolean over_peak) { JPopupMenu menu = new JPopupMenu(); if (over_peak) { updatePeakActions();/*from w w w . j a v a 2 s. c o m*/ ButtonGroup group = new ButtonGroup(); if (shown_mslevel.equals("ms")) { for (GlycanAction a : theApplication.getPluginManager().getMsPeakActions()) { JRadioButtonMenuItem last = new JRadioButtonMenuItem( new GlycanAction(a, "annotatepeaks", -1, "", this)); menu.add(last); last.setSelected(a == ms_action); group.add(last); } } else { for (GlycanAction a : theApplication.getPluginManager().getMsMsPeakActions()) { JRadioButtonMenuItem last = new JRadioButtonMenuItem( new GlycanAction(a, "annotatepeaks", -1, "", this)); menu.add(last); last.setSelected(a == msms_action); group.add(last); } } menu.addSeparator(); } menu.add(theActionManager.get("zoomnone")); menu.add(theActionManager.get("zoomin")); menu.add(theActionManager.get("zoomout")); return menu; }
From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java
private void valueLeafActionEdit(final MouseEvent mouseEvent, final TreePath selectedPath, final XmlDomAdapterNode clickedItem, final JTree tree) { final JPopupMenu popup = new JPopupMenu(); // Basic type : edit final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("EDIT")); menuItem.addActionListener(new ActionListener() { @Override/*www . ja v a2 s.c o m*/ public void actionPerformed(ActionEvent actionEvent) { final String newValue = JOptionPane.showInputDialog(ResourceUtils.getI18n("EDIT"), clickedItem.node.getNodeValue()); if (newValue != null) { try { if (clickedItem.node instanceof Attr) { ((Attr) clickedItem.node).setValue(newValue); } else { clickedItem.node.setNodeValue(newValue); } //clickedItem.setNewValue(newValue); } catch (NumberFormatException e) { showErrorMessage(newValue, tree); } validationPolicyTreeModel.fireTreeChanged(selectedPath); } } }); popup.add(menuItem); popup.show(tree, mouseEvent.getX(), mouseEvent.getY()); }
From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java
private void createPopupMenu() { JMenuItem menuItem;//from w w w. j av a 2 s.c o m //Create the popup menu. JPopupMenu popup = new JPopupMenu(); menuItem = new JMenuItem("Rename ..."); menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK)); menuItem.addActionListener(this); popup.add(menuItem); /*popup.add(new javax.swing.JSeparator());*/ menuItem = new JMenuItem("Delete"); menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK)); menuItem.addActionListener(this); popup.add(menuItem); popup.add(new javax.swing.JSeparator()); menuItem = new JMenuItem("Refresh All"); menuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK)); menuItem.addActionListener(this); popup.add(menuItem); //Add listener to the tree MouseListener popupListener = new PreviousRunsTreePopupListener(popup); jTree1.addMouseListener(popupListener); jTree1.addMouseMotionListener(new PreviousRunsTreeMouseMoveListener()); }