Example usage for java.awt.event MouseEvent getPoint

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

Introduction

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

Prototype

public Point getPoint() 

Source Link

Document

Returns the x,y position of the event relative to the source component.

Usage

From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.DrawBanklineWidget.java

@Override
public void mousePressed(final MouseEvent event) {
    if (event.getButton() != MouseEvent.BUTTON1)
        return;/*from   ww w.  ja va 2  s.  c  o  m*/

    event.consume();

    final IMapPanel mapPanel = getMapPanel();
    if (mapPanel == null)
        return;

    final Point p = event.getPoint();

    m_currentPos = MapUtilities.transform(mapPanel, p);

    /* If we have a node, take this position, else take the current one */
    // final GM_Point currentPos = MapUtilities.transform( mapPanel, p );

    if (!m_edit) {
        try {
            final GM_Curve curve = (GM_Curve) m_lineBuilder.addPoint(m_currentPos);
            if (curve != null)
                finishLine(curve);
        } catch (final Exception e) {
            e.printStackTrace();
            reinit();
        }
    }
}

From source file:edu.purdue.cc.bionet.ui.HeatMap.java

/**
 * The mouseClicked method of the MouseListener interface.
 * //from w  w w.  ja  va2s.c om
 * @param event The MouseEvent which triggered this action.
 */
public void mouseClicked(MouseEvent event) {
    if (mapPosition.contains(event.getPoint())) {
        Correlation clicked = this.getCorrelationFromPoint(new Point(event.getX(), event.getY()));
        if (clicked != null && this.range.contains(Math.abs(clicked.getValue(this.correlationMethod)))) {
            this.fireGraphMouseEvent(clicked, event);
        }
    }

}

From source file:edu.ku.brc.ui.dnd.SimpleGlassPane.java

/**
 * @param e/*from  ww w . ja va  2  s. c  o m*/
 */
protected void checkMouseEvent(MouseEvent e) {
    Rectangle r = getInternalBounds();
    Point p = e.getPoint();

    if (r.contains(p)) {
        if (!dblClickProgBar || !getProgressBarRect().contains(p)) {
            e.consume();
        }
    }
}

From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java

/**
 * {@inheritDoc}/*  w w w  .  j  a  v  a2s  .  com*/
 */
@Override
public void mouseReleased(MouseEvent e) {
    //Don't create node or edge with right click !
    if (!e.isPopupTrigger()) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();

        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphWithOperations graph = (GraphWithOperations) layout.getGraph();

        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();

        if (pickSupport != null) {
            CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            // if no vertex create one on the fly
            if (vertex == null) {
                final CNode newNode = vertexFactory.create();
                final Point2D newPos = vv.getRenderContext().getMultiLayerTransformer()
                        .inverseTransform(e.getPoint());
                graph.addVertex(newNode, new CPoint(newPos.getX(), newPos.getY()));
                layout.lock(newNode, false);
                vertex = newNode;
            } else {
                //reset to initial color if needed
                if (startVertex != null && !startVertex.equals(vertex)) {
                    if (pointedVertices.containsKey(vertex)) {
                        vertex.setColor(pointedVertices.get(vertex));
                    }
                }
                layout.lock(vertex, false);
            }
            // if the source & destination vertex are not the same : create edge
            if (vertex != null && startVertex != null) {
                if (!startVertex.equals(vertex)) {
                    transformEdgeShape(down, down);
                    transformArrowShape(down, e.getPoint());
                    graph.addEdge(edgeFactory.create(), startVertex, vertex, edgeIsDirected);
                }
            }
        }
        //Reset fields
        startVertex = null;
        down = null;
        edgeIsDirected = EdgeType.UNDIRECTED;
        vv.removePostRenderPaintable(edgePaintable);
        vv.removePostRenderPaintable(arrowPaintable);

        //clear color mapping map
        pointedVertices.clear();
        dragVertex = null;
        lastDragVertex = null;

        vv.repaint();
    }
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

/**
 * Handle mouse moved event/*  w  w  w.  ja v  a  2 s .c o m*/
 *
 * @param e the mouse event
 */
