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:com.github.dougkelly88.FLIMPlateReaderGUI.FLIMClasses.GUIComponents.FLIMPanel.java

private void setControlDefaults() {

    String[] colName = { "Delays (ps)" };
    int max = 16666;
    try {/*from   ww  w .  ja  v  a2s . c  om*/
        max = Integer.parseInt(core_.getProperty("Laser", "Frequency"));
    } catch (Exception e) {
    }

    tableModel_ = new DelayTableModel(colName, (sap_.getDelaysArray()).get(0), 0, max, 25);
    tableModel_.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            sap_.setDelaysArray(0, tableModel_.getData());
            fm_.setGatingData((sap_.getDelaysArray()).get(0));
            var_.delays = tableModel_.getData();
        }
    });
    delayTable_ = new JTable() {
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component comp = super.prepareRenderer(renderer, row, column);
            int modelRow = convertRowIndexToModel(row);
            int modelColumn = convertColumnIndexToModel(column);
            if (modelColumn != 0 && modelRow != 0) {
                comp.setBackground(Color.GREEN);
            }

            return comp;
        }
    };
    delayTable_.setModel(tableModel_);
    delayTable_.setSurrendersFocusOnKeystroke(true);
    delayTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    JScrollPane scroller = new javax.swing.JScrollPane(delayTable_);
    delayTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(60, 100));
    delayTablePanel.setLayout(new BorderLayout());
    delayTablePanel.add(scroller, BorderLayout.CENTER);

    final JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete delay");
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = delayTable_.getSelectedRow();
            tableModel_.removeRow(r);
        }
    });
    JMenuItem addItem = new JMenuItem("Add delay");
    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = delayTable_.getSelectedRow();
            tableModel_.insertRow(r + 1, 0);
        }
    });
    popupMenu.add(addItem);
    popupMenu.add(deleteItem);
    delayTable_.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            //                System.out.println("pressed");
        }

        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                JTable source = (JTable) e.getSource();
                int row = source.rowAtPoint(e.getPoint());
                int column = source.columnAtPoint(e.getPoint());

                if (!source.isRowSelected(row))
                    source.changeSelection(row, column, false, false);

                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    // Set up slider controls
    mcpSlider_ = new SliderControl("MCP voltage (V)", 300, 850, 750);
    mcpVoltagePanel.setLayout(new BorderLayout());
    mcpVoltagePanel.add(mcpSlider_, BorderLayout.SOUTH);
    mcpSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            mcpSliderPropertyChange(evt);
        }
    });

    gatewidthSlider_ = new SliderControl("Gate width (ps)", 200, 7000, 3000);
    gatewidthPanel.setLayout(new BorderLayout());
    gatewidthPanel.add(gatewidthSlider_, BorderLayout.SOUTH);
    gatewidthSlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            gatewidthSliderPropertyChange(evt);
        }
    });

    HRIControlsPanel.revalidate();
    HRIControlsPanel.repaint();

    slowDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0);
    slowCurrentDelayPanel.setLayout(new BorderLayout());
    slowCurrentDelayPanel.add(slowDelaySlider_, BorderLayout.SOUTH);
    slowDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            slowDelaySlider_.setValue(tableModel_.validateData(slowDelaySlider_.getValue().intValue()));
            slowDelaySliderPropertyChange(evt);
        }
    });

    fastDelaySlider_ = new SliderControl("Current delay setting (ps)", 0, 20000, 0);
    fastCurrentDelayPanel.setLayout(new BorderLayout());
    fastCurrentDelayPanel.add(fastDelaySlider_, BorderLayout.SOUTH);
    fastDelaySlider_.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            fastDelaySlider_.setValue(tableModel_.validateData(fastDelaySlider_.getValue().intValue()));
            fastDelaySliderPropertyChange(evt);
        }
    });

    delayBoxTabbedPane.revalidate();
    delayBoxTabbedPane.repaint();

    fm_ = new FindMaxpoint();
    maxpointGraphPanel.setLayout(new BorderLayout());
    chartPanel_ = new ChartPanel(fm_.getChart());
    maxpointGraphPanel.add(chartPanel_, BorderLayout.NORTH);
    // for some reason maxpointGraphPanel's height and width are returned 0
    // so hardcode for now...
    chartPanel_.setMaximumDrawWidth(500);
    chartPanel_.setMaximumDrawHeight(200);
    chartPanel_.setPreferredSize(new Dimension(500, 200));

    // Set values for other controls based on underlying data to ensure
    // that all controls are in a consistent state. 
    scanDelCheck.setSelected(sap_.getUseScanFLIM());

}

