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

Line | Hits | Source
--- | --- | ---
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 |  | `*/`
34 | 0 | `public MouseListenerTranslator(GraphMouseListener gel, VisualizationViewer vv) {`
35 | 0 | `this.gel = gel;`
36 | 0 | `this.vv = vv;`
37 | 0 | `}`
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`
48 | 0 | `PickSupport pickSupport = vv.getPickSupport();`
49 | 0 | `Vertex v = null;`
50 | 0 | `if(pickSupport != null) {`
51 | 0 | `Point2D p = vv.inverseViewTransform(point);`
52 | 0 | `v = pickSupport.getVertex(p.getX(), p.getY());`
53 |  | `}`
54 | 0 | `return v;`
55 |  | `}`
56 |  | `/**`
57 |  | `* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)`
58 |  | `*/`
59 |  | `public void mouseClicked(MouseEvent e) {`
60 | 0 | `Vertex v = getVertex(e.getPoint());`
61 | 0 | `if ( v != null ) {`
62 | 0 | `gel.graphClicked(v, e );`
63 |  | `}`
64 | 0 | `}`
65 |  | ``
66 |  | `/**`
67 |  | `* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)`
68 |  | `*/`
69 |  | `public void mousePressed(MouseEvent e) {`
70 | 0 | `Vertex v = getVertex(e.getPoint());`
71 | 0 | `if ( v != null ) {`
72 | 0 | `gel.graphPressed(v, e );`
73 |  | `}`
74 | 0 | `}`
75 |  | ``
76 |  | `/**`
77 |  | `* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)`
78 |  | `*/`
79 |  | `public void mouseReleased(MouseEvent e) {`
80 | 0 | `Vertex v = getVertex(e.getPoint());`
81 | 0 | `if ( v != null ) {`
82 | 0 | `gel.graphReleased(v, e );`
83 |  | `}`
84 | 0 | `}`
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.