Example usage for javax.swing JPopupMenu add

List of usage examples for javax.swing JPopupMenu add

Introduction

In this page you can find the example usage for javax.swing JPopupMenu add.

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Appends a new menu item to the end of the menu which dispatches the specified Action object.

Usage

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private AssetPanel createAssetPanel() {
    final AssetPanel panel = new AssetPanel("mainAssetPanel");
    panel.addImagePanelMouseListener(new MouseAdapter() {
        @Override/*from   w ww  . j  av a  2 s.com*/
        public void mouseReleased(MouseEvent e) {
            // TODO use for real popup logic
            //            if (SwingUtilities.isLeftMouseButton(e)) {
            //               if (e.getClickCount() == 2) {
            //
            //                  List<Object> idList = panel.getSelectedIds();
            //                  if (idList == null || idList.size() == 0) {
            //                     return;
            //                  }
            //
            //                  final int index = (Integer) idList.get(0);
            //                  createZone(panel.getAsset(index));
            //               }
            //            }
            if (SwingUtilities.isRightMouseButton(e) && MapTool.getPlayer().isGM()) {
                List<Object> idList = panel.getSelectedIds();
                if (idList == null || idList.size() == 0) {
                    return;
                }
                final int index = (Integer) idList.get(0);

                JPopupMenu menu = new JPopupMenu();
                menu.add(new JMenuItem(new AbstractAction() {
                    {
                        putValue(NAME, I18N.getText("action.newMap"));
                    }

                    public void actionPerformed(ActionEvent e) {
                        createZone(panel.getAsset(index));
                    }
                }));
                panel.showImagePanelPopup(menu, e.getX(), e.getY());
            }
        }

        private void createZone(Asset asset) {
            Zone zone = ZoneFactory.createZone();
            zone.setName(asset.getName());
            BufferedImage image = ImageManager.getImageAndWait(asset.getId());
            if (image.getWidth() < 200 || image.getHeight() < 200) {
                zone.setBackgroundPaint(new DrawableTexturePaint(asset));
            } else {
                zone.setMapAsset(asset.getId());
                zone.setBackgroundPaint(new DrawableColorPaint(Color.black));
            }
            MapPropertiesDialog newMapDialog = new MapPropertiesDialog(MapTool.getFrame());
            newMapDialog.setZone(zone);
            newMapDialog.setVisible(true);

            if (newMapDialog.getStatus() == MapPropertiesDialog.Status.OK) {
                MapTool.addZone(zone);
            }
        }
    });
    return panel;
}

From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java

/**
 * Process popup trigger events occurring on an icon cell in the table. Show a menu where the user can choose which
 * external resource to open for the entry. If no relevant external resources exist, let the normal popup trigger
 * handler do its thing instead./*from  w w w.j  av a  2 s .  c o  m*/
 *
 * @param e The mouse event defining this popup trigger.
 * @param row The row where the event occurred.
 * @param column the MainTableColumn associated with this table cell.
 */
