Coverage details for edu.uci.ics.jung.visualization.transform.shape.TransformingGraphics

LineHitsSource
1 /*
2  * Copyright (c) 2005, 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  * Created on Jul 11, 2005
9  */
10  
11 package edu.uci.ics.jung.visualization.transform.shape;
12  
13 import java.awt.Graphics;
14 import java.awt.Graphics2D;
15 import java.awt.Rectangle;
16 import java.awt.Shape;
17  
18 import edu.uci.ics.jung.visualization.transform.HyperbolicTransformer;
19 import edu.uci.ics.jung.visualization.transform.Transformer;
20  
21  
22 /**
23  * subclassed to pass certain operations thru the transformer
24  * before the base class method is applied
25  * This is useful when you want to apply non-affine transformations
26  * to the Graphics2D used to draw elements of the graph.
27  *
28  * @author Tom Nelson - RABA Technologies
29  *
30  *
31  */
32 public class TransformingGraphics extends GraphicsDecorator {
33     
34     /**
35      * the transformer to apply
36      */
37     protected Transformer transformer;
38     
39     public TransformingGraphics(Transformer transformer) {
400        this(transformer, null);
410    }
42     
43     public TransformingGraphics(Transformer transformer, Graphics2D delegate) {
440        super(delegate);
450        this.transformer = transformer;
460    }
47     
48     /**
49      * @return Returns the transformer.
50      */
51     public Transformer getTransformer() {
520        return transformer;
53     }
54     
55     /**
56      * @param transformer The transformer to set.
57      */
58     public void setTransformer(Transformer transformer) {
590        this.transformer = transformer;
600    }
61     
62     /**
63      * transform the shape before letting the delegate draw it
64      */
65     public void draw(Shape s) {
660        Shape shape = ((ShapeTransformer)transformer).transform(s);
670        delegate.draw(shape);
680    }
69     
70     public void draw(Shape s, float flatness) {
710        Shape shape = null;
720        if(transformer instanceof HyperbolicTransformer) {
730            shape = ((HyperbolicShapeTransformer)transformer).transform(s, flatness);
74         } else {
750            shape = ((ShapeTransformer)transformer).transform(s);
76         }
770        delegate.draw(shape);
78         
790    }
80     
81     /**
82      * transform the shape before letting the delegate fill it
83      */
84     public void fill(Shape s) {
850        Shape shape = ((ShapeTransformer)transformer).transform(s);
860        delegate.fill(shape);
870    }
88     
89     public void fill(Shape s, float flatness) {
900        Shape shape = null;
910        if(transformer instanceof HyperbolicTransformer) {
920            shape = ((HyperbolicShapeTransformer)transformer).transform(s, flatness);
93         } else {
940            shape = ((ShapeTransformer)transformer).transform(s);
95         }
960        delegate.fill(shape);
970    }
98     
99     /**
100      * transform the shape before letting the delegate apply 'hit'
101      * with it
102      */
103     public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
1040        Shape shape = ((ShapeTransformer)transformer).transform(s);
1050        return delegate.hit(rect, shape, onStroke);
106     }
107     
108     public Graphics create() {
1090        return delegate.create();
110     }
111     
112     public void dispose() {
1130        delegate.dispose();
1140    }
115     
116 }

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.