1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.visualization.transform;
12
13 import java.awt.Color;
14 import java.awt.Graphics;
15 import java.awt.Graphics2D;
16 import java.awt.Paint;
17 import java.awt.geom.RectangularShape;
18
19 import edu.uci.ics.jung.visualization.VisualizationViewer;
20 import edu.uci.ics.jung.visualization.VisualizationServer.Paintable;
21 import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
22
23
24
25
26
27
28
29
30
31
32 public abstract class AbstractLensSupport<V,E> implements LensSupport {
33
34 protected VisualizationViewer<V,E> vv;
35 protected VisualizationViewer.GraphMouse graphMouse;
36 protected LensTransformer lensTransformer;
37 protected ModalGraphMouse lensGraphMouse;
38 protected Lens lens;
39 protected LensControls lensControls;
40 protected String defaultToolTipText;
41
42 protected static final String instructions =
43 "<html><center>Mouse-Drag the Lens center to move it<p>"+
44 "Mouse-Drag the Lens edge to resize it<p>"+
45 "Ctrl+MouseWheel to change magnification</center></html>";
46
47
48
49
50
51
52 public AbstractLensSupport(VisualizationViewer<V,E> vv, ModalGraphMouse lensGraphMouse) {
53 this.vv = vv;
54 this.graphMouse = vv.getGraphMouse();
55 this.defaultToolTipText = vv.getToolTipText();
56 this.lensGraphMouse = lensGraphMouse;
57 }
58
59 public void activate(boolean state) {
60 if(state) activate();
61 else deactivate();
62 }
63
64 public LensTransformer getLensTransformer() {
65 return lensTransformer;
66 }
67
68
69
70
71 public ModalGraphMouse getGraphMouse() {
72 return lensGraphMouse;
73 }
74
75
76
77
78
79
80
81 public static class Lens implements Paintable {
82 LensTransformer lensTransformer;
83 RectangularShape lensShape;
84 Paint paint = Color.decode("0xdddddd");
85
86 public Lens(LensTransformer lensTransformer) {
87 this.lensTransformer = lensTransformer;
88 this.lensShape = lensTransformer.getLensShape();
89 }
90
91
92
93
94 public Paint getPaint() {
95 return paint;
96 }
97
98
99
100
101 public void setPaint(Paint paint) {
102 this.paint = paint;
103 }
104
105
106
107
108
109 public void paint(Graphics g) {
110
111 Graphics2D g2d = (Graphics2D)g;
112 g2d.setPaint(paint);
113 g2d.fill(lensShape);
114 }
115
116 public boolean useTransform() {
117 return true;
118 }
119 }
120
121
122
123
124
125
126
127 public static class LensControls implements Paintable {
128 LensTransformer lensTransformer;
129 RectangularShape lensShape;
130 Paint paint = Color.gray;
131
132 public LensControls(LensTransformer lensTransformer) {
133 this.lensTransformer = lensTransformer;
134 this.lensShape = lensTransformer.getLensShape();
135 }
136
137
138
139
140 public Paint getPaint() {
141 return paint;
142 }
143
144
145
146
147 public void setPaint(Paint paint) {
148 this.paint = paint;
149 }
150
151
152
153
154
155 public void paint(Graphics g) {
156
157 Graphics2D g2d = (Graphics2D)g;
158 g2d.setPaint(paint);
159 g2d.draw(lensShape);
160 int centerX = (int)Math.round(lensShape.getCenterX());
161 int centerY = (int)Math.round(lensShape.getCenterY());
162 g.drawOval(centerX-10, centerY-10, 20, 20);
163 }
164
165 public boolean useTransform() {
166 return true;
167 }
168 }
169
170
171
172
173 public Lens getLens() {
174 return lens;
175 }
176
177
178
179
180 public void setLens(Lens lens) {
181 this.lens = lens;
182 }
183
184
185
186
187 public LensControls getLensControls() {
188 return lensControls;
189 }
190
191
192
193
194 public void setLensControls(LensControls lensControls) {
195 this.lensControls = lensControls;
196 }
197
198 }