1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.control;
12
13 import java.awt.Dimension;
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 SatelliteShearingGraphMousePlugin extends ShearingGraphMousePlugin {
30
31 public SatelliteShearingGraphMousePlugin() {
32 super();
33 }
34
35 public SatelliteShearingGraphMousePlugin(int modifiers) {
36 super(modifiers);
37 }
38
39
40
41
42 public void mouseDragged(MouseEvent e) {
43 if(down == null) return;
44 VisualizationViewer vv = (VisualizationViewer)e.getSource();
45 boolean accepted = checkModifiers(e);
46 if(accepted) {
47 if(vv instanceof SatelliteVisualizationViewer) {
48 VisualizationViewer vvMaster =
49 ((SatelliteVisualizationViewer)vv).getMaster();
50
51 MutableTransformer modelTransformerMaster =
52 vvMaster.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
53
54 vv.setCursor(cursor);
55 Point2D q = down;
56 Point2D p = e.getPoint();
57 float dx = (float) (p.getX()-q.getX());
58 float dy = (float) (p.getY()-q.getY());
59
60 Dimension d = vv.getSize();
61 float shx = 2.f*dx/d.height;
62 float shy = 2.f*dy/d.width;
63
64
65
66
67 Point2D center = vv.getRenderContext().getMultiLayerTransformer().transform(vvMaster.getRenderContext().getMultiLayerTransformer().inverseTransform(vvMaster.getCenter()));
68 if(p.getX() < center.getX()) {
69 shy = -shy;
70 }
71 if(p.getY() < center.getY()) {
72 shx = -shx;
73 }
74 modelTransformerMaster.shear(-shx, -shy, vvMaster.getCenter());
75
76 down.x = e.getX();
77 down.y = e.getY();
78 }
79 e.consume();
80 }
81 }
82 }