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.shape; | |
10 | ||
11 | import java.awt.Component; | |
12 | import java.awt.Shape; | |
13 | import java.awt.geom.GeneralPath; | |
14 | import java.awt.geom.PathIterator; | |
15 | import java.awt.geom.Point2D; | |
16 | ||
17 | import edu.uci.ics.jung.visualization.transform.MagnifyTransformer; | |
18 | import edu.uci.ics.jung.visualization.transform.MutableTransformer; | |
19 | ||
20 | /** | |
21 | * MagnifyShapeTransformer extends MagnifyTransformer and | |
22 | * adds implementations for methods in ShapeTransformer. | |
23 | * It modifies the shapes (Vertex, Edge, and Arrowheads) so that | |
24 | * they are enlarged by the magnify transformation | |
25 | * | |
26 | * @author Tom Nelson - RABA Technologies | |
27 | * | |
28 | * | |
29 | */ | |
30 | public class MagnifyShapeTransformer extends MagnifyTransformer | |
31 | implements ShapeTransformer { | |
32 | ||
33 | /** | |
34 | * Create an instance, setting values from the passed component | |
35 | * and registering to listen for size changes on the component. | |
36 | */ | |
37 | public MagnifyShapeTransformer(Component component) { | |
38 | 0 | this(component, null); |
39 | 0 | } |
40 | ||
41 | /** | |
42 | * Create an instance, setting values from the passed component | |
43 | * and registering to listen for size changes on the component, | |
44 | * with a possibly shared transform <code>delegate</code>. | |
45 | */ | |
46 | public MagnifyShapeTransformer(Component component, MutableTransformer delegate) { | |
47 | 0 | super(component, delegate); |
48 | 0 | } |
49 | ||
50 | /** | |
51 | * Transform the supplied shape with the overridden transform | |
52 | * method so that the shape is distorted by the hyperbolic | |
53 | * transform. | |
54 | * @param shape a shape to transform | |
55 | * @return a GeneralPath for the transformed shape | |
56 | */ | |
57 | public Shape transform(Shape shape) { | |
58 | 0 | return transform(shape, 0); |
59 | } | |
60 | public Shape transform(Shape shape, float flatness) { | |
61 | 0 | GeneralPath newPath = new GeneralPath(); |
62 | 0 | float[] coords = new float[6]; |
63 | 0 | PathIterator iterator = null; |
64 | 0 | if(flatness == 0) { |
65 | 0 | iterator = shape.getPathIterator(null); |
66 | } else { | |
67 | 0 | iterator = shape.getPathIterator(null, flatness); |
68 | } | |
69 | for( ; | |
70 | 0 | iterator.isDone() == false; |
71 | 0 | iterator.next()) { |
72 | 0 | int type = iterator.currentSegment(coords); |
73 | 0 | switch(type) { |
74 | case PathIterator.SEG_MOVETO: | |
75 | 0 | Point2D p = transform(new Point2D.Float(coords[0], coords[1])); |
76 | 0 | newPath.moveTo((float)p.getX(), (float)p.getY()); |
77 | 0 | break; |
78 | ||
79 | case PathIterator.SEG_LINETO: | |
80 | 0 | p = transform(new Point2D.Float(coords[0], coords[1])); |
81 | 0 | newPath.lineTo((float)p.getX(), (float) p.getY()); |
82 | 0 | break; |
83 | ||
84 | case PathIterator.SEG_QUADTO: | |
85 | 0 | p = transform(new Point2D.Float(coords[0], coords[1])); |
86 | 0 | Point2D q = transform(new Point2D.Float(coords[2], coords[3])); |
87 | 0 | newPath.quadTo((float)p.getX(), (float)p.getY(), (float)q.getX(), (float)q.getY()); |
88 | 0 | break; |
89 | ||
90 | case PathIterator.SEG_CUBICTO: | |
91 | 0 | p = transform(new Point2D.Float(coords[0], coords[1])); |
92 | 0 | q = transform(new Point2D.Float(coords[2], coords[3])); |
93 | 0 | Point2D r = transform(new Point2D.Float(coords[4], coords[5])); |
94 | 0 | newPath.curveTo((float)p.getX(), (float)p.getY(), |
95 | (float)q.getX(), (float)q.getY(), | |
96 | (float)r.getX(), (float)r.getY()); | |
97 | 0 | break; |
98 | ||
99 | case PathIterator.SEG_CLOSE: | |
100 | 0 | newPath.closePath(); |
101 | break; | |
102 | ||
103 | } | |
104 | } | |
105 | 0 | return newPath; |
106 | } | |
107 | ||
108 | public Shape inverseTransform(Shape shape) { | |
109 | 0 | GeneralPath newPath = new GeneralPath(); |
110 | 0 | float[] coords = new float[6]; |
111 | 0 | for(PathIterator iterator=shape.getPathIterator(null); |
112 | 0 | iterator.isDone() == false; |
113 | 0 | iterator.next()) { |
114 | 0 | int type = iterator.currentSegment(coords); |
115 | 0 | switch(type) { |
116 | case PathIterator.SEG_MOVETO: | |
117 | 0 | Point2D p = inverseTransform(new Point2D.Float(coords[0], coords[1])); |
118 | 0 | newPath.moveTo((float)p.getX(), (float)p.getY()); |
119 | 0 | break; |
120 | ||
121 | case PathIterator.SEG_LINETO: | |
122 | 0 | p = inverseTransform(new Point2D.Float(coords[0], coords[1])); |
123 | 0 | newPath.lineTo((float)p.getX(), (float) p.getY()); |
124 | 0 | break; |
125 | ||
126 | case PathIterator.SEG_QUADTO: | |
127 | 0 | p = inverseTransform(new Point2D.Float(coords[0], coords[1])); |
128 | 0 | Point2D q = inverseTransform(new Point2D.Float(coords[2], coords[3])); |
129 | 0 | newPath.quadTo((float)p.getX(), (float)p.getY(), (float)q.getX(), (float)q.getY()); |
130 | 0 | break; |
131 | ||
132 | case PathIterator.SEG_CUBICTO: | |
133 | 0 | p = inverseTransform(new Point2D.Float(coords[0], coords[1])); |
134 | 0 | q = inverseTransform(new Point2D.Float(coords[2], coords[3])); |
135 | 0 | Point2D r = inverseTransform(new Point2D.Float(coords[4], coords[5])); |
136 | 0 | newPath.curveTo((float)p.getX(), (float)p.getY(), |
137 | (float)q.getX(), (float)q.getY(), | |
138 | (float)r.getX(), (float)r.getY()); | |
139 | 0 | break; |
140 | ||
141 | case PathIterator.SEG_CLOSE: | |
142 | 0 | newPath.closePath(); |
143 | break; | |
144 | ||
145 | } | |
146 | } | |
147 | 0 | return newPath; |
148 | } | |
149 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |