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

private void setControlDefaults() {

    pmdp_ = new PlateMapDrawPanel(this);
    sap_ = SeqAcqProps.getInstance();/* w w  w .  j  a v a 2  s  .  c o  m*/
    plateMapBasePanel.setLayout(new BorderLayout());
    plateMapBasePanel.add(pmdp_, BorderLayout.CENTER);

    tableModel_ = new FOVTableModel(pp_);
    searchFOVtableModel_ = new FOVTableModel(pp_); //Not sure if this is the best way, but try it for now.
    tableModel_.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {

        }
    });

    fovTable_ = new JTable();
    fovTable_.setModel(tableModel_);
    fovTable_.setSurrendersFocusOnKeystroke(true);
    fovTable_.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    JScrollPane scroller = new javax.swing.JScrollPane(fovTable_);
    fovTable_.setPreferredScrollableViewportSize(new java.awt.Dimension(190, 130));
    fovTablePanel.setLayout(new BorderLayout());
    fovTablePanel.add(scroller, BorderLayout.CENTER);

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

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

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fovTable_.getSelectedRow();
            tableModel_.insertRow(r, new FOV("A1", pp_, 6000));
        }
    });
    JMenuItem goToFOVItem = new JMenuItem("Go to FOV");
    goToFOVItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int r = fovTable_.getSelectedRow();
            //                FOV fov = tableModel_.getData().get(r);
            xyzmi_.gotoFOV(tableModel_.getData().get(r));
            if (!zAsOffset_) {
                double zval = tableModel_.getData().get(r).getZ();
                xyzmi_.moveZAbsolute(zval);
            } else {
                // obviously, this isn't quite right - we want to get
                // the offset of the CURRENT FOV (perhaps from parent in 
                // later implementations?) and subtract from that of the 
                // NEWLY SELECTED FOV. 
                // TODO: fix for proper zAsOffset behaviour. 
                // Wait for move completion
                while (xyzmi_.isStageBusy()) {
                    System.out.println("Stage moving...");
                }
                ;

                if (parent_.checkifAFenabled()) {
                    // If we have gone to the FOV, and have AF, do AF
                    xyzmi_.customAutofocus(parent_.getAFOffset());
                } else {
                    // If we don't have AF, go to the 'good offset position'
                    xyzmi_.moveZAbsolute(parent_.getFixedAFDefault());
                }
                //Now do the relative shift
                xyzmi_.moveZRelative(tableModel_.getData().get(r).getZ());
                System.out.println("Z value" + tableModel_.getData().get(r).getZ());
            }
        }
    });

    popupMenu.add(addItem);
    popupMenu.add(deleteItem);
    popupMenu.add(goToFOVItem);

    fovTable_.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            //                System.out.println("pressed");
        }

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

                if (!source.isRowSelected(row)) {
                    source.changeSelection(row, column, false, false);
                }
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    //        fovTable_.setDefaultRenderer(FOV.class, new TableRenderer());
    setupInsertComboBox();
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

public void fileTableClicked(FileObjectTableModel fileObjectTableModel, JTableX<FileObject> table,
        MouseEvent e) {//from www .  j a  v a  2 s.c o  m
    int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint()));
    //int column = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint()));
    final Collection<FileObject> selectedFileObjects = table.getSelectedObjects();

    final FileObject f = fileObjectTableModel.getRowObjects().get(row);

    if (SwingUtilities.isRightMouseButton(e)) {
        JPopupMenu m = new JPopupMenu();
        {
            JMenuItem menuitem = new JMenuItem("ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFile(f);
                }
            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Ordner ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFolder(f);
                }
            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Herunterladen (ber SOAP)");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    downloadFiles(selectedFileObjects, DownloadMethod.WEBSERVICE);
                }

            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Herunterladen (ber WEBDAV)");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!syncService.getIliasSoapService().isWebdavAuthenticationActive()) {
                        syncService.getIliasSoapService().enableWebdavAuthentication(
                                mainFrame.getFieldLogin().getText(),
                                mainFrame.getFieldPassword().getPassword());
                    }
                    downloadFiles(selectedFileObjects, DownloadMethod.WEBDAV);
                }

            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("In Ilias ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openInIlias(f);
                }
            });
            m.add(menuitem);
        }
        {
            m.add(new JSeparator());
        }
        {
            JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem("Ignorieren");
            menuitem.setSelected(iliasProperties.getBlockedFiles().contains(f.getRefId()));
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    switchIgnoreState(selectedFileObjects);
                }
            });
            m.add(menuitem);
        }
        {
            m.add(new JSeparator());
        }
        {
            JMenuItem menuitem = new JMenuItem("Fehler anzeigen");
            menuitem.setEnabled(f.getException() != null);
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showError("Fehler bei " + f.getTargetFile().getAbsolutePath(), f.getException());
                }

            });
            m.add(menuitem);
        }
        m.show(table, e.getX(), e.getY());
    }

    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
        openFile(f);
    }
}

