Example usage for javax.swing JPopupMenu show

List of usage examples for javax.swing JPopupMenu show

Introduction

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

Prototype

public void show(Component invoker, int x, int y) 

Source Link

Document

Displays the popup menu at the position x,y in the coordinate space of the component invoker.

Usage

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

/**
 * @param actionTree/*from w  ww  . j  av a  2  s .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:hermes.browser.components.ClasspathGroupTable.java

private void init() {
    final JPopupMenu popupMenu = new JPopupMenu();
    final JMenuItem addItem = new JMenuItem("Add Group");
    final JMenuItem removeItem = new JMenuItem("Remove Group");
    final JMenuItem renameItem = new JMenuItem("Rename");

    popupMenu.add(addItem);//from  w w  w  . jav a 2 s.c  om
    popupMenu.add(removeItem);
    popupMenu.add(renameItem);

    addItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                doAddGroup();
                dialog.setDirty();
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }
        }
    });

    removeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (getSelectedRowCount() > 0) {
                for (int row : getSelectedRows()) {
                    getClasspathGroupTableModel().removeRow(row);
                }
                dialog.setDirty();
            }
        }
    });

    renameItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (getSelectedRow() != -1) {
                doRename();
            }
        }
    });

    mouseAdapter = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                removeItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0);
                renameItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0);
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };

    addMouseListener(mouseAdapter);
    getTableHeader().addMouseListener(mouseAdapter);

    if (dialog != null) {
        addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                //
                // Think this is ok, seems 2 do the job.

                if (evt.getPropertyName().equals("tableCellEditor")) {
                    dialog.setDirty();
                }
            }
        });
    }
}

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

public GamePanel() throws IOException {

    makeActions();/* w ww  .  j  a va 2 s . co  m*/

    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:de.fhbingen.wbs.wpOverview.tabs.APCalendarPanel.java

/**
 * Initialize the work package calendar panel inclusive the listeners.
 *///  www. j av  a 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:edu.ku.brc.specify.tasks.ExpressSearchTask.java

/**
 * Shows the Reset menu.//  w w w.  j a v  a  2s. co  m
 * @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:lcmc.common.ui.ResourceGraph.java

protected final void showPopup(final JPopupMenu popup, final Point2D p) {
    final int posX = (int) p.getX();
    final int posY = (int) p.getY();
    swingUtils.invokeAndWait(new Runnable() {
        @Override/*from w  ww  . j a  va2 s.c  o  m*/
        public void run() {
            if (visualizationViewer.isShowing() && visualizationViewer.isDisplayable()) {
                popup.show(visualizationViewer, posX, posY);
                popup.repaint();
            }
        }
    });
}

From source file:com.ivli.roim.controls.ChartControl.java

@Override
public void mouseReleased(MouseEvent e) {
    if (SwingUtilities.isRightMouseButton(e)
            && (iMarker instanceof DomainMarker || iSeries instanceof XYSeries)) {
        JPopupMenu mnu = new JPopupMenu(
                java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("MNU_MARKER_OPERATIONS"));
        if (iSeries instanceof XYSeries) {
            mnu.add(MENUS.ADD.makeItem(this));
            mnu.add(MENUS.EXPORT_CSV.makeItem(this));
            mnu.add(MENUS.DELETE_ALL.makeItem(this));
        } else if (iMarker instanceof DomainMarker) {
            JMenu mi1 = new JMenu(MENUS.MOVE_TO_MIN.iText);
            mi1.add(MENUS.MOVE_TO_MIN.makeItem(this));
            //  mi1.add(MENUS.MOVE_TO_MIN_LEFT.makeItem(this));
            //  mi1.add(MENUS.MOVE_TO_MIN_RIGHT.makeItem(this));
            mnu.add(mi1);//  w  w  w .j a v a 2 s.  com
            JMenu mi2 = new JMenu(MENUS.MOVE_TO_MAX.iText);
            mi2.add(MENUS.MOVE_TO_MAX.makeItem(this));
            //  mi2.add(MENUS.MOVE_TO_MAX_LEFT.makeItem(this));
            //  mi2.add(MENUS.MOVE_TO_MAX_RIGHT.makeItem(this));

            mnu.add(mi2);
            mnu.add(MENUS.MOVE_TO_MEDIAN.makeItem(this));

            //if(!getDomainMarkersForSeries()){
            JMenu mi3 = new JMenu(
                    java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("MARKER_COMMAND.FIT"));
            mi3.add(MENUS.FIT_LEFT.makeItem(this));
            mi3.add(MENUS.FIT_RIGHT.makeItem(this));
            mnu.add(mi3);
            //}

            mnu.add(MENUS.DELETE.makeItem(this));
        }

        mnu.show(this, e.getX(), e.getY());
    } else {
        super.mouseReleased(e);
        dropSelection();
    }
}

