List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:picocash.components.mode.buttons.MonthModeButton.java
@Override protected void fillPopupMenu(JPopupMenu popupMenu) { for (JMenuItem jMenuItem : months) { popupMenu.add(jMenuItem); }//www. ja v a 2 s . c o m }
From source file:picocash.components.mode.buttons.YearModeButton.java
@Override protected void fillPopupMenu(JPopupMenu popupMenu) { for (YearMenuItem yearItem : items) { popupMenu.add(yearItem); }//from w w w .java 2 s . co m }
From source file:pl.kotcrab.arget.gui.ContactsPanel.java
public ContactsPanel(final Profile profile, MainWindowCallback callback) { this.profile = profile; setLayout(new BorderLayout()); table = new JTable(new ContactsTableModel(profile.contacts)); table.setDefaultRenderer(ContactInfo.class, new ContactsTableEditor(table, callback)); table.setDefaultEditor(ContactInfo.class, new ContactsTableEditor(table, callback)); table.setShowGrid(false);/*from ww w . ja va 2 s.c o m*/ table.setTableHeader(null); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowHeight(40); final JPopupMenu popupMenu = new JPopupMenu(); { JMenuItem menuModify = new JMenuItem("Modify"); JMenuItem menuDelete = new JMenuItem("Delete"); popupMenu.add(menuModify); popupMenu.add(menuDelete); menuModify.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String key = Base64.encodeBase64String(profile.rsa.getPublicKey().getEncoded()); new CreateContactDialog(MainWindow.instance, key, (ContactInfo) table.getValueAt(table.getSelectedRow(), 0)); ProfileIO.saveProfile(profile); updateContactsTable(); } }); menuDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ContactInfo contact = (ContactInfo) table.getValueAt(table.getSelectedRow(), 0); if (contact.status == ContactStatus.CONNECTED_SESSION) { JOptionPane.showMessageDialog(MainWindow.instance, "This contact cannot be deleted because session is open.", "Error", JOptionPane.ERROR_MESSAGE); return; } int result = JOptionPane.showConfirmDialog(MainWindow.instance, "Are you sure you want to delete '" + contact.name + "'?", "Warning", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.NO_OPTION || result == JOptionPane.CLOSED_OPTION) return; profile.contacts.remove(contact); ProfileIO.saveProfile(profile); updateContactsTable(); } }); } table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), table); int rowNumber = table.rowAtPoint(p); table.editCellAt(rowNumber, 0); table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }); JScrollPane tableScrollPane = new JScrollPane(table); tableScrollPane.setBorder(new EmptyBorder(0, 0, 0, 0)); add(tableScrollPane, BorderLayout.CENTER); }
From source file:pl.otros.logview.gui.LogViewPanel.java
private JPopupMenu initMessageDetailPopupMenu() { JPopupMenu jPopupMenu = new JPopupMenu(); jPopupMenu.add(new CopySelectedText(otrosApplication, logDetailTextArea)); jPopupMenu.add(new CopyStyledMessageDetailAction(otrosApplication, dateFormat, selectedMessageColorizersContainer, selectedMessageFormattersContainer)); return jPopupMenu; }
From source file:pl.otros.logview.gui.LogViewPanel.java
private JPopupMenu initTableContextMenu() { JPopupMenu menu = new JPopupMenu("Menu"); JMenuItem mark = new JMenuItem("Mark selected rows"); mark.addActionListener(new MarkRowAction(otrosApplication)); JMenuItem unmark = new JMenuItem("Unmark selected rows"); unmark.addActionListener(new UnMarkRowAction(otrosApplication)); JMenuItem autoResizeMenu = new JMenu("Table auto resize mode"); autoResizeMenu.setIcon(Icons.TABLE_RESIZE); JMenuItem autoResizeSubsequent = new JMenuItem("Subsequent columns"); autoResizeSubsequent/*from w w w . ja v a 2 s.c om*/ .addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS)); JMenuItem autoResizeLast = new JMenuItem("Last column"); autoResizeLast.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_LAST_COLUMN)); JMenuItem autoResizeNext = new JMenuItem("Next column"); autoResizeNext.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_NEXT_COLUMN)); JMenuItem autoResizeAll = new JMenuItem("All columns"); autoResizeAll.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_ALL_COLUMNS)); JMenuItem autoResizeOff = new JMenuItem("Auto resize off"); autoResizeOff.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_OFF)); autoResizeMenu.add(autoResizeSubsequent); autoResizeMenu.add(autoResizeOff); autoResizeMenu.add(autoResizeNext); autoResizeMenu.add(autoResizeLast); autoResizeMenu.add(autoResizeAll); JMenu removeMenu = new JMenu("Remove log events"); removeMenu.setFont(menuLabelFont); removeMenu.setIcon(Icons.BIN); JLabel removeLabel = new JLabel("Remove by:"); removeLabel.setFont(menuLabelFont); removeMenu.add(removeLabel); Map<String, Set<String>> propKeyValue = getPropertiesOfSelectedLogEvents(); for (AcceptCondition acceptCondition : acceptConditionList) { removeMenu.add(new JMenuItem(new RemoveByAcceptanceCriteria(acceptCondition, otrosApplication))); } for (String propertyKey : propKeyValue.keySet()) { for (String propertyValue : propKeyValue.get(propertyKey)) { PropertyAcceptCondition propAcceptCondition = new PropertyAcceptCondition(propertyKey, propertyValue); removeMenu .add(new JMenuItem(new RemoveByAcceptanceCriteria(propAcceptCondition, otrosApplication))); } } menu.add(new JSeparator()); JLabel labelMarkingRows = new JLabel("Marking/unmarking rows"); labelMarkingRows.setFont(menuLabelFont); menu.add(labelMarkingRows); menu.add(new JSeparator()); menu.add(mark); menu.add(unmark); JMenu[] markersMenu = getAutomaticMarkersMenu(); menu.add(markersMenu[0]); menu.add(markersMenu[1]); menu.add(new ClearMarkingsAction(otrosApplication)); menu.add(new JSeparator()); JLabel labelQuickFilters = new JLabel("Quick filters"); labelQuickFilters.setFont(menuLabelFont); menu.add(labelQuickFilters); menu.add(new JSeparator()); menu.add(focusOnThisThreadAction); menu.add(focusOnEventsAfter); menu.add(focusOnEventsBefore); menu.add(focusOnSelectedClassesAction); menu.add(ignoreSelectedEventsClasses); menu.add(focusOnSelectedLoggerNameAction); menu.add(showCallHierarchyAction); for (String propertyKey : propKeyValue.keySet()) { for (String propertyValue : propKeyValue.get(propertyKey)) { menu.add(new FocusOnSelectedPropertyAction(propertyFilter, propertyFilterPanel.getEnableCheckBox(), otrosApplication, propertyKey, propertyValue)); } } menu.add(new JSeparator()); menu.add(removeMenu); menu.add(new JSeparator()); JLabel labelTableOptions = new JLabel("Table options"); labelTableOptions.setFont(menuLabelFont); menu.add(labelTableOptions); menu.add(new JSeparator()); menu.add(autoResizeMenu); menu.add(new JSeparator()); List<MenuActionProvider> menuActionProviders = otrosApplication.getLogViewPanelMenuActionProvider(); for (MenuActionProvider menuActionProvider : menuActionProviders) { try { List<OtrosAction> actions = menuActionProvider.getActions(otrosApplication, this); if (actions == null) { continue; } for (OtrosAction action : actions) { menu.add(action); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Cant get action from from provider " + menuActionProvider, e); } } return menu; }
From source file:pl.otros.logview.gui.LogViewPanel.java
private void showMessageFormatterOrColorizerPopupMenu(MouseEvent e, String menuTitle, PluginableElementsContainer<? extends PluginableElement> selectedPluginableElementsContainer, PluginableElementsContainer<? extends PluginableElement> pluginableElementsContainer) { final JPopupMenu popupMenu = new JPopupMenu(menuTitle); popupMenu.add(new JLabel(menuTitle)); ArrayList<PluginableElement> elements = new ArrayList<PluginableElement>( pluginableElementsContainer.getElements()); Collections.sort(elements, new PluginableElementNameComparator()); for (final PluginableElement pluginableElement : elements) { addMessageFormatterOrColorizerToMenu(popupMenu, pluginableElement, selectedPluginableElementsContainer); }/* ww w . jav a 2s.com*/ popupMenu.show(e.getComponent(), e.getX(), e.getY()); }
From source file:pl.otros.logview.gui.LogViewPanel.java
private void addMessageFormatterOrColorizerToMenu(final JPopupMenu menu, final PluginableElement pluginable, final PluginableElementsContainer selectedPluginableContainer) { {// www . j a v a2s . c o m final JCheckBoxMenuItem boxMenuItem = new JCheckBoxMenuItem(pluginable.getName(), selectedPluginableContainer.contains(pluginable)); boxMenuItem.setToolTipText(pluginable.getDescription()); menu.add(boxMenuItem); boxMenuItem.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (boxMenuItem.isSelected() && !selectedPluginableContainer.contains(pluginable)) { selectedPluginableContainer.addElement(pluginable); } else if (!boxMenuItem.isSelected() && selectedPluginableContainer.contains(pluginable)) { selectedPluginableContainer.removeElement(pluginable); } } }); } }
From source file:pl.otros.vfs.browser.VfsBrowser.java
License:asdf
private JPopupMenu addPopupMenu(JList list, String... actions) { JPopupMenu favoritesPopupMenu = new JPopupMenu(); for (String action : actions) { favoritesPopupMenu.add(list.getActionMap().get(action)); }//w w w. j a va 2 s. c o m list.addKeyListener(new PopupListener(favoritesPopupMenu)); list.addMouseListener(new PopupListener(favoritesPopupMenu)); return favoritesPopupMenu; }
From source file:processing.app.Editor.java
protected void configurePopupMenu(final SketchTextArea textarea) { JPopupMenu menu = textarea.getPopupMenu(); menu.addSeparator();//from w w w . j a va 2s . co m JMenuItem item = createToolMenuItem("cc.arduino.packages.formatter.AStyle"); item.setName("menuToolsAutoFormat"); menu.add(item); item = newJMenuItem(_("Comment/Uncomment"), '/'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCommentUncomment(); } }); menu.add(item); item = newJMenuItem(_("Increase Indent"), ']'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(true); } }); menu.add(item); item = newJMenuItem(_("Decrease Indent"), '['); item.setName("menuDecreaseIndent"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(false); } }); menu.add(item); item = new JMenuItem(_("Copy for Forum")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDiscourseCopy(); } }); menu.add(item); item = new JMenuItem(_("Copy as HTML")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleHTMLCopy(); } }); menu.add(item); final JMenuItem referenceItem = new JMenuItem(_("Find in Reference")); referenceItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleFindReference(); } }); menu.add(referenceItem); final JMenuItem openURLItem = new JMenuItem(_("Open URL")); openURLItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.openURL(e.getActionCommand()); } }); menu.add(openURLItem); menu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { String referenceFile = base.getPdeKeywords().getReference(getCurrentKeyword()); referenceItem.setEnabled(referenceFile != null); int offset = textarea.getCaretPosition(); org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset); if (token != null && token.isHyperlink()) { openURLItem.setEnabled(true); openURLItem.setActionCommand(token.getLexeme()); } else { openURLItem.setEnabled(false); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); }
From source file:processing.app.EditorTab.java
private void configurePopupMenu(final SketchTextArea textarea) { JPopupMenu menu = textarea.getPopupMenu(); menu.addSeparator();//from ww w .ja v a2 s . c o m JMenuItem item = editor.createToolMenuItem("cc.arduino.packages.formatter.AStyle"); if (item == null) { throw new NullPointerException("Tool cc.arduino.packages.formatter.AStyle unavailable"); } item.setName("menuToolsAutoFormat"); menu.add(item); item = new JMenuItem(tr("Comment/Uncomment"), '/'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleCommentUncomment(); } }); menu.add(item); item = new JMenuItem(tr("Increase Indent"), ']'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(true); } }); menu.add(item); item = new JMenuItem(tr("Decrease Indent"), '['); item.setName("menuDecreaseIndent"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleIndentOutdent(false); } }); menu.add(item); item = new JMenuItem(tr("Copy for Forum")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDiscourseCopy(); } }); menu.add(item); item = new JMenuItem(tr("Copy as HTML")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleHTMLCopy(); } }); menu.add(item); final JMenuItem referenceItem = new JMenuItem(tr("Find in Reference")); referenceItem.addActionListener(editor::handleFindReference); menu.add(referenceItem); final JMenuItem openURLItem = new JMenuItem(tr("Open URL")); openURLItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.openURL(e.getActionCommand()); } }); menu.add(openURLItem); menu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { String referenceFile = editor.base.getPdeKeywords().getReference(getCurrentKeyword()); referenceItem.setEnabled(referenceFile != null); int offset = textarea.getCaretPosition(); org.fife.ui.rsyntaxtextarea.Token token = RSyntaxUtilities.getTokenAtOffset(textarea, offset); if (token != null && token.isHyperlink()) { openURLItem.setEnabled(true); openURLItem.setActionCommand(token.getLexeme()); } else { openURLItem.setEnabled(false); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); }