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.geom.Point2D; | |
13 | ||
14 | /** | |
15 | * MagnifyTransformer wraps a MutableAffineTransformer and modifies | |
16 | * the transform and inverseTransform methods so that they create an | |
17 | * enlarging projection of the graph points. | |
18 | * | |
19 | * MagnifyTransformer uses an | |
20 | * affine transform to cause translation, scaling, rotation, and shearing | |
21 | * while applying a separate magnification filter in its transform and | |
22 | * inverseTransform methods. | |
23 | * | |
24 | * @author Tom Nelson - RABA Technologies | |
25 | * | |
26 | * | |
27 | */ | |
28 | public class MagnifyTransformer extends LensTransformer implements MutableTransformer { | |
29 | ||
30 | ||
31 | /** | |
32 | * create an instance, setting values from the passed component | |
33 | * and registering to listen for size changes on the component | |
34 | * @param component | |
35 | */ | |
36 | public MagnifyTransformer(Component component) { | |
37 | 0 | this(component, new MutableAffineTransformer()); |
38 | 0 | } |
39 | /** | |
40 | * create an instance with a possibly shared transform | |
41 | * @param component | |
42 | * @param delegate | |
43 | */ | |
44 | public MagnifyTransformer(Component component, MutableTransformer delegate) { | |
45 | 0 | super(component, delegate); |
46 | 0 | this.magnification = 3.f; |
47 | 0 | } |
48 | ||
49 | /** | |
50 | * override base class transform to project the fisheye effect | |
51 | */ | |
52 | public Point2D transform(Point2D graphPoint) { | |
53 | 0 | if(graphPoint == null) return null; |
54 | 0 | Point2D viewCenter = getViewCenter(); |
55 | 0 | double viewRadius = getViewRadius(); |
56 | 0 | double ratio = getRatio(); |
57 | // transform the point from the graph to the view | |
58 | 0 | Point2D viewPoint = delegate.transform(graphPoint); |
59 | // calculate point from center | |
60 | 0 | double dx = viewPoint.getX() - viewCenter.getX(); |
61 | 0 | double dy = viewPoint.getY() - viewCenter.getY(); |
62 | // factor out ellipse | |
63 | 0 | dx *= ratio; |
64 | 0 | Point2D pointFromCenter = new Point2D.Double(dx, dy); |
65 | ||
66 | 0 | PolarPoint polar = cartesianToPolar(pointFromCenter); |
67 | 0 | double theta = polar.getTheta(); |
68 | 0 | double radius = polar.getRadius(); |
69 | 0 | if(radius > viewRadius) return viewPoint; |
70 | ||
71 | 0 | double mag = magnification; |
72 | 0 | radius *= mag; |
73 | ||
74 | 0 | radius = Math.min(radius, viewRadius); |
75 | 0 | Point2D projectedPoint = polarToCartesian(theta, radius); |
76 | 0 | projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY()); |
77 | 0 | Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(), |
78 | projectedPoint.getY()+viewCenter.getY()); | |
79 | 0 | return translatedBack; |
80 | } | |
81 | ||
82 | /** | |
83 | * override base class to un-project the fisheye effect | |
84 | */ | |
85 | public Point2D inverseTransform(Point2D viewPoint) { | |
86 | ||
87 | 0 | Point2D viewCenter = getViewCenter(); |
88 | 0 | double viewRadius = getViewRadius(); |
89 | 0 | double ratio = getRatio(); |
90 | 0 | double dx = viewPoint.getX() - viewCenter.getX(); |
91 | 0 | double dy = viewPoint.getY() - viewCenter.getY(); |
92 | // factor out ellipse | |
93 | 0 | dx *= ratio; |
94 | ||
95 | 0 | Point2D pointFromCenter = new Point2D.Double(dx, dy); |
96 | ||
97 | 0 | PolarPoint polar = cartesianToPolar(pointFromCenter); |
98 | ||
99 | 0 | double radius = polar.getRadius(); |
100 | 0 | if(radius > viewRadius) return delegate.inverseTransform(viewPoint); |
101 | ||
102 | 0 | double mag = magnification; |
103 | 0 | radius /= mag; |
104 | 0 | polar.setRadius(radius); |
105 | 0 | Point2D projectedPoint = polarToCartesian(polar); |
106 | 0 | projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY()); |
107 | 0 | Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(), |
108 | projectedPoint.getY()+viewCenter.getY()); | |
109 | 0 | return delegate.inverseTransform(translatedBack); |
110 | } | |
111 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |