root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / adapter / PolyLineAdapter.java @ 9641
History | View | Annotate | Download (3.91 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.fmap.core.adapter; |
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 com.iver.cit.gvsig.fmap.core.FPolyline2D; |
49 |
import com.iver.cit.gvsig.fmap.core.FShape; |
50 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
51 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
52 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
53 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
54 |
|
55 |
|
56 |
/**
|
57 |
* DOCUMENT ME!
|
58 |
*
|
59 |
* @author Vicente Caballero Navarro
|
60 |
*/
|
61 |
public class PolyLineAdapter extends GeometryAdapter { |
62 |
private Point2D pointPosition = new Point2D.Double(); |
63 |
private AffineTransform identity = new AffineTransform(); |
64 |
|
65 |
/**
|
66 |
* DOCUMENT ME!
|
67 |
*
|
68 |
* @param p DOCUMENT ME!
|
69 |
*/
|
70 |
public void obtainShape(Point2D p) { |
71 |
Point2D[] points = getPoints(); |
72 |
GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
73 |
points.length); |
74 |
|
75 |
if (points.length > 0) { |
76 |
elShape.moveTo(((Point2D) points[0]).getX(), |
77 |
((Point2D) points[0]).getY()); |
78 |
} |
79 |
|
80 |
for (int i = 0; i < points.length; i++) { |
81 |
elShape.lineTo(((Point2D) points[i]).getX(),
|
82 |
((Point2D) points[i]).getY());
|
83 |
} |
84 |
|
85 |
if (points.length > 0) { |
86 |
elShape.lineTo(p.getX(), p.getY()); |
87 |
} |
88 |
|
89 |
setGPX(elShape); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* DOCUMENT ME!
|
94 |
*
|
95 |
* @return DOCUMENT ME!
|
96 |
*/
|
97 |
protected FShape getShape(AffineTransform at) { |
98 |
GeneralPathX polyLine = new GeneralPathX(new FPolyline2D(getGPX())); |
99 |
polyLine.transform(at); |
100 |
|
101 |
return new FPolyline2D(polyLine); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* DOCUMENT ME!
|
106 |
*
|
107 |
* @param g DOCUMENT ME!
|
108 |
* @param at DOCUMENT ME!
|
109 |
* @param symbol DOCUMENT ME!
|
110 |
*/
|
111 |
public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) { |
112 |
FShape shapeAux =getShape(at); |
113 |
symbol.draw(g,at,shapeAux); |
114 |
// FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
|
115 |
} |
116 |
|
117 |
/**
|
118 |
* DOCUMENT ME!
|
119 |
*
|
120 |
* @param g DOCUMENT ME!
|
121 |
* @param at DOCUMENT ME!
|
122 |
* @param andLastPoint DOCUMENT ME!
|
123 |
*/
|
124 |
public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) { |
125 |
if (andLastPoint) {
|
126 |
obtainShape(pointPosition); |
127 |
} |
128 |
|
129 |
FShape shapeAux=getShape(at); |
130 |
ISymbol symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red); |
131 |
symbol.draw(g, identity, shapeAux); |
132 |
// FGraphicUtilities.DrawShape(g, identity, shapeAux,
|
133 |
// new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red));
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* DOCUMENT ME!
|
138 |
*
|
139 |
* @param p DOCUMENT ME!
|
140 |
*/
|
141 |
public void pointPosition(Point2D p) { |
142 |
pointPosition = p; |
143 |
} |
144 |
} |