# Coverage details for edu.uci.ics.jung.visualization.Lens

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2003, the JUNG Project and the Regents of the University of`
3 |  | `* California All rights reserved.`
4 |  | `*`
5 |  | `* This software is open-source under the BSD license; see either "license.txt"`
6 |  | `* or http://jung.sourceforge.net/license.txt for a description.`
7 |  | `*`
8 |  | `*`
9 |  | `*/`
10 |  | `package edu.uci.ics.jung.visualization;`
11 |  | ``
12 |  | `import java.awt.Dimension;`
13 |  | `import java.awt.Point;`
14 |  | `import java.awt.event.MouseEvent;`
15 |  | `import java.awt.event.MouseListener;`
16 |  | `import java.awt.event.MouseMotionListener;`
17 |  | `import java.awt.geom.AffineTransform;`
18 |  | `import java.awt.geom.Line2D;`
19 |  | `import java.awt.geom.Point2D;`
20 |  | `import java.awt.geom.Rectangle2D;`
21 |  | `import java.beans.PropertyChangeSupport;`
22 |  | ``
23 |  | `import edu.uci.ics.jung.visualization.transform.MutableTransformer;`
24 |  | ``
25 |  | ``
26 |  | `/**`
27 |  | `* Lens is intended to be used as an overlay on the`
28 |  | `* BirdsEyeVisualizationViewer. It is a Rectangle that`
29 |  | `* acts as a MouseListener (for moving and resizing the`
30 |  | `* Rectangle).`
31 |  | `*`
32 |  | `* @deprecated use the SatelliteVisualizationViewer instead`
33 |  | `*`
34 |  | `* @author Tom Nelson - RABA Technologies`
35 |  | `*`
36 |  | `*`
37 |  | `*/`
38 |  | `public class Lens extends Rectangle2D.Float implements MouseListener,`
39 |  | `MouseMotionListener {`
40 |  | ``
41 |  | `/**`
42 |  | `* true if we are dragging the Rectangle around`
43 |  | `*/`
44 |  | `protected boolean pan;`
45 |  | ``
46 |  | `/**`
47 |  | `* true if we are dragging the right leg`
48 |  | `*/`
49 |  | `protected boolean dragRightLeg;`
50 |  | ``
51 |  | `/**`
52 |  | `* true if we are dragging the base`
53 |  | `*/`
54 |  | `protected boolean dragBase;`
55 |  | ``
56 |  | `/**`
57 |  | `* true if we are dragging the left leg`
58 |  | `*/`
59 |  | `protected boolean dragLeftLeg;`
60 |  | ``
61 |  | `/**`
62 |  | `* true if we are dragging the top`
63 |  | `*/`
64 |  | `protected boolean dragTop;`
65 |  | ``
66 |  | `/**`
67 |  | `* true if the mouse pointer is outside the window`
68 |  | `*/`
69 |  | `protected boolean outside;`
70 |  | ``
71 |  | `/**`
72 |  | `* the offset in the x direction, as a percentage of width`
73 |  | `*/`
74 |  | `protected float offx;`
75 |  | ``
76 |  | `/**`
77 |  | `* the offset in the y direction, as a percentage of height`
78 |  | `*/`
79 |  | `protected float offy;`
80 |  | ``
81 |  | `/**`
82 |  | `* the left leg of the rectangle`
83 |  | `*/`
84 |  | `protected Line2D leftLeg;`
85 |  | ``
86 |  | `/**`
87 |  | `* the right leg of the rectangle`
88 |  | `*/`
89 |  | `protected Line2D rightLeg;`
90 |  | ``
91 |  | `/**`
92 |  | `* the base of the rectangle`
93 |  | `*/`
94 |  | `protected Line2D base;`
95 |  | ``
96 |  | `/**`
97 |  | `* the top of the rectangle`
98 |  | `*/`
99 |  | `protected Line2D top;`
100 |  | ``
101 |  | `/**`
102 |  | `* the scale of the BirdsEyeVisualizationViewer compared to`
103 |  | `* the graph display`
104 |  | `*/`
105 |  | `protected float scalex;`
106 |  | ``
107 |  | `/**`
108 |  | `* the scale of the BirdsEyeVisualizationViewer compared to`
109 |  | `* the graph display`
110 |  | `*/`
111 |  | `protected float scaley;`
112 |  | ``
113 |  | `/**`
114 |  | `* the layout being used by the BirdsEye`
115 |  | `*/`
116 |  | `protected Layout layout;`
117 |  | ``
118 |  | `/**`
119 |  | `* the VisualizationViewer that is scaled and translated`
120 |  | `* by this Lens`
121 |  | `*/`
122 |  | `protected VisualizationViewer vv;`
123 |  | ``
124 |  | `/**`
125 |  | `* support for property changes`
126 |  | `*/`
127 |  | `protected PropertyChangeSupport support;`
128 |  | ``
129 |  | `/**`
130 |  | `* ratio of width to height`
131 |  | `*/`
132 |  | `protected float aspectRatio;`
133 |  | ``
134 |  | `protected Point down;`
135 |  | ``
136 |  | `protected AffineTransform lensXform;`
137 |  | ``
138 |  | `/**`
139 |  | `* Create a Lens that is centered in the`
140 |  | `* BirdsEyeVisualizationViewer`
141 |  | `*`
142 |  | `*/`
143 |  | `public Lens(VisualizationViewer vv, float scalex, float scaley) {`
144 | 0 | `super(vv.getGraphLayout().getCurrentSize().width * scalex / 4,`
145 |  | `vv.getGraphLayout().getCurrentSize().height * scaley / 4,`
146 |  | `vv.getGraphLayout().getCurrentSize().width * scalex / 2,`
147 |  | `vv.getGraphLayout().getCurrentSize().height * scaley / 2);`
148 | 0 | `this.vv = vv;`
149 | 0 | `this.layout = vv.getGraphLayout();`
150 | 0 | `this.scalex = scalex;`
151 | 0 | `this.scaley = scaley;`
152 | 0 | `lensXform = AffineTransform.getScaleInstance(1/scalex, 1/scaley);`
153 | 0 | `this.aspectRatio = (float)((getMaxX() - getMinX()) / (getMaxY() - getMinY()));`
154 | 0 | `rightLeg = new Line2D.Float((float)getMaxX(), (float)getMinY(), (float)getMaxX(), (float)getMaxY());`
155 | 0 | `leftLeg = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMinX(), (float)getMaxY());`
156 | 0 | `base = new Line2D.Float((float)getMinX(), (float)getMaxY(), (float)getMaxX(), (float)getMaxY());`
157 | 0 | `top = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMaxX(), (float)getMinY());`
158 | 0 | `}`
159 |  | ``
160 |  | `/**`
161 |  | `* reset the rectangle to the full size of the BirdsEyeVisualizationViewer`
162 |  | `* This will result in no zoom or pan of the main display`
163 |  | `*`
164 |  | `*/`
165 |  | `public void reset() {`
166 | 0 | `Dimension d = vv.getSize();`
167 | 0 | `Dimension ld = vv.getGraphLayout().getCurrentSize();`
168 | 0 | `vv.getViewTransformer().setScale((float)d.width/ld.width, (float)d.height/ld.height, new Point2D.Float());`
169 | 0 | `}`
170 |  | ``
171 |  | `public void setFrame(VisualizationViewer vv) {`
172 | 0 | `MutableTransformer viewTransformer = vv.getViewTransformer();`
173 | 0 | `Dimension d = new Dimension(`
174 |  | `(int) (vv.getSize().width * scalex ),`
175 |  | `(int) (vv.getSize().height * scaley ));`
176 | 0 | `float width = (float) (d.width/(viewTransformer.getScaleX()));`
177 | 0 | `float height = (float) (d.height/(viewTransformer.getScaleY()));`
178 | 0 | `float x = -(float) (viewTransformer.getTranslateX()*scalex/(viewTransformer.getScaleX()));`
179 | 0 | `float y = -(float) (viewTransformer.getTranslateY()*scaley/(viewTransformer.getScaleY()));`
180 | 0 | `setFrame(x,y,width,height);`
181 | 0 | `}`
182 |  | ``
183 |  | `/**`
184 |  | `* set the Rectangle to be centered in the BirdsEyeVisualizationViewer`
185 |  | `*`
186 |  | `*/`
187 |  | `public void init() {`
188 | 0 | `vv.getViewTransformer().setScale(2.0f, 2.0f, vv.getCenter());`
189 | 0 | `}`
190 |  | ``
191 |  | `/*`
192 |  | `* (non-Javadoc)`
193 |  | `*`
194 |  | `* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)`
195 |  | `*/`
196 |  | `public void mouseClicked(MouseEvent e) {`
197 | 0 | `}`
198 |  | ``
199 |  | `/*`
200 |  | `* (non-Javadoc)`
201 |  | `*`
202 |  | `* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)`
203 |  | `*/`
204 |  | `public void mousePressed(MouseEvent e) {`
205 |  | ``
206 | 0 | `down = e.getPoint();`
207 |  | ``
208 | 0 | `if (leftLeg.ptLineDist(down) < 5) {`
209 | 0 | `dragLeftLeg = true;`
210 | 0 | `} else if (rightLeg.ptLineDist(down) < 5) {`
211 | 0 | `dragRightLeg = true;`
212 | 0 | `} else if (base.ptLineDist(down) < 5) {`
213 | 0 | `dragBase = true;`
214 | 0 | `} else if (top.ptLineDist(down) < 5) {`
215 | 0 | `dragTop = true;`
216 | 0 | `} else if (contains(down)) {`
217 | 0 | `pan = true;`
218 |  | `} else {`
219 | 0 | `pan = dragLeftLeg = dragRightLeg = dragBase = dragTop = false;`
220 |  | `}`
221 | 0 | `}`
222 |  | ``
223 |  | `/*`
224 |  | `* (non-Javadoc)`
225 |  | `*`
226 |  | `* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)`
227 |  | `*/`
228 |  | `public void mouseReleased(MouseEvent e) {`
229 | 0 | `pan = dragLeftLeg = dragRightLeg = dragTop = dragBase = false;`
230 | 0 | `}`
231 |  | ``
232 |  | `/*`
233 |  | `* (non-Javadoc)`
234 |  | `*`
235 |  | `* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)`
236 |  | `*/`
237 |  | `public void mouseEntered(MouseEvent e) {`
238 | 0 | `outside = false;`
239 | 0 | `}`
240 |  | ``
241 |  | `/*`
242 |  | `* (non-Javadoc)`
243 |  | `*`
244 |  | `* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)`
245 |  | `*/`
246 |  | `public void mouseExited(MouseEvent e) {`
247 | 0 | `outside = true;`
248 | 0 | `}`
249 |  | ``
250 |  | `/*`
251 |  | `* (non-Javadoc)`
252 |  | `*`
253 |  | `* @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)`
254 |  | `*/`
255 |  | `public void mouseDragged(MouseEvent e) {`
256 | 0 | `if (outside)`
257 | 0 | `return;`
258 |  | ``
259 | 0 | `Point2D q = down;`
260 | 0 | `Point2D p = e.getPoint();`
261 | 0 | `if (pan) {`
262 | 0 | `vv.getViewTransformer().translate((q.getX()-p.getX())/scalex, (q.getY()-p.getY())/scaley);`
263 |  | `} else {`
264 | 0 | `float dw = 0.0f;`
265 | 0 | `float dh = 0.0f;`
266 |  | ``
267 | 0 | `if (dragRightLeg) {`
268 | 0 | `dw = (float) (p.getX()-q.getX());`
269 | 0 | `dh = dw / aspectRatio;`
270 |  | ``
271 | 0 | `} else if (dragLeftLeg) {`
272 | 0 | `dw = (float) (q.getX()-p.getX());`
273 | 0 | `dh = dw / aspectRatio;`
274 |  | ``
275 | 0 | `} else if (dragBase) {`
276 | 0 | `dh = (float) (p.getY()-q.getY());`
277 | 0 | `dw = dh * aspectRatio;`
278 |  | ``
279 | 0 | `} else if (dragTop) {`
280 | 0 | `dh = (float) (q.getY()-p.getY());`
281 | 0 | `dw = dh * aspectRatio;`
282 |  | `}`
283 | 0 | `float pwidth = (float)getMaxX() - (float)getMinX();`
284 | 0 | `float pheight = (float)getMaxY() - (float)getMinY();`
285 | 0 | `float newWidth = pwidth + 2 * dw;`
286 | 0 | `float newHeight = pheight + 2 * dh;`
287 | 0 | `if (newWidth < 3 || newHeight < 3)`
288 | 0 | `return;`
289 | 0 | `vv.getViewTransformer().scale(pwidth/newWidth, pheight/newHeight, vv.getCenter());`
290 |  | `}`
291 | 0 | `down = e.getPoint();`
292 |  | ``
293 | 0 | `rightLeg = new Line2D.Float((float)getMaxX(), (float)getMinY(), (float)getMaxX(), (float)getMaxY());`
294 | 0 | `leftLeg = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMinX(), (float)getMaxY());`
295 | 0 | `base = new Line2D.Float((float)getMinX(), (float)getMaxY(), (float)getMaxX(), (float)getMaxY());`
296 | 0 | `top = new Line2D.Float((float)getMinX(), (float)getMinY(), (float)getMaxX(), (float)getMinY());`
297 | 0 | `}`
298 |  | ``
299 |  | `/*`
300 |  | `* (non-Javadoc)`
301 |  | `*`
302 |  | `* @see java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)`
303 |  | `*/`
304 |  | `public void mouseMoved(MouseEvent e) {`
305 | 0 | `}`
306 |  | `}`

this report was generated by version 1.0.5 of jcoverage. visit www.jcoverage.com for updates. | copyright © 2003, jcoverage ltd. all rights reserved. Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.