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:org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement.java

public SQLComponent createComponent() {

    return new BaseSQLComponent(this) {

        private ValidState validVarName;
        private JRadioButton radioVal = new JRadioButton("Valeur");
        private JRadioButton radioFormule = new JRadioButton("Formule");

        private final JTextField textValeur = new JTextField();
        // private final ITextArea textFormule = new ITextArea();
        private final VariableTree treeVariable = new VariableTree();
        private final JTextField textNom = new JTextField();
        private final JLabel labelWarningBadVar = new JLabelWarning();
        private ElementComboBox comboSelSal;
        private EditFrame edit = null;
        private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree());

        public void addViews() {
            this.setLayout(new GridBagLayout());
            final GridBagConstraints c = new DefaultGridBagConstraints();

            this.validVarName = null;
            this.textFormule.setEditable(false);

            // Arbre des variables
            JScrollPane sc = new JScrollPane(this.treeVariable);
            sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height));

            this.treeVariable.addMouseListener(new MouseAdapter() {
                public void mousePressed(final MouseEvent mE) {
                    if (mE.getButton() == MouseEvent.BUTTON3) {
                        JPopupMenu menuDroit = new JPopupMenu();

                        TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x,
                                mE.getPoint().y);

                        final Object obj = path.getLastPathComponent();

                        if ((obj == null) || !(obj instanceof VariableRowTreeNode)) {
                            return;
                        }/*from  w  w  w.jav  a 2  s  .  co  m*/

                        menuDroit.add(new AbstractAction("Editer") {
                            public void actionPerformed(ActionEvent e) {
                                if (edit == null) {
                                    edit = new EditFrame(getElement(), EditFrame.MODIFICATION);
                                }

                                System.err.println("Action performed");

                                if (obj != null) {
                                    System.err.println("Object not null --> " + obj.toString());
                                    if (obj instanceof VariableRowTreeNode) {
                                        System.err.println("Object VariableRowTreeNode");
                                        VariableRowTreeNode varNode = (VariableRowTreeNode) obj;

                                        edit.selectionId(varNode.getID(), 1);
                                        edit.setVisible(true);
                                    }
                                }
                            }
                        });
                        menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y);
                    } else {
                        if (mE.getClickCount() == 2) {
                            TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x,
                                    mE.getPoint().y);
                            Object obj = path.getLastPathComponent();

                            if (obj != null) {
                                if (obj instanceof FormuleTreeNode) {
                                    final FormuleTreeNode n = (FormuleTreeNode) obj;

                                    int start = textFormule.getSelectionStart();
                                    String tmp = textFormule.getText();
                                    textFormule.setText(tmp.substring(0, start) + n.getTextValue()
                                            + tmp.substring(start, tmp.length()));
                                }
                            }
                        }
                    }
                }
            });

            JPanel panelDroite = new JPanel();
            panelDroite.setLayout(new GridBagLayout());

            // Categorie
            JTextField textCategorie = new JTextField();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridheight = 1;
            c.gridx = 1;
            c.gridy = 0;
            JLabel labelCategorie = new JLabel("Catgorie");
            panelDroite.add(labelCategorie, c);
            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            panelDroite.add(textCategorie, c);
            c.gridwidth = 1;

            // Nom
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridheight = 1;
            c.gridx = 1;
            c.gridy++;
            JLabel labelNom = new JLabel("Nom");
            panelDroite.add(labelNom, c);

            c.gridx++;
            c.weightx = 1;
            panelDroite.add(this.textNom, c);

            this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() {
                @Override
                public void update(DocumentEvent e) {
                    updateValidVarName();
                }
            });

            c.gridx++;
            c.weightx = 0;
            panelDroite.add(this.labelWarningBadVar, c);

            // Description
            JLabel labelInfos = new JLabel(getLabelFor("INFOS"));
            ITextArea textInfos = new ITextArea();
            c.gridy++;
            c.gridx = 1;
            c.gridwidth = 1;
            c.weightx = 0;
            panelDroite.add(labelInfos, c);
            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weightx = 1;
            c.weighty = 0;
            panelDroite.add(textInfos, c);

            // Valeur
            c.gridx = 1;
            c.gridy++;
            c.gridwidth = 1;
            c.weightx = 0;
            panelDroite.add(this.radioVal, c);

            c.gridx++;
            c.weightx = 1;
            c.gridwidth = GridBagConstraints.REMAINDER;
            panelDroite.add(this.textValeur, c);

            c.gridwidth = 1;
            c.gridx = 1;
            c.gridy++;
            panelDroite.add(this.radioFormule, c);

            c.gridx++;
            c.weightx = 1;
            c.weighty = 1;
            c.fill = GridBagConstraints.BOTH;
            c.gridwidth = GridBagConstraints.REMAINDER;
            panelDroite.add(this.textFormule, c);
            c.gridwidth = 1;

            ButtonGroup group = new ButtonGroup();
            group.add(this.radioVal);
            group.add(this.radioFormule);

            this.radioVal.setSelected(true);
            setFormuleEnabled(false);

            this.radioVal.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    setFormuleEnabled(false);
                }
            });
            this.radioFormule.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {

                    setFormuleEnabled(true);
                }
            });

            c.gridy++;
            c.gridx = 1;
            c.weighty = 0;
            c.weightx = 0;
            c.fill = GridBagConstraints.HORIZONTAL;

            this.comboSelSal = new ElementComboBox(false);
            this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class));

            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weightx = 0;
            panelDroite.add(this.comboSelSal, c);
            c.gridwidth = 1;

            JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite);

            c.fill = GridBagConstraints.BOTH;
            c.gridx = 0;
            c.gridy = 0;
            c.weightx = 1;
            c.weighty = 1;
            this.add(split, c);

            this.addRequiredSQLObject(this.textNom, "NOM");
            this.addSQLObject(this.textValeur, "VALEUR");
            this.addSQLObject(this.textFormule, "FORMULE");
            this.addSQLObject(textCategorie, "CATEGORIE");
            this.addSQLObject(textInfos, "INFOS");

            this.comboSelSal.addValueListener(new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    // TODO Auto-generated method stub
                    textFormule.setSalarieID(comboSelSal.getSelectedId());
                }
            });
        }

        @Override
        public synchronized ValidState getValidState() {
            return super.getValidState().and(this.validVarName);
        }

        private void setFormuleEnabled(boolean b) {

            if (b) {
                this.textValeur.setText("");
            } else {
                this.textFormule.setText("");
            }

            this.textValeur.setEditable(!b);
            this.textValeur.setEnabled(!b);
            this.textFormule.setEditable(b);
            this.textFormule.setEnabled(b);
            this.treeVariable.setEnabled(b);
            this.treeVariable.setEditable(b);
        }

        private void setValidVarName(ValidState s) {
            if (!s.equals(this.validVarName)) {
                this.validVarName = s;
                final boolean warningVisible = !s.isValid();
                if (warningVisible)
                    this.labelWarningBadVar.setText(s.getValidationText());
                this.labelWarningBadVar.setVisible(warningVisible);
                this.fireValidChange();
            }
        }

        private void updateValidVarName() {
            this.setValidVarName(this.computeValidVarName());
        }

        private ValidState computeValidVarName() {
            // on vrifie si la syntaxe de la variable est correct (chiffre lettre et _)
            final String varName = this.textNom.getText().trim();

            System.err.println("Verification de la validit du nom de la variable.");

            if (varName.length() == 0) {
                return VAR_NO_NAME;
            }

            // ne contient que des chiffre lettre et _ et ne commence pas par un chiffre
            if (!isJavaVar(varName)) {
                return VAR_NAME_NOT_CORRECT;
            }

            // on vrifie que la variable n'existe pas dja
            SQLSelect selAllVarName = new SQLSelect(getTable().getBase());

            selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID"));
            Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName);
            w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID()));
            selAllVarName.setWhere(w);

            String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "'
            // REGEXP VARIABLE_PAYE.NOM";
            Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName,
                    new ArrayListHandler())).toArray();

            if (objKeysRowName.length > 0) {
                return VAR_ALREADY_EXIST;
            } else {

                // Impossible de crer une variable du meme nom qu'un champ du salarie
                if (isForbidden(varName))
                    return VAR_ALREADY_EXIST;

                this.textFormule.setVarAssign(varName);
                return ValidState.getTrueInstance();
            }
        }

        private boolean isJavaVar(String s) {
            if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) {
                System.err.println("Erreur la variable commence par un chiffre!!");
                return false;
            } else {
                for (int i = 0; i < s.length(); i++) {

                    if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9'))
                            || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z')
                            || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) {
                        System.err.println("Erreur la variable contient un caractere incorrect!!");
                        return false;
                    }
                }

                return (!CTokenMarker.getKeywords().isExisting(s));
            }
        }

        @Override
        public void select(SQLRowAccessor r) {

            super.select(r);
            // System.err.println("Select RowAccess -------> " + r.getID() + " For Object " +
            // this.hashCode());
            if (r != null) {
                if (r.getString("FORMULE").trim().length() == 0) {
                    this.radioVal.setSelected(true);
                    setFormuleEnabled(false);
                } else {
                    this.radioFormule.setSelected(true);
                    setFormuleEnabled(true);
                }

                this.textFormule.setVarAssign(r.getString("NOM"));
            }

            this.updateValidVarName();
        }
    };
}

