Example usage for javax.swing.event PopupMenuListener PopupMenuListener

List of usage examples for javax.swing.event PopupMenuListener PopupMenuListener

Introduction

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

Prototype

PopupMenuListener

Source Link

Usage

From source file:cz.muni.fi.javaseminar.kafa.bookregister.gui.MainWindow.java

private void initAuthorsTable() {
    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override/* w  ww  .j av a 2 s.c o  m*/
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    authorsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    ListSelectionModel selectionModel = authorsTable.getSelectionModel();
    selectionModel.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            DefaultListSelectionModel source = (DefaultListSelectionModel) e.getSource();
            if (source.getMinSelectionIndex() >= 0) {
                authorsTableModel.setCurrentSlectedIndex(source.getMinSelectionIndex());
            }

            if (!e.getValueIsAdjusting()) {
                booksTableModel.setAuthorIndex(source.getMinSelectionIndex());
            }

        }
    });

    authorsTable.getColumnModel().getColumn(2)
            .setCellEditor(new DatePickerCellEditor(new SimpleDateFormat("dd. MM. yyyy")));
    authorsTable.getColumnModel().getColumn(2).setCellRenderer(new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable jtable, Object value, boolean selected,
                boolean hasFocus, int row, int column) {

            if (value instanceof Date) {

                // You could use SimpleDateFormatter instead
                value = new SimpleDateFormat("dd. MM. yyyy").format(value);

            }

            return super.getTableCellRendererComponent(jtable, value, selected, hasFocus, row, column);

        }
    });

    JPopupMenu authorsPopupMenu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");

    authorsPopupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    int rowAtPoint = authorsTable.rowAtPoint(
                            SwingUtilities.convertPoint(authorsPopupMenu, new Point(0, 0), authorsTable));
                    if (rowAtPoint > -1) {
                        authorsTable.setRowSelectionInterval(rowAtPoint, rowAtPoint);
                        authorsTableModel.setCurrentSlectedIndex(rowAtPoint);
                    }
                }
            });
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    deleteItem.addActionListener(new ActionListener() {
        private Author author;

        @Override
        public void actionPerformed(ActionEvent e) {
            new SwingWorker<Void, Void>() {

                @Override
                protected Void doInBackground() throws Exception {
                    author = authorsTableModel.getAuthors().get(authorsTable.getSelectedRow());
                    log.debug("Deleting author: " + author.getFirstname() + " " + author.getSurname()
                            + " from database.");
                    authorManager.deleteAuthor(author);

                    return null;
                }

                @Override
                protected void done() {
                    try {
                        get();
                    } catch (InterruptedException | ExecutionException e) {
                        if (e.getCause() instanceof DataIntegrityViolationException) {
                            JOptionPane.showMessageDialog(MainWindow.this,
                                    "Couldn't delete author; there are still some books assigned to him.",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                        log.error("There was an exception thrown during deletion author: "
                                + author.getFirstname() + " " + author.getSurname(), e);

                        return;
                    }

                    updateModel();
                }
            }.execute();
        }
    });
    authorsPopupMenu.add(deleteItem);
    authorsTable.setComponentPopupMenu(authorsPopupMenu);
}

From source file:es.emergya.ui.gis.FleetControlMapViewer.java

@Override
protected JPopupMenu getContextMenu() {
    JPopupMenu menu = new JPopupMenu();

    menu.setBackground(Color.decode("#E8EDF6"));

    // Ttulo/*from   ww w .j av  a 2 s  .  co m*/
    final JMenuItem titulo = new JMenuItem(i18n.getString("map.menu.titulo.puntoGenerico"));
    titulo.setFont(LogicConstants.deriveBoldFont(10.0f));
    titulo.setBackground(Color.decode("#A4A4A4"));
    titulo.setFocusable(false);

    menu.add(titulo);

    menu.addSeparator();

    // Actualizar posicin
    final JMenuItem gps = new JMenuItem(i18n.getString("map.menu.gps"), KeyEvent.VK_P);
    gps.setIcon(LogicConstants.getIcon("menucontextual_icon_actualizargps"));
    menu.add(gps);
    gps.addActionListener(this);
    gps.setEnabled(false);

    menu.addSeparator();

    // Mostrar ms cercanos
    final JMenuItem mmc = new JMenuItem(i18n.getString("map.menu.showNearest"), KeyEvent.VK_M);
    mmc.setIcon(LogicConstants.getIcon("menucontextual_icon_mascercano"));
    mmc.addActionListener(this);
    menu.add(mmc);
    // Centrar aqui
    final JMenuItem cent = new JMenuItem(i18n.getString("map.menu.centerHere"), KeyEvent.VK_C);
    cent.setIcon(LogicConstants.getIcon("menucontextual_icon_centrar"));
    cent.addActionListener(this);
    menu.add(cent);
    // Nueva Incidencia
    final JMenuItem newIncidence = new JMenuItem(i18n.getString("map.menu.newIncidence"), KeyEvent.VK_I);
    newIncidence.setIcon(LogicConstants.getIcon("menucontextual_icon_newIncidence"));
    newIncidence.addActionListener(this);
    menu.add(newIncidence);
    // Calcular ruta desde aqui
    final JMenuItem from = new JMenuItem(i18n.getString("map.menu.route.from"), KeyEvent.VK_D);
    from.setIcon(LogicConstants.getIcon("menucontextual_icon_origenruta"));
    from.addActionListener(this);
    menu.add(from);
    // Calcular ruta hasta aqui
    final JMenuItem to = new JMenuItem(i18n.getString("map.menu.route.to"), KeyEvent.VK_H);
    to.setIcon(LogicConstants.getIcon("menucontextual_icon_destinoruta"));
    to.addActionListener(this);
    menu.add(to);

    menu.addSeparator();

    // Ver ficha [recurso / incidencia]
    final JMenuItem summary = new JMenuItem(i18n.getString("map.menu.summary"), KeyEvent.VK_F);
    summary.setIcon(LogicConstants.getIcon("menucontextual_icon_ficha"));
    summary.addActionListener(this);
    menu.add(summary);
    summary.setEnabled(false);

    menu.addPopupMenuListener(new PopupMenuListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            eventOriginal = FleetControlMapViewer.this.mapView.lastMEvent;
            gps.setEnabled(false);
            summary.setEnabled(false);
            titulo.setText(i18n.getString("map.menu.titulo.puntoGenerico"));
            menuObjective = null;
            Point p = new Point(mapView.lastMEvent.getX(), mapView.lastMEvent.getY());
            for (Layer l : mapView.getAllLayers()) { // por cada capa...
                if (l instanceof MarkerLayer) { // ...de marcadores
                    for (Marker marker : ((MarkerLayer) l).data) { // miramos
                        // los
                        // marcadores
                        if ((marker instanceof CustomMarker) && marker.containsPoint(p)) { // y si
                            // estamos
                            // pinchando
                            // en uno
                            CustomMarker m = (CustomMarker) marker;
                            log.trace("Hemos pinchado en " + marker);

                            switch (m.getType()) {
                            case RESOURCE:
                                Recurso r = (Recurso) m.getObject();
                                log.trace("Es un recurso: " + r);
                                if (r != null) {
                                    menuObjective = r;
                                    if (r.getPatrullas() != null) {
                                        titulo.setText(
                                                i18n.getString(Locale.ROOT, "map.menu.titulo.recursoPatrulla",
                                                        r.getIdentificador(), r.getPatrullas()));
                                    } else {
                                        titulo.setText(r.getIdentificador());
                                    }
                                    gps.setEnabled(true);
                                    summary.setEnabled(true);
                                }
                                break;
                            case INCIDENCE:
                                Incidencia i = (Incidencia) m.getObject();
                                log.trace("Es una incidencia: " + i);
                                if (i != null) {
                                    menuObjective = i;
                                    titulo.setText(i.getTitulo());
                                    gps.setEnabled(false);
                                    summary.setEnabled(true);
                                }
                                break;
                            case UNKNOWN:
                                log.trace("Hemos pinchado en un marcador desconocido");
                                break;
                            }

                        }
                    }
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
        }
    });

    return menu;
}

From source file:edu.ku.brc.af.ui.db.TextFieldWithQuery.java

/**
 *
 * @param advanceFocus//from   w w w .jav  a  2  s.co  m
 */
protected void showPopup(final int advanceFocus) {
    final Vector<Integer> idListClosure = (Vector<Integer>) idList.clone();
    if (!isEnabled()) {
        return;
    }

    if (hasNewText || currentText.length() == 0) {
        ActionListener al = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                itemSelected((JMenuItem) e.getSource(), advanceFocus, idListClosure);
            }
        };

        popupMenu = new JPopupMenu();
        if (popupMenuListener != null) {
            popupMenu.addPopupMenuListener(popupMenuListener);
        }

        popupMenu.addPopupMenuListener(new PopupMenuListener() {
            public void popupMenuCanceled(PopupMenuEvent e) {
                isPopupShowing = false;

                cachedPrevText = null;

                if (selectedId == null) {
                    setText(""); //$NON-NLS-1$
                }
            }

            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                isPopupShowing = false;

                cachedPrevText = prevEnteredText;

                if (selectedId == null) {
                    setText(""); //$NON-NLS-1$
                }
                //textField.requestFocus();
            }

            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                cachedPrevText = null;
                isPopupShowing = true;
            }
        });

        if (doAddAddItem) {
            JMenuItem mi = new JMenuItem(UIRegistry.getResourceString("TFWQ_ADD_LABEL")); //$NON-NLS-1$
            setControlSize(mi);

            popupMenu.add(mi);
            mi.addActionListener(al);
        }

        for (String str : list) {
            String label = str;
            if (uiFieldFormatter != null) {
                label = uiFieldFormatter.formatToUI(label).toString();
            }
            JMenuItem mi = new JMenuItem(label);
            setControlSize(mi);

            popupMenu.add(mi);
            mi.addActionListener(al);
        }
    }

    if (popupMenu != null) {
        if (list.size() > 0 || doAddAddItem) {
            UIHelper.addSpecialKeyListenerForPopup(popupMenu);

            final Point location = getLocation();
            final Dimension size = getSize();

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    popupMenu.setInvoker(TextFieldWithQuery.this);
                    popupMenu.show(TextFieldWithQuery.this, location.x, location.y + size.height);
                    Dimension popupSize = popupMenu.getPreferredSize();
                    popupMenu.setPopupSize(Math.max(size.width, popupSize.width), popupSize.height);
                    popupMenu.requestFocus();
                }
            });
        } else {
            popupMenu = null;
        }
    }

}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private void definePopup() {
    // These key bindings are just to have the shortcuts displayed
    // in the popup menu. The actual keystroke processing is in
    // BasePanel (entryTable.addKeyListener(...)).
    groupsContextMenu.add(editGroupPopupAction);
    groupsContextMenu.add(addGroupPopupAction);
    groupsContextMenu.add(addSubgroupPopupAction);
    groupsContextMenu.addSeparator();//from   w  w w.j a  va2  s .  co m
    groupsContextMenu.add(removeGroupAndSubgroupsPopupAction);
    groupsContextMenu.add(removeGroupKeepSubgroupsPopupAction);
    groupsContextMenu.add(removeSubgroupsPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(expandSubtreePopupAction);
    groupsContextMenu.add(collapseSubtreePopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(moveSubmenu);
    sortSubmenu.add(sortDirectSubgroupsPopupAction);
    sortSubmenu.add(sortAllSubgroupsPopupAction);
    groupsContextMenu.add(sortSubmenu);
    moveSubmenu.add(moveNodeUpPopupAction);
    moveSubmenu.add(moveNodeDownPopupAction);
    moveSubmenu.add(moveNodeLeftPopupAction);
    moveSubmenu.add(moveNodeRightPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(addToGroup);
    groupsContextMenu.add(moveToGroup);
    groupsContextMenu.add(removeFromGroup);
    groupsTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (path == null) {
                return;
            }
            GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent();
            // the root node is "AllEntries" and cannot be edited
            if (node.getNode().isRoot()) {
                return;
            }
            if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { // edit
                editGroupAction.actionPerformed(null); // dummy event
            } else if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
                annotationEvent(node);
            }
        }
    });
    // be sure to remove a possible border highlight when the popup menu
    // disappears
    groupsContextMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            // nothing to do
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }
    });
}

