Example usage for java.awt.event MouseEvent getX

List of usage examples for java.awt.event MouseEvent getX

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getX.

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

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  w w .ja va  2  s .  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.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//from w w  w  . j  av  a  2  s.  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.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   w ww  .  ja v  a 2  s  .co  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:base.BasePlayer.Main.java

@Override
public void mousePressed(MouseEvent event) {
    //if(Logo.frame.isVisible()) {
    //   frame.requestFocus();
    //   }/*from  w  ww .  j ava2s  . c o m*/
    //   Logo.frame.setVisible(false);
    mouseX = event.getX();

    if (event.getSource() == refDropdown) {
        switch (event.getModifiers()) {
        case InputEvent.BUTTON1_MASK: {
            if (Main.genomehash.size() == 0) {
                if (AddGenome.frame == null) {
                    AddGenome.createAndShowGUI();
                }
                AddGenome.frame.setTitle("Add new genome");
                AddGenome.annotation = false;
                AddGenome.remove.setEnabled(false);
                AddGenome.download.setEnabled(false);
                AddGenome.frame.setVisible(true);
                AddGenome.frame.setLocation(
                        frame.getLocationOnScreen().x + frame.getWidth() / 2 - AddGenome.frame.getWidth() / 2,
                        frame.getLocationOnScreen().y + frame.getHeight() / 6);

                AddGenome.frame.setState(JFrame.NORMAL);
            }
            rightclick = false;
            break;
        }
        case InputEvent.BUTTON3_MASK: {
            rightclick = true;
            break;
        }
        }
    } else if (event.getSource() == geneDropdown) {
        switch (event.getModifiers()) {
        case InputEvent.BUTTON1_MASK: {
            if (Main.genomehash.size() == 0) {
                if (AddGenome.frame == null) {
                    AddGenome.createAndShowGUI();
                }
                AddGenome.frame.setTitle("Add new genome");
                AddGenome.annotation = false;
                AddGenome.remove.setEnabled(false);
                AddGenome.download.setEnabled(false);
                AddGenome.frame.setVisible(true);
                AddGenome.frame.setLocation(
                        frame.getLocationOnScreen().x + frame.getWidth() / 2 - AddGenome.frame.getWidth() / 2,
                        frame.getLocationOnScreen().y + frame.getHeight() / 6);

                AddGenome.frame.setState(JFrame.NORMAL);
            }
            rightclick = false;
            break;
        }
        case InputEvent.BUTTON3_MASK: {
            rightclick = true;
            break;
        }
        }
    } else if (event.getSource() == chromlabel) {
        chromosomeDropdown.showPopup();

    }

    else if (event.getSource() == splitPaneDivider) {
        Main.vardivider = bedCanvas.nodeImage.getHeight() / (double) varPaneDivider.getY();

        //      Main.bedCanvas.resize = true;
    } else if (event.getSource() == varPaneDivider) {
        //      Main.bedCanvas.resize = true;         
        Main.vardivider = bedCanvas.nodeImage.getHeight() / (double) varPaneDivider.getY();

    } else if (event.getSource() == filemenu) {
        /*if(!filemenu.isSelected()){            
           filemenu.doClick();         
        }
        */
    } else if (event.getSource() == toolmenu) {
        /*if(!toolmenu.isSelected()){            
           toolmenu.doClick();         
        }*/

    } else if (drawCanvas.loadingtext.equals("note")) {
        Main.drawCanvas.loadingtext = "";
        Main.drawCanvas.ready("note");

    }

    else if (event.getSource() == drawScroll.getVerticalScrollBar()) {

        if (Main.glassPane.getCursor().getType() != Cursor.WAIT_CURSOR) {
            Main.glassPane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        }
        Draw.setGlasspane(true);

    } else if (event.getSource() == searchField) {
        searchField.requestFocus();
        searchField.setForeground(Color.black);
        if (searchField.getText().contains("Search by")) {
            searchField.setText("");
        }

    } else if (event.getSource() == addGenome) {
        if (AddGenome.frame == null) {
            AddGenome.createAndShowGUI();
        }
        AddGenome.frame.setTitle("Add new genome");
        AddGenome.annotation = false;
        AddGenome.remove.setEnabled(false);
        AddGenome.download.setEnabled(false);
        AddGenome.frame.setVisible(true);
        AddGenome.frame.setLocation(
                frame.getLocationOnScreen().x + frame.getWidth() / 2 - AddGenome.frame.getWidth() / 2,
                frame.getLocationOnScreen().y + frame.getHeight() / 6);
        AddGenome.frame.setState(JFrame.NORMAL);

    } else if (event.getComponent().getName() != null) {
        if (event.getComponent().getName().equals("frame0")) {
            return;
        }

        try {
            if (event.getComponent().getName().equals("add_annotation")) {
                if (AddGenome.frame == null) {
                    AddGenome.createAndShowGUI();
                }
                AddGenome.annotation = true;
                AddGenome.frame.setTitle("Add new annotation file for " + Main.selectedGenome);
                AddGenome.remove.setEnabled(false);
                AddGenome.download.setEnabled(false);
                AddGenome.frame.setVisible(true);
                AddGenome.frame.setLocation(
                        frame.getLocationOnScreen().x + frame.getWidth() / 2 - AddGenome.frame.getWidth() / 2,
                        frame.getLocationOnScreen().y + frame.getHeight() / 6);
                AddGenome.genomeName.setText(hoverGenome);
                return;
            }

            if (hoverAnnotation.length() > 0) {
                for (int j = 0; j < genomehash.get(hoverGenome).size(); j++) {
                    if (genomehash.get(hoverGenome).get(j).getName().contains(hoverAnnotation)) {
                        annotationfile = genomehash.get(hoverGenome).get(j).getName();
                        Main.annotation = j;
                        break;
                    }
                }

                defaultGenome = hoverGenome;

                setChromDrop(defaultGenome);
                getBands();
                if (genomehash.get(defaultGenome).size() > 0
                        && genomehash.get(defaultGenome).get(annotation) != null) {

                    changeAnnotation(annotation);

                }
                //drawCanvas.chrom = chromosomeDropdown.getItemAt(0);
                chromosomeDropdown.setSelectedIndex(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

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  a va  2s .  c  o m
            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:lu.fisch.unimozer.Diagram.java

@Override
public void mouseDragged(MouseEvent e) {
    if (mousePressed == true && isEnabled()) {
        if (mode == MODE_EXTENDS) {
            extendsDragPoint = e.getPoint();
            repaint();/*from  w ww.ja v a2  s  .  co  m*/
        } else {
            boolean doRepaint = false;
            if (mouseClass != null) {
                mouseClass.setPosition(
                        new Point(e.getX() - mouseRelativePoint.x, e.getY() - mouseRelativePoint.y));
                doRepaint = true;
            } else if (mousePackage != null) {
                for (MyClass myClass : classes.values()) {
                    if (myClass.getPackagename().equals(mousePackage.getName())) {
                        myClass.setPosition(new Point(myClass.getPosition().x + e.getX() - mouseRelativePoint.x,
                                myClass.getPosition().y + e.getY() - mouseRelativePoint.y));
                    }
                    doRepaint = true;
                }
                mouseRelativePoint = e.getPoint();
            }
            if (doRepaint)
                repaint();
        }
    }
}

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 .ja  v a 2 s  .c o  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.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Get the chosen Wrapper from the tree node that was clicked on.
 * /*from  ww  w .  j  ava  2s  .  co m*/
 * @param event
 *          The mouse click event
 * 
 * @return The Wrapper instance or null if the node is not a Wrapper
 */
private Wrapper getSelectedWrapperInTree(MouseEvent event) {
    Wrapper chosenWrapper = null;

    LOGGER.debug("Tree mouse event: " + event.paramString());
    final TreePath path = ontModelTree.getPathForLocation(event.getX(), event.getY());
    if (path != null) {
        LOGGER.debug("Tree right-mouse event on: " + path.getLastPathComponent() + " of class "
                + path.getLastPathComponent().getClass());
        if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
            final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            final Object selectedObject = selectedNode.getUserObject();
            LOGGER.debug("Class of object in the selected tree node: " + selectedObject.getClass().getName());
            if (selectedObject instanceof Wrapper) {
                chosenWrapper = (Wrapper) selectedObject;
                LOGGER.debug("Wrapper found: " + selectedObject);
            }
        }
    }

    return chosenWrapper;
}

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

/**
 * Shows Parent Form's Context Menu./*from  w  w  w .  ja  v  a 2  s  .  com*/
 * @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_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 .j a va 2s.c o  m
            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());
}