From source file:com.t3.client.ui.T3Frame.java

private AssetPanel createAssetPanel() {
    final AssetPanel panel = new AssetPanel("mainAssetPanel");
    panel.addImagePanelMouseListener(new MouseAdapter() {
        @Override/*from w ww  .  ja v  a  2s  .  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) && TabletopTool.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"));
                    }

                    @Override
                    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(TabletopTool.getFrame());
            newMapDialog.setZone(zone);
            newMapDialog.setVisible(true);

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

From source file:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java

/**
 * Initialize the work package calendar panel inclusive the listeners.
 *///from ww w . j a va  2s.  co  m
private void init() {
    List<Workpackage> userWp = new ArrayList<Workpackage>(WpManager.getUserWp(WPOverview.getUser()));

    Collections.sort(userWp, new APLevelComparator());

    dataset = createDataset(userWp);
    chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);

    final JPopupMenu popup = new JPopupMenu();
    JMenuItem miSave = new JMenuItem(LocalizedStrings.getButton().save(LocalizedStrings.getWbs().timeLine()));
    miSave.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {

            JFileChooser chooser = new JFileChooser();
            chooser.setFileFilter(new ExtensionAndFolderFilter("jpg", "jpeg")); //NON-NLS
            chooser.setSelectedFile(new File("chart-" //NON-NLS
                    + System.currentTimeMillis() + ".jpg"));
            int returnVal = chooser.showSaveDialog(reference);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    File outfile = chooser.getSelectedFile();
                    ChartUtilities.saveChartAsJPEG(outfile, chart, chartPanel.getWidth(),
                            chartPanel.getWidth());
                    Controller.showMessage(
                            LocalizedStrings.getMessages().timeLineSaved(outfile.getCanonicalPath()));
                } catch (IOException e) {
                    Controller.showError(LocalizedStrings.getErrorMessages().timeLineExportError());
                }
            }
        }

    });
    popup.add(miSave);

    chartPanel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                popup.show(e.getComponent(), e.getX(), e.getY());
            }
        }

    });
    chartPanel.setMinimumDrawHeight(50 + 15 * userWp.size());
    chartPanel.setMaximumDrawHeight(50 + 15 * userWp.size());
    chartPanel.setMaximumDrawWidth(9999);
    chartPanel.setPreferredSize(
            new Dimension((int) chartPanel.getPreferredSize().getWidth(), 50 + 15 * userWp.size()));

    chartPanel.setPopupMenu(null);

    this.setLayout(new BorderLayout());

    this.removeAll();

    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    panel.add(chartPanel, constraints);

    panel.setBackground(Color.white);
    this.add(panel, BorderLayout.CENTER);

    GanttRenderer.setDefaultShadowsVisible(false);
    GanttRenderer.setDefaultBarPainter(new BarPainter() {

        @Override
        public void paintBar(final Graphics2D g, final BarRenderer arg1, final int row, final int col,
                final RectangularShape rect, final RectangleEdge arg5) {

            String wpName = (String) dataset.getColumnKey(col);
            int i = 0;
            int spaceCount = 0;
            while (wpName.charAt(i++) == ' ' && spaceCount < 17) {
                spaceCount++;
            }

            g.setColor(new Color(spaceCount * 15, spaceCount * 15, spaceCount * 15));
            g.fill(rect);
            g.setColor(Color.black);
            g.setStroke(new BasicStroke());
            g.draw(rect);
        }

        @Override
        public void paintBarShadow(final Graphics2D arg0, final BarRenderer arg1, final int arg2,
                final int arg3, final RectangularShape arg4, final RectangleEdge arg5, final boolean arg6) {

        }

    });

    ((CategoryPlot) chart.getPlot()).setRenderer(new GanttRenderer() {
        private static final long serialVersionUID = -6078915091070733812L;

        public void drawItem(final Graphics2D g2, final CategoryItemRendererState state,
                final Rectangle2D dataArea, final CategoryPlot plot, final CategoryAxis domainAxis,
                final ValueAxis rangeAxis, final CategoryDataset dataset, final int row, final int column,
                final int pass) {
            super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass);
        }
    });

}

From source file:com.mirth.connect.client.ui.components.MirthTable.java

private JPopupMenu getColumnMenu() {
    JPopupMenu columnMenu = new JPopupMenu();
    DefaultTableModel model = (DefaultTableModel) getModel();

    for (int i = 0; i < model.getColumnCount(); i++) {
        final String columnName = model.getColumnName(i);
        // Get the column object by name. Using an index may not return the column object if the column is hidden
        TableColumnExt column = getColumnExt(columnName);

        // Create the menu item
        final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName);
        // Show or hide the checkbox
        menuItem.setSelected(column.isVisible());

        menuItem.addActionListener(new ActionListener() {
            @Override//from  w  w w  .j a v  a 2  s  .  c  o m
            public void actionPerformed(ActionEvent evt) {
                TableColumnExt column = getColumnExt(menuItem.getText());
                // Determine whether to show or hide the selected column
                boolean enable = !column.isVisible();
                // Do not hide a column if it is the last remaining visible column              
                if (enable || getColumnCount() > 1) {
                    column.setVisible(enable);
                    saveColumnOrder();
                }
            }
        });

        columnMenu.add(menuItem);
    }

    columnMenu.addSeparator();

    JMenuItem menuItem = new JMenuItem("Restore Default");
    menuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            restoreDefaultColumnPreferences();

        }

    });
    columnMenu.add(menuItem);

    return columnMenu;
}

From source file:edu.ku.brc.af.ui.forms.IconViewObj.java

private void showContextMenu(MouseEvent e) {
    final FormDataObjIFace selection = iconTray.getSelectedValue();

    if (selection instanceof ObjectAttachmentIFace<?>) {
        final File original = AttachmentUtils
                .getAttachmentFile(((ObjectAttachmentIFace) selection).getAttachment());

        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("AttachmentUtils.OPEN_IN_EV"));
        menuItem.addActionListener(new ActionListener() {
            @Override/* w  w w.j av  a  2 s.  c om*/
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    AttachmentUtils.openFile(original);
                } catch (Exception ex) {
                    UIRegistry.showLocalizedMsg("AttachmentUtils.NEV_TITLE", "AttachmentUtils.NEV_MSG");
                }
            }
        });
        popup.add(menuItem);
        popup.show(e.getComponent(), e.getX(), e.getY());
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java

/**
 * Shows the Reset menu./*from  ww w  .  j  a  v a  2  s.  c om*/
 * @param e the mouse event
 */
private void showContextMenu(final 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("");
            }
        });
        popup.add(menuItem);
        popup.show(e.getComponent(), e.getX(), e.getY());

    }
}

From source file:net.panthema.BispanningGame.GamePanel.java

public GamePanel() throws IOException {

    makeActions();// www  .  j a  v a 2s .c  om

    setBackground(Color.WHITE);

    ImageAlice = ImageIO.read(
            getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Alice.png"));
    ImageBob = ImageIO.read(
            getClass().getClassLoader().getResourceAsStream("net/panthema/BispanningGame/images/Bob.png"));

    logTextArea = new JTextArea();

    makeNewRandomGraph(8);
    mLayout = MyGraphLayoutFactory(mGraph);

    mVV = new VisualizationViewer<Integer, MyEdge>(mLayout);
    mVV.setSize(new Dimension(1000, 800));
    mVV.setBackground(Color.WHITE);

    // Bob's play does not repeat.
    mPlayBob.setRepeats(false);

    // set up mouse handling
    PluggableGraphMouse gm = new PluggableGraphMouse();
    gm.add(new MyEditingGraphMousePlugin<Integer, MyEdge>(MouseEvent.CTRL_MASK, new MyVertexFactory(),
            new MyEdgeFactory()));
    gm.add(new TranslatingGraphMousePlugin(MouseEvent.BUTTON3_MASK));
    gm.add(new MyGraphMousePlugin(MouseEvent.BUTTON1_MASK | MouseEvent.BUTTON3_MASK));
    gm.add(new PickingGraphMousePlugin<Integer, MyEdge>());
    gm.add(new ScalingGraphMousePlugin(new LayoutScalingControl(), 0, 1.1f, 0.9f));
    mVV.setGraphMouse(gm);

    // set vertex and label drawing
    mVV.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.black));
    mVV.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() {
        public String transform(Integer v) {
            return "v" + v;
        }
    });
    mVV.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Integer>());
    mVV.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    mVV.getRenderer().setEdgeRenderer(new MyEdgeRenderer());
    mVV.getRenderContext().setVertexDrawPaintTransformer(new MyVertexDrawPaintTransformer<Integer>());
    mVV.getRenderContext().setVertexFillPaintTransformer(new MyVertexFillPaintTransformer());

    mVV.getRenderContext().setEdgeStrokeTransformer(new MyEdgeStrokeTransformer());
    MyQuadCurve<Integer, MyEdge> quadcurve = new MyQuadCurve<Integer, MyEdge>();
    mVV.getRenderContext().setEdgeShapeTransformer(quadcurve);
    mVV.getRenderContext().setParallelEdgeIndexFunction(quadcurve);

    mVV.getRenderContext().setEdgeDrawPaintTransformer(new MyEdgeDrawPaintTransformer());
    mVV.getRenderContext().setEdgeFillPaintTransformer(new MyEdgeFillPaintTransformer());
    mVV.getRenderContext().setEdgeArrowStrokeTransformer(new MyEdgeInnerStrokeTransformer());

    mVV.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.black));
    mVV.getRenderContext().setEdgeLabelTransformer(new Transformer<MyEdge, String>() {
        public String transform(MyEdge e) {
            return e.toString();
        }
    });
    mVV.getRenderContext().setLabelOffset(6);

    // create pick support to select closest nodes and edges
    mPickSupport = new ShapePickSupport<Integer, MyEdge>(mVV, mPickDistance);

    // add pre renderer to draw Alice and Bob
    mVV.addPreRenderPaintable(new MyGraphPreRenderer());

    // add post renderer to show error messages in background
    mVV.addPostRenderPaintable(new MyGraphPostRenderer());

    setLayout(new BorderLayout());
    add(mVV, BorderLayout.CENTER);

    JPanel panelSouth = new JPanel();
    add(panelSouth, BorderLayout.SOUTH);
    panelSouth.setLayout(new GridLayout(0, 2, 0, 0));

    JPanel panelButtons = new JPanel();
    panelSouth.add(panelButtons);
    panelButtons.setLayout(new GridLayout(2, 2, 0, 0));
    panelSouth.setPreferredSize(new Dimension(800, 60));

    final JButton btnNewRandomGraph = new JButton("New Random Graph");
    btnNewRandomGraph.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();

            for (int i = 0; i < actionRandomGraph.length; ++i) {
                if (actionRandomGraph[i] != null)
                    popup.add(actionRandomGraph[i]);
            }
            popup.addSeparator();
            popup.add(getActionNewGraphType());

            popup.show(btnNewRandomGraph, e.getX(), e.getY());
        }
    });
    panelButtons.add(btnNewRandomGraph);

    final JButton btnNewNamedGraph = new JButton("New Named Graph");
    btnNewNamedGraph.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();

            for (int i = 0; i < actionNamedGraph.size(); ++i) {
                if (actionNamedGraph.get(i) != null)
                    popup.add(actionNamedGraph.get(i));
            }

            popup.show(btnNewNamedGraph, e.getX(), e.getY());
        }
    });
    panelButtons.add(btnNewNamedGraph);

    final JButton btnRelayout = new JButton("Relayout");
    btnRelayout.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            relayoutGraph();
        }
    });
    panelButtons.add(btnRelayout);

    final JButton btnOptions = new JButton("Options");
    btnOptions.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            JPopupMenu popup = new JPopupMenu();

            addPopupActions(popup);
            popup.addSeparator();

            popup.show(btnOptions, e.getX(), e.getY());
        }
    });
    panelButtons.add(btnOptions);

    JScrollPane scrollPane = new JScrollPane(logTextArea);
    panelSouth.add(scrollPane);

    logTextArea.setEditable(false);

    setSize(new Dimension(1000, 800));
    relayoutGraph();
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * @param actionTree//from w w  w . j a v a  2s . c o  m
 */
private void registerPrintContextMenu(final JTree actionTree) {
    actionTree.addMouseListener(new MouseAdapter() {
        private void displayMenu(MouseEvent e) {
            if (e.isPopupTrigger()) {
                JPopupMenu menu = new JPopupMenu();
                JMenuItem printMenu = new JMenuItem(UIRegistry.getResourceString("Print"));
                menu.add(printMenu);
                menu.show(e.getComponent(), e.getX(), e.getY());
                printMenu.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ev) {
                        print(actionTree);
                    }
                });
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            displayMenu(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            super.mousePressed(e);
            displayMenu(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            super.mouseReleased(e);
            displayMenu(e);
        }

    });
}

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

/**
 * Adds the Context PopupMenu for the RecordSet.
 * @param roc the RolloverCommand btn to add the pop to
 */// w  ww.  j a  v  a2  s .  co  m
public void addPopMenu(final RolloverCommand roc, final boolean isOKDelete, final boolean isOKModify) {
    if (roc.getLabelText() != null) {
        final JPopupMenu popupMenu = new JPopupMenu();

        if (isOKModify) {
            JMenuItem renameMenuItem = new JMenuItem(UIRegistry.getResourceString("Rename"));
            renameMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    roc.startEditting(RecordSetTask.this);
                }
            });
            popupMenu.add(renameMenuItem);
        }

        if (isOKDelete) {
            JMenuItem delMenuItem = new JMenuItem(UIRegistry.getResourceString("Delete"));
            delMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent actionEvent) {
                    CommandDispatcher.dispatch(new CommandAction(RECORD_SET, DELETE_CMD_ACT, roc));
                }
            });
            popupMenu.add(delMenuItem);
        }

        JMenuItem viewMenuItem = new JMenuItem(UIRegistry.getResourceString("View"));
        viewMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                CommandAction cmdAction = new CommandAction("Express_Search", "ViewRecordSet", roc);
                cmdAction.setProperty("canModify", isOKDelete);
                CommandDispatcher.dispatch(cmdAction);
            }
        });
        popupMenu.add(viewMenuItem);

        MouseListener mouseListener = new MouseAdapter() {
            private boolean showIfPopupTrigger(MouseEvent mouseEvent) {
                if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) {
                    popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
                return false;
            }

            @Override
            public void mousePressed(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }

            @Override
            public void mouseReleased(MouseEvent mouseEvent) {
                if (roc.isEnabled()) {
                    showIfPopupTrigger(mouseEvent);
                }
            }
        };
        roc.addMouseListener(mouseListener);
    }
}

From source file:medsavant.enrichment.app.OntologyAggregatePanel.java

private JPopupMenu createPopup() {
    JPopupMenu menu = new JPopupMenu();

    SortableTreeTableModel model = (SortableTreeTableModel) tree.getModel();
    final int[] selRows = tree.getSelectedRows();

    JMenuItem posItem = new JMenuItem(String.format("<html>Filter by %s</html>",
            selRows.length == 1 ? "Ontology Term <i>" + model.getValueAt(selRows[0], 0) + "</i>"
                    : "Selected Ontology Terms"));
    posItem.addActionListener(new ActionListener() {
        @Override/*from w w  w  .  j a  v a 2 s  .c  om*/
        public void actionPerformed(ActionEvent ae) {
            ThreadController.getInstance().cancelWorkers(pageName);

            List<OntologyTerm> terms = new ArrayList<OntologyTerm>();
            SortableTreeTableModel model = (SortableTreeTableModel) tree.getModel();
            for (int r : selRows) {
                OntologyNode rowNode = (OntologyNode) model.getRowAt(r);
                terms.add(rowNode.term);
            }

            OntologyType ont = terms.get(0).getOntology();
            GeneticsFilterPage.getSearchBar().loadFilters(
                    OntologyFilterView.wrapState(OntologyFilter.ontologyToTitle(ont), ont, terms, false));
        }

    });
    menu.add(posItem);

    return menu;
}