Example usage for javax.swing JPopupMenu JPopupMenu

List of usage examples for javax.swing JPopupMenu JPopupMenu

Introduction

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

Prototype

public JPopupMenu() 

Source Link

Document

Constructs a JPopupMenu without an "invoker".

Usage

From source file:op.care.nursingprocess.DlgNursingProcess.java

private void tblPlanungMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPlanungMousePressed
    if (!SwingUtilities.isRightMouseButton(evt)) {
        return;/* w  w w .j a  v a2s  . c o  m*/
    }

    Point p = evt.getPoint();
    ListSelectionModel lsm = tblPlanung.getSelectionModel();
    int row = tblPlanung.rowAtPoint(p);
    if (lsm.isSelectionEmpty() || (lsm.getMinSelectionIndex() == lsm.getMaxSelectionIndex())) {
        lsm.setSelectionInterval(row, row);
    }

    menu = new JPopupMenu();

    /***
     *      _ _                 ____                         ____       _      _
     *     (_) |_ ___ _ __ ___ |  _ \ ___  _ __  _   _ _ __ |  _ \  ___| | ___| |_ ___
     *     | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \| | | |/ _ \ |/ _ \ __/ _ \
     *     | | ||  __/ | | | | |  __/ (_) | |_) | |_| | |_) | |_| |  __/ |  __/ ||  __/
     *     |_|\__\___|_| |_| |_|_|   \___/| .__/ \__,_| .__/|____/ \___|_|\___|\__\___|
     *                                    |_|         |_|
     */
    JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete);
    itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            for (int row : tblPlanung.getSelectedRows()) {
                listInterventionSchedule2Remove
                        .add(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row));
                nursingProcess.getInterventionSchedule()
                        .remove(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row));
            }
            ((TMPlan) tblPlanung.getModel()).fireTableDataChanged();
        }
    });
    menu.add(itemPopupDelete);

    /***
     *      _ _                 ____                        ____       _              _       _
     *     (_) |_ ___ _ __ ___ |  _ \ ___  _ __  _   _ _ __/ ___|  ___| |__   ___  __| |_   _| | ___
     *     | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \___ \ / __| '_ \ / _ \/ _` | | | | |/ _ \
     *     | | ||  __/ | | | | |  __/ (_) | |_) | |_| | |_) |__) | (__| | | |  __/ (_| | |_| | |  __/
     *     |_|\__\___|_| |_| |_|_|   \___/| .__/ \__,_| .__/____/ \___|_| |_|\___|\__,_|\__,_|_|\___|
     *                                    |_|         |_|
     */
    final JMenuItem itemPopupSchedule = new JMenuItem(SYSTools.xx("misc.commands.editsheduling"),
            SYSConst.icon22clock);
    itemPopupSchedule.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            final JidePopup popup = new JidePopup();

            /**
             * This routine uses the <b>first</b> element of the selection as the template for editing
             * the schedule. After the edit it clones this "template", removes the original
             * InterventionSchedules (copying the apropriate Intervention of every single
             * Schedule first) and finally creates new schedules and adds them to
             * the CareProcess in question.
             */
            int row = tblPlanung.getSelectedRows()[0];
            InterventionSchedule firstInterventionScheduleWillBeTemplate = ((TMPlan) tblPlanung.getModel())
                    .getInterventionSchedule(row);
            JPanel dlg = new PnlSchedule(firstInterventionScheduleWillBeTemplate, new Closure() {
                @Override
                public void execute(Object o) {
                    if (o != null) {
                        InterventionSchedule template = (InterventionSchedule) o;
                        ArrayList<InterventionSchedule> listInterventionSchedule2Add = new ArrayList();
                        for (int row : tblPlanung.getSelectedRows()) {
                            InterventionSchedule oldTermin = ((TMPlan) tblPlanung.getModel())
                                    .getInterventionSchedule(row);
                            InterventionSchedule newTermin = template.clone();
                            newTermin.setIntervention(oldTermin.getIntervention());
                            listInterventionSchedule2Remove.add(oldTermin);
                            listInterventionSchedule2Add.add(newTermin);
                        }
                        nursingProcess.getInterventionSchedule().removeAll(listInterventionSchedule2Remove);
                        nursingProcess.getInterventionSchedule().addAll(listInterventionSchedule2Add);
                        popup.hidePopup();
                        Collections.sort(nursingProcess.getInterventionSchedule());
                        ((TMPlan) tblPlanung.getModel()).fireTableDataChanged();
                    }
                }
            });

            popup.setMovable(false);
            popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
            popup.getContentPane().add(dlg);
            popup.setOwner(jspPlanung);
            popup.removeExcludedComponent(jspPlanung);
            popup.setDefaultFocusComponent(dlg);

            GUITools.showPopup(popup, SwingConstants.SOUTH_WEST);
        }
    });
    menu.add(itemPopupSchedule);

    menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());
}