private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn column) {
    BibEntry entry = tableRows.get(row);
    JPopupMenu menu = new JPopupMenu();
    boolean showDefaultPopup = true;

    // See if this is a simple file link field, or if it is a file-list
    // field that can specify a list of links:
    if (!column.getBibtexFields().isEmpty()) {
        for (String field : column.getBibtexFields()) {
            if (FieldName.FILE.equals(field)) {
                // We use a FileListTableModel to parse the field content:
                FileListTableModel fileList = new FileListTableModel();
                entry.getFieldOptional(field).ifPresent(fileList::setContent);
                for (int i = 0; i < fileList.getRowCount(); i++) {
                    FileListEntry flEntry = fileList.getEntry(i);
                    if (column.isFileFilter()
                            && (!flEntry.type.get().getName().equalsIgnoreCase(column.getColumnName()))) {
                        continue;
                    }
                    String description = flEntry.description;
                    if ((description == null) || (description.trim().isEmpty())) {
                        description = flEntry.link;
                    }
                    menu.add(new ExternalFileMenuItem(panel.frame(), entry, description, flEntry.link,
                            flEntry.type.get().getIcon(), panel.getBibDatabaseContext(), flEntry.type));
                    showDefaultPopup = false;
                }
            } else {
                if (SpecialFieldsUtils.isSpecialField(column.getColumnName())) {
                    // full pop should be shown as left click already shows short popup
                    showDefaultPopup = true;
                } else {
                    if (entry.hasField(field)) {
                        String content = entry.getField(field);
                        Icon icon;
                        JLabel iconLabel = GUIGlobals.getTableIcon(field);
                        if (iconLabel == null) {
                            icon = IconTheme.JabRefIcon.FILE.getIcon();
                        } else {
                            icon = iconLabel.getIcon();
                        }
                        menu.add(new ExternalFileMenuItem(panel.frame(), entry, content, content, icon,
                                panel.getBibDatabaseContext(), field));
                        showDefaultPopup = false;
                    }
                }
            }
        }
        if (showDefaultPopup) {
            processPopupTrigger(e, row);
        } else {
            menu.show(table, e.getX(), e.getY());
        }
    }
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

public void fileTableClicked(FileObjectTableModel fileObjectTableModel, JTableX<FileObject> table,
        MouseEvent e) {//ww  w .  java  2s  .c  om
    int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint()));
    //int column = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint()));
    final Collection<FileObject> selectedFileObjects = table.getSelectedObjects();

    final FileObject f = fileObjectTableModel.getRowObjects().get(row);

    if (SwingUtilities.isRightMouseButton(e)) {
        JPopupMenu m = new JPopupMenu();
        {
            JMenuItem menuitem = new JMenuItem("ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFile(f);
                }
            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Ordner ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFolder(f);
                }
            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Herunterladen (ber SOAP)");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    downloadFiles(selectedFileObjects, DownloadMethod.WEBSERVICE);
                }

            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Herunterladen (ber WEBDAV)");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!syncService.getIliasSoapService().isWebdavAuthenticationActive()) {
                        syncService.getIliasSoapService().enableWebdavAuthentication(
                                mainFrame.getFieldLogin().getText(),
                                mainFrame.getFieldPassword().getPassword());
                    }
                    downloadFiles(selectedFileObjects, DownloadMethod.WEBDAV);
                }

            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("In Ilias ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openInIlias(f);
                }
            });
            m.add(menuitem);
        }
        {
            m.add(new JSeparator());
        }
        {
            JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem("Ignorieren");
            menuitem.setSelected(iliasProperties.getBlockedFiles().contains(f.getRefId()));
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    switchIgnoreState(selectedFileObjects);
                }
            });
            m.add(menuitem);
        }
        {
            m.add(new JSeparator());
        }
        {
            JMenuItem menuitem = new JMenuItem("Fehler anzeigen");
            menuitem.setEnabled(f.getException() != null);
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showError("Fehler bei " + f.getTargetFile().getAbsolutePath(), f.getException());
                }

            });
            m.add(menuitem);
        }
        m.show(table, e.getX(), e.getY());
    }

    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
        openFile(f);
    }
}

From source file:org.rdv.viz.chart.ChartViz.java

/**
 * Create the chart and setup it's UI.//from   w  w w  .  jav a2 s  .  co  m
 */
private void initChart() {
    XYToolTipGenerator toolTipGenerator;

    if (xyMode) {
        dataCollection = new XYTimeSeriesCollection();

        NumberAxis domainAxis = new NumberAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        domainAxis.addChangeListener(new AxisChangeListener() {
            public void axisChanged(AxisChangeEvent ace) {
                boundsChanged();
            }
        });
        this.domainAxis = domainAxis;

        toolTipGenerator = new StandardXYToolTipGenerator("{0}: {1} , {2}", new DecimalFormat(),
                new DecimalFormat());
    } else {
        dataCollection = new TimeSeriesCollection();

        domainAxis = new FixedAutoAdjustRangeDateAxis();
        domainAxis.setLabel("Time");
        domainAxis.setAutoRange(false);

        toolTipGenerator = new StandardXYToolTipGenerator("{0}: {1} , {2}",
                new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"), new DecimalFormat());
    }

    rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.addChangeListener(new AxisChangeListener() {
        public void axisChanged(AxisChangeEvent ace) {
            boundsChanged();
        }
    });

    FastXYItemRenderer renderer = new FastXYItemRenderer(StandardXYItemRenderer.LINES, toolTipGenerator);
    renderer.setBaseCreateEntities(false);
    renderer.setBaseStroke(new BasicStroke(0.5f));
    if (xyMode) {
        renderer.setCursorVisible(true);
    }

    xyPlot = new XYPlot(dataCollection, domainAxis, rangeAxis, renderer);

    chart = new JFreeChart(xyPlot);
    chart.setAntiAlias(false);

    seriesLegend = chart.getLegend();
    chart.removeLegend();

    chartPanel = new ChartPanel(chart, true);
    chartPanel.setInitialDelay(0);

    // get the chart panel standard popup menu
    JPopupMenu popupMenu = chartPanel.getPopupMenu();

    // create a popup menu item to copy an image to the clipboard
    final JMenuItem copyChartMenuItem = new JMenuItem("Copy");
    copyChartMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyChart();
        }
    });
    popupMenu.insert(copyChartMenuItem, 2);

    popupMenu.insert(new JPopupMenu.Separator(), 3);

    popupMenu.add(new JPopupMenu.Separator());

    showLegendMenuItem = new JCheckBoxMenuItem("Show Legend", true);
    showLegendMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setShowLegend(showLegendMenuItem.isSelected());
        }
    });
    popupMenu.add(showLegendMenuItem);

    if (xyMode) {
        popupMenu.add(new JPopupMenu.Separator());

        JMenuItem addLocalSeriesMenuItem = new JMenuItem("Add local series...");
        addLocalSeriesMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                addLocalSeries();
            }
        });

        popupMenu.add(addLocalSeriesMenuItem);
    }

    chartPanelPanel = new JPanel();
    chartPanelPanel.setLayout(new BorderLayout());
    chartPanelPanel.add(chartPanel, BorderLayout.CENTER);
}

