root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / geometryadapters / CircleAdapter.java @ 27419
History | View | Annotate | Download (5.16 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.Ellipse2D; |
47 |
import java.awt.geom.Point2D; |
48 |
|
49 |
import javax.print.attribute.PrintRequestAttributeSet; |
50 |
|
51 |
import org.gvsig.fmap.dal.exception.ReadException; |
52 |
import org.gvsig.fmap.geom.Geometry; |
53 |
import org.gvsig.fmap.geom.GeometryLocator; |
54 |
import org.gvsig.fmap.geom.GeometryManager; |
55 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
56 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
57 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
58 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
59 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
60 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
61 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleLineSymbol; |
62 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
63 |
import org.slf4j.Logger; |
64 |
import org.slf4j.LoggerFactory; |
65 |
|
66 |
import com.iver.cit.gvsig.gui.styling.SymbolSelector; |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
/**
|
72 |
* DOCUMENT ME!
|
73 |
*
|
74 |
* @author Vicente Caballero Navarro
|
75 |
*/
|
76 |
public class CircleAdapter extends GeometryAdapter { |
77 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
78 |
private static final Logger logger = LoggerFactory.getLogger(CircleAdapter.class); |
79 |
private Point2D pointPosition = new Point2D.Double(); |
80 |
private AffineTransform identity = new AffineTransform(); |
81 |
/**
|
82 |
* DOCUMENT ME!
|
83 |
*
|
84 |
* @return DOCUMENT ME!
|
85 |
*/
|
86 |
public Geometry getGeometry(AffineTransform at) { |
87 |
GeneralPathX polyLine; |
88 |
try {
|
89 |
polyLine = new GeneralPathX(geomManager.createSurface(getGPX(), SUBTYPES.GEOM2D));
|
90 |
polyLine.transform(at); |
91 |
return geomManager.createSurface(polyLine, SUBTYPES.GEOM2D);
|
92 |
} catch (CreateGeometryException e) {
|
93 |
logger.error("Error creating a surface", e);
|
94 |
} |
95 |
return null; |
96 |
} |
97 |
|
98 |
/**
|
99 |
* DOCUMENT ME!
|
100 |
*
|
101 |
* @param g DOCUMENT ME!
|
102 |
* @param at DOCUMENT ME!
|
103 |
* @param symbol DOCUMENT ME!
|
104 |
*/
|
105 |
public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) { |
106 |
Geometry shapeAux=getGeometry(at); |
107 |
symbol.draw(g,at,shapeAux, null);
|
108 |
// FGraphicUtilities.DrawShape(g, at, shapeAux, symbol);
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* DOCUMENT ME!
|
113 |
*
|
114 |
* @param g DOCUMENT ME!
|
115 |
* @param at DOCUMENT ME!
|
116 |
* @param andLastPoint DOCUMENT ME!
|
117 |
*/
|
118 |
public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) { |
119 |
if (getPoints().length > 0) { |
120 |
if (andLastPoint) {
|
121 |
obtainShape(pointPosition); |
122 |
} |
123 |
|
124 |
Geometry shapeAux=getGeometry(at); |
125 |
|
126 |
ILineSymbol symbol = SymbologyFactory.createDefaultLineSymbol(); |
127 |
SimpleLineSymbol redOutline = new SimpleLineSymbol();
|
128 |
redOutline.setLineColor(Color.red);
|
129 |
symbol.draw(g, identity, shapeAux, null);
|
130 |
} |
131 |
} |
132 |
|
133 |
/**
|
134 |
* DOCUMENT ME!
|
135 |
*
|
136 |
* @param p DOCUMENT ME!
|
137 |
*/
|
138 |
public void pointPosition(Point2D p) { |
139 |
pointPosition = p; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* DOCUMENT ME!
|
144 |
*
|
145 |
* @param p DOCUMENT ME!
|
146 |
*/
|
147 |
public void obtainShape(Point2D p) { |
148 |
Point2D[] points = getPoints(); |
149 |
|
150 |
double x = (points[0]).getX(); //-(pointPosition.getX()-((Point2D)points.get(0)).getX()); |
151 |
double y = (points[0]).getY(); //-(pointPosition.getY()-((Point2D)points.get(0)).getY()); |
152 |
double r = p.distance(points[0]); |
153 |
Ellipse2D ellipse = new Ellipse2D.Double(x - r, y - r, 2. * r, 2. * r); |
154 |
|
155 |
setGPX(new GeneralPathX(ellipse));
|
156 |
} |
157 |
|
158 |
public void print(Graphics2D g, AffineTransform at, ISymbol symbol, PrintRequestAttributeSet properties) { |
159 |
Geometry shapeAux=getGeometry(at); |
160 |
try {
|
161 |
symbol.print(g,at,shapeAux, properties); |
162 |
} catch (ReadException e) {
|
163 |
// TODO Auto-generated catch block
|
164 |
e.printStackTrace(); |
165 |
} |
166 |
} |
167 |
|
168 |
} |