Line | Hits | Source |
---|---|---|
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) { | |
40 | 0 | this(transformer, null); |
41 | 0 | } |
42 | ||
43 | public TransformingGraphics(Transformer transformer, Graphics2D delegate) { | |
44 | 0 | super(delegate); |
45 | 0 | this.transformer = transformer; |
46 | 0 | } |
47 | ||
48 | /** | |
49 | * @return Returns the transformer. | |
50 | */ | |
51 | public Transformer getTransformer() { | |
52 | 0 | return transformer; |
53 | } | |
54 | ||
55 | /** | |
56 | * @param transformer The transformer to set. | |
57 | */ | |
58 | public void setTransformer(Transformer transformer) { | |
59 | 0 | this.transformer = transformer; |
60 | 0 | } |
61 | ||
62 | /** | |
63 | * transform the shape before letting the delegate draw it | |
64 | */ | |
65 | public void draw(Shape s) { | |
66 | 0 | Shape shape = ((ShapeTransformer)transformer).transform(s); |
67 | 0 | delegate.draw(shape); |
68 | 0 | } |
69 | ||
70 | public void draw(Shape s, float flatness) { | |
71 | 0 | Shape shape = null; |
72 | 0 | if(transformer instanceof HyperbolicTransformer) { |
73 | 0 | shape = ((HyperbolicShapeTransformer)transformer).transform(s, flatness); |
74 | } else { | |
75 | 0 | shape = ((ShapeTransformer)transformer).transform(s); |
76 | } | |
77 | 0 | delegate.draw(shape); |
78 | ||
79 | 0 | } |
80 | ||
81 | /** | |
82 | * transform the shape before letting the delegate fill it | |
83 | */ | |
84 | public void fill(Shape s) { | |
85 | 0 | Shape shape = ((ShapeTransformer)transformer).transform(s); |
86 | 0 | delegate.fill(shape); |
87 | 0 | } |
88 | ||
89 | public void fill(Shape s, float flatness) { | |
90 | 0 | Shape shape = null; |
91 | 0 | if(transformer instanceof HyperbolicTransformer) { |
92 | 0 | shape = ((HyperbolicShapeTransformer)transformer).transform(s, flatness); |
93 | } else { | |
94 | 0 | shape = ((ShapeTransformer)transformer).transform(s); |
95 | } | |
96 | 0 | delegate.fill(shape); |
97 | 0 | } |
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) { | |
104 | 0 | Shape shape = ((ShapeTransformer)transformer).transform(s); |
105 | 0 | return delegate.hit(rect, shape, onStroke); |
106 | } | |
107 | ||
108 | public Graphics create() { | |
109 | 0 | return delegate.create(); |
110 | } | |
111 | ||
112 | public void dispose() { | |
113 | 0 | delegate.dispose(); |
114 | 0 | } |
115 | ||
116 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |