Coverage details for edu.uci.ics.jung.visualization.transform.MagnifyTransformer

LineHitsSource
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) {
370        this(component, new MutableAffineTransformer());
380    }
39     /**
40      * create an instance with a possibly shared transform
41      * @param component
42      * @param delegate
43      */
44     public MagnifyTransformer(Component component, MutableTransformer delegate) {
450            super(component, delegate);
460        this.magnification = 3.f;
470   }
48     
49     /**
50      * override base class transform to project the fisheye effect
51      */
52     public Point2D transform(Point2D graphPoint) {
530        if(graphPoint == null) return null;
540        Point2D viewCenter = getViewCenter();
550        double viewRadius = getViewRadius();
560        double ratio = getRatio();
57         // transform the point from the graph to the view
580        Point2D viewPoint = delegate.transform(graphPoint);
59         // calculate point from center
600        double dx = viewPoint.getX() - viewCenter.getX();
610        double dy = viewPoint.getY() - viewCenter.getY();
62         // factor out ellipse
630        dx *= ratio;
640        Point2D pointFromCenter = new Point2D.Double(dx, dy);
65         
660        PolarPoint polar = cartesianToPolar(pointFromCenter);
670        double theta = polar.getTheta();
680        double radius = polar.getRadius();
690        if(radius > viewRadius) return viewPoint;
70         
710        double mag = magnification;
720        radius *= mag;
73         
740        radius = Math.min(radius, viewRadius);
750        Point2D projectedPoint = polarToCartesian(theta, radius);
760        projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY());
770        Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(),
78                 projectedPoint.getY()+viewCenter.getY());
790        return translatedBack;
80     }
81     
82     /**
83      * override base class to un-project the fisheye effect
84      */
85     public Point2D inverseTransform(Point2D viewPoint) {
86         
870        Point2D viewCenter = getViewCenter();
880        double viewRadius = getViewRadius();
890        double ratio = getRatio();
900        double dx = viewPoint.getX() - viewCenter.getX();
910        double dy = viewPoint.getY() - viewCenter.getY();
92         // factor out ellipse
930        dx *= ratio;
94  
950        Point2D pointFromCenter = new Point2D.Double(dx, dy);
96         
970        PolarPoint polar = cartesianToPolar(pointFromCenter);
98  
990        double radius = polar.getRadius();
1000        if(radius > viewRadius) return delegate.inverseTransform(viewPoint);
101         
1020        double mag = magnification;
1030        radius /= mag;
1040        polar.setRadius(radius);
1050        Point2D projectedPoint = polarToCartesian(polar);
1060        projectedPoint.setLocation(projectedPoint.getX()/ratio, projectedPoint.getY());
1070        Point2D translatedBack = new Point2D.Double(projectedPoint.getX()+viewCenter.getX(),
108                 projectedPoint.getY()+viewCenter.getY());
1090        return delegate.inverseTransform(translatedBack);
110     }
111 }

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.