From source file:op.care.prescription.DlgRegular.java

private void tblDosisMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDosisMousePressed
    if (!SwingUtilities.isRightMouseButton(evt)) {
        return;//www  . j  a va  2s.  c om
    }

    final TMDose tm = (TMDose) tblDosis.getModel();
    if (tm.getRowCount() == 0) {
        return;
    }
    Point p = evt.getPoint();
    Point p2 = evt.getPoint();
    // Convert a coordinate relative to a component's bounds to screen coordinates
    SwingUtilities.convertPointToScreen(p2, tblDosis);

    //        final Point screenposition = p2;
    final int row = tblDosis.rowAtPoint(p);

    ListSelectionModel lsm = tblDosis.getSelectionModel();
    lsm.setSelectionInterval(row, row);

    // Meneintrge
    SYSTools.unregisterListeners(menu);
    menu = new JPopupMenu();

    //-----------------------------------------
    JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.msg.delete"), SYSConst.icon22delete);
    itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
            PrescriptionSchedule schedule = prescription.getPrescriptionSchedule().get(row);
            prescription.getPrescriptionSchedule().remove(schedule);
            schedules2delete.add(schedule);
            reloadTable();
        }
    });
    menu.add(itemPopupDelete);
    menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());

}

From source file:op.care.sysfiles.PnlFiles.java

private void tblFilesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFilesMousePressed

    Point p = evt.getPoint();//from  www  .j  a  va2 s  .  com
    ListSelectionModel lsm = tblFiles.getSelectionModel();
    Point p2 = evt.getPoint();
    SwingUtilities.convertPointToScreen(p2, tblFiles);
    final Point screenposition = p2;

    boolean singleRowSelected = lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex();

    final int row = tblFiles.rowAtPoint(p);
    final int col = tblFiles.columnAtPoint(p);

    if (singleRowSelected) {
        lsm.setSelectionInterval(row, row);
    }

    final TMSYSFiles tm = (TMSYSFiles) tblFiles.getModel();
    final SYSFiles sysfile = tm.getRow(tblFiles.convertRowIndexToModel(row));

    if (SwingUtilities.isRightMouseButton(evt)) {

        SYSTools.unregisterListeners(menu);
        menu = new JPopupMenu();

        // SELECT
        JMenuItem itemPopupShow = new JMenuItem(SYSTools.xx("misc.commands.show"), SYSConst.icon22magnify1);
        itemPopupShow.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN);
            }
        });
        menu.add(itemPopupShow);

        if (col == TMSYSFiles.COL_DESCRIPTION
                && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {

            final JMenuItem itemPopupEdit = new JMenuItem(SYSTools.xx("misc.commands.edit"),
                    SYSConst.icon22edit3);
            itemPopupEdit.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    final JidePopup popup = new JidePopup();
                    popup.setMovable(false);
                    popup.getContentPane()
                            .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));

                    final JComponent editor = new JTextArea(sysfile.getBeschreibung(), 10, 40);
                    ((JTextArea) editor).setLineWrap(true);
                    ((JTextArea) editor).setWrapStyleWord(true);
                    ((JTextArea) editor).setEditable(true);

                    popup.getContentPane().add(new JScrollPane(editor));
                    final JButton saveButton = new JButton(SYSConst.icon22apply);
                    saveButton.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent actionEvent) {
                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();
                                popup.hidePopup();
                                SYSFiles mySysfile = em.merge(sysfile);
                                mySysfile.setBeschreibung(((JTextArea) editor).getText().trim());
                                em.getTransaction().commit();
                                tm.setSYSFile(tblFiles.convertRowIndexToModel(row), mySysfile);
                            } catch (Exception e) {
                                em.getTransaction().rollback();
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }

                        }
                    });

                    saveButton.setHorizontalAlignment(SwingConstants.RIGHT);
                    JPanel pnl = new JPanel(new BorderLayout(10, 10));
                    JScrollPane pnlEditor = new JScrollPane(editor);

                    pnl.add(pnlEditor, BorderLayout.CENTER);
                    JPanel buttonPanel = new JPanel();
                    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
                    buttonPanel.add(saveButton);
                    pnl.setBorder(new EmptyBorder(10, 10, 10, 10));
                    pnl.add(buttonPanel, BorderLayout.SOUTH);

                    popup.setOwner(tblFiles);
                    popup.removeExcludedComponent(tblFiles);
                    popup.getContentPane().add(pnl);
                    popup.setDefaultFocusComponent(editor);

                    popup.showPopup(screenposition.x, screenposition.y);

                }
            });
            menu.add(itemPopupEdit);
        }

        if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) {
            JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"),
                    SYSConst.icon22delete);
            itemPopupDelete.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {

                    new DlgYesNo(
                            SYSTools.xx("misc.questions.delete1") + "<br/><b>" + sysfile.getFilename()
                                    + "</b><br/>" + SYSTools.xx("misc.questions.delete2"),
                            new ImageIcon(getClass().getResource("/artwork/48x48/bw/trashcan_empty.png")),
                            new Closure() {
                                @Override
                                public void execute(Object o) {
                                    if (o.equals(JOptionPane.YES_OPTION)) {
                                        SYSFilesTools.deleteFile(sysfile);
                                        reloadTable();
                                    }
                                }
                            });

                }
            });
            menu.add(itemPopupDelete);
            itemPopupDelete.setEnabled(singleRowSelected);
        }

        menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY());
    } else if (evt.getClickCount() == 2) {
        SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN);
    }

}

