1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.control;
12
13 import java.awt.Color;
14 import java.awt.Dimension;
15 import java.awt.Graphics;
16 import java.awt.Graphics2D;
17 import java.awt.Shape;
18 import java.awt.geom.AffineTransform;
19
20 import edu.uci.ics.jung.visualization.Layer;
21 import edu.uci.ics.jung.visualization.VisualizationModel;
22 import edu.uci.ics.jung.visualization.VisualizationViewer;
23 import edu.uci.ics.jung.visualization.transform.MutableAffineTransformer;
24 import edu.uci.ics.jung.visualization.transform.shape.ShapeTransformer;
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @SuppressWarnings("serial")
39 public class SatelliteVisualizationViewer<V, E>
40 extends VisualizationViewer<V,E> {
41
42
43
44
45 protected VisualizationViewer<V,E> master;
46
47
48
49
50
51 public SatelliteVisualizationViewer(VisualizationViewer<V,E> master) {
52 this(master, master.getModel());
53 }
54
55
56
57
58
59
60 public SatelliteVisualizationViewer(VisualizationViewer<V,E> master,
61 Dimension preferredSize) {
62 this(master, master.getModel(), preferredSize);
63 }
64
65
66
67
68
69
70
71 protected SatelliteVisualizationViewer(VisualizationViewer<V,E> master, VisualizationModel<V,E> model) {
72 this(master, model, new Dimension(300,300));
73 }
74
75
76
77
78
79
80
81
82 protected SatelliteVisualizationViewer(VisualizationViewer<V,E> master, VisualizationModel<V,E> model,
83 Dimension preferredSize) {
84 super(model, preferredSize);
85 this.master = master;
86
87
88 ModalGraphMouse gm = new ModalSatelliteGraphMouse();
89 setGraphMouse(gm);
90
91
92 addPreRenderPaintable(new ViewLens<V,E>(this, master));
93
94
95
96 AffineTransform modelLayoutTransform =
97 new AffineTransform(master.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).getTransform());
98
99
100
101 getRenderContext().getMultiLayerTransformer().setTransformer(Layer.LAYOUT, new MutableAffineTransformer(modelLayoutTransform));
102
103
104 master.addChangeListener(this);
105
106
107 setPickedVertexState(master.getPickedVertexState());
108 setPickedEdgeState(master.getPickedEdgeState());
109 }
110
111
112
113
114 public VisualizationViewer<V,E> getMaster() {
115 return master;
116 }
117
118
119
120
121
122
123
124
125
126 static class ViewLens<V,E> implements Paintable {
127
128 VisualizationViewer<V,E> master;
129 VisualizationViewer<V,E> vv;
130
131 public ViewLens(VisualizationViewer<V,E> vv, VisualizationViewer<V,E> master) {
132 this.vv = vv;
133 this.master = master;
134 }
135 public void paint(Graphics g) {
136 ShapeTransformer masterViewTransformer =
137 master.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);
138 ShapeTransformer masterLayoutTransformer = master.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
139 ShapeTransformer vvLayoutTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
140
141 Shape lens = master.getBounds();
142 lens = masterViewTransformer.inverseTransform(lens);
143 lens = masterLayoutTransformer.inverseTransform(lens);
144 lens = vvLayoutTransformer.transform(lens);
145 Graphics2D g2d = (Graphics2D)g;
146 Color old = g.getColor();
147 Color lensColor = master.getBackground();
148 vv.setBackground(lensColor.darker());
149 g.setColor(lensColor);
150 g2d.fill(lens);
151 g.setColor(Color.gray);
152 g2d.draw(lens);
153 g.setColor(old);
154 }
155
156 public boolean useTransform() {
157 return true;
158 }
159 }
160
161 }