public void mouseMoved(MouseEvent e) {

    final GraphNode n = findNode(e.getPoint());
    if (selectedNode != n) {
        showHeadHotSpot = false;
        showTailHotSpot = false;
        selectedNode = n;

        repaint();
    }
    if (selectedNode != null) {
        final int hotspotSize = GraphNode.getHotSpotSize();
        final Point headPoint = new Point(n.getPos().x, n.getPos().y + selectedNode.getHotSpotOffset());
        final Point tailPoint = new Point(n.getPos().x + n.getWidth() - hotspotSize,
                n.getPos().y + selectedNode.getHotSpotOffset());

        if (isWithinRect(headPoint, hotspotSize, hotspotSize, e.getPoint())) {
            showHeadHotSpot = true;
            connectSourceTargetNode = selectedNode;
            repaint();
        } else if (isWithinRect(tailPoint, hotspotSize, hotspotSize, e.getPoint())) {
            showTailHotSpot = true;
            connectSourceTargetNode = selectedNode;
            repaint();
        } else if (showHeadHotSpot || showTailHotSpot) {
            showHeadHotSpot = false;
            showTailHotSpot = false;
            repaint();
        }
    }
}

From source file:graph.eventhandlers.MyEditingGraphMousePlugin.java

/**
 * If startVertex is non-null, stretch an edge shape between startVertex and
 * the mouse pointer to simulate edge creation
 *///  w ww  .ja  v a2s.  c o m
public void mouseDragged(MouseEvent e) {
    if (checkModifiers(e)) {
        if (startVertex != null) {
            transformEdgeShape(down, e.getPoint());
            if (edgeIsDirected) {
                transformArrowShape(down, e.getPoint());
            }
        }
        VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract> vv = (VisualizationViewer<BiologicalNodeAbstract, BiologicalEdgeAbstract>) e
                .getSource();
        vv.repaint();
    }
}

From source file:io.github.jeremgamer.editor.panels.Labels.java

public Labels(final JFrame frame, final LabelPanel lp, final PanelSave ps) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;//ww  w.  ja v  a  2  s  . c  o  m
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(labelList),
                        "Nommez le label :", "Crer un label", JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new LabelSave(name);
                    ActionPanel.updateLists();
                    OtherPanel.updateLists();
                    PanelsPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (labelList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/labels/"
                            + labelList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(labelList),
                            "tes-vous sr de vouloir supprimer ce label?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        File dir = new File("projects/" + Editor.getProjectName() + "/panels");
                        for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            if (!f.isDirectory()) {
                                try {
                                    ps.load(f);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                for (String section : ps
                                        .getSectionsContaining(labelList.getSelectedValue() + " (Label)")) {
                                    ps.removeSection(section);
                                    try {
                                        ps.save(f);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                        if (labelList.getSelectedValue().equals(lp.getFileName())) {
                            lp.setFileName("");
                        }
                        lp.hide();
                        file.delete();
                        data.remove(labelList.getSelectedIndex());
                        ActionPanel.updateLists();
                        OtherPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    labelList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    lp.show();
                    lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            lp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            lp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        lp.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    lp.show();
                    lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            lp.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            lp.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            lp.load(new File("projects/" + Editor.getProjectName() + "/labels/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        lp.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(labelList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);

}

From source file:org.zaproxy.zap.extension.ascan.PolicyManagerDialog.java

private JTable getParamsTable() {
    if (paramsTable == null) {
        paramsTable = new JTable();
        paramsTable.setModel(getParamsModel());
        paramsTable.addMouseListener(new MouseListener() {
            @Override//from  w  w  w . j a v a 2  s.co  m
            public void mouseClicked(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getClickCount() >= 2) {
                    int row = paramsTable.rowAtPoint(e.getPoint());
                    if (row >= 0) {
                        String name = (String) getParamsModel().getValueAt(row, 0);
                        if (name != null) {
                            try {
                                extension.showPolicyDialog(PolicyManagerDialog.this, name);
                            } catch (ConfigurationException e1) {
                                logger.error(e1.getMessage(), e1);
                            }
                        }
                    }
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }
        });
        paramsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (getParamsTable().getSelectedRowCount() == 0) {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                } else if (getParamsTable().getSelectedRowCount() == 1) {
                    getModifyButton().setEnabled(true);
                    // Dont let the last policy be removed
                    getRemoveButton().setEnabled(getParamsModel().getRowCount() > 1);
                    getExportButton().setEnabled(true);
                } else {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                }
            }
        });
    }
    return paramsTable;
}

From source file:lu.lippmann.cdb.graph.mouse.CadralGraphMouse.java

/**
 * {@inheritDoc}/*from   w  w  w  .  ja v  a 2  s .  c o  m*/
 * Mode.PICKING      : Move node & edge
 * Mode.EDITING      : Add  node & edge
 * Mode.TRANSFORMING : Move graph layout
 */
@Override
public void mousePressed(MouseEvent e) {
    before.clear();
    //System.out.println("Before map cleared");
    if (!mode.equals(Mode.EDITING)) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();
        final Point2D p = e.getPoint();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            final CNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
            final CEdge edge = pickSupport.getEdge(layout, p.getX(), p.getY());

            if (mode.equals(Mode.TRANSFORMING)) {
                if (vertex != null || edge != null) {
                    setMode(Mode.PICKING);
                    vv.setCursor(Cursor.getPredefinedCursor(12));
                }
                if ((vertex == null && edge == null) && (e.isShiftDown())) {
                    setMode(Mode.PICKING);
                    vv.setCursor(Cursor.getPredefinedCursor(12));
                }
            } else if (mode.equals(Mode.PICKING) && !e.isShiftDown()) {
                if (vertex == null && edge == null) {
                    setMode(Mode.TRANSFORMING);
                }
            }
            //Final choosen mode is transforming ! -> Deselect all nodes
            if (mode.equals(Mode.TRANSFORMING)) {
                commandDispatcher.dispatch(new DeselectAllCommand());
            }

            //Save initial positions
            if (mode.equals(Mode.PICKING)) {
                if (vertex != null) {
                    saveInitialPositionOfPickedNodes(vv);
                }
            }
        }
    }

    //will call either :
    // - CadralEditingGraphMousePlugin.mousePressed(e)
    // - CadralPickingGraphMousePlugin.mousePressed(e)
    super.mousePressed(e);

    //System.out.println("Coords clicked : " + e.getPoint());
}

From source file:ru.jcorp.smartstreets.gui.map.bundle.GraphPopupMousePlugin.java

@Override
protected void handlePopup(MouseEvent e) {

    // noinspection unchecked
    final VisualizationViewer<GraphNode, GraphLink> viewer = (VisualizationViewer<GraphNode, GraphLink>) e
            .getSource();//from ww w  .j a  va 2 s  . co m

    final Layout<GraphNode, GraphLink> layout = viewer.getGraphLayout();
    final Graph<GraphNode, GraphLink> graph = layout.getGraph();
    final Point2D p = e.getPoint();
    final SmartStreetsApp app = SmartStreetsApp.getInstance();

    GraphElementAccessor<GraphNode, GraphLink> pickSupport = viewer.getPickSupport();
    if (pickSupport != null) {
        popup.removeAll();

        final GraphNode vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
        final GraphLink edge = pickSupport.getEdge(layout, p.getX(), p.getY());
        final PickedState<GraphNode> pickedVertexState = viewer.getPickedVertexState();
        final PickedState<GraphLink> pickedEdgeState = viewer.getPickedEdgeState();

        if (vertex != null) {
            popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.setSource")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    SmartMapNode mapNode = vertex.getMapNode();
                    editor.setSourceNode(mapNode);
                }
            }));
            popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.setDest")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    SmartMapNode mapNode = vertex.getMapNode();
                    editor.setDestNode(mapNode);
                }
            }));
            popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.properties")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    SmartMapNode mapNode = vertex.getMapNode();
                    NodeEditor nodeEditor = new NodeEditor(mapNode);
                    nodeEditor.setLocationRelativeTo(editor);
                    nodeEditor.setVisible(true);

                    editor.clearPathSheduled();
                    viewer.repaint();
                }
            }));
            popup.add(new AbstractAction(app.getMessage("graph.deleteVertex")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    editor.clearPathSheduled();

                    pickedVertexState.pick(vertex, false);
                    graph.removeVertex(vertex);

                    editor.getMapContext().removeNode(vertex.getMapNode());

                    viewer.repaint();
                }
            });
        } else if (edge != null) {
            popup.add(new JMenuItem(new AbstractAction(app.getMessage("edit.properties")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    SmartMapLine mapLine = edge.getMapLine();
                    LineEditor lineEditor = new LineEditor(mapLine, edge.getRoadSign());
                    lineEditor.setLocationRelativeTo(editor);
                    lineEditor.setVisible(true);

                    editor.clearPathSheduled();
                    viewer.repaint();
                }
            }));
            popup.add(new AbstractAction(app.getMessage("graph.deleteEdge")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    editor.clearPathSheduled();

                    pickedEdgeState.pick(edge, false);
                    graph.removeEdge(edge);
                    graph.removeEdge(edge.getNeighbor());

                    editor.getMapContext().removeLine(edge.getMapLine());

                    viewer.repaint();
                }
            });
        } else {
            popup.add(new AbstractAction(app.getMessage("graph.createVertex")) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    editor.clearPathSheduled();

                    GraphNode newVertex = vertexFactory.create();
                    graph.addVertex(newVertex);
                    layout.setLocation(newVertex,
                            viewer.getRenderContext().getMultiLayerTransformer().inverseTransform(p));
                    viewer.repaint();
                }
            });
        }
        if (popup.getComponentCount() > 0) {
            popup.show(viewer, e.getX(), e.getY());
        }
    }
}