# Coverage details for edu.uci.ics.jung.visualization.transform.LensTransformer

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 |  | `package edu.uci.ics.jung.visualization.transform;`
10 |  | ``
11 |  | `import java.awt.Component;`
12 |  | `import java.awt.Dimension;`
13 |  | `import java.awt.event.ComponentAdapter;`
14 |  | `import java.awt.event.ComponentEvent;`
15 |  | `import java.awt.geom.Ellipse2D;`
16 |  | `import java.awt.geom.Point2D;`
17 |  | ``
18 |  | `/**`
19 |  | `* LensTransformer wraps a MutableAffineTransformer and modifies`
20 |  | `* the transform and inverseTransform methods so that they create a`
21 |  | `* projection of the graph points within an elliptical lens.`
22 |  | `*`
23 |  | `* LensTransformer uses an`
24 |  | `* affine transform to cause translation, scaling, rotation, and shearing`
25 |  | `* while applying a possibly non-affine filter in its transform and`
26 |  | `* inverseTransform methods.`
27 |  | `*`
28 |  | `* @author Tom Nelson - RABA Technologies`
29 |  | `*`
30 |  | `*`
31 |  | `*/`
32 | 0 | `public abstract class LensTransformer extends MutableTransformerDecorator implements MutableTransformer {`
33 |  | ``
34 |  | `/**`
35 |  | `* the area affected by the transform`
36 |  | `*/`
37 | 0 | `protected Ellipse2D ellipse = new Ellipse2D.Float();`
38 |  | ``
39 | 0 | `protected float magnification = 0.7f;`
40 |  | ``
41 |  | `/**`
42 |  | `* create an instance, setting values from the passed component`
43 |  | `* and registering to listen for size changes on the component`
44 |  | `* @param component`
45 |  | `*/`
46 |  | `public LensTransformer(Component component) {`
47 | 0 | `this(component, new MutableAffineTransformer());`
48 | 0 | `}`
49 |  | `/**`
50 |  | `* create an instance with a possibly shared transform`
51 |  | `* @param component`
52 |  | `* @param delegate`
53 |  | `*/`
54 |  | `public LensTransformer(Component component, MutableTransformer delegate) {`
55 | 0 | `super(delegate);`
56 | 0 | `setComponent(component);`
57 | 0 | `component.addComponentListener(new ComponentListenerImpl());`
58 | 0 | `}`
59 |  | ``
60 |  | `/**`
61 |  | `* set values from the passed component.`
62 |  | `* declared private so it can't be overridden`
63 |  | `* @param component`
64 |  | `*/`
65 |  | `private void setComponent(Component component) {`
66 | 0 | `Dimension d = component.getSize();`
67 | 0 | `if(d.width <= 0 || d.height <= 0) {`
68 | 0 | `d = component.getPreferredSize();`
69 |  | `}`
70 | 0 | `float ewidth = d.width/1.5f;`
71 | 0 | `float eheight = d.height/1.5f;`
72 | 0 | `ellipse.setFrame(d.width/2-ewidth/2, d.height/2-eheight/2, ewidth, eheight);`
73 | 0 | `}`
74 |  | ``
75 |  | `/**`
76 |  | `* @return Returns the magnification.`
77 |  | `*/`
78 |  | `public float getMagnification() {`
79 | 0 | `return magnification;`
80 |  | `}`
81 |  | `/**`
82 |  | `* @param magnification The magnification to set.`
83 |  | `*/`
84 |  | `public void setMagnification(float magnification) {`
85 | 0 | `this.magnification = magnification;`
86 | 0 | `}`
87 |  | `/**`
88 |  | `* @return Returns the viewCenter.`
89 |  | `*/`
90 |  | `public Point2D getViewCenter() {`
91 | 0 | `return new Point2D.Double(ellipse.getCenterX(), ellipse.getCenterY());`
92 |  | `}`
93 |  | `/**`
94 |  | `* @param viewCenter The viewCenter to set.`
95 |  | `*/`
96 |  | `public void setViewCenter(Point2D viewCenter) {`
97 | 0 | `double width = ellipse.getWidth();`
98 | 0 | `double height = ellipse.getHeight();`
99 | 0 | `ellipse.setFrame(viewCenter.getX()-width/2,`
100 |  | `viewCenter.getY()-height/2,`
101 |  | `width, height);`
102 | 0 | `}`
103 |  | ``
104 |  | `/**`
105 |  | `* @return Returns the viewRadius.`
106 |  | `*/`
107 |  | `public double getViewRadius() {`
108 | 0 | `return ellipse.getHeight()/2;`
109 |  | `}`
110 |  | `/**`
111 |  | `* @param viewRadius The viewRadius to set.`
112 |  | `*/`
113 |  | `public void setViewRadius(double viewRadius) {`
114 | 0 | `double x = ellipse.getCenterX();`
115 | 0 | `double y = ellipse.getCenterY();`
116 | 0 | `double viewRatio = getRatio();`
117 | 0 | `ellipse.setFrame(x-viewRadius/viewRatio,`
118 |  | `y-viewRadius,`
119 |  | `2*viewRadius/viewRatio,`
120 |  | `2*viewRadius);`
121 | 0 | `}`
122 |  | ``
123 |  | `/**`
124 |  | `* @return Returns the ratio.`
125 |  | `*/`
126 |  | `public double getRatio() {`
127 | 0 | `return ellipse.getHeight()/ellipse.getWidth();`
128 |  | `}`
129 |  | ``
130 |  | `public void setEllipse(Ellipse2D ellipse) {`
131 | 0 | `this.ellipse = ellipse;`
132 | 0 | `}`
133 |  | `public Ellipse2D getEllipse() {`
134 | 0 | `return ellipse;`
135 |  | `}`
136 |  | `public void setToIdentity() {`
137 | 0 | `this.delegate.setToIdentity();`
138 | 0 | `}`
139 |  | ``
140 |  | `/**`
141 |  | `* react to size changes on a component`
142 |  | `*/`
143 |  | `protected class ComponentListenerImpl extends ComponentAdapter {`
144 |  | `public void componentResized(ComponentEvent e) {`
145 |  | `setComponent(e.getComponent());`
146 |  | `}`
147 |  | `}`
148 |  | ``
149 |  | `/**`
150 |  | `* a convenience class to represent a point in`
151 |  | `* polar coordinates`
152 |  | `*/`
153 |  | `protected static class PolarPoint extends Point2D.Double {`
154 |  | `public PolarPoint(double theta, double radius) {`
155 |  | `super(theta, radius);`
156 |  | `}`
157 |  | `public double getTheta() { return getX(); }`
158 |  | `public double getRadius() { return getY(); }`
159 |  | `public void setTheta(double theta) { setLocation(theta, getRadius()); }`
160 |  | `public void setRadius(double radius) { setLocation(getTheta(), radius); }`
161 |  | `}`
162 |  | ``
163 |  | `/**`
164 |  | `* Returns the result of converting <code>polar</code> to Cartesian coordinates.`
165 |  | `*/`
166 |  | `protected Point2D polarToCartesian(PolarPoint polar) {`
167 | 0 | `return polarToCartesian(polar.getTheta(), polar.getRadius());`
168 |  | `}`
169 |  | ``
170 |  | `/**`
171 |  | `* Returns the result of converting <code>(theta, radius)</code> to Cartesian coordinates.`
172 |  | `*/`
173 |  | `protected Point2D polarToCartesian(double theta, double radius) {`
174 | 0 | `return new Point2D.Double(radius*Math.cos(theta), radius*Math.sin(theta));`
175 |  | `}`
176 |  | ``
177 |  | `/**`
178 |  | `* Returns the result of converting <code>point</code> to polar coordinates.`
179 |  | `*/`
180 |  | `protected PolarPoint cartesianToPolar(Point2D point) {`
181 | 0 | `return cartesianToPolar(point.getX(), point.getY());`
182 |  | `}`
183 |  | ``
184 |  | `/**`
185 |  | `* Returns the result of converting <code>(x, y)</code> to polar coordinates.`
186 |  | `*/`
187 |  | `protected PolarPoint cartesianToPolar(double x, double y) {`
188 | 0 | `double theta = Math.atan2(y,x);`
189 | 0 | `double radius = Math.sqrt(x*x+y*y);`
190 | 0 | `return new PolarPoint(theta, radius);`
191 |  | `}`
192 |  | ``
193 |  | `/**`
194 |  | `* override base class transform to project the fisheye effect`
195 |  | `*/`
196 |  | `public abstract Point2D transform(Point2D graphPoint);`
197 |  | ``
198 |  | `/**`
199 |  | `* override base class to un-project the fisheye effect`
200 |  | `*/`
201 |  | `public abstract Point2D inverseTransform(Point2D viewPoint);`
202 |  | ``
203 |  | `public double getDistanceFromCenter(Point2D p) {`
204 | 0 | `double dx = ellipse.getCenterX()-p.getX();`
205 | 0 | `double dy = ellipse.getCenterY()-p.getY();`
206 | 0 | `dx *= getRatio();`
207 | 0 | `return Math.sqrt(dx*dx + dy*dy);`
208 |  | `}`
209 |  | `}`

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.