From source file:ca.phon.app.project.ProjectWindow.java

/**
 * Displays the session list menu/*from   w  w w  .  ja v a 2s .co  m*/
 * 
 * @param clickPoint
 */
private void showSessionListContextMenu(Point clickPoint) {
    List<String> selectedSessions = getSelectedSessionNames();

    JPopupMenu contextMenu = new JPopupMenu();

    if (selectedSessions.size() == 1) {
        // open item
        JMenuItem openItem = new JMenuItem(new OpenSessionAction(this));
        contextMenu.add(openItem);

        contextMenu.addSeparator();
    }

    // rename item
    JMenuItem duplicateItem = new JMenuItem(new DuplicateSessionAction(this));
    if (selectedSessions.size() > 1) {
        duplicateItem.setText("Duplicate Sessions");
    }
    contextMenu.add(duplicateItem);

    if (selectedSessions.size() == 1) {
        JMenuItem renameItem = new JMenuItem(new RenameSessionAction(this));
        contextMenu.add(renameItem);
    }

    // delete item
    JMenuItem deleteItem = new JMenuItem(new DeleteSessionAction(this));
    if (selectedSessions.size() > 1) {
        deleteItem.setText("Delete Sessions");
    }
    contextMenu.add(deleteItem);

    contextMenu.show(sessionList, clickPoint.x, clickPoint.y);
}

From source file:ca.phon.app.project.ProjectWindow.java

/** 
 * Displays the corpus list menu//from w  w  w.j a  va2  s  . c  o 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:com.clough.android.adbv.view.UpdateTableDialog.java

private void showTableChangeOptionMenu(int x, int y, final int rowIndex) {
    JPopupMenu tableChangeOptionPopupMenu = new JPopupMenu();
    JMenuItem newRowMenuItem = new JMenuItem("Add row");
    newRowMenuItem.addActionListener(new ActionListener() {

        @Override/*from w ww  . j a  va2  s. c  om*/
        public void actionPerformed(ActionEvent e) {
            new AddUpdateRowDialog(defaultTableModel, rowController, columnNames, null, -1).setVisible(true);
        }
    });
    JMenuItem updateRowMenuItem = new JMenuItem("Update row");
    updateRowMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Object[] row = new Object[columnNames.length];
            for (int columnIndex = 0; columnIndex < row.length; columnIndex++) {
                row[columnIndex] = defaultTableModel.getValueAt(rowIndex, columnIndex);
            }
            new AddUpdateRowDialog(defaultTableModel, rowController, columnNames, row, rowIndex)
                    .setVisible(true);
            tableColumnAdjuster.adjustColumns();
        }
    });
    JMenuItem removeRowMenuItem = new JMenuItem("Remove row");
    removeRowMenuItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove this row?", "Remove row",
                    JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                defaultTableModel.removeRow(rowIndex);
                rowController.removeRow(rowIndex);
                tableColumnAdjuster.adjustColumns();
            }
        }
    });
    tableChangeOptionPopupMenu.add(newRowMenuItem);
    tableChangeOptionPopupMenu.add(updateRowMenuItem);
    tableChangeOptionPopupMenu.add(removeRowMenuItem);
    tableChangeOptionPopupMenu.show(this, x, y);
}