From source file:net.sf.jabref.groups.GroupSelector.java

private void definePopup() {
    // These key bindings are just to have the shortcuts displayed
    // in the popup menu. The actual keystroke processing is in
    // BasePanel (entryTable.addKeyListener(...)).
    groupsContextMenu.add(editGroupPopupAction);
    groupsContextMenu.add(addGroupPopupAction);
    groupsContextMenu.add(addSubgroupPopupAction);
    groupsContextMenu.addSeparator();//from  w ww .  j  ava 2s . c om
    groupsContextMenu.add(removeGroupAndSubgroupsPopupAction);
    groupsContextMenu.add(removeGroupKeepSubgroupsPopupAction);
    groupsContextMenu.add(removeSubgroupsPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(expandSubtreePopupAction);
    groupsContextMenu.add(collapseSubtreePopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(moveSubmenu);
    sortSubmenu.add(sortDirectSubgroupsPopupAction);
    sortSubmenu.add(sortAllSubgroupsPopupAction);
    groupsContextMenu.add(sortSubmenu);
    moveSubmenu.add(moveNodeUpPopupAction);
    moveSubmenu.add(moveNodeDownPopupAction);
    moveSubmenu.add(moveNodeLeftPopupAction);
    moveSubmenu.add(moveNodeRightPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(addToGroup);
    groupsContextMenu.add(moveToGroup);
    groupsContextMenu.add(removeFromGroup);
    groupsTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (path == null) {
                return;
            }
            GroupTreeNode node = (GroupTreeNode) path.getLastPathComponent();
            // the root node is "AllEntries" and cannot be edited
            if (node.isRoot()) {
                return;
            }
            if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { // edit
                editGroupAction.actionPerformed(null); // dummy event
            } else if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
                annotationEvent(node);
            }
        }
    });
    // be sure to remove a possible border highlight when the popup menu
    // disappears
    groupsContextMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            // nothing to do
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }
    });
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 * @return/*from w w w  .j a va  2s  .  c o  m*/
 */
private JPanel createSchemeComboBoxPanel() {
    JPanel schemeListPanel = new JPanel(new GridBagLayout());

    // create categories configuration panel
    {

        GridBagConstraints itemConstraint = new GridBagConstraints();

        // Add active scheme label
        JLabel actviceSchemeLabel = new ResourceLabel(
                "plotter.configuration_dialog.color_scheme_dialog.active_scheme");
        {
            itemConstraint.fill = GridBagConstraints.HORIZONTAL;
            itemConstraint.anchor = GridBagConstraints.WEST;
            itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
            itemConstraint.insets = new Insets(0, 5, 5, 5);
            itemConstraint.weightx = 1.0;

            actviceSchemeLabel.setBackground(Color.red);

            schemeListPanel.add(actviceSchemeLabel, itemConstraint);
        }

        // add button panel
        {
            JPanel buttonPanel = new JPanel(new GridBagLayout());

            // rename scheme button
            {
                renameSchemeButton = new JButton(new ResourceAction(true,
                        "plotter.configuration_dialog.color_scheme_dialog.rename_scheme_button") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String newName = createNameDialog(currentActiveColorSchemeName);
                        if (newName != null && !newName.equals(currentActiveColorSchemeName)) {
                            renameColorSchemeAction(newName);
                        }
                    }

                });

                itemConstraint = new GridBagConstraints();
                itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
                itemConstraint.fill = GridBagConstraints.NONE;

                buttonPanel.add(renameSchemeButton, itemConstraint);
            }

            // remove scheme button
            {
                removeSchemeButton = new JButton(new ResourceAction(true,
                        "plotter.configuration_dialog.color_scheme_dialog.remove_scheme_button") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        ConfirmDialog dialog = new ConfirmDialog(
                                SwingUtilities.getWindowAncestor((Component) e.getSource()),
                                "plotter.configuration_dialog.confirm_color_scheme_delete",
                                ConfirmDialog.YES_NO_OPTION, false);
                        dialog.setLocationRelativeTo((Component) e.getSource());
                        dialog.setVisible(true);
                        if (dialog.getReturnOption() == ConfirmDialog.YES_OPTION) {
                            removeColorSchemeAction((ColorScheme) colorSchemeComboBox.getSelectedItem());
                        }
                    }

                });

                itemConstraint = new GridBagConstraints();
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.fill = GridBagConstraints.NONE;

                buttonPanel.add(removeSchemeButton, itemConstraint);
            }

            itemConstraint = new GridBagConstraints();
            itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
            itemConstraint.fill = GridBagConstraints.NONE;
            itemConstraint.anchor = GridBagConstraints.EAST;
            itemConstraint.insets = new Insets(0, 5, 5, 5);

            schemeListPanel.add(buttonPanel, itemConstraint);

        }

        {

            colorSchemeComboBox = new JComboBox(colorSchemeComboBoxModel);
            actviceSchemeLabel.setLabelFor(colorSchemeComboBox);
            colorSchemeComboBox.setRenderer(new ColorSchemeComboBoxRenderer());
            colorSchemeComboBox.addPopupMenuListener(new PopupMenuListener() {

                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                    return;

                }

                @Override
                public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    Object selectedValue = colorSchemeComboBox.getSelectedItem();
                    if (selectedValue instanceof ColorScheme) {
                        ColorScheme selection = (ColorScheme) selectedValue;
                        if (selection != null) {
                            if (!currentActiveColorSchemeName.equals(selection.getName())) {
                                currentActiveColorSchemeName = selection.getName();
                                adaptModels();
                            }
                        }
                    } else {
                        String newName = I18N.getGUILabel("plotter.new_color_scheme_name.label");
                        String suffix = "";
                        int counter = 1;
                        while (currentColorSchemes.get(newName + suffix) != null) {
                            suffix = "_" + counter;
                            counter++;
                        }
                        newName += suffix;
                        String userSelectedName = createNameDialog(newName);
                        if (userSelectedName == null) {
                            colorSchemeComboBox.setSelectedItem(getCurrentActiveColorScheme());
                            return;
                        }
                        addNewColorSchemeAction(userSelectedName);
                    }
                }

                @Override
                public void popupMenuCanceled(PopupMenuEvent e) {
                    return;
                }
            });

            itemConstraint = new GridBagConstraints();
            itemConstraint.fill = GridBagConstraints.BOTH;
            itemConstraint.weightx = 0.0;
            itemConstraint.weighty = 0.0;
            itemConstraint.gridwidth = GridBagConstraints.REMAINDER;

            schemeListPanel.add(colorSchemeComboBox, itemConstraint);
        }

    }
    return schemeListPanel;
}

From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java

protected void processPopUp(final Point point, final AbstractElement elementUnderMouse) {
    if (this.controller != null) {
        final ElementPart partUnderMouse = elementUnderMouse == null ? null
                : elementUnderMouse.findPartForPoint(point);

        if (elementUnderMouse != null && !this.selectedTopics.contains(elementUnderMouse.getModel())) {
            this.selectedTopics.clear();
            this.select(elementUnderMouse.getModel(), false);
        }/*from  w ww .  j  a  va  2s  .co  m*/

        final JPopupMenu menu = this.controller.makePopUpForMindMapPanel(this, point, elementUnderMouse,
                partUnderMouse);
        if (menu != null) {

            final MindMapPanel theInstance = this;
            menu.addPopupMenuListener(new PopupMenuListener() {

                @Override
                public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
                    theInstance.mouseDragSelection = null;
                    theInstance.popupMenuActive = true;
                }

                @Override
                public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
                    theInstance.mouseDragSelection = null;
                    theInstance.popupMenuActive = false;
                }

                @Override
                public void popupMenuCanceled(final PopupMenuEvent e) {
                    theInstance.mouseDragSelection = null;
                    theInstance.popupMenuActive = false;
                }
            });

            menu.show(this, point.x, point.y);
        }
    }
}

From source file:org.broad.igv.track.TrackMenuUtils.java

/**
 * Return a popup menu with items applicable to the collection of tracks.
 *
 * @param tracks//  w  ww  .  ja  v a 2s  .  c  om
 * @return
 */
public static IGVPopupMenu getPopupMenu(final Collection<Track> tracks, String title, TrackClickEvent te) {

    if (log.isDebugEnabled()) {
        log.debug("enter getPopupMenu");
    }

    //JidePopupMenu menu = new JidePopupMenu();
    IGVPopupMenu menu = new IGVPopupMenu();

    JLabel popupTitle = new JLabel(LEADING_HEADING_SPACER + title, JLabel.CENTER);
    popupTitle.setFont(UIConstants.boldFont);
    if (popupTitle != null) {
        menu.add(popupTitle);
        menu.addSeparator();
    }

    addStandardItems(menu, tracks, te);

    menu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) {

        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent popupMenuEvent) {
            close();
        }

        public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) {
            close();
        }

        private void close() {
            IGV.getInstance().clearSelections();
            IGV.getInstance().repaint();
        }

    });

    return menu;

}

From source file:org.docear.plugin.core.CoreConfiguration.java

private void addMenus(ModeController modeController) {
    modeController.addAction(new DocearRemoveNodeLinkAction());
    if ("true".equals(System.getProperty("docear.debug", "false"))) {
        modeController.addAction(new DocearSetNodePrivacyAction());
    }/*from  w ww  .  ja va 2s  .  c  o m*/
    modeController.addMenuContributor(new IMenuContributor() {
        public void updateMenus(ModeController modeController, MenuBuilder builder) {
            //add entries to project menu
            final String MENU_PROJECT_KEY = "/menu_bar/project";
            builder.addSeparator(MENU_PROJECT_KEY, MenuBuilder.AS_CHILD);
            final AWorkspaceAction addAction = new DocearAddRepositoryPathAction();
            builder.addAction(MENU_PROJECT_KEY, addAction, MenuBuilder.AS_CHILD);
            final AWorkspaceAction removeAction = new DocearRemoveRepositoryPathAction();
            builder.addAction(MENU_PROJECT_KEY, removeAction, MenuBuilder.AS_CHILD);
            Object obj = builder.get(MENU_PROJECT_KEY).getUserObject();
            if (obj instanceof JMenu) {
                ((JMenu) obj).getPopupMenu().addPopupMenuListener(new PopupMenuListener() {
                    public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
                        addAction.setEnabled();
                        removeAction.setEnabled();
                    }

                    public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
                    }

                    public void popupMenuCanceled(PopupMenuEvent e) {
                    }
                });
            }

            //add entries to
            builder.addAction("/menu_bar/help", new DocearShowTermsOfUseAction(), MenuBuilder.AS_CHILD);
            builder.addAction("/menu_bar/help", new DocearShowDataPrivacyStatementAction(),
                    MenuBuilder.AS_CHILD);
            builder.addAction("/menu_bar/help", new DocearShowDataProcessingTermsAction(),
                    MenuBuilder.AS_CHILD);
            //builder.addAction("/menu_bar/help", new DocearShowNotificationBar(),   MenuBuilder.AS_CHILD);

            //add node privacy actions
            if ("true".equals(System.getProperty("docear.debug", "false"))) {
                builder.addSeparator("/menu_bar/edit", MenuBuilder.AS_CHILD);
                builder.addAction("/menu_bar/edit", new DocearSetNodePrivacyAction(), MenuBuilder.AS_CHILD);
                builder.addSeparator("/node_popup", MenuBuilder.AS_CHILD);
                builder.addAction("/node_popup", new DocearSetNodePrivacyAction(), MenuBuilder.AS_CHILD);

            }
            String key = (String) builder.getKeyByUserObject(
                    WorkspaceController.getAction(modeController, "ExtractLinkFromTextAction"));
            if (key != null) {
                builder.addAction(key,
                        WorkspaceController.getAction(modeController, DocearRemoveNodeLinkAction.KEY),
                        MenuBuilder.AFTER);
            } else {
                builder.addSeparator("popup_navigate", MenuBuilder.AS_CHILD);
                builder.addAction("popup_navigate",
                        WorkspaceController.getAction(modeController, DocearRemoveNodeLinkAction.KEY),
                        MenuBuilder.AS_CHILD);
            }

        }
    });
    File file = new File(Compat.getApplicationUserDirectory(), "docear_core_ribbon.xml");
    if (file.exists()) {
        LogUtils.info("using alternative ribbon configuration file: " + file.getAbsolutePath());
        try {
            modeController.getUserInputListenerFactory().getRibbonBuilder().updateRibbon(file.toURI().toURL());
        } catch (MalformedURLException e) {
            LogUtils.severe("MModeControllerFactory.createStandardControllers(): " + e.getMessage());
        }
    } else {
        modeController.getUserInputListenerFactory().getRibbonBuilder().registerContributorFactory(
                "nodePrivacyActionContributor", new DocearNodePrivacyContributorFactory());
        modeController.getUserInputListenerFactory().getRibbonBuilder()
                .updateRibbon(DocearController.class.getResource("/xml/ribbons.xml"));
    }

}

From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java

private QueryEditorAutoCompletePopupPanel popupMenu() {

    if (autoCompletePopup == null) {

        autoCompletePopup = new QueryEditorAutoCompletePopupPanel();
        autoCompletePopup.addAutoCompletePopupListener(this);

        autoCompletePopup.addPopupMenuListener(new PopupMenuListener() {

            public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {

                popupHidden();//w ww. j av  a 2 s  . com
            }

            public void popupMenuCanceled(PopupMenuEvent e) {

                popupHidden();
            }

            public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            }

        });

    }

    return autoCompletePopup;
}