1
2
3
4
5
6
7
8
9
10
11
12 package edu.uci.ics.jung.visualization.control;
13
14 import java.awt.geom.Point2D;
15
16 import edu.uci.ics.jung.visualization.Layer;
17 import edu.uci.ics.jung.visualization.VisualizationServer;
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
30
31
32
33 public class CrossoverScalingControl implements ScalingControl {
34
35
36
37
38 protected double crossover = 1.0;
39
40
41
42
43 public void setCrossover(double crossover) {
44 this.crossover = crossover;
45 }
46
47
48
49
50 public double getCrossover() {
51 return crossover;
52 }
53
54
55
56
57 public void scale(VisualizationServer<?,?> vv, float amount, Point2D at) {
58
59 MutableTransformer layoutTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
60 MutableTransformer viewTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);
61 double modelScale = layoutTransformer.getScale();
62 double viewScale = viewTransformer.getScale();
63 double inverseModelScale = Math.sqrt(crossover)/modelScale;
64 double inverseViewScale = Math.sqrt(crossover)/viewScale;
65 double scale = modelScale * viewScale;
66
67 Point2D transformedAt = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, at);
68
69 if((scale*amount - crossover)*(scale*amount - crossover) < 0.001) {
70
71 layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt);
72 viewTransformer.scale(inverseViewScale, inverseViewScale, at);
73 } else if(scale*amount < crossover) {
74
75 viewTransformer.scale(amount, amount, at);
76 layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt);
77 } else {
78
79 layoutTransformer.scale(amount, amount, transformedAt);
80 viewTransformer.scale(inverseViewScale, inverseViewScale, at);
81 }
82 vv.repaint();
83 }
84 }