1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.control;
12
13 import java.awt.event.MouseEvent;
14 import java.awt.geom.Point2D;
15
16 import edu.uci.ics.jung.visualization.Layer;
17 import edu.uci.ics.jung.visualization.VisualizationViewer;
18 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
19
20
21
22
23
24
25
26
27 public class SatelliteRotatingGraphMousePlugin extends RotatingGraphMousePlugin {
28
29 public SatelliteRotatingGraphMousePlugin() {
30 super();
31 }
32
33 public SatelliteRotatingGraphMousePlugin(int modifiers) {
34 super(modifiers);
35 }
36
37
38
39
40 public void mouseDragged(MouseEvent e) {
41 if(down == null) return;
42 VisualizationViewer vv = (VisualizationViewer)e.getSource();
43 boolean accepted = checkModifiers(e);
44 if(accepted) {
45 if(vv instanceof SatelliteVisualizationViewer) {
46 VisualizationViewer vvMaster =
47 ((SatelliteVisualizationViewer)vv).getMaster();
48
49 MutableTransformer modelTransformerMaster =
50 vvMaster.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
51
52
53 vv.setCursor(cursor);
54
55
56
57
58 Point2D center = vv.getRenderContext().getMultiLayerTransformer().transform(vvMaster.getRenderContext().getMultiLayerTransformer().inverseTransform(vvMaster.getCenter()));
59 Point2D q = down;
60 Point2D p = e.getPoint();
61 Point2D v1 = new Point2D.Double(center.getX()-p.getX(), center.getY()-p.getY());
62 Point2D v2 = new Point2D.Double(center.getX()-q.getX(), center.getY()-q.getY());
63 double theta = angleBetween(v1, v2);
64 modelTransformerMaster.rotate(-theta,
65 vvMaster.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, vvMaster.getCenter()));
66 down.x = e.getX();
67 down.y = e.getY();
68 }
69 e.consume();
70 }
71 }
72
73 }