From source file:edu.harvard.i2b2.previousquery.ui.QueryPreviousRunsPanel.java

private void createPopupMenu() {
    JMenuItem menuItem;//from  www  .  j av  a2s.  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());
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
 * CReates the popup menu for a cell. (THis really needs to be moved outside of this class).
 * @param pnt the point to pop it up/*from   w  w  w .  j a v a  2 s.  co m*/
 * @return the popup menu
 */
protected JPopupMenu createMenuForSelection(final Point pnt) {
    //final int row = rowAtPoint(pnt);

    Class<?> cellClass = getModel().getColumnClass(convertColumnIndexToModel(columnAtPoint(pnt)));
    boolean isImage = cellClass == ImageIcon.class || cellClass == Image.class;

    JPopupMenu pMenu = new JPopupMenu();
    UsageTracker.incrUsageCount("WB.SpreadsheetContextMenu");
    if (getSelectedColumnCount() == 1) {
        final int[] rows = getSelectedRowModelIndexes();
        if (rows.length > 1) {
            //if (row == rows[0])
            //{
            if (!isImage) {
                JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("SpreadSheet.FillDown")));
                mi.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        int selectedUICol = getSelectedColumn();
                        int selectedModelCol = convertColumnIndexToModel(selectedUICol);
                        model.fill(selectedModelCol, rows[0], rows);
                        popupMenu.setVisible(false);
                    }
                });
            }
            //} else if (row == rows[rows.length-1])
            //{
            if (!isImage) {
                JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("Spreadsheet.FillUp")));
                mi.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        int selectedUICol = getSelectedColumn();
                        int selectedModelCol = convertColumnIndexToModel(selectedUICol);
                        model.fill(selectedModelCol, rows[rows.length - 1], rows);
                        popupMenu.setVisible(false);
                    }
                });
            }
            //}
        }
    }

    if (!isImage) {
        JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("SpreadSheet.ClearCells")));
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int[] rows = getSelectedRowModelIndexes();
                int[] cols = getSelectedColumnModelIndexes();

                model.clearCells(rows, cols);
                popupMenu.setVisible(false);
            }
        });
    }

    if (deleteAction != null) {
        JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("SpreadSheet.DeleteRows")));
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                deleteAction.actionPerformed(ae);
                popupMenu.setVisible(false);
            }
        });
    }

    //add copy, paste, cut
    if (!isImage) //copy, paste currently only implemented for string data
    {
        boolean isSelection = getSelectedColumnCount() > 0 && getSelectedRowCount() > 0;
        if (pMenu.getComponentCount() > 0) {
            pMenu.add(new JPopupMenu.Separator());
        }
        JMenuItem mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("CutMenu")));
        mi.setEnabled(isSelection && !isImage); // copy, paste currently
        // only implemented for
        // string data
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                SwingUtilities.invokeLater(new Runnable() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        cutOrCopy(true);

                    }

                });
            }
        });
        mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("CopyMenu")));
        mi.setEnabled(isSelection && !isImage);
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                SwingUtilities.invokeLater(new Runnable() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        cutOrCopy(false);

                    }

                });
            }
        });
        mi = pMenu.add(new JMenuItem(UIRegistry.getResourceString("PasteMenu")));
        mi.setEnabled(isSelection && !isImage && canPasteFromClipboard());
        mi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                SwingUtilities.invokeLater(new Runnable() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see java.lang.Runnable#run()
                     */
                    @Override
                    public void run() {
                        paste();

                    }

                });
            }
        });

    }

    pMenu.setInvoker(this);
    return pMenu;
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
protected JPopupMenu createPopupMenu(boolean properties, boolean copy, boolean save, boolean print,
        boolean zoom) {
    JPopupMenu menu = super.createPopupMenu(properties, copy, save, print, zoom);
    menu.addSeparator();/* w  ww .  j av  a2s  .co m*/
    legendMenu = new JMenu("Legend Position");
    menu.add(legendMenu);

    legendNone = new JRadioButtonMenuItem("None");
    legendNone.setActionCommand(LEGEND_NONE_COMMAND);
    legendNone.addActionListener(this);
    legendMenu.add(legendNone);

    legendInternal = new JRadioButtonMenuItem("Internal");
    legendInternal.setActionCommand(LEGEND_INTERNAL_COMMAND);
    legendInternal.addActionListener(this);
    legendMenu.add(legendInternal);

    legendBottom = new JRadioButtonMenuItem("Bottom");
    legendBottom.setActionCommand(LEGEND_BOTTOM_COMMAND);
    legendBottom.addActionListener(this);
    legendMenu.add(legendBottom);

    legendRight = new JRadioButtonMenuItem("Right");
    legendRight.setActionCommand(LEGEND_RIGHT_COMMAND);
    legendRight.addActionListener(this);
    legendMenu.add(legendRight);

    menu.addSeparator();
    curveManagementMenu = new JMenu("Focus on Curve");
    menu.add(curveManagementMenu);

    //        this.removeSelectedMaskMenuItem = new JMenuItem();
    //        this.removeSelectedMaskMenuItem.setActionCommand(REMOVE_SELECTED_MASK_COMMAND);
    //        this.removeSelectedMaskMenuItem.addActionListener(this);
    //        menu.addSeparator();
    //        menu.add(removeSelectedMaskMenuItem);
    //        maskManagementMenu = new JMenu("Mask Management");
    //        menu.add(maskManagementMenu);

    return menu;
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
protected JPopupMenu createPopupMenu(boolean properties, boolean copy, boolean save, boolean print,
        boolean zoom) {
    JPopupMenu menu = super.createPopupMenu(properties, copy, save, print, zoom);

    this.resetColorScaleMenuItem = new JMenuItem("Reset Color Scale");
    this.resetColorScaleMenuItem.setActionCommand(RESET_COLOR_SCALE_COMMAND);
    this.resetColorScaleMenuItem.addActionListener(this);
    menu.addSeparator();//from w ww . j  a v  a2  s.c  o m
    menu.add(resetColorScaleMenuItem);
    return menu;
}

From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java

/**
 * Shows the Reset menu./* w w w .  j  av  a 2s  .c  om*/
 * @param e the mouse event
 */
protected void showContextMenu(MouseEvent e) {
    if (e.isPopupTrigger()) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("ES_TEXT_RESET"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ex) {
                searchText.setEnabled(true);
                searchText.setBackground(textBGColor);
                searchText.setText("");

                if (statusBar != null) {
                    statusBar.setProgressDone(EXPRESSSEARCH);
                }
            }
        });
        popup.add(menuItem);
        popup.show(e.getComponent(), e.getX(), e.getY());

    }
}

From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java

private JPopupMenu createDataviewPopup() {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem addColGroup = new JMenuItem("Group Column");
    JMenuItem addGroup = new JMenuItem("Group series");
    JMenuItem addData = new JMenuItem("Edit dataset..");
    menu.add(addColGroup);
    menu.add(addGroup);//from   ww  w  . ja  v  a 2 s  .co  m
    menu.add(addData);
    addColGroup.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            groupCategoryByCol();
            refreshData();
        }
    });
    addGroup.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            groupCategory();
            refreshData();
        }
    });
    addData.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {

                    new DatasetEditor(table, datasetTable, table.getName(), new IDataRefreshListener() {
                        @Override
                        public void refreshDataset() {
                            refreshData();
                        }
                    }).setVisible(true);

                }
            });
        }
    });
    return menu;
}