Coverage details for edu.uci.ics.jung.visualization.MouseListenerTranslator

LineHitsSource
1 /*
2  * Copyright (c) 2003, the JUNG Project and the Regents of the University
3  * of California
4  * All rights reserved.
5  *
6  * This software is open-source under the BSD license; see either
7  * "license.txt" or
8  * http://jung.sourceforge.net/license.txt for a description.
9  *
10  * Created on Feb 17, 2004
11  */
12 package edu.uci.ics.jung.visualization;
13  
14 import java.awt.event.MouseAdapter;
15 import java.awt.event.MouseEvent;
16 import java.awt.geom.Point2D;
17  
18 import edu.uci.ics.jung.graph.Vertex;
19  
20 /**
21  * This class translates mouse clicks into vertex clicks
22  *
23  * @author danyelf
24  */
25 public class MouseListenerTranslator extends MouseAdapter {
26  
27     private VisualizationViewer vv;
28     private GraphMouseListener gel;
29  
30     /**
31      * @param gel
32      * @param vv
33      */
340    public MouseListenerTranslator(GraphMouseListener gel, VisualizationViewer vv) {
350        this.gel = gel;
360        this.vv = vv;
370    }
38     
39     /**
40      * Transform the point to the coordinate system in the
41      * VisualizationViewer, then use either PickSuuport
42      * (if available) or Layout to find a Vertex
43      * @param point
44      * @return
45      */
46     private Vertex getVertex(Point2D point) {
47         // adjust for scale and offset in the VisualizationViewer
480        PickSupport pickSupport = vv.getPickSupport();
490        Vertex v = null;
500        if(pickSupport != null) {
510            Point2D p = vv.inverseViewTransform(point);
520            v = pickSupport.getVertex(p.getX(), p.getY());
53         }
540        return v;
55     }
56     /**
57      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
58      */
59     public void mouseClicked(MouseEvent e) {
600        Vertex v = getVertex(e.getPoint());
610        if ( v != null ) {
620            gel.graphClicked(v, e );
63         }
640    }
65  
66     /**
67      * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
68      */
69     public void mousePressed(MouseEvent e) {
700        Vertex v = getVertex(e.getPoint());
710        if ( v != null ) {
720            gel.graphPressed(v, e );
73         }
740    }
75  
76     /**
77      * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
78      */
79     public void mouseReleased(MouseEvent e) {
800        Vertex v = getVertex(e.getPoint());
810        if ( v != null ) {
820            gel.graphReleased(v, e );
83         }
840    }
85 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.