From source file:org.accada.hal.impl.sim.GraphicSimulator.java

/**
 * creates the context menu if it does not already exists
 * //from   w w  w .j ava2s.co m
 * @return context menu
 */
private JPopupMenu getContextMenu() {
    if (contextMenu == null) {
        contextMenu = new JPopupMenu();

        // add new antenna item
        JMenuItem newAntennaContextMenuItem = new JMenuItem(guiTextConfig.getString("AddNewAntennaMenuItem"));
        newAntennaContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddAntennaDialog();
                contextMenu.setVisible(false);
            }
        });
        //contextMenu.add(newAntennaContextMenuItem);

        // add new tag item 
        JMenuItem newTagContextMenuItem = new JMenuItem(guiTextConfig.getString("AddNewTagMenuItem"));
        newTagContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddTagDialog();
                contextMenu.setVisible(false);
            }
        });
        contextMenu.add(newTagContextMenuItem);
    }
    return contextMenu;
}

From source file:org.accada.hal.impl.sim.GraphicSimulator.java

/**
 * Returns the management simulator menu.
 * //from   w  w w . j a  v  a  2s. c o  m
 * @return The management simulator menu
 */
private JPopupMenu getMgmtSimMenu() {
    if (mgmtSimMenu == null) {
        mgmtSimMenu = new JPopupMenu();
        JMenuItem newMgmtContextMenuItem = new JMenuItem("Simulate an error");
        newMgmtContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                mgmtSimMenu.setVisible(false);
                showMgmtSimDialog();
            }
        });
        mgmtSimMenu.add(newMgmtContextMenuItem);

        // add new tag item
        JMenuItem newTagContextMenuItem = new JMenuItem(guiTextConfig.getString("AddNewTagMenuItem"));
        newTagContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddTagDialog();
                mgmtSimMenu.setVisible(false);
            }
        });
        mgmtSimMenu.add(newTagContextMenuItem);

        //         MenuElement[] elements = contextMenu.getSubElements();
        //         for (int i = 0; i < elements.length; i++) {
        //            mgmtSimMenu.add((JMenuItem) elements[i]);
        //         }
    }
    return mgmtSimMenu;
}

From source file:org.accada.hal.impl.sim.multi.GraphicSimulatorServer.java

/**
 * creates the context menu if it does not already exists
 * //from w w w. j  a  v a 2s .  c  o m
 * @return context menu
 */
private JPopupMenu getContextMenu() {
    if (contextMenu == null) {
        contextMenu = new JPopupMenu();

        // add new tag item 
        JMenuItem newTagContextMenuItem = new JMenuItem(guiTextConfig.getString("AddNewTagMenuItem"));
        newTagContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddTagDialog();
                contextMenu.setVisible(false);
            }
        });
        contextMenu.add(newTagContextMenuItem);
    }
    return contextMenu;
}

From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java

/**
 * creates the context menu if it does not already exists
 * /* w  w w.  j  ava 2 s .  c  om*/
 * @return context menu
 */
private JPopupMenu getContextMenu() {
    if (contextMenu == null) {
        contextMenu = new JPopupMenu();

        // add new antenna item
        JMenuItem newAntennaContextMenuItem = new JMenuItem(guiText.getString("AddNewAntennaMenuItem"));
        newAntennaContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddAntennaDialog();
                contextMenu.setVisible(false);
            }
        });
        //contextMenu.add(newAntennaContextMenuItem);

        // add new tag item 
        JMenuItem newTagContextMenuItem = new JMenuItem(guiText.getString("AddNewTagMenuItem"));
        newTagContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddTagDialog();
                contextMenu.setVisible(false);
            }
        });
        contextMenu.add(newTagContextMenuItem);
    }
    return contextMenu;
}

From source file:org.accada.reader.hal.impl.sim.GraphicSimulator.java

/**
 * Returns the management simulator menu.
 * /*  w  w  w .j av a  2s.c o  m*/
 * @return The management simulator menu
 */
private JPopupMenu getMgmtSimMenu() {
    if (mgmtSimMenu == null) {
        mgmtSimMenu = new JPopupMenu();
        JMenuItem newMgmtContextMenuItem = new JMenuItem("Simulate an error");
        newMgmtContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                mgmtSimMenu.setVisible(false);
                showMgmtSimDialog();
            }
        });
        mgmtSimMenu.add(newMgmtContextMenuItem);

        // add new tag item
        JMenuItem newTagContextMenuItem = new JMenuItem(guiText.getString("AddNewTagMenuItem"));
        newTagContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddTagDialog();
                mgmtSimMenu.setVisible(false);
            }
        });
        mgmtSimMenu.add(newTagContextMenuItem);

        //         MenuElement[] elements = contextMenu.getSubElements();
        //         for (int i = 0; i < elements.length; i++) {
        //            mgmtSimMenu.add((JMenuItem) elements[i]);
        //         }
    }
    return mgmtSimMenu;
}

From source file:org.accada.reader.hal.impl.sim.multi.GraphicSimulatorServer.java

/**
 * creates the context menu if it does not already exists
 * //w w  w . ja va  2  s. c  o m
 * @return context menu
 */
private JPopupMenu getContextMenu() {
    if (contextMenu == null) {
        contextMenu = new JPopupMenu();

        // add new tag item 
        JMenuItem newTagContextMenuItem = new JMenuItem(guiText.getString("AddNewTagMenuItem"));
        newTagContextMenuItem.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                showAddTagDialog();
                contextMenu.setVisible(false);
            }
        });
        contextMenu.add(newTagContextMenuItem);
    }
    return contextMenu;
}

From source file:org.accretegb.modules.phenotype.PhenotypeInfoPanel.java

/**
 * populates parameter names from database
 *///from   www. j  a va2s. c  o  m
public void populateParameterNames() {
    parameterName = new JButton();
    parametersCheckBoxes = new ArrayList<JCheckBox>();
    List<String> parameters = new ArrayList<String>();
    List<MeasurementParameter> results = MeasurementParameterDAO.getInstance().findAll();
    for (MeasurementParameter obj : results) {
        parameters.add(obj.getParameterName());
        parameter_id.put(obj.getParameterName(), String.valueOf(obj.getMeasurementParameterId()));
    }
    final JPopupMenu columnsPopupMenu = new JPopupMenu();
    final JCheckBox[] columnNameCheckBox = new JCheckBox[parameters.size()];
    JPanel columnsPopupPanel = new JPanel(new MigLayout("insets 0, gap 0"));
    JScrollPane scrollPane = new JScrollPane(columnsPopupPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    for (int columnCounter = 0; columnCounter < columnNameCheckBox.length; ++columnCounter) {
        columnNameCheckBox[columnCounter] = new JCheckBox(parameters.get(columnCounter));
        parametersCheckBoxes.add(columnNameCheckBox[columnCounter]);
        columnsPopupPanel.add(columnNameCheckBox[columnCounter], "wrap");
    }
    scrollPane.setPreferredSize(new Dimension(150, 300));

    columnsPopupMenu.add(scrollPane);
    parameterName.setAction(new AbstractAction("select") {
        public void actionPerformed(ActionEvent e) {
            columnsPopupMenu.show(parameterName, 0, parameterName.getHeight());
        }
    });
}