1
2
3
4
5
6
7
8
9
10
11
12 package edu.uci.ics.jung.visualization.control;
13
14 import java.awt.event.InputEvent;
15 import java.awt.event.MouseEvent;
16 import java.awt.event.MouseListener;
17 import java.awt.event.MouseMotionListener;
18 import java.awt.geom.Point2D;
19
20 import edu.uci.ics.jung.algorithms.layout.Layout;
21 import edu.uci.ics.jung.visualization.Layer;
22 import edu.uci.ics.jung.visualization.VisualizationViewer;
23
24
25
26
27
28
29
30
31
32 public class SatelliteAnimatedPickingGraphMousePlugin<V,E> extends AnimatedPickingGraphMousePlugin<V,E>
33 implements MouseListener, MouseMotionListener {
34
35
36
37
38
39 public SatelliteAnimatedPickingGraphMousePlugin() {
40 this(InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK);
41 }
42
43 public SatelliteAnimatedPickingGraphMousePlugin(int selectionModifiers) {
44 super(selectionModifiers);
45 }
46
47
48
49
50
51
52 @SuppressWarnings("unchecked")
53 public void mouseReleased(MouseEvent e) {
54 if (e.getModifiers() == modifiers) {
55 final VisualizationViewer<V,E> vv = (VisualizationViewer) e.getSource();
56 if (vv instanceof SatelliteVisualizationViewer) {
57 final VisualizationViewer<V,E> vvMaster =
58 ((SatelliteVisualizationViewer) vv).getMaster();
59
60 if (vertex != null) {
61 Layout<V,E> layout = vvMaster.getGraphLayout();
62 Point2D q = layout.transform(vertex);
63 Point2D lvc =
64 vvMaster.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.LAYOUT, vvMaster.getCenter());
65 final double dx = (lvc.getX() - q.getX()) / 10;
66 final double dy = (lvc.getY() - q.getY()) / 10;
67
68 Runnable animator = new Runnable() {
69
70 public void run() {
71 for (int i = 0; i < 10; i++) {
72 vvMaster.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).translate(dx,
73 dy);
74 try {
75 Thread.sleep(100);
76 } catch (InterruptedException ex) {
77 }
78 }
79 }
80 };
81 Thread thread = new Thread(animator);
82 thread.start();
83 }
84 }
85 }
86 }
87 }