root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / geometryadapters / PolyLineAdapter.java @ 27035
History | View | Annotate | Download (4.7 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 com.iver.cit.gvsig.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 javax.print.attribute.PrintRequestAttributeSet; |
49 |
|
50 |
import org.gvsig.fmap.dal.exception.ReadException; |
51 |
import org.gvsig.fmap.geom.Geometry; |
52 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
53 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
54 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
55 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
56 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
57 |
|
58 |
|
59 |
|
60 |
/**
|
61 |
* DOCUMENT ME!
|
62 |
*
|
63 |
* @author Vicente Caballero Navarro
|
64 |
*/
|
65 |
public class PolyLineAdapter extends GeometryAdapter { |
66 |
protected Point2D pointPosition = new Point2D.Double(); |
67 |
private AffineTransform identity = new AffineTransform(); |
68 |
|
69 |
/**
|
70 |
* DOCUMENT ME!
|
71 |
*
|
72 |
* @param p DOCUMENT ME!
|
73 |
*/
|
74 |
public void obtainShape(Point2D p) { |
75 |
Point2D[] points = getPoints(); |
76 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
77 |
points.length); |
78 |
|
79 |
if (points.length > 0) { |
80 |
elShape.moveTo((points[0]).getX(),
|
81 |
(points[0]).getY());
|
82 |
} |
83 |
|
84 |
for (int i = 0; i < points.length; i++) { |
85 |
elShape.lineTo((points[i]).getX(), |
86 |
(points[i]).getY()); |
87 |
} |
88 |
|
89 |
if (points.length > 0) { |
90 |
elShape.lineTo(p.getX(), p.getY()); |
91 |
} |
92 |
|
93 |
setGPX(elShape); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* DOCUMENT ME!
|
98 |
*
|
99 |
* @return DOCUMENT ME!
|
100 |
*/
|
101 |
public Geometry getGeometry(AffineTransform at) { |
102 |
GeneralPathX polyLine = new GeneralPathX(UtilFunctions.createCurve(getGPX()));
|
103 |
polyLine.transform(at); |
104 |
|
105 |
return UtilFunctions.createCurve(polyLine);
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* DOCUMENT ME!
|
110 |
*
|
111 |
* @param g DOCUMENT ME!
|
112 |
* @param at DOCUMENT ME!
|
113 |
* @param symbol DOCUMENT ME!
|
114 |
*/
|
115 |
public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) { |
116 |
Geometry shapeAux =getGeometry(at); |
117 |
symbol.draw(g,at,shapeAux, null);
|
118 |
// FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
|
119 |
} |
120 |
public void print(Graphics2D g, AffineTransform at, ISymbol symbol,PrintRequestAttributeSet properties) { |
121 |
Geometry shapeAux =getGeometry(at); |
122 |
try {
|
123 |
symbol.print(g,at,shapeAux, properties); |
124 |
} catch (ReadException e) {
|
125 |
// TODO Auto-generated catch block
|
126 |
e.printStackTrace(); |
127 |
} |
128 |
// FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
|
129 |
} |
130 |
/**
|
131 |
* DOCUMENT ME!
|
132 |
*
|
133 |
* @param g DOCUMENT ME!
|
134 |
* @param at DOCUMENT ME!
|
135 |
* @param andLastPoint DOCUMENT ME!
|
136 |
*/
|
137 |
public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) { |
138 |
if (andLastPoint) {
|
139 |
obtainShape(pointPosition); |
140 |
} |
141 |
|
142 |
Geometry shapeAux=getGeometry(at); |
143 |
//ISymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
144 |
ILineSymbol symbol = SymbologyFactory.createDefaultLineSymbol(); |
145 |
symbol.setLineColor(Color.RED);
|
146 |
symbol.draw(g, identity, shapeAux, null);
|
147 |
// FGraphicUtilities.DrawShape(g, identity, shapeAux,
|
148 |
// new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red));
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* DOCUMENT ME!
|
153 |
*
|
154 |
* @param p DOCUMENT ME!
|
155 |
*/
|
156 |
public void pointPosition(Point2D p) { |
157 |
pointPosition = p; |
158 |
} |
159 |
} |