From source file:org.openconcerto.erp.model.FamilleArticleTree.java

public void mousePressed(MouseEvent e) {

    Object o = this.getSelectionPath().getLastPathComponent();

    int id = 1;/* w  ww  .java2 s  . c  om*/

    if (e.getButton() == MouseEvent.BUTTON3) {
        if (o instanceof FamilleTreeNode) {

            final FamilleTreeNode nodeSelect = (FamilleTreeNode) o;
            id = nodeSelect.getId();
        }

        final int idSelect = id;

        // Ajouter, supprimer, modifier une famille

        JPopupMenu menu = new JPopupMenu();
        menu.add(new AbstractAction("Ajouter une famille") {
            public void actionPerformed(ActionEvent e) {
                EditFrame frameAddFamille = new EditFrame(familleElt, EditFrame.CREATION);
                SQLRowValues rowVals = new SQLRowValues(familleElt.getTable());
                rowVals.put("ID_FAMILLE_ARTICLE_PERE", idSelect);
                frameAddFamille.getSQLComponent().select(rowVals);
                frameAddFamille.setVisible(true);

            }
        });

        if (idSelect > 1) {
            menu.add(new AbstractAction("Modifier") {
                public void actionPerformed(ActionEvent e) {
                    EditFrame frameModFamille = new EditFrame(familleElt, EditFrame.MODIFICATION);
                    frameModFamille.selectionId(idSelect, 1);
                    frameModFamille.setVisible(true);

                }
            });

            menu.add(new AbstractAction("Supprimer") {
                public void actionPerformed(ActionEvent e) {
                    try {
                        familleElt.archive(idSelect);
                    } catch (SQLException e1) {
                        e1.printStackTrace();
                    }
                }
            });
        }
        menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
    }

}

From source file:org.openconcerto.erp.panel.ITreeSelection.java

public void mousePressed(MouseEvent e) {

    TreePath path = this.getSelectionPath();
    if (path != null) {
        Object o = path.getLastPathComponent();

        int id = 1;

        if (e.getButton() == MouseEvent.BUTTON3) {

            final int idSelect = getSelectedID();

            // Ajouter, supprimer, modifier un lment dans l'arbre

            JPopupMenu menu = new JPopupMenu();
            menu.add(new AbstractAction("Ajouter un lment") {
                public void actionPerformed(ActionEvent e) {
                    addElement(idSelect);
                }/*from  ww w  .j  a  va 2 s.com*/
            });

            if (idSelect > 1) {
                menu.add(new AbstractAction("Modifier") {
                    public void actionPerformed(ActionEvent e) {
                        modifyElement(idSelect);
                    }
                });

                menu.add(new AbstractAction("Supprimer") {
                    public void actionPerformed(ActionEvent e) {
                        removeElement(idSelect);
                    }
                });
            }
            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
        }
    }
}

From source file:org.openconcerto.map.ui.ITextComboVilleViewer.java

public ITextComboVilleViewer() {
    this.setOpaque(false);
    this.setLayout(new BorderLayout());

    this.supp = new ValueChangeSupport<String>(this);
    this.emptyHelper = new EmptyObjectHelper(this, new Predicate() {
        public boolean evaluate(final Object object) {
            // object: le getUncheckedValue()
            return ITextComboVilleViewer.this.getValue() == null
                    || ITextComboVilleViewer.this.getValue().trim().length() == 0;
        }// ww  w.ja  v  a  2 s .  com
    });
    this.text.addValueListener(new PropertyChangeListener() {
        public void propertyChange(final PropertyChangeEvent evt) {
            ITextComboVilleViewer.this.supp.fireValueChange();
        }
    });

    this.cache = new ITextComboCacheVille();
    this.text.initCache(this.cache);
    this.add(this.text, BorderLayout.CENTER);

    this.add(this.button, BorderLayout.EAST);
    this.button.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final JFrame f = new JFrame();
            final MapViewerPanel mapViewerPanel = new MapViewerPanel(true);

            f.setContentPane(mapViewerPanel);
            f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            f.setSize(600, 500);
            f.setMinimumSize(new Dimension(600, 500));
            final File conf = new File(System.getProperty("user.home"),
                    ".java" + File.separator + "ilm" + File.separator + "map" + File.separator);
            new WindowStateManager(f, new File(conf, "Configuration" + File.separator + "MapFrame.properties"),
                    true).loadState();
            f.setVisible(true);
            if (ITextComboVilleViewer.this.currentVille != null) {
                final long x = ITextComboVilleViewer.this.currentVille.getXLambert();
                final long y = ITextComboVilleViewer.this.currentVille.getYLambert();
                f.setTitle(ITextComboVilleViewer.this.currentVille.getName());
                mapViewerPanel.getVilleRendererPanel().centerScreenXYLambert(x, y);
                mapViewerPanel.getVilleRendererPanel().setHighlight(ITextComboVilleViewer.this.currentVille);
                mapViewerPanel.getVilleRendererPanel().setAlwayVisible(ITextComboVilleViewer.this.currentVille);
            }
        }
    });
    this.text.getDocument().addDocumentListener(new DocumentListener() {

        public void changedUpdate(final DocumentEvent e) {
            ITextComboVilleViewer.this.currentVille = Ville
                    .getVilleFromVilleEtCode(ITextComboVilleViewer.this.text.getValue());
            ITextComboVilleViewer.this.button.setEnabled(
                    ITextComboVilleViewer.this.currentVille != null && ITextComboVilleViewer.this.isEnabled());

        }

        public void insertUpdate(final DocumentEvent e) {
            this.changedUpdate(e);
        }

        public void removeUpdate(final DocumentEvent e) {
            this.changedUpdate(e);
        }
    });
    final JPopupMenu popupMenu = new JPopupMenu();
    // FIXME ajouter la possibilit de supprimer une ville prcdemment enregistre
    final JMenuItem menuItem = new JMenuItem("Enregistrer cette ville");
    menuItem.addActionListener(new ActionListener() {

        public void actionPerformed(final ActionEvent e) {
            final String t = ITextComboVilleViewer.this.text.getTextComp().getText();
            ITextComboVilleViewer.this.cache.addToCache(t);
            final Ville createVilleFrom = ITextComboVilleViewer.this.cache.createVilleFrom(t);
            if (createVilleFrom != null) {
                final String villeEtCode = createVilleFrom.getVilleEtCode();
                ITextComboVilleViewer.this.setValue(villeEtCode);
                ITextComboVilleViewer.this.firePropertyChange("value", null, villeEtCode);
            }
        }
    });
    popupMenu.add(menuItem);

    this.text.getTextComp().addMouseListener(new PopupMouseListener(popupMenu));

}