From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java

private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath,
        final XmlDomAdapterNode clickedItem, final JTree tree) {
    final Element clickedElement = (Element) clickedItem.node;
    // popup menu for list -> add
    final JPopupMenu popup = new JPopupMenu();
    //delete node
    final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE"));
    menuItemToDelete.addActionListener(new ActionListener() {
        @Override//  w  ww  .  java2s.  c om
        public void actionPerformed(ActionEvent actionEvent) {
            // find the order# of the child to delete
            final int index = clickedItem.getParent().index(clickedItem);

            Node oldChild = clickedElement.getParentNode().removeChild(clickedElement);
            if (index > -1) {
                validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild);
            }
        }
    });
    popup.add(menuItemToDelete);

    //Add node/value
    final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree();
    final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree);
    for (final XsdNode xsdChild : children) {
        final String xmlName = xsdChild.getLastNameOfPath();

        final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " "
                + xsdChild.getType().toString().toLowerCase() + ")");
        popup.add(menuItem);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                Document document = getModel().getValidationPolicy().getDocument();

                final Node newElement;
                if (xsdChild.getType() == XsdNodeType.TEXT) {
                    // TEXT element always appended (last child)
                    newElement = clickedElement.appendChild(document.createTextNode("VALUE"));
                } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) {
                    newElement = document.createAttributeNS(null, xmlName);
                    ((Attr) newElement).setValue("VALUE");
                    clickedElement.setAttributeNode((Attr) newElement);
                } else if (xsdChild.getType() == XsdNodeType.ELEMENT) {
                    final Element childToAdd = document
                            .createElementNS("http://dss.markt.ec.europa.eu/validation/diagnostic", xmlName);
                    // find the correct possition to add the child
                    // Get all allowed children
                    Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree);
                    boolean toAddSeen = false;
                    Element elementIsToAddBeforeThisOne = null;
                    for (final XsdNode allowed : childrenMap.keySet()) {
                        if (!toAddSeen && allowed == xsdChild) {
                            toAddSeen = true;
                            continue;
                        }
                        if (toAddSeen) {
                            final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS(
                                    "http://dss.markt.ec.europa.eu/validation/diagnostic",
                                    allowed.getLastNameOfPath());
                            if (elementsByTagNameNS.getLength() > 0) {
                                // we found an element that is supposed to be after the one to add
                                elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0);
                                break;
                            }
                        }
                    }

                    if (elementIsToAddBeforeThisOne != null) {
                        newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne);
                    } else {
                        newElement = clickedElement.appendChild(childToAdd);
                    }
                } else {
                    throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType());
                }

                document.normalizeDocument();

                int indexOfAddedItem = 0;
                final int childCount = clickedItem.childCount();
                for (int i = 0; i < childCount; i++) {
                    if (clickedItem.child(i).node == newElement) {
                        indexOfAddedItem = i;
                        break;
                    }
                }

                TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath,
                        new int[] { indexOfAddedItem }, new Object[] { newElement });
                validationPolicyTreeModel.fireTreeNodesInserted(event);
                tree.expandPath(selectedPath);

                //Update model
                getModel().getValidationPolicy().setXmlDom(new XmlDom(document));
            }
        });

    }
    popup.show(tree, mouseEvent.getX(), mouseEvent.getY());
}

From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java

