List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:net.sf.jabref.openoffice.OpenOfficePanel.java
private void showSettingsPopup() { JPopupMenu menu = new JPopupMenu(); final JCheckBoxMenuItem autoSync = new JCheckBoxMenuItem( Localization.lang("Automatically sync bibliography when inserting citations"), Globals.prefs.getBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING)); final JRadioButtonMenuItem useActiveBase = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in the active tab only")); final JRadioButtonMenuItem useAllBases = new JRadioButtonMenuItem( Localization.lang("Look up BibTeX entries in all open databases")); final JMenuItem clearConnectionSettings = new JMenuItem(Localization.lang("Clear connection settings")); ButtonGroup bg = new ButtonGroup(); bg.add(useActiveBase);//from w w w. j av a 2 s . c o m bg.add(useAllBases); if (Globals.prefs.getBoolean(JabRefPreferences.USE_ALL_OPEN_BASES)) { useAllBases.setSelected(true); } else { useActiveBase.setSelected(true); } autoSync.addActionListener( e -> Globals.prefs.putBoolean(JabRefPreferences.SYNC_OO_WHEN_CITING, autoSync.isSelected())); useAllBases.addActionListener( e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, useAllBases.isSelected())); useActiveBase.addActionListener( e -> Globals.prefs.putBoolean(JabRefPreferences.USE_ALL_OPEN_BASES, !useActiveBase.isSelected())); clearConnectionSettings.addActionListener(e -> { Globals.prefs.clear(JabRefPreferences.OO_PATH); Globals.prefs.clear(JabRefPreferences.OO_EXECUTABLE_PATH); Globals.prefs.clear(JabRefPreferences.OO_JARS_PATH); frame.output(Localization.lang("Cleared connection settings.")); }); menu.add(autoSync); menu.addSeparator(); menu.add(useActiveBase); menu.add(useAllBases); menu.addSeparator(); menu.add(clearConnectionSettings); menu.show(settingsB, 0, settingsB.getHeight()); }
From source file:com.pironet.tda.TDA.java
public void createPopupMenu() { //Create the popup menu. JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Diff Selection"); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem("Find long running threads..."); menuItem.addActionListener(this); popup.add(menuItem);//from w w w . j a va 2s . c o m showDumpMenuItem = new JMenuItem("Show selected Dump in logfile"); showDumpMenuItem.addActionListener(this); showDumpMenuItem.setEnabled(false); if (!runningAsJConsolePlugin && !runningAsVisualVMPlugin) { popup.addSeparator(); menuItem = new JMenuItem("Parse loggc-logfile..."); menuItem.addActionListener(this); if (!PrefManager.get().getForceLoggcLoading()) { menuItem.setEnabled(!isFoundClassHistogram); } popup.add(menuItem); menuItem = new JMenuItem("Close logfile..."); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); popup.add(showDumpMenuItem); } else { popup.addSeparator(); if (!runningAsVisualVMPlugin) { menuItem = new JMenuItem("Request Thread Dump..."); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); menuItem = new JMenuItem("Preferences"); menuItem.addActionListener(this); popup.add(menuItem); menuItem = new JMenuItem("Filters"); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); menuItem = new JMenuItem("Save Logfile..."); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); menuItem = new JCheckBoxMenuItem("Show Toolbar", PrefManager.get().getShowToolbar()); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); menuItem = new JMenuItem("Help"); menuItem.addActionListener(this); popup.add(menuItem); popup.addSeparator(); } menuItem = new JMenuItem("About TDA"); menuItem.addActionListener(this); popup.add(menuItem); } //Add listener to the text area so the popup menu can come up. MouseListener popupListener = new PopupListener(popup); tree.addMouseListener(popupListener); }
From source file:org.esa.beam.visat.toolviews.stat.StatisticsPanel.java
private AbstractButton getExportButton() { final AbstractButton export = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);/*from www . j av a 2s . c o m*/ export.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPopupMenu viewPopup = new JPopupMenu("Export"); viewPopup.add(exportAsCsvAction); viewPopup.add(putStatisticsIntoVectorDataAction); final Rectangle buttonBounds = export.getBounds(); viewPopup.show(export, 1, buttonBounds.height + 1); } }); export.setEnabled(false); return export; }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected JPopupMenu createWindowPopupMenu(final Window window) { JPopupMenu popupMenu = new JPopupMenu(); ClientConfig clientConfig = configuration.getConfig(ClientConfig.class); if (clientConfig.getManualScreenSettingsSaving()) { JMenuItem saveSettingsItem = new JMenuItem(messages.getMainMessage("actions.saveSettings")); saveSettingsItem.addActionListener(new ActionListener() { @Override/*from w w w. j a v a 2 s .c o m*/ public void actionPerformed(ActionEvent e) { window.saveSettings(); } }); popupMenu.add(saveSettingsItem); JMenuItem restoreToDefaultsItem = new JMenuItem(messages.getMainMessage("actions.restoreToDefaults")); restoreToDefaultsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { window.deleteSettings(); } }); popupMenu.add(restoreToDefaultsItem); } if (clientConfig.getLayoutAnalyzerEnabled()) { JMenuItem analyzeLayoutItem = new JMenuItem(messages.getMainMessage("actions.analyzeLayout")); analyzeLayoutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LayoutAnalyzer analyzer = new LayoutAnalyzer(); List<LayoutTip> tipsList = analyzer.analyze(window); if (tipsList.isEmpty()) { showNotification("No layout problems found", NotificationType.HUMANIZED); } else { window.openWindow("layoutAnalyzer", OpenType.DIALOG, ParamsMap.of("tipsList", tipsList)); } } }); popupMenu.add(analyzeLayoutItem); } return popupMenu; }
From source file:net.sf.jabref.gui.JabRefFrame.java
private JPopupMenu tabPopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); // Close actions JMenuItem close = new JMenuItem(Localization.lang("Close")); JMenuItem closeOthers = new JMenuItem(Localization.lang("Close Others")); JMenuItem closeAll = new JMenuItem(Localization.lang("Close All")); close.addActionListener(closeDatabaseAction); closeOthers.addActionListener(closeOtherDatabasesAction); closeAll.addActionListener(closeAllDatabasesAction); popupMenu.add(close); popupMenu.add(closeOthers);/* www . jav a2s .com*/ popupMenu.add(closeAll); popupMenu.addSeparator(); JMenuItem databaseProperties = new JMenuItem(Localization.lang("Database properties")); databaseProperties.addActionListener(this.databaseProperties); popupMenu.add(databaseProperties); JMenuItem bibtexKeyPatternBtn = new JMenuItem(Localization.lang("BibTeX key patterns")); bibtexKeyPatternBtn.addActionListener(bibtexKeyPattern); popupMenu.add(bibtexKeyPatternBtn); JMenuItem manageSelectorsBtn = new JMenuItem(Localization.lang("Manage content selectors")); manageSelectorsBtn.addActionListener(manageSelectors); popupMenu.add(manageSelectorsBtn); return popupMenu; }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Creates a popup menu for the panel./*from w ww . j a v a 2 s . co m*/ * * @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. */ protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { JPopupMenu result = new JPopupMenu("Chart:"); boolean separator = false; if (properties) { JMenuItem propertiesItem = new JMenuItem(localizationResources.getString("Properties...")); propertiesItem.setActionCommand(PROPERTIES_COMMAND); propertiesItem.addActionListener(this); result.add(propertiesItem); separator = true; } if (save) { if (separator) { result.addSeparator(); separator = false; } JMenuItem saveItem = new JMenuItem(localizationResources.getString("Save_as...")); saveItem.setActionCommand(SAVE_COMMAND); saveItem.addActionListener(this); result.add(saveItem); separator = true; } if (print) { if (separator) { result.addSeparator(); separator = false; } JMenuItem printItem = new JMenuItem(localizationResources.getString("Print...")); printItem.setActionCommand(PRINT_COMMAND); printItem.addActionListener(this); result.add(printItem); separator = true; } if (zoom) { if (separator) { result.addSeparator(); separator = false; } JMenu zoomInMenu = new JMenu(localizationResources.getString("Zoom_In")); this.zoomInBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); this.zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_COMMAND); this.zoomInBothMenuItem.addActionListener(this); zoomInMenu.add(this.zoomInBothMenuItem); zoomInMenu.addSeparator(); this.zoomInDomainMenuItem = new JMenuItem(localizationResources.getString("Domain_Axis")); this.zoomInDomainMenuItem.setActionCommand(ZOOM_IN_DOMAIN_COMMAND); this.zoomInDomainMenuItem.addActionListener(this); zoomInMenu.add(this.zoomInDomainMenuItem); this.zoomInRangeMenuItem = new JMenuItem(localizationResources.getString("Range_Axis")); this.zoomInRangeMenuItem.setActionCommand(ZOOM_IN_RANGE_COMMAND); this.zoomInRangeMenuItem.addActionListener(this); zoomInMenu.add(this.zoomInRangeMenuItem); result.add(zoomInMenu); JMenu zoomOutMenu = new JMenu(localizationResources.getString("Zoom_Out")); this.zoomOutBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); this.zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_COMMAND); this.zoomOutBothMenuItem.addActionListener(this); zoomOutMenu.add(this.zoomOutBothMenuItem); zoomOutMenu.addSeparator(); this.zoomOutDomainMenuItem = new JMenuItem(localizationResources.getString("Domain_Axis")); this.zoomOutDomainMenuItem.setActionCommand(ZOOM_OUT_DOMAIN_COMMAND); this.zoomOutDomainMenuItem.addActionListener(this); zoomOutMenu.add(this.zoomOutDomainMenuItem); this.zoomOutRangeMenuItem = new JMenuItem(localizationResources.getString("Range_Axis")); this.zoomOutRangeMenuItem.setActionCommand(ZOOM_OUT_RANGE_COMMAND); this.zoomOutRangeMenuItem.addActionListener(this); zoomOutMenu.add(this.zoomOutRangeMenuItem); result.add(zoomOutMenu); JMenu autoRangeMenu = new JMenu(localizationResources.getString("Auto_Range")); this.zoomResetBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); this.zoomResetBothMenuItem.setActionCommand(ZOOM_RESET_BOTH_COMMAND); this.zoomResetBothMenuItem.addActionListener(this); autoRangeMenu.add(this.zoomResetBothMenuItem); autoRangeMenu.addSeparator(); this.zoomResetDomainMenuItem = new JMenuItem(localizationResources.getString("Domain_Axis")); this.zoomResetDomainMenuItem.setActionCommand(ZOOM_RESET_DOMAIN_COMMAND); this.zoomResetDomainMenuItem.addActionListener(this); autoRangeMenu.add(this.zoomResetDomainMenuItem); this.zoomResetRangeMenuItem = new JMenuItem(localizationResources.getString("Range_Axis")); this.zoomResetRangeMenuItem.setActionCommand(ZOOM_RESET_RANGE_COMMAND); this.zoomResetRangeMenuItem.addActionListener(this); autoRangeMenu.add(this.zoomResetRangeMenuItem); result.addSeparator(); result.add(autoRangeMenu); } return result; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Creates a JMenuItem./* w w w.j a v a2 s . co m*/ * @param menu parent menu * @param label the label of the menu item * @param mnemonic the mnemonic * @param accessibleDescription the accessible Description * @param enabled enabled * @param action the aciton * @return menu item */ public static JMenuItem createMenuItemWithAction(final JPopupMenu menu, final String label, final String mnemonic, final String accessibleDescription, final boolean enabled, final Action action) { JMenuItem mi = new JMenuItem(action); mi.setText(label); if (menu != null) { menu.add(mi); } if (isNotEmpty(mnemonic)) { mi.setMnemonic(mnemonic.charAt(0)); } if (isNotEmpty(accessibleDescription)) { mi.getAccessibleContext().setAccessibleDescription(accessibleDescription); } if (action != null) { action.addPropertyChangeListener(new MenuItemPropertyChangeListener(mi)); action.setEnabled(enabled); } return mi; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Creates a JMenuItem./*from ww w. j a v a2 s. c o m*/ * @param popupMenu * @param key * @param mnemonic * @param accessibleDescription * @param enabled * @param al * @return */ public static JMenuItem createLocalizedMenuItem(final JPopupMenu popupMenu, final String key, final String mnemonic, final String accessibleDescription, final boolean enabled, final ActionListener al) { JMenuItem mi = createLocalizedMenuItem(key, mnemonic, accessibleDescription, enabled, al); if (popupMenu != null) { popupMenu.add(mi); } return mi; }
From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java
private void initBooksTable() { booksTable.getColumnModel().getColumn(2) .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy"))); booksTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() { @Override// w w w . j a v a 2s .com public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected, boolean hasFocus, int row, int column) { if (value instanceof Date) { // You could use SimpleDateFormatter instead value = new SimpleDateFormat("dd. MM. yyyy").format(value); } return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column); } }); booksTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPopupMenu booksPopupMenu = new JPopupMenu(); JMenuItem deleteBook = new JMenuItem("Delete"); booksPopupMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { int rowAtPoint = booksTable.rowAtPoint( SwingUtilities.convertPoint(booksPopupMenu, new Point(0, 0), booksTable)); if (rowAtPoint > -1) { booksTable.setRowSelectionInterval(rowAtPoint, rowAtPoint); } } }); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // TODO Auto-generated method stub } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); deleteBook.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (booksTable.getSelectedRow() == -1) { JOptionPane.showMessageDialog(MainWindow.this, "You haven't selected any book."); return; } Book book = booksTableModel.getBooks().get(booksTable.getSelectedRow()); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { log.debug("Deleting book: " + book.getName() + " from database."); bookManager.deleteBook(book); return null; } @Override protected void done() { try { get(); } catch (Exception e) { log.error("There was an exception thrown while deleting a book.", e); return; } updateModel(); } }.execute(); } }); booksPopupMenu.add(deleteBook); booksTable.setComponentPopupMenu(booksPopupMenu); }
From source file:ca.phon.ipamap.IpaMap.java
/** * Create the context menu based on source component *//*from w ww . j a va 2 s . co m*/ 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); }