Coverage Report - edu.uci.ics.jung.visualization.jai.PerspectiveTransformer
 
Classes in this File Line Coverage Branch Coverage Complexity
PerspectiveTransformer
0%
0/25
0%
0/4
1.7
 
 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.jai;
 10  
 
 11  
 import java.awt.geom.NoninvertibleTransformException;
 12  
 import java.awt.geom.Point2D;
 13  
 
 14  
 import javax.media.jai.PerspectiveTransform;
 15  
 
 16  
 import edu.uci.ics.jung.visualization.transform.MutableAffineTransformer;
 17  
 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
 18  
 import edu.uci.ics.jung.visualization.transform.MutableTransformerDecorator;
 19  
 
 20  
 /**
 21  
  * PerspectiveTransformer wraps a MutableAffineTransformer and modifies
 22  
  * the transform and inverseTransform methods so that they create a
 23  
  * perspective projection of the graph points.
 24  
  * 
 25  
  * @author Tom Nelson
 26  
  *
 27  
  */
 28  
 public class PerspectiveTransformer extends MutableTransformerDecorator implements MutableTransformer {
 29  
 
 30  
     protected PerspectiveTransform perspectiveTransform;
 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 PerspectiveTransformer(PerspectiveTransform perspectiveTransform) {
 37  0
         this(perspectiveTransform, new MutableAffineTransformer());
 38  0
     }
 39  
     /**
 40  
      * create an instance with a possibly shared transform
 41  
      * @param component
 42  
      * @param delegate
 43  
      */
 44  
     public PerspectiveTransformer(PerspectiveTransform perspectiveTransform, MutableTransformer delegate) {
 45  0
                     super(delegate);
 46  0
                     this.perspectiveTransform = perspectiveTransform;
 47  0
    }
 48  
     
 49  
     @Override
 50  
     public void setToIdentity() {
 51  0
         this.perspectiveTransform.setToIdentity();
 52  0
     }
 53  
     
 54  
     public PerspectiveTransform createInverse() {
 55  
         try {
 56  0
             return perspectiveTransform.createInverse();
 57  0
         } catch (NoninvertibleTransformException e) {
 58  0
             e.printStackTrace();
 59  0
         } catch (CloneNotSupportedException e) {
 60  0
             e.printStackTrace();
 61  0
         }
 62  0
         return null;
 63  
     }
 64  
 
 65  
     /**
 66  
      * override base class transform to project the perspective effect
 67  
      */
 68  
     @Override
 69  
     public Point2D transform(Point2D graphPoint) {
 70  0
         if(graphPoint == null) return null;
 71  0
         Point2D p2 = super.transform(graphPoint);
 72  0
         return perspectiveTransform.transform(p2, null);
 73  
     }
 74  
     
 75  
     /**
 76  
      * override base class to un-project the perspective effect
 77  
      */
 78  
     @Override
 79  
     public Point2D inverseTransform(Point2D viewPoint) {
 80  0
         Point2D p2 = createInverse().transform(viewPoint, null);
 81  0
         return super.inverseTransform(p2);
 82  
 
 83  
     }
 84  
     public Point2D perspectiveTransform(Point2D graphPoint) {
 85  0
         if(graphPoint == null) return null;
 86  0
         return perspectiveTransform.transform(graphPoint, null);
 87  
     }
 88  
     
 89  
     /**
 90  
      * override base class to un-project the perspective effect
 91  
      */
 92  
     public Point2D inversePerspectiveTransform(Point2D viewPoint) {
 93  0
         return createInverse().transform(viewPoint, null);
 94  
     }
 95  
 
 96  
     public PerspectiveTransform getPerspectiveTransform() {
 97  0
         return perspectiveTransform;
 98  
     }
 99  
     public void setPerspectiveTransform(PerspectiveTransform perspectiveTransform) {
 100  0
         this.perspectiveTransform = perspectiveTransform;
 101  0
     }
 102  
 }