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