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:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java

@Override
public GUILink getEdge(MouseEvent e) {
    final VisualizationViewer<GUINode, GUILink> vv = (VisualizationViewer<GUINode, GUILink>) e.getSource();
    GraphElementAccessor<GUINode, GUILink> pickSupport = vv.getPickSupport();
    if (pickSupport != null) {
        final Point p = e.getPoint();
        return pickSupport.getEdge(vv.getModel().getGraphLayout(), p.getX(), p.getY());
    }//from  w  w  w  . jav  a  2s .c  o m

    return null;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java

/**
 * Cree un JTable contenant les ecritures du compte pass en argument
 * //from w  w w. ja v  a  2  s  .c om
 * @param compte
 * @return null si aucune ecriture
 */
private JTable createJTableCompte(Compte compte) {

    // on cree la JTable
    final JTable tableTmp = creerJTable(compte);

    if (tableTmp != null) {

        // On met en place le renderer
        EcritureGrandLivreRenderer ecritureRenderer = new EcritureGrandLivreRenderer(
                ((TableSorter) tableTmp.getModel()));

        for (int j = 0; j < tableTmp.getColumnCount(); j++) {
            tableTmp.getColumnModel().getColumn(j).setCellRenderer(ecritureRenderer);
        }

        // Gestion de la souris sur la JTable
        tableTmp.addMouseListener(new MouseAdapter() {

            public void mousePressed(final MouseEvent mE) {

                if (mE.getButton() == MouseEvent.BUTTON3) {
                    JPopupMenu menuDroit = new JPopupMenu();

                    menuDroit.add(new AbstractAction("Voir la source") {

                        public void actionPerformed(ActionEvent e) {
                            int row = tableTmp.rowAtPoint(mE.getPoint());

                            TableSorter s = (TableSorter) tableTmp.getModel();

                            int modelIndex = s.modelIndex(row);
                            ConsultCompteModel consultCompteModel = ((ConsultCompteModel) s.getTableModel());
                            Ecriture ecriture = consultCompteModel.getEcritures().get(modelIndex);

                            MouvementSQLElement.showSource(ecriture.getIdMvt());

                        }
                    });
                    menuDroit.show(mE.getComponent(), mE.getX(), mE.getY());
                }
            }
        });

    }
    return tableTmp;
}

From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java

@Override
public GUINode getVertex(MouseEvent e) {
    final VisualizationViewer<GUINode, GUILink> vv = (VisualizationViewer<GUINode, GUILink>) e.getSource();
    GraphElementAccessor<GUINode, GUILink> pickSupport = vv.getPickSupport();
    if (pickSupport != null) {
        final Point p = e.getPoint();
        final GUINode vertex = pickSupport.getVertex(vv.getModel().getGraphLayout(), p.getX(), p.getY());
        if (vertex != null)
            return vertex;
    }/*  w w  w  .  j  a  v  a 2 s  .c  o m*/

    return null;
}

From source file:edu.uci.ics.jung.visualization.control.LabelEditingGraphMousePlugin.java

/**
 * For primary modifiers (default, MouseButton1):
 * pick a single Vertex or Edge that//w ww .j  a va 2s .  c om
  * is under the mouse pointer. If no Vertex or edge is under
  * the pointer, unselect all picked Vertices and edges, and
  * set up to draw a rectangle for multiple selection
  * of contained Vertices.
  * For additional selection (default Shift+MouseButton1):
  * Add to the selection, a single Vertex or Edge that is
  * under the mouse pointer. If a previously picked Vertex
  * or Edge is under the pointer, it is un-picked.
  * If no vertex or Edge is under the pointer, set up
  * to draw a multiple selection rectangle (as above)
  * but do not unpick previously picked elements.
 * 
 * @param e the event
 */
@SuppressWarnings("unchecked")
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == modifiers && e.getClickCount() == 2) {
        VisualizationViewer<V, E> vv = (VisualizationViewer) e.getSource();
        GraphElementAccessor<V, E> pickSupport = vv.getPickSupport();
        if (pickSupport != null) {
            Transformer<V, String> vs = vv.getRenderContext().getVertexLabelTransformer();
            if (vs instanceof MapTransformer) {
                Map<V, String> map = ((MapTransformer) vs).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();

                V vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
                if (vertex != null) {
                    String newLabel = vs.transform(vertex);
                    newLabel = JOptionPane.showInputDialog("New Vertex Label for " + vertex);
                    if (newLabel != null) {
                        map.put(vertex, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
            Transformer<E, String> es = vv.getRenderContext().getEdgeLabelTransformer();
            if (es instanceof MapTransformer) {
                Map<E, String> map = ((MapTransformer) es).getMap();
                Layout<V, E> layout = vv.getGraphLayout();
                // p is the screen point for the mouse event
                Point2D p = e.getPoint();
                // take away the view transform
                Point2D ip = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, p);
                E edge = pickSupport.getEdge(layout, ip.getX(), ip.getY());
                if (edge != null) {
                    String newLabel = JOptionPane.showInputDialog("New Edge Label for " + edge);
                    if (newLabel != null) {
                        map.put(edge, newLabel);
                        vv.repaint();
                    }
                    return;
                }
            }
        }
        e.consume();
    }
}

From source file:pts4.googlemaps.Gmaps.java

public void createStage() {

    GeoPosition Utrecht = new GeoPosition(52.0907370, 5.1214200);
    /*// Create a waypoint painter that takes all the waypoints
     WaypointPainter<Waypoint> waypointPainter = new WaypointPainter<Waypoint>();
     waypointPainter.setWaypoints(waypoints);*/
    // Set the focus
    mapViewer.setZoom(10);//from ww  w  .  j  ava  2  s .co  m
    mapViewer.setAddressLocation(Utrecht);

    // Add interactions
    MouseInputListener mia = new PanMouseInputListener(mapViewer);

    mapViewer.addMouseListener(sa);
    mapViewer.addMouseMotionListener(sa);
    mapViewer.setOverlayPainter(sp);
    mapViewer.addMouseListener(mia);
    mapViewer.addMouseMotionListener(mia);
    //mapViewer.addMouseListener(new CenterMapListener(mapViewer));
    mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCenter(mapViewer));
    mapViewer.addKeyListener(new PanKeyListener(mapViewer));

    mapViewer.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent me) {

            //Rechter muisknop klik
            if (me.getButton() == MouseEvent.BUTTON3) {
                GeoPosition mousepoint = mapViewer.convertPointToGeoPosition(me.getPoint());
                Double lat1 = mousepoint.getLatitude();
                Double lng1 = mousepoint.getLongitude();
                Double lat2;
                Double lng2;

                for (MyWaypoint u : units) {
                    lat2 = u.getPosition().getLatitude();
                    lng2 = u.getPosition().getLongitude();

                    if (UnitControl.distFrom(lat1.floatValue(), lng1.floatValue(), lat2.floatValue(),
                            lng2.floatValue()) < (mapViewer.getZoom() * mapViewer.getZoom()
                                    * mapViewer.getZoom() * 2)) {
                        Platform.runLater(new Runnable() {

                            @Override
                            public void run() {

                                MessageBox msg = new MessageBox("Send message to unit " + u.getLabel() + "?",
                                        MessageBoxType.YES_NO);
                                msg.showAndWait();

                                if (msg.getMessageBoxResult() == MessageBoxResult.YES) {

                                    try {
                                        if (gui.messageToUnit(u.getLabel()) == false) {
                                            MessageBox msg2 = new MessageBox("Error connecting to unit",
                                                    MessageBoxType.OK_ONLY);
                                            msg2.show();

                                        }
                                    } catch (IOException ex) {
                                        Logger.getLogger(Gmaps.class.getName()).log(Level.SEVERE, null, ex);
                                    }

                                } else {
                                    //msg.close();
                                }
                            }

                        });
                    }
                }

            } else {
                if (createUnit == true) {
                    Color kleur = null;
                    if (type == 1) {
                        kleur = Color.cyan;
                    }
                    if (type == 2) {
                        kleur = Color.YELLOW;
                    }
                    if (type == 3) {
                        kleur = Color.RED;
                    }
                    GeoPosition plek = mapViewer.convertPointToGeoPosition(me.getPoint());
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            gui.setUnit(plek.getLongitude(), plek.getLatitude());
                        }
                    });

                    for (MyWaypoint p : orders) {
                        if (p.getLabel().equals(id)) {
                            orders.remove(p);
                        }
                    }
                    orders.add(new MyWaypoint(id, kleur, plek));
                    for (Unit a : EmergencyUnits) {
                        if (a.getName().equals(id)) {
                            GeoPosition plek2 = new GeoPosition(a.getLatidude(), a.getLongitude());
                            ChatMessage chat = new ChatMessage(
                                    gui.getIncidentorder() + "\n" + gui.getUnitDescription(), "Meldkamer", id);
                            server.sendMessage(chat);
                            a.setIncident(incidentstring);
                            new Animation(plek, plek2, id, orders, units, Gmaps.this, waypointPainter3);
                        }
                    }
                    createUnit = false;
                    // Create a waypoint painter that takes all the waypoints
                    waypointPainter3.setWaypoints(orders);
                    waypointPainter3.setRenderer(new FancyWaypointRenderer());
                    draw();
                }

                if (simulation == true) {
                    Color kleur = null;
                    if (type == 1) {
                        kleur = Color.cyan;
                    }
                    if (type == 2) {
                        kleur = Color.YELLOW;
                    }
                    if (type == 3) {
                        kleur = Color.RED;
                    }
                    GeoPosition plek = mapViewer.convertPointToGeoPosition(me.getPoint());
                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            gui.setUnit(plek.getLongitude(), plek.getLatitude());
                        }
                    });

                    for (MyWaypoint p : orders) {
                        if (p.getLabel().equals(id)) {
                            orders.remove(p);
                        }
                    }
                    orders.add(new MyWaypoint(id, kleur, plek));
                    for (Unit a : EmergencyUnits) {
                        if (a.getName().equals(id)) {
                            GeoPosition plek2 = new GeoPosition(a.getLatidude(), a.getLongitude());
                            ChatMessage chat = new ChatMessage(
                                    gui.getIncidentorder() + "\n" + gui.getUnitDescription(), "Meldkamer", id);
                            server.sendMessage(chat);
                            a.setIncident(incidentstring);
                            Point2D fire = mapViewer.getTileFactory().geoToPixel(plek, mapViewer.getZoom());
                            simulations = new Simulation(plek, plek2, id, orders, units, Gmaps.this,
                                    waypointPainter3);
                            new SimulationAnimation(simulations, plek, plek2, id, orders, units, Gmaps.this,
                                    waypointPainter3);

                        }
                    }
                    createUnit = false;
                    // Create a waypoint painter that takes all the waypoints
                    waypointPainter3.setWaypoints(orders);
                    waypointPainter3.setRenderer(new FancyWaypointRenderer());
                    /*
                     List<Painter<JXMapViewer>> painters = new ArrayList<Painter<JXMapViewer>>();
                     painters.add(simulations);
                     CompoundPainter<JXMapViewer> painter = new CompoundPainter<JXMapViewer>(painters);
                                
                     mapViewer.setOverlayPainter(painter);*/
                    draw();
                    simulation = false;
                }

                if (weather == true) {
                    GeoPosition mousepoint = mapViewer.convertPointToGeoPosition(me.getPoint());
                    Double lat1 = mousepoint.getLatitude();
                    Double lng1 = mousepoint.getLongitude();
                    try {
                        new Weather(lng1, lat1);
                    } catch (IOException ex) {
                        Logger.getLogger(Gmaps.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (JSONException ex) {
                        Logger.getLogger(Gmaps.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }); // end MouseAdapter

}

From source file:org.kuali.test.ui.components.sqlquerytree.SqlQueryTree.java

@Override
public void mousePressed(MouseEvent e) {
    TreePath path = getPathForLocation(e.getX(), e.getY());
    if (path != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        if (node != null) {
            if (node.getUserObject() instanceof ColumnData) {
                ColumnData cd = (ColumnData) node.getUserObject();

                if (cd.isSelected()) {
                    columnsSelected--;//w  ww .  j  a v  a  2s  . c o m
                } else {
                    columnsSelected++;
                }

                cd.setSelected(!cd.isSelected());
                getComponentAt(e.getPoint()).repaint();
                e.consume();
            }
        }
    }
}

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

/**
 * Handle mouse dragged event/* www  .j a v a2s .c  o m*/
 *
 * @param e the mouse event
 */
public void mouseDragged(MouseEvent e) {

    if (selectedNode != null && !connectingSourceFromHead && !connectingSourceFromTail) {
        final Point p = new Point(e.getX() - (lastMousePos.x - selectedNode.getPos().x),
                e.getY() - (lastMousePos.y - selectedNode.getPos().y));
        selectedNode.setPos(p);
        lastMousePos = e.getPoint();
        repaint();
    }
    if (connectingSourceFromHead || connectingSourceFromTail) {
        connectingSourcePos = e.getPoint();
        repaint();
    }
}

From source file:org.esa.nest.dat.views.polarview.PolarView.java

/**
 * Handle mouse clicked event// w w  w  . j a  v  a 2s  . c o m
 *
 * @param e the mouse event
 */
public void mouseClicked(MouseEvent e) {
    checkPopup(e);

    final Object src = e.getSource();
    final PolarCanvas polarCanvas = polarPanel.getPolarCanvas();
    if (src == polarCanvas) {
        final Axis axis = polarCanvas.selectAxis(e.getPoint());
        if (axis != null && axis == polarCanvas.getColourAxis()) {
            callColourScaleDlg();
        }
    }
}

From source file:org.executequery.gui.resultset.ResultSetTable.java

protected JTableHeader createDefaultTableHeader() {

    return new JTableHeader(columnModel) {

        public String getToolTipText(MouseEvent e) {

            if (getModel() instanceof TableSorter) {

                TableSorter model = (TableSorter) getModel();
                if (model.getTableModel() instanceof ResultSetTableModel) {

                    ResultSetTableModel resultSetTableModel = (ResultSetTableModel) model.getTableModel();

                    Point point = e.getPoint();
                    int index = columnModel.getColumnIndexAtX(point.x);
                    int realIndex = columnModel.getColumn(index).getModelIndex();

                    return resultSetTableModel.getColumnNameHint(realIndex);
                }/*from  w ww  .ja  v  a 2 s  .  c o  m*/
            }

            return super.getToolTipText(e);
        }

    };
}

From source file:gdt.jgui.tool.JEntityEditor.java

private void showElement(Sack entity, String element$) {
    try {/*from ww  w. ja v a2  s. c  o  m*/
        //      System.out.println("EntityEditor:showElement:"+element$);
        Core[] ca = null;
        if ("attributes".equals(element$))
            ca = entity.attributesGet();
        else
            ca = entity.elementGet(element$);
        final JTable table = new JTable();
        DefaultTableModel model = new DefaultTableModel(null, new String[] { "type", "name", "value" });
        table.setModel(model);
        table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer());
        table.getTableHeader().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int col = table.columnAtPoint(e.getPoint());
                String name = table.getColumnName(col);
                //              System.out.println("Column index selected " + col + " " + name);
                sort(name);
            }
        });
        JScrollPane scrollPane = new JScrollPane();
        tabbedPane.add(element$, scrollPane);
        scrollPane.add(table);
        scrollPane.setViewportView(table);
        if (ca != null)
            for (Core aCa : ca) {
                model.addRow(new String[] { aCa.type, aCa.name, aCa.value });
            }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}