svn-gvsig-desktop / tags / Root_v06 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameGraphics.java @ 4811
History | View | Annotate | Download (13 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 |
|
49 |
import com.iver.cit.gvsig.fmap.DriverException; |
50 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
51 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
52 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
53 |
import com.iver.cit.gvsig.fmap.core.FShape; |
54 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
56 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
57 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
58 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
59 |
import com.iver.cit.gvsig.gui.layout.Layout; |
60 |
import com.iver.cit.gvsig.gui.project.SaveException; |
61 |
////import com.iver.cit.gvsig.gui.layout.Line;
|
62 |
|
63 |
import com.iver.utiles.XMLEntity; |
64 |
|
65 |
import java.awt.Color; |
66 |
import java.awt.Graphics2D; |
67 |
import java.awt.Shape; |
68 |
import java.awt.geom.AffineTransform; |
69 |
import java.awt.geom.Ellipse2D; |
70 |
import java.awt.geom.Line2D; |
71 |
import java.awt.geom.Point2D; |
72 |
import java.awt.geom.Rectangle2D; |
73 |
import java.awt.image.BufferedImage; |
74 |
|
75 |
|
76 |
/**
|
77 |
* FFrame para contener un gr?fico.
|
78 |
*
|
79 |
* @author Vicente Caballero Navarro
|
80 |
*/
|
81 |
public class FFrameGraphics extends FFrame { |
82 |
private int m_type = FConstant.SHAPE_TYPE_POINT; |
83 |
private FSymbol m_symbol = null; |
84 |
private Color m_color = null; |
85 |
private AffineTransform mT = null; |
86 |
private int size = 0; |
87 |
////private Line polyline;
|
88 |
//private AffineTransform aT = null;
|
89 |
|
90 |
/**
|
91 |
* Crea un nuevo FFrameGraphics.
|
92 |
*/
|
93 |
public FFrameGraphics() {
|
94 |
mT = new AffineTransform(); |
95 |
mT.setToIdentity(); |
96 |
} |
97 |
/* public FFrameGraphics(Line line){
|
98 |
mT = new AffineTransform();
|
99 |
mT.setToIdentity();
|
100 |
polyline=line;
|
101 |
}
|
102 |
*/
|
103 |
/**
|
104 |
* Rellena el color que se utlizar? para dibujar el s?mbolo.
|
105 |
*
|
106 |
* @param color
|
107 |
*/
|
108 |
public void setColor(Color color) { |
109 |
m_color = color; |
110 |
} |
111 |
|
112 |
/**
|
113 |
* Actualiza el Fsymbol a partir del tipo de Gr?fico que se pase como
|
114 |
* par?metro.
|
115 |
*
|
116 |
* @param type tipo de gr?fico.
|
117 |
* @param at Transformada.
|
118 |
*/
|
119 |
public void update(int type, AffineTransform at) { |
120 |
m_type = type; |
121 |
|
122 |
//aT = at;
|
123 |
if (m_color == null) { |
124 |
m_color = Color.red;
|
125 |
} |
126 |
|
127 |
switch (m_type) {
|
128 |
case (Layout.POINT):
|
129 |
m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
|
130 |
|
131 |
break;
|
132 |
|
133 |
case (Layout.RECTANGLESIMPLE):
|
134 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
135 |
m_symbol.setColor(null);
|
136 |
|
137 |
break;
|
138 |
|
139 |
case (Layout.LINE):
|
140 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
141 |
|
142 |
break;
|
143 |
|
144 |
case (Layout.POLYLINE):
|
145 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
146 |
|
147 |
break;
|
148 |
|
149 |
case (Layout.POLYGON):
|
150 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
151 |
|
152 |
break;
|
153 |
|
154 |
case (Layout.CIRCLE):
|
155 |
m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
156 |
m_symbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
157 |
m_symbol.setOutlined(true);
|
158 |
m_symbol.setOutlineColor(Color.red);
|
159 |
m_symbol.setColor(null);
|
160 |
|
161 |
break;
|
162 |
} |
163 |
} |
164 |
|
165 |
/**
|
166 |
* Devuelve el FSymbol que se representa.
|
167 |
*
|
168 |
* @return DOCUMENT ME!
|
169 |
*/
|
170 |
public FSymbol getFSymbol() {
|
171 |
return m_symbol;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* Rellena el FSymbol que se representara al dibujar.
|
176 |
*
|
177 |
* @param symbol
|
178 |
*/
|
179 |
public void setFSymbol(FSymbol symbol) { |
180 |
m_symbol = symbol; |
181 |
} |
182 |
|
183 |
/**
|
184 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
185 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
186 |
* de dibujar.
|
187 |
*
|
188 |
* @param g Graphics
|
189 |
* @param at Transformada afin.
|
190 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
191 |
* @param imgBase DOCUMENT ME!
|
192 |
*/
|
193 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
194 |
BufferedImage imgBase) {
|
195 |
Rectangle2D.Double rect = getBoundingBox(at);
|
196 |
g.rotate(Math.toRadians(getRotation()), rect.x + (rect.width / 2), |
197 |
rect.y + (rect.height / 2));
|
198 |
|
199 |
if (intersects(rv, rect)) {
|
200 |
g.setColor(Color.black);
|
201 |
|
202 |
FShape m_shape = null;
|
203 |
|
204 |
switch (m_type) {
|
205 |
case (Layout.POINT):
|
206 |
|
207 |
if (size != 0) { |
208 |
rect.width = size + 10;
|
209 |
rect.height = size + 10;
|
210 |
setBoundBox(FLayoutUtilities.toSheetRect(rect, at)); |
211 |
size = 0;
|
212 |
} else {
|
213 |
if (rect.width < rect.height) {
|
214 |
m_symbol.setSize((int) rect.width - 10); |
215 |
} else {
|
216 |
m_symbol.setSize((int) rect.height - 10); |
217 |
} |
218 |
} |
219 |
|
220 |
Point2D.Double p = new Point2D.Double((int) rect.getCenterX(), |
221 |
(int) rect.getCenterY());
|
222 |
m_shape = new FPoint2D(p.x, p.y);
|
223 |
|
224 |
///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
225 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
226 |
|
227 |
break;
|
228 |
|
229 |
case (Layout.RECTANGLESIMPLE):
|
230 |
|
231 |
GeneralPathX rectAux = new GeneralPathX(rect);
|
232 |
rectAux.transform(mT); |
233 |
m_shape = new FPolygon2D(rectAux); //FConstant.SHAPE_TYPE_POLYLINE, rectAux); |
234 |
|
235 |
///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
236 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
237 |
|
238 |
break;
|
239 |
|
240 |
case (Layout.LINE):
|
241 |
|
242 |
Line2D line = new Line2D.Double(); |
243 |
line.setLine(new Point2D.Double(rect.x, rect.y), |
244 |
new Point2D.Double(rect.getMaxX(), rect.getMaxY())); |
245 |
|
246 |
GeneralPathX rectA = new GeneralPathX(line);
|
247 |
rectA.transform(mT); |
248 |
m_shape = new FPolyline2D(rectA);
|
249 |
|
250 |
///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
251 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
252 |
|
253 |
//g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
|
254 |
break;
|
255 |
|
256 |
case (Layout.POLYLINE):
|
257 |
////GeneralPathX polyLine=new GeneralPathX(polyline.getShape());
|
258 |
////polyLine.transform(at);
|
259 |
////m_shape = new FPolyline2D(polyLine);
|
260 |
////FGraphicUtilities.DrawShape(g, at, m_shape, m_symbol);
|
261 |
g.drawString("POLYLINE", (float) rect.getCenterX(), |
262 |
(float) rect.getCenterY());
|
263 |
|
264 |
break;
|
265 |
|
266 |
case (Layout.POLYGON):
|
267 |
g.drawString("POLYGON", (float) rect.getCenterX(), |
268 |
(float) rect.getCenterY());
|
269 |
|
270 |
break;
|
271 |
|
272 |
case (Layout.CIRCLE):
|
273 |
|
274 |
Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(), |
275 |
(int) rect.getCenterY());
|
276 |
m_shape = new FPoint2D(pc.x, pc.y);
|
277 |
|
278 |
double x = rect.getX();
|
279 |
double y = rect.getY();
|
280 |
double w = rect.getWidth();
|
281 |
double h = rect.getHeight();
|
282 |
|
283 |
if (w < h) {
|
284 |
y = rect.getCenterY() - (w / 2);
|
285 |
h = w; |
286 |
m_symbol.setSize((int) rect.width - 10); |
287 |
} else {
|
288 |
x = rect.getCenterX() - (h / 2);
|
289 |
w = h; |
290 |
m_symbol.setSize((int) rect.height - 10); |
291 |
} |
292 |
|
293 |
Shape circle = new Ellipse2D.Double(x, y, w, h); |
294 |
m_shape = new FPolygon2D(new GeneralPathX(circle)); |
295 |
|
296 |
///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
297 |
FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
298 |
|
299 |
break;
|
300 |
} |
301 |
} |
302 |
|
303 |
g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
304 |
rect.y + (rect.height / 2));
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
309 |
*/
|
310 |
public XMLEntity getXMLEntity() throws SaveException{ |
311 |
XMLEntity xml = new XMLEntity();
|
312 |
try{
|
313 |
xml.putProperty("className", this.getClass().getName()); |
314 |
xml.putProperty("m_name", m_name);
|
315 |
xml.putProperty("x", getBoundBox().x);
|
316 |
xml.putProperty("y", getBoundBox().y);
|
317 |
xml.putProperty("w", getBoundBox().width);
|
318 |
xml.putProperty("h", getBoundBox().height);
|
319 |
xml.putProperty("m_Selected", m_Selected);
|
320 |
xml.putProperty("type", Layout.GRAPHICS);
|
321 |
xml.putProperty("m_type", m_type);
|
322 |
xml.putProperty("tag", getTag());
|
323 |
xml.putProperty("m_rotation", getRotation());
|
324 |
xml.addChild(m_symbol.getXMLEntity()); |
325 |
}catch (Exception e) { |
326 |
throw new SaveException(e,this.getClass().getName()); |
327 |
} |
328 |
return xml;
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
|
333 |
*
|
334 |
* @param xml XMLEntity
|
335 |
*
|
336 |
* @return Objeto de esta clase.
|
337 |
*/
|
338 |
public static FFrameGraphics createFFrameGraphics(XMLEntity xml) { |
339 |
FFrameGraphics fframe = new FFrameGraphics();
|
340 |
|
341 |
if (xml.getIntProperty("m_Selected") != 0) { |
342 |
fframe.setSelected(true);
|
343 |
} else {
|
344 |
fframe.setSelected(false);
|
345 |
} |
346 |
|
347 |
/// fframe.m_type = xml.getIntProperty("m_type");
|
348 |
/// fframe.m_symbol = FSymbol.createFSymbol(xml.getChild(0));
|
349 |
return fframe;
|
350 |
} |
351 |
|
352 |
/**
|
353 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#updateNum()
|
354 |
*/
|
355 |
public void updateNum() { |
356 |
} |
357 |
|
358 |
/**
|
359 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNum()
|
360 |
*/
|
361 |
public int getNum() { |
362 |
return 0; |
363 |
} |
364 |
|
365 |
/**
|
366 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
367 |
* com.iver.cit.gvsig.project.Project)
|
368 |
*/
|
369 |
public void setXMLEntity(XMLEntity xml) { |
370 |
m_Selected = xml.getIntProperty("m_Selected");
|
371 |
m_type = xml.getIntProperty("m_type");
|
372 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
373 |
m_symbol = FSymbol.createFromXML(xml.getChild(0));
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
378 |
* com.iver.cit.gvsig.project.Project)
|
379 |
*/
|
380 |
public void setXMLEntity03(XMLEntity xml, Layout p) { |
381 |
m_Selected = xml.getIntProperty("m_Selected");
|
382 |
m_type = xml.getIntProperty("m_type");
|
383 |
m_symbol = FSymbol.createFromXML03(xml.getChild(0));
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
388 |
*/
|
389 |
public String getNameFFrame() { |
390 |
return PluginServices.getText(this, "Gr?ficos") + num; |
391 |
} |
392 |
|
393 |
/**
|
394 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
395 |
* java.awt.geom.AffineTransform)
|
396 |
*/
|
397 |
public void print(Graphics2D g, AffineTransform at) |
398 |
throws DriverException {
|
399 |
draw(g, at, null, null); |
400 |
} |
401 |
|
402 |
/**
|
403 |
* Inserta el tama?o del punto.
|
404 |
*
|
405 |
* @param size entero que representa el tama?o del punto.
|
406 |
*/
|
407 |
public void setSize(int size) { |
408 |
this.size = size;
|
409 |
} |
410 |
|
411 |
/**
|
412 |
* Devuelve el tipo de gr?fico que contiene el fframe.
|
413 |
*
|
414 |
* @return tipo de
|
415 |
*/
|
416 |
public int getType() { |
417 |
return m_type;
|
418 |
} |
419 |
public void initialize() { |
420 |
// TODO Auto-generated method stub
|
421 |
|
422 |
} |
423 |
} |