root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / geometryadapters / PolyLineAdapter.java @ 30011
History | View | Annotate | Download (4.87 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.app.project.documents.layout.geometryadapters; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.AffineTransform; |
46 |
import java.awt.geom.Point2D; |
47 |
|
48 |
import org.gvsig.compat.print.PrintAttributes; |
49 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.GeometryLocator; |
51 |
import org.gvsig.fmap.geom.GeometryManager; |
52 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
53 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
54 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
55 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
56 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
57 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
58 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
59 |
import org.slf4j.Logger; |
60 |
import org.slf4j.LoggerFactory; |
61 |
|
62 |
|
63 |
|
64 |
/**
|
65 |
* DOCUMENT ME!
|
66 |
*
|
67 |
* @author Vicente Caballero Navarro
|
68 |
*/
|
69 |
public class PolyLineAdapter extends GeometryAdapter { |
70 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
71 |
private static final Logger logger = LoggerFactory.getLogger(PolyLineAdapter.class); |
72 |
protected Point2D pointPosition = new Point2D.Double(); |
73 |
private AffineTransform identity = new AffineTransform(); |
74 |
|
75 |
private MapContextManager mapContextManager = MapContextLocator
|
76 |
.getMapContextManager(); |
77 |
|
78 |
/**
|
79 |
* DOCUMENT ME!
|
80 |
*
|
81 |
* @param p DOCUMENT ME!
|
82 |
*/
|
83 |
public void obtainShape(Point2D p) { |
84 |
Point2D[] points = getPoints(); |
85 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
86 |
points.length); |
87 |
|
88 |
if (points.length > 0) { |
89 |
elShape.moveTo((points[0]).getX(),
|
90 |
(points[0]).getY());
|
91 |
} |
92 |
|
93 |
for (int i = 0; i < points.length; i++) { |
94 |
elShape.lineTo((points[i]).getX(), |
95 |
(points[i]).getY()); |
96 |
} |
97 |
|
98 |
if (points.length > 0) { |
99 |
elShape.lineTo(p.getX(), p.getY()); |
100 |
} |
101 |
|
102 |
setGPX(elShape); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* DOCUMENT ME!
|
107 |
*
|
108 |
* @return DOCUMENT ME!
|
109 |
*/
|
110 |
public Geometry getGeometry(AffineTransform at) { |
111 |
GeneralPathX polyLine; |
112 |
try {
|
113 |
polyLine = new GeneralPathX(geomManager.createCurve(getGPX(), SUBTYPES.GEOM2D).getPathIterator(null)); |
114 |
polyLine.transform(at); |
115 |
|
116 |
return geomManager.createCurve(polyLine, SUBTYPES.GEOM2D);
|
117 |
} catch (CreateGeometryException e) {
|
118 |
logger.error("Error creating a curve", e);
|
119 |
} |
120 |
return null; |
121 |
} |
122 |
|
123 |
/**
|
124 |
* DOCUMENT ME!
|
125 |
*
|
126 |
* @param g DOCUMENT ME!
|
127 |
* @param at DOCUMENT ME!
|
128 |
* @param symbol DOCUMENT ME!
|
129 |
*/
|
130 |
public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) { |
131 |
Geometry shapeAux =getGeometry(at); |
132 |
symbol.draw(g,at,shapeAux, null);
|
133 |
// FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
|
134 |
} |
135 |
public void print(Graphics2D g, AffineTransform at, ISymbol symbol, |
136 |
PrintAttributes properties) { |
137 |
Geometry shapeAux =getGeometry(at); |
138 |
symbol.print(g,at,shapeAux, properties); |
139 |
} |
140 |
/**
|
141 |
* DOCUMENT ME!
|
142 |
*
|
143 |
* @param g DOCUMENT ME!
|
144 |
* @param at DOCUMENT ME!
|
145 |
* @param andLastPoint DOCUMENT ME!
|
146 |
*/
|
147 |
public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) { |
148 |
if (andLastPoint) {
|
149 |
obtainShape(pointPosition); |
150 |
} |
151 |
|
152 |
Geometry shapeAux=getGeometry(at); |
153 |
//ISymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
154 |
ILineSymbol symbol = (ILineSymbol) mapContextManager.createSymbol( |
155 |
ILineSymbol.SYMBOL_NAME); |
156 |
symbol.setLineColor(Color.RED);
|
157 |
symbol.draw(g, identity, shapeAux, null);
|
158 |
// FGraphicUtilities.DrawShape(g, identity, shapeAux,
|
159 |
// new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red));
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* DOCUMENT ME!
|
164 |
*
|
165 |
* @param p DOCUMENT ME!
|
166 |
*/
|
167 |
public void pointPosition(Point2D p) { |
168 |
pointPosition = p; |
169 |
} |
170 |
} |