svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / impl / DrawGeometryShape.java @ 40435
History | View | Annotate | Download (3.48 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-${year} gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.impl; |
24 |
|
25 |
import java.awt.Rectangle; |
26 |
import java.awt.Shape; |
27 |
import java.awt.geom.AffineTransform; |
28 |
import java.awt.geom.FlatteningPathIterator; |
29 |
import java.awt.geom.PathIterator; |
30 |
import java.awt.geom.Point2D; |
31 |
import java.awt.geom.Rectangle2D; |
32 |
|
33 |
import org.gvsig.fmap.geom.Geometry; |
34 |
|
35 |
/**
|
36 |
* Shape implementation used to draw in AWT a {@link Geometry} object.
|
37 |
* The {@link Geometry} coordinates will become converted to integer after
|
38 |
* applying any needed transformations. Also they will be simplified by
|
39 |
* ignoring repeated points.
|
40 |
*
|
41 |
* @author gvSIG Team
|
42 |
*/
|
43 |
public class DrawGeometryShape implements Shape { |
44 |
|
45 |
private Geometry geometry;
|
46 |
private AffineTransform affineTransform = null; |
47 |
|
48 |
/**
|
49 |
* Constructor.
|
50 |
*
|
51 |
* @param geometry
|
52 |
* to draw in AWT
|
53 |
*/
|
54 |
public DrawGeometryShape(Geometry geometry) {
|
55 |
this.geometry = geometry;
|
56 |
} |
57 |
|
58 |
public DrawGeometryShape(Geometry geometry,
|
59 |
AffineTransform affineTransform) {
|
60 |
this.geometry = geometry;
|
61 |
this.affineTransform = affineTransform;
|
62 |
} |
63 |
|
64 |
public Rectangle getBounds() { |
65 |
return geometry.getBounds();
|
66 |
} |
67 |
|
68 |
public boolean contains(double x, double y) { |
69 |
return geometry.contains(x, y);
|
70 |
} |
71 |
|
72 |
public boolean contains(Point2D p) { |
73 |
return geometry.contains(p);
|
74 |
} |
75 |
|
76 |
public boolean intersects(double x, double y, double w, double h) { |
77 |
return geometry.intersects(x, y, w, h);
|
78 |
} |
79 |
|
80 |
public boolean intersects(Rectangle2D r) { |
81 |
return geometry.intersects(r);
|
82 |
} |
83 |
|
84 |
public boolean contains(double x, double y, double w, double h) { |
85 |
return geometry.contains(x, y, w, h);
|
86 |
} |
87 |
|
88 |
public Rectangle2D getBounds2D() { |
89 |
return geometry.getBounds2D();
|
90 |
} |
91 |
|
92 |
public boolean contains(Rectangle2D r) { |
93 |
return geometry.contains(r);
|
94 |
} |
95 |
|
96 |
public PathIterator getPathIterator(AffineTransform at) { |
97 |
AffineTransform applicableTransform = at;
|
98 |
|
99 |
if (affineTransform != null) { |
100 |
if (at != null && at.getType() != AffineTransform.TYPE_IDENTITY) { |
101 |
applicableTransform = (AffineTransform) at.clone();
|
102 |
applicableTransform.concatenate(affineTransform); |
103 |
} else {
|
104 |
applicableTransform = affineTransform; |
105 |
} |
106 |
} |
107 |
|
108 |
return new DrawGeneralPathXIterator(geometry.getGeneralPath(), |
109 |
applicableTransform); |
110 |
} |
111 |
|
112 |
public PathIterator getPathIterator(AffineTransform at, double flatness) { |
113 |
return new FlatteningPathIterator(getPathIterator(at), flatness); |
114 |
} |
115 |
|
116 |
} |