From source file:org.openconcerto.task.TodoListPanel.java

void initPopUp() {
    TablePopupMouseListener.add(this.t, new ITransformer<MouseEvent, JPopupMenu>() {

        @Override//from   ww w  . jav a  2s . c  o  m
        public JPopupMenu transformChecked(MouseEvent evt) {
            final JTable table = (JTable) evt.getSource();
            final int modelIndex = TodoListPanel.this.sorter.modelIndex(table.getSelectedRow());
            final JPopupMenu res = new JPopupMenu();

            // Avancer d'un jour
            Action act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
                    if (element != null) {
                        final Date ts = element.getExpectedDate();
                        final Calendar cal = Calendar.getInstance();
                        cal.setTimeInMillis(ts.getTime());
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                ts.setTime(cal.getTimeInMillis());
                                element.setExpectedDate(ts);
                                element.commitChangesAndWait();
                                table.repaint();
                            }
                        });
                    }
                }
            };
            act.putValue(Action.NAME, TM.tr("moveOneDay"));
            res.add(act);

            // Marquer comme ralis
            act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
                    if (element != null) {
                        element.setDone(true);
                        element.commitChangesAndWait();
                        table.repaint();
                    }
                }
            };
            act.putValue(Action.NAME, TM.tr("markDone"));
            res.add(act);

            // Suppression
            act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    TodoListPanel.this.model.deleteTaskAtIndex(modelIndex);
                    table.repaint();
                }
            };
            act.putValue(Action.NAME, TM.tr("delete"));
            res.add(act);

            final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
            SQLRowValues rowTache = element.getRowValues();

            List<AbstractAction> actions = TacheActionManager.getInstance().getActionsForTaskRow(rowTache);

            for (AbstractAction abstractAction : actions) {
                res.add(abstractAction);
            }

            return res;
        }
    });
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * MouseListener used to select items from the list of Rule descriptions, allows for deletion of Rules
 * /*  w  w  w.ja  va  2s . c  om*/
 * @return
 */
private MouseListener getRuleListMouseAdapter() {

    return new MouseListener() {

        private JList list;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                list = ((JList) e.getSource());
                list.setSelectedIndex(getRow(e.getPoint()));

                JPopupMenu menu = new JPopupMenu();
                menu.add(new RemoveRule(list));

                Point pt = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), list);
                menu.show(list, pt.x, pt.y);
            }
        }

        private int getRow(Point point) {
            return list.locationToIndex(point);
        }

        public void mouseClicked(MouseEvent arg0) {

        }

        public void mouseEntered(MouseEvent arg0) {

        }

        public void mouseExited(MouseEvent arg0) {

        }

        public void mouseReleased(MouseEvent arg0) {

        }
    };
}

From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java

private JPopupMenu createActionMenu(final DbHelloWorldObject object) {
    // create a popup menu for the Hello World sidebar
    final JPopupMenu popup = new JPopupMenu();

    // add action into the popup menu for sidebar refresh
    popup.add(new JMenuItem(new HelloWorldPlugin.SidebarRefreshAction()));

    // add action into the popup menu for a new object
    popup.add(new JMenuItem(new HelloWorldPlugin.ObjectFormAction()));

    // no object is selected in the sidebar
    //noinspection StatementWithEmptyBody
    if (object == null) {
    }/*from   w ww  .  j a v  a2s  . c o  m*/

    // add further actions for the selected sidebar entry
    else {
        String title = StringUtils.abbreviate(StringUtils.trimToEmpty(object.name), 30);
        popup.add(
                ImmoToolUtils.createMenuSeparator("<html>" + StringEscapeUtils.escapeHtml4(title) + "</html>"));

        // add action into the popup menu for editing the selected object
        popup.add(new HelloWorldPlugin.ObjectFormAction(object.id));

        // add action into the popup menu for removing the selected object
        popup.add(new HelloWorldPlugin.ObjectRemoveAction(object.id));
    }

    // return the created popup menu
    return popup;
}

From source file:org.openestate.tool.helloworld.HelloWorldObjectViewPanel.java

@Override
protected void doShowActions(Component component, int x, int y) {
    JPopupMenu popup = new JPopupMenu();
    popup.add(createDefaultCopyAction(currentObject != null && currentObject.id > 0
            && HelloWorldPlugin.isUserAllowedTo(HelloWorldPermission.OBJECTS_EDIT)));
    popup.add(createDefaultRemoveAction(currentObject != null && currentObject.id > 0 && mayRemoveObject));

    boolean addonItemAdded = false;
    for (ObjectViewExtension addon : addons) {
        JMenuItem[] items = addon.createActionMenuItems(currentObject);
        if (ArrayUtils.isEmpty(items))
            continue;
        for (JMenuItem item : items) {
            if (!addonItemAdded) {
                addonItemAdded = true;//from w w w .  j av  a  2 s . co  m
                popup.addSeparator();
            }
            popup.add(item);
        }
    }

    popup.show(component, x, y);
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/**
 * Creates the menus corresponding to the passed id and brings it on screen.
 * // w w  w .j  a  v a  2s.  co m
 * @param menuID    The id of the menu. One out of the following constants:
 *                  {@link ImViewer#COLOR_PICKER_MENU},
 *                  {@link ImViewer#CATEGORY_MENU}.
 * @param source   The component that requested the popup menu.
 * @param location   The point at which to display the menu, relative to the
 *                  <code>component</code>'s coordinates.
 */
void showMenu(int menuID, Component source, Point location) {
    switch (menuID) {
    case ImViewer.COLOR_PICKER_MENU:
        List<ChannelData> data = model.getChannelData();
        ChannelData d;
        JPopupMenu menu = new JPopupMenu();
        ChannelColorMenuItem item;
        Iterator<ChannelData> i = data.iterator();
        int index;
        while (i.hasNext()) {
            d = i.next();
            index = d.getIndex();
            item = new ChannelColorMenuItem(d.getChannelLabeling(), model.getChannelColor(index), index);
            menu.add(item);
            item.addPropertyChangeListener(controller);
        }
        menu.show(source, location.x, location.y);
    }
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java

/**
 * Creates and displays the menu /*from   w  w  w . ja  v  a  2 s.  com*/
 * @param src The invoker.
 * @param p   The location where to show the menu.
 */
private void displayMenu(Component src, Point p) {
    JPopupMenu menu = new JPopupMenu();
    ButtonGroup group = new ButtonGroup();
    JCheckBoxMenuItem item = createMenuItem(SHOW_ALL);
    group.add(item);
    menu.add(item);
    item = createMenuItem(ADDED_BY_ME);
    group.add(item);
    menu.add(item);
    item = createMenuItem(ADDED_BY_OTHERS);
    group.add(item);
    menu.add(item);
    menu.show(src, p.x, p.y);
}