root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGraphics.java @ 2183
History | View | Annotate | Download (9.05 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-jun-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout.fframes; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
import com.iver.cit.gvsig.fmap.DriverException; |
49 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
50 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
51 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
52 |
import com.iver.cit.gvsig.fmap.core.FShape; |
53 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
56 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
57 |
import com.iver.cit.gvsig.gui.layout.Layout; |
58 |
|
59 |
import com.iver.utiles.XMLEntity; |
60 |
|
61 |
import java.awt.Color; |
62 |
import java.awt.Graphics2D; |
63 |
import java.awt.geom.AffineTransform; |
64 |
import java.awt.geom.Line2D; |
65 |
import java.awt.geom.Point2D; |
66 |
import java.awt.geom.Rectangle2D; |
67 |
import java.awt.image.BufferedImage; |
68 |
|
69 |
|
70 |
/**
|
71 |
* FFrame para contener un gr?fico.
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class FFrameGraphics extends FFrame { |
76 |
private int m_type = FConstant.SHAPE_TYPE_POINT; |
77 |
private FSymbol m_symbol = null; |
78 |
private Color m_color = null; |
79 |
private AffineTransform mT = null; |
80 |
private AffineTransform aT = null; |
81 |
|
82 |
/**
|
83 |
* Crea un nuevo FFrameGraphics.
|
84 |
*/
|
85 |
public FFrameGraphics() {
|
86 |
mT = new AffineTransform(); |
87 |
mT.setToIdentity(); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* Rellena el color que se utlizar? para dibujar el s?mbolo.
|
92 |
*
|
93 |
* @param color
|
94 |
*/
|
95 |
public void setColor(Color color) { |
96 |
m_color = color; |
97 |
} |
98 |
|
99 |
/**
|
100 |
* Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
|
101 |
* par?metro.
|
102 |
*
|
103 |
* @param type tipo de gr?fico.
|
104 |
* @param at Transformada.
|
105 |
*/
|
106 |
public void update(int type, AffineTransform at) { |
107 |
m_type = type; |
108 |
aT = at; |
109 |
|
110 |
if (m_color == null) { |
111 |
m_color = Color.red;
|
112 |
} |
113 |
|
114 |
switch (m_type) {
|
115 |
case (Layout.POINT):
|
116 |
m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
|
117 |
|
118 |
break;
|
119 |
|
120 |
case (Layout.RECTANGLESIMPLE):
|
121 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
122 |
m_symbol.setColor(null);
|
123 |
|
124 |
break;
|
125 |
|
126 |
case (Layout.LINE):
|
127 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
128 |
|
129 |
break;
|
130 |
|
131 |
case (Layout.POLYLINE):
|
132 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
133 |
|
134 |
break;
|
135 |
|
136 |
case (Layout.POLYGON):
|
137 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
138 |
|
139 |
break;
|
140 |
|
141 |
case (Layout.CIRCLE):
|
142 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
143 |
m_symbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
144 |
m_symbol.setOutlined(true);
|
145 |
m_symbol.setOutlineColor(Color.red);
|
146 |
m_symbol.setColor(null);
|
147 |
|
148 |
break;
|
149 |
} |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Devuelve el FSymbol que se representa.
|
154 |
*
|
155 |
* @return DOCUMENT ME!
|
156 |
*/
|
157 |
public FSymbol getFSymbol() {
|
158 |
return m_symbol;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Rellena el FSymbol que se representara al dibujar.
|
163 |
*
|
164 |
* @param symbol
|
165 |
*/
|
166 |
public void setFSymbol(FSymbol symbol) { |
167 |
m_symbol = symbol; |
168 |
} |
169 |
|
170 |
/**
|
171 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
172 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
173 |
* de dibujar.
|
174 |
*
|
175 |
* @param g Graphics
|
176 |
* @param at Transformada afin.
|
177 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
178 |
* @param imgBase DOCUMENT ME!
|
179 |
*/
|
180 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
181 |
BufferedImage imgBase) {
|
182 |
Rectangle2D.Double rect = getBoundingBox(at);
|
183 |
|
184 |
if (intersects(rv, rect)) {
|
185 |
g.setColor(Color.black);
|
186 |
|
187 |
FShape m_shape = null;
|
188 |
|
189 |
switch (m_type) {
|
190 |
case (Layout.POINT):
|
191 |
|
192 |
Point2D.Double p = new Point2D.Double((int) rect.getCenterX(), |
193 |
(int) rect.getCenterY());
|
194 |
m_shape = new FPoint2D(p.x, p.y);
|
195 |
|
196 |
if (rect.width < rect.height) {
|
197 |
m_symbol.setSize((int) rect.width - 10); |
198 |
} else {
|
199 |
m_symbol.setSize((int) rect.height - 10); |
200 |
} |
201 |
|
202 |
///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
203 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
204 |
|
205 |
break;
|
206 |
|
207 |
case (Layout.RECTANGLESIMPLE):
|
208 |
|
209 |
GeneralPathX rectAux = new GeneralPathX(rect);
|
210 |
rectAux.transform(mT); |
211 |
m_shape = new FPolygon2D(rectAux); //FConstant.SHAPE_TYPE_POLYLINE, rectAux); |
212 |
|
213 |
///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
214 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
215 |
|
216 |
break;
|
217 |
|
218 |
case (Layout.LINE):
|
219 |
|
220 |
Line2D line = new Line2D.Double(); |
221 |
line.setLine(new Point2D.Double(rect.x, rect.y), |
222 |
new Point2D.Double(rect.getMaxX(), rect.getMaxY())); |
223 |
|
224 |
GeneralPathX rectA = new GeneralPathX(line);
|
225 |
rectA.transform(mT); |
226 |
m_shape = new FPolyline2D(rectA);
|
227 |
|
228 |
///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
229 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
230 |
|
231 |
//g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
|
232 |
break;
|
233 |
|
234 |
case (Layout.POLYLINE):
|
235 |
g.drawString("POLYLINE", (float) rect.getCenterX(), |
236 |
(float) rect.getCenterY());
|
237 |
|
238 |
break;
|
239 |
|
240 |
case (Layout.POLYGON):
|
241 |
g.drawString("POLYGON", (float) rect.getCenterX(), |
242 |
(float) rect.getCenterY());
|
243 |
|
244 |
break;
|
245 |
|
246 |
case (Layout.CIRCLE):
|
247 |
|
248 |
Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(), |
249 |
(int) rect.getCenterY());
|
250 |
m_shape = new FPoint2D(pc.x, pc.y);
|
251 |
|
252 |
if (rect.width < rect.height) {
|
253 |
m_symbol.setSize((int) rect.width - 10); |
254 |
} else {
|
255 |
m_symbol.setSize((int) rect.height - 10); |
256 |
} |
257 |
|
258 |
///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
259 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
260 |
|
261 |
break;
|
262 |
} |
263 |
} |
264 |
} |
265 |
|
266 |
/**
|
267 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
268 |
*/
|
269 |
public XMLEntity getXMLEntity() {
|
270 |
XMLEntity xml = new XMLEntity();
|
271 |
xml.putProperty("className",this.getClass().getName()); |
272 |
xml.putProperty("m_name", m_name);
|
273 |
xml.putProperty("x", getBoundBox().x);
|
274 |
xml.putProperty("y", getBoundBox().y);
|
275 |
xml.putProperty("w", getBoundBox().width);
|
276 |
xml.putProperty("h", getBoundBox().height);
|
277 |
xml.putProperty("m_Selected", m_Selected);
|
278 |
xml.putProperty("type", Layout.GRAPHICS);
|
279 |
xml.putProperty("m_type", m_type);
|
280 |
xml.putProperty("tag", getTag());
|
281 |
xml.addChild(m_symbol.getXMLEntity()); |
282 |
return xml;
|
283 |
} |
284 |
|
285 |
/**
|
286 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
287 |
*
|
288 |
* @param xml XMLEntity
|
289 |
*
|
290 |
* @return Objeto de esta clase.
|
291 |
*/
|
292 |
public static FFrameGraphics createFFrameGraphics(XMLEntity xml) { |
293 |
FFrameGraphics fframe = new FFrameGraphics();
|
294 |
|
295 |
if (xml.getIntProperty("m_Selected") != 0) { |
296 |
fframe.setSelected(true);
|
297 |
} else {
|
298 |
fframe.setSelected(false);
|
299 |
} |
300 |
|
301 |
/// fframe.m_type = xml.getIntProperty("m_type");
|
302 |
/// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
|
303 |
return fframe;
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
308 |
*/
|
309 |
public void updateNum() { |
310 |
} |
311 |
|
312 |
/**
|
313 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
|
314 |
*/
|
315 |
public int getNum() { |
316 |
return 0; |
317 |
} |
318 |
|
319 |
/**
|
320 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
321 |
* com.iver.cit.gvsig.project.Project)
|
322 |
*/
|
323 |
public void setXMLEntity(XMLEntity xml, Layout p) { |
324 |
m_Selected=xml.getIntProperty("m_Selected");
|
325 |
m_type=xml.getIntProperty("m_type");
|
326 |
m_symbol=FSymbol.createFromXML(xml.getChild(0));
|
327 |
} |
328 |
|
329 |
/**
|
330 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
331 |
* com.iver.cit.gvsig.project.Project)
|
332 |
*/
|
333 |
public void setXMLEntity03(XMLEntity xml, Layout p) { |
334 |
m_Selected=xml.getIntProperty("m_Selected");
|
335 |
m_type=xml.getIntProperty("m_type");
|
336 |
m_symbol=FSymbol.createFromXML03(xml.getChild(0));
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
341 |
*/
|
342 |
public String getNameFFrame() { |
343 |
return PluginServices.getText(this, "Gr?ficos") + num; |
344 |
} |
345 |
|
346 |
/**
|
347 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
348 |
* java.awt.geom.AffineTransform)
|
349 |
*/
|
350 |
public void print(Graphics2D g, AffineTransform at) |
351 |
throws DriverException {
|
352 |
draw(g, at, null, null); |
353 |
} |
354 |
} |