1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.control;
12
13 import java.awt.Cursor;
14 import java.awt.event.MouseEvent;
15 import java.awt.geom.Point2D;
16
17 import edu.uci.ics.jung.visualization.Layer;
18 import edu.uci.ics.jung.visualization.VisualizationViewer;
19 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
20
21
22
23
24
25
26
27
28
29 public class SatelliteTranslatingGraphMousePlugin extends
30 TranslatingGraphMousePlugin {
31
32 public SatelliteTranslatingGraphMousePlugin() {
33 super();
34 }
35
36 public SatelliteTranslatingGraphMousePlugin(int modifiers) {
37 super(modifiers);
38 }
39
40
41
42
43
44
45 public void mouseDragged(MouseEvent e) {
46 VisualizationViewer vv = (VisualizationViewer)e.getSource();
47 boolean accepted = checkModifiers(e);
48 if(accepted) {
49 if(vv instanceof SatelliteVisualizationViewer) {
50 VisualizationViewer vvMaster =
51 ((SatelliteVisualizationViewer)vv).getMaster();
52
53 MutableTransformer modelTransformerMaster =
54 vvMaster.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
55 vv.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
56 try {
57 Point2D q = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(down);
58 Point2D p = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(e.getPoint());
59 float dx = (float) (p.getX()-q.getX());
60 float dy = (float) (p.getY()-q.getY());
61
62 modelTransformerMaster.translate(-dx, -dy);
63 down.x = e.getX();
64 down.y = e.getY();
65 } catch(RuntimeException ex) {
66 System.err.println("down = "+down+", e = "+e);
67 throw ex;
68 }
69 }
70 e.consume();
71 }
72 }
73
74
75 }