private void nodeActionAdd(MouseEvent mouseEvent, final int selectedRow, final TreePath selectedPath,
        final XmlDomAdapterNode clickedItem, final JTree tree) {
    final Element clickedElement = (Element) clickedItem.node;
    // popup menu for list -> add
    final JPopupMenu popup = new JPopupMenu();
    //delete node
    final JMenuItem menuItemToDelete = new JMenuItem(ResourceUtils.getI18n("DELETE"));
    menuItemToDelete.addActionListener(new ActionListener() {
        @Override/*w  w w  . j ava  2s  .c  o  m*/
        public void actionPerformed(ActionEvent actionEvent) {
            // find the order# of the child to delete
            final int index = clickedItem.getParent().index(clickedItem);

            Node oldChild = clickedElement.getParentNode().removeChild(clickedElement);
            if (index > -1) {
                validationPolicyTreeModel.fireTreeNodesRemoved(selectedPath.getParentPath(), index, oldChild);
            }
        }
    });
    popup.add(menuItemToDelete);

    //Add node/value
    final Map<XsdNode, Object> xsdTree = validationPolicyTreeModel.getXsdTree();
    final List<XsdNode> children = getChildrenToAdd(clickedElement, xsdTree);
    for (final XsdNode xsdChild : children) {
        final String xmlName = xsdChild.getLastNameOfPath();

        final JMenuItem menuItem = new JMenuItem(ResourceUtils.getI18n("ADD") + " (" + xmlName + " "
                + xsdChild.getType().toString().toLowerCase() + ")");
        popup.add(menuItem);
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                Document document = getModel().getValidationPolicy().getDocument();

                final Node newElement;
                if (xsdChild.getType() == XsdNodeType.TEXT) {
                    // TEXT element always appended (last child)
                    newElement = clickedElement.appendChild(document.createTextNode("VALUE"));
                } else if (xsdChild.getType() == XsdNodeType.ATTRIBUTE) {
                    newElement = document.createAttributeNS(null, xmlName);
                    ((Attr) newElement).setValue("VALUE");
                    clickedElement.setAttributeNode((Attr) newElement);
                } else if (xsdChild.getType() == XsdNodeType.ELEMENT) {
                    final Element childToAdd = document
                            .createElementNS("http://dss.esig.europa.eu/validation/diagnostic", xmlName);
                    // find the correct possition to add the child
                    // Get all allowed children
                    Map<XsdNode, Object> childrenMap = getChild(getXPath(clickedElement), xsdTree);
                    boolean toAddSeen = false;
                    Element elementIsToAddBeforeThisOne = null;
                    for (final XsdNode allowed : childrenMap.keySet()) {
                        if (!toAddSeen && (allowed == xsdChild)) {
                            toAddSeen = true;
                            continue;
                        }
                        if (toAddSeen) {
                            final NodeList elementsByTagNameNS = clickedElement.getElementsByTagNameNS(
                                    "http://dss.esig.europa.eu/validation/diagnostic",
                                    allowed.getLastNameOfPath());
                            if (elementsByTagNameNS.getLength() > 0) {
                                // we found an element that is supposed to be after the one to add
                                elementIsToAddBeforeThisOne = (Element) elementsByTagNameNS.item(0);
                                break;
                            }
                        }
                    }

                    if (elementIsToAddBeforeThisOne != null) {
                        newElement = clickedElement.insertBefore(childToAdd, elementIsToAddBeforeThisOne);
                    } else {
                        newElement = clickedElement.appendChild(childToAdd);
                    }
                } else {
                    throw new IllegalArgumentException("Unknow XsdNode NodeType " + xsdChild.getType());
                }

                document.normalizeDocument();

                int indexOfAddedItem = 0;
                final int childCount = clickedItem.childCount();
                for (int i = 0; i < childCount; i++) {
                    if (clickedItem.child(i).node == newElement) {
                        indexOfAddedItem = i;
                        break;
                    }
                }

                TreeModelEvent event = new TreeModelEvent(validationPolicyTreeModel, selectedPath,
                        new int[] { indexOfAddedItem }, new Object[] { newElement });
                validationPolicyTreeModel.fireTreeNodesInserted(event);
                tree.expandPath(selectedPath);

                //Update model
                getModel().getValidationPolicy().setXmlDom(new XmlDom(document));
            }
        });

    }
    popup.show(tree, mouseEvent.getX(), mouseEvent.getY());
}

From source file:maltcms.ui.fileHandles.csv.CSVTableView.java

private void createAndShowPopupMenu(MouseEvent me) {
    if (me.getButton() == MouseEvent.BUTTON3 && this.jTable1.getSelectedRowCount() > 0 && this.jfctc != null) {

        JPopupMenu jpm = new JPopupMenu();

        //more than one column selected
        if (jTable1.getSelectedColumnCount() > 0) {
            jpm.add(new AbstractAction("Add as y-values") {

                @Override//from www.  j  ava2s  .c  o m
                public void actionPerformed(ActionEvent ae) {
                    for (int col : jTable1.getSelectedColumns()) {
                        columnsToPlot.add(col);
                        jTable1.getColumnModel().getColumn(col).setCellRenderer(new ColorColumnRenderer(
                                new Color(238, 187, 0, 255), jTable1.getSelectedRows()));
                    }
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
            //selected rows
            for (final int col : jTable1.getSelectedColumns()) {
                if (columnsToPlot.contains(col)) {
                    jpm.add(new AbstractAction("Remove y-values from chart") {

                        @Override
                        public void actionPerformed(ActionEvent ae) {
                            jTable1.getColumnModel().getColumn(col).setCellRenderer(
                                    new ColorColumnRenderer(Color.WHITE, jTable1.getSelectedRows()));
                            columnsToPlot.remove(col);
                            jfctc.setChart(buildChart(labelColumn, domainColumn, columnsToPlot,
                                    jTable1.getSelectedRows()));
                        }
                    });
                    break;
                }
            }
            jpm.add(new JPopupMenu.Separator());
            jpm.add(new AbstractAction("Log10 transform") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    final int[] cols = jTable1.getSelectedColumns();
                    for (int i = 0; i < jTable1.getSelectedColumnCount(); i++) {
                        logTransformColumn(cols[i], 10.0d);
                    }

                }
            });
            jpm.add(new AbstractAction("Inverse Log10 transform") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    final int[] cols = jTable1.getSelectedColumns();
                    for (int i = 0; i < jTable1.getSelectedColumnCount(); i++) {
                        inverseLogTransformColumn(cols[i], 10.0d);
                    }

                }
            });
        }
        jpm.add(new JPopupMenu.Separator());
        //exactly one selected column, no domain column
        if (jTable1.getSelectedColumnCount() == 1 && domainColumn == -1) {
            jpm.add(new AbstractAction("Set as x-values") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    domainColumn = jTable1.getSelectedColumn();
                    jTable1.getColumnModel().getColumn(domainColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 0, 0, 255), jTable1.getSelectedRows()));
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });

        }
        //one domainColumn
        if (domainColumn != -1) {
            jpm.add(new AbstractAction("Reset x-axis values") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    jTable1.getColumnModel().getColumn(domainColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 255, 255, 255), jTable1.getSelectedRows()));
                    domainColumn = -1;
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
        }
        jpm.add(new JPopupMenu.Separator());
        if (jTable1.getSelectedColumnCount() == 1 && labelColumn == -1) {
            jpm.add(new AbstractAction("Set as series labels") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    labelColumn = jTable1.getSelectedColumn();
                    jTable1.getColumnModel().getColumn(labelColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 255, 0, 255), jTable1.getSelectedRows()));
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
        }

        if (jTable1.getSelectedColumnCount() == 1 && labelColumn != -1) {
            jpm.add(new AbstractAction("Reset series labels") {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    jTable1.getColumnModel().getColumn(labelColumn).setCellRenderer(
                            new ColorColumnRenderer(new Color(255, 255, 255, 255), jTable1.getSelectedRows()));
                    labelColumn = -1;
                    jfctc.setChart(
                            buildChart(labelColumn, domainColumn, columnsToPlot, jTable1.getSelectedRows()));
                }
            });
        }

        jpm.show(me.getComponent(), me.getX(), me.getY());
    }
}

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_node.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<Node> rowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<Node> selectedNodes = (List<Node>) (List<?>) getSelectedElements().getFirst();
    if (!selectedNodes.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this node traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this node traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override//from w w w  .j av a  2  s  .  c om
            public void actionPerformed(ActionEvent e) {
                if (selectedNodes.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedNodes.get(0),
                        callback.getDesign().getNetworkLayerDefault(), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedNodes.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedNodes.get(0),
                        callback.getDesign().getNetworkLayerDefault(), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!rowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);
                removeItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            callback.getDesign().getNodeFromId((long) itemId).remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ErrorHandling.addErrorOrException(ex, getClass());
                            ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                        }
                    }
                });

                popup.add(removeItem);
                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in the table");

            removeItems.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    NetPlan netPlan = callback.getDesign();

                    try {
                        if (rf == null)
                            netPlan.removeAllNodes();
                        else
                            for (Node n : rowsInTheTable)
                                n.remove();
                        callback.getVisualizationState()
                                .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                        callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        ErrorHandling.showErrorDialog(ex.getMessage(),
                                "Unable to remove all " + networkElementType + "s");
                    }
                }
            });

            popup.add(removeItems);

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

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

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

/**
 * Shows Parent Form's Context Menu.//from w  w  w.  java 2s . c  o m
 * @param e the mouse event
 */
protected void showContextMenu(MouseEvent e) {
    if (e.isPopupTrigger() && mvParent != null && mvParent.isTopLevel() && isEditing) {
        JPopupMenu popup = new JPopupMenu();
        JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("CONFIG_CARRY_FORWARD_MENU"));
        menuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ex) {
                configureCarryForward();
            }
        });
        popup.add(menuItem);

        JCheckBoxMenuItem chkMI = new JCheckBoxMenuItem(
                UIRegistry.getResourceString("CARRY_FORWARD_CHECKED_MENU"));
        chkMI.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ex) {
                toggleCarryForward();
            }
        });
        chkMI.setSelected(isCarryForwardConfgured() && isDoCarryForward());
        chkMI.setEnabled(isCarryForwardConfgured());
        popup.add(chkMI);

        popup.addSeparator();
        chkMI = new JCheckBoxMenuItem(UIRegistry.getAction(AUTO_NUM));
        /*chkMI.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ex)
        {
            toggleAutoNumberOnOffState();
        }
        });*/
        chkMI.setSelected(isAutoNumberOn);
        popup.add(chkMI);

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

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_demand.java

public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();

    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<Demand> demandRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<Demand> selectedDemands = (List<Demand>) (List<?>) getSelectedElements().getFirst();
    if (!selectedDemands.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this demand traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this demand traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override/*  ww  w. j a v  a2s . co  m*/
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!demandRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                removeItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();

                        try {
                            final Demand demand = netPlan.getDemandFromId((long) itemId);
                            demand.remove();
                            callback.getVisualizationState().resetPickedState();
                            callback.updateVisualizationAfterChanges(
                                    Collections.singleton(NetworkElementType.DEMAND));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ErrorHandling.addErrorOrException(ex, getClass());
                            ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                        }
                    }
                });

                popup.add(removeItem);

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }

            JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in the table");
            removeItems.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    NetPlan netPlan = callback.getDesign();

                    try {
                        if (rf == null)
                            netPlan.removeAllDemands();
                        else
                            for (Demand d : demandRowsInTheTable)
                                d.remove();

                        callback.getVisualizationState().resetPickedState();
                        callback.updateVisualizationAfterChanges(
                                Collections.singleton(NetworkElementType.DEMAND));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        ErrorHandling.showErrorDialog(ex.getMessage(),
                                "Unable to remove all " + networkElementType + "s");
                    }
                }
            });

            popup.add(removeItems);

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

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

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<Link> linkRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<Link> selectedLinks = (List<Link>) (List<?>) getSelectedElements().getFirst();
    if (!selectedLinks.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this link traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this link traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override// w w  w .  ja  v  a 2 s.  c  om
            public void actionPerformed(ActionEvent e) {
                if (selectedLinks.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedLinks.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedLinks.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedLinks.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!linkRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);
                removeItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();

                        try {
                            Link link = netPlan.getLinkFromId((long) itemId);
                            link.remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ErrorHandling.addErrorOrException(ex, getClass());
                            ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                        }
                    }
                });

                popup.add(removeItem);
            }

            addPopupMenuAttributeOptions(e, row, itemId, popup);

            JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in table");

            removeItems.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    NetPlan netPlan = callback.getDesign();

                    try {
                        if (rf == null)
                            netPlan.removeAllLinks();
                        else
                            for (Link ee : linkRowsInTheTable)
                                ee.remove();
                        callback.getVisualizationState()
                                .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                        callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    } catch (Throwable ex) {
                        ex.printStackTrace();
                        ErrorHandling.showErrorDialog(ex.getMessage(),
                                "Unable to remove all " + networkElementType + "s");
                    }
                }
            });

            popup.add(removeItems);

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

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

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java

@Override
public void doPopup(final MouseEvent e, final int row, final Object itemId) {
    JPopupMenu popup = new JPopupMenu();
    final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter();
    final List<MulticastDemand> demandRowsInTheTable = getVisibleElementsInTable();

    /* Add the popup menu option of the filters */
    final List<MulticastDemand> selectedDemands = (List<MulticastDemand>) (List<?>) getSelectedElements()
            .getFirst();/*from   ww w .  j a v  a 2  s .co  m*/
    if (!selectedDemands.isEmpty()) {
        final JMenu submenuFilters = new JMenu("Filters");
        final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem(
                "This layer: Keep elements associated to this demand traffic");
        final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem(
                "All layers: Keep elements associated to this demand traffic");
        submenuFilters.add(filterKeepElementsAffectedThisLayer);
        if (callback.getDesign().getNumberOfLayers() > 1)
            submenuFilters.add(filterKeepElementsAffectedAllLayers);
        filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), true);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (selectedDemands.size() > 1)
                    throw new RuntimeException();
                TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedDemands.get(0), false);
                callback.getVisualizationState().updateTableRowFilter(filter);
                callback.updateVisualizationJustTables();
            }
        });
        popup.add(submenuFilters);
        popup.addSeparator();
    }

    if (callback.getVisualizationState().isNetPlanEditable()) {
        popup.add(getAddOption());
        for (JComponent item : getExtraAddOptions())
            popup.add(item);
    }

    if (!demandRowsInTheTable.isEmpty()) {
        if (callback.getVisualizationState().isNetPlanEditable()) {
            if (row != -1) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();

                if (networkElementType == NetworkElementType.LAYER
                        && callback.getDesign().getNumberOfLayers() == 1) {

                } else {
                    JMenuItem removeItem = new JMenuItem("Remove " + networkElementType);

                    removeItem.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            NetPlan netPlan = callback.getDesign();

                            try {
                                netPlan.getMulticastDemandFromId((long) itemId).remove();
                                callback.getVisualizationState()
                                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                                callback.updateVisualizationAfterChanges(
                                        Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                            } catch (Throwable ex) {
                                ErrorHandling.addErrorOrException(ex, getClass());
                                ErrorHandling.showErrorDialog("Unable to remove " + networkElementType);
                            }
                        }
                    });

                    popup.add(removeItem);
                }

                addPopupMenuAttributeOptions(e, row, itemId, popup);
            }
            if (networkElementType != NetworkElementType.LAYER) {
                JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in table");

                removeItems.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        NetPlan netPlan = callback.getDesign();
                        try {
                            if (rf == null)
                                netPlan.removeAllMulticastDemands();
                            else
                                for (MulticastDemand d : demandRowsInTheTable)
                                    d.remove();
                            callback.getVisualizationState()
                                    .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                            callback.updateVisualizationAfterChanges(
                                    Collections.singleton(NetworkElementType.MULTICAST_DEMAND));
                            callback.getUndoRedoNavigationManager().addNetPlanChange();
                        } catch (Throwable ex) {
                            ex.printStackTrace();
                            ErrorHandling.showErrorDialog(ex.getMessage(),
                                    "Unable to remove all " + networkElementType + "s");
                        }
                    }
                });
                popup.add(removeItems);
            }

            List<JComponent> extraOptions = getExtraOptions(row, itemId);
            if (!extraOptions.isEmpty()) {
                if (popup.getSubElements().length > 0)
                    popup.addSeparator();
                for (JComponent item : extraOptions)
                    popup.add(item);
            }
        }

        List<JComponent> forcedOptions = getForcedOptions();
        if (!forcedOptions.isEmpty()) {
            if (popup.getSubElements().length > 0)
                popup.addSeparator();
            for (JComponent item : forcedOptions)
                popup.add(item);
        }
    }

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