1
2
3
4
5
6
7
8
9
10
11
12
13 package edu.uci.ics.jung.visualization.control;
14
15 import java.awt.event.MouseAdapter;
16 import java.awt.event.MouseEvent;
17 import java.awt.geom.Point2D;
18
19 import edu.uci.ics.jung.algorithms.layout.GraphElementAccessor;
20 import edu.uci.ics.jung.algorithms.layout.Layout;
21 import edu.uci.ics.jung.visualization.VisualizationViewer;
22
23
24
25
26
27
28 public class MouseListenerTranslator<V, E> extends MouseAdapter {
29
30 private VisualizationViewer<V,E> vv;
31 private GraphMouseListener<V> gel;
32
33
34
35
36
37 public MouseListenerTranslator(GraphMouseListener<V> gel, VisualizationViewer<V,E> vv) {
38 this.gel = gel;
39 this.vv = vv;
40 }
41
42
43
44
45
46
47
48
49 private V getVertex(Point2D point) {
50
51 Point2D p = point;
52
53 GraphElementAccessor<V,E> pickSupport = vv.getPickSupport();
54 Layout<V,E> layout = vv.getGraphLayout();
55 V v = null;
56 if(pickSupport != null) {
57 v = pickSupport.getVertex(layout, p.getX(), p.getY());
58 }
59 return v;
60 }
61
62
63
64 public void mouseClicked(MouseEvent e) {
65 V v = getVertex(e.getPoint());
66 if ( v != null ) {
67 gel.graphClicked(v, e );
68 }
69 }
70
71
72
73
74 public void mousePressed(MouseEvent e) {
75 V v = getVertex(e.getPoint());
76 if ( v != null ) {
77 gel.graphPressed(v, e );
78 }
79 }
80
81
82
83
84 public void mouseReleased(MouseEvent e) {
85 V v = getVertex(e.getPoint());
86 if ( v != null ) {
87 gel.graphReleased(v, e );
88 }
89 }
90 }