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 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 22-jun-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig.gui.layout.fframes; |
46 | |||
47 | 2745 | caballero | import com.iver.andami.PluginServices; |
48 | 2428 | caballero | |
49 | 1073 | vcaballero | 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 | 2745 | caballero | import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
59 | 1073 | vcaballero | import com.iver.cit.gvsig.gui.layout.Layout; |
60 | 3185 | caballero | import com.iver.cit.gvsig.gui.project.SaveException; |
61 | 3115 | caballero | ////import com.iver.cit.gvsig.gui.layout.Line;
|
62 | 2745 | caballero | |
63 | 1073 | vcaballero | import com.iver.utiles.XMLEntity; |
64 | |||
65 | 2745 | caballero | 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 | 312 | fernando | |
75 | 2745 | caballero | |
76 | 312 | fernando | /**
|
77 | * FFrame para contener un gr?fico.
|
||
78 | *
|
||
79 | * @author Vicente Caballero Navarro
|
||
80 | */
|
||
81 | public class FFrameGraphics extends FFrame { |
||
82 | 2745 | caballero | 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 | 3115 | caballero | ////private Line polyline;
|
88 | 2745 | caballero | //private AffineTransform aT = null;
|
89 | 312 | fernando | |
90 | 2745 | caballero | /**
|
91 | * Crea un nuevo FFrameGraphics.
|
||
92 | */
|
||
93 | public FFrameGraphics() {
|
||
94 | mT = new AffineTransform(); |
||
95 | mT.setToIdentity(); |
||
96 | } |
||
97 | 3115 | caballero | /* public FFrameGraphics(Line line){
|
98 | mT = new AffineTransform();
|
||
99 | mT.setToIdentity();
|
||
100 | polyline=line;
|
||
101 | }
|
||
102 | */
|
||
103 | 2745 | caballero | /**
|
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 | 312 | fernando | |
112 | 2745 | caballero | /**
|
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 | 312 | fernando | |
122 | 2745 | caballero | //aT = at;
|
123 | if (m_color == null) { |
||
124 | m_color = Color.red;
|
||
125 | } |
||
126 | 1073 | vcaballero | |
127 | 2745 | caballero | switch (m_type) {
|
128 | case (Layout.POINT):
|
||
129 | m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, m_color);
|
||
130 | 1073 | vcaballero | |
131 | 2745 | caballero | break;
|
132 | 1073 | vcaballero | |
133 | 2745 | caballero | case (Layout.RECTANGLESIMPLE):
|
134 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL, m_color);
|
||
135 | m_symbol.setColor(null);
|
||
136 | 1073 | vcaballero | |
137 | 2745 | caballero | break;
|
138 | 1073 | vcaballero | |
139 | 2745 | caballero | case (Layout.LINE):
|
140 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, m_color);
|
||
141 | 1073 | vcaballero | |
142 | 2745 | caballero | break;
|
143 | 1073 | vcaballero | |
144 | 2745 | caballero | case (Layout.POLYLINE):
|
145 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
||
146 | 1073 | vcaballero | |
147 | 2745 | caballero | break;
|
148 | 1073 | vcaballero | |
149 | 2745 | caballero | case (Layout.POLYGON):
|
150 | m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT, m_color);
|
||
151 | 1073 | vcaballero | |
152 | 2745 | caballero | break;
|
153 | 1073 | vcaballero | |
154 | 2745 | caballero | 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 | 312 | fernando | |
161 | 2745 | caballero | break;
|
162 | } |
||
163 | } |
||
164 | 312 | fernando | |
165 | 2745 | caballero | /**
|
166 | * Devuelve el FSymbol que se representa.
|
||
167 | *
|
||
168 | * @return DOCUMENT ME!
|
||
169 | */
|
||
170 | public FSymbol getFSymbol() {
|
||
171 | return m_symbol;
|
||
172 | } |
||
173 | 312 | fernando | |
174 | 2745 | caballero | /**
|
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 | 312 | fernando | |
183 | 2745 | caballero | /**
|
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 | 1073 | vcaballero | |
199 | 2745 | caballero | if (intersects(rv, rect)) {
|
200 | g.setColor(Color.black);
|
||
201 | 1073 | vcaballero | |
202 | 2745 | caballero | FShape m_shape = null;
|
203 | 1073 | vcaballero | |
204 | 2745 | caballero | switch (m_type) {
|
205 | case (Layout.POINT):
|
||
206 | 1073 | vcaballero | |
207 | 2745 | caballero | 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 | 1073 | vcaballero | |
220 | 2745 | caballero | Point2D.Double p = new Point2D.Double((int) rect.getCenterX(), |
221 | (int) rect.getCenterY());
|
||
222 | m_shape = new FPoint2D(p.x, p.y);
|
||
223 | 1073 | vcaballero | |
224 | 2745 | caballero | ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
225 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
226 | 1073 | vcaballero | |
227 | 2745 | caballero | break;
|
228 | 1073 | vcaballero | |
229 | 2745 | caballero | case (Layout.RECTANGLESIMPLE):
|
230 | 1073 | vcaballero | |
231 | 2745 | caballero | GeneralPathX rectAux = new GeneralPathX(rect);
|
232 | rectAux.transform(mT); |
||
233 | m_shape = new FPolygon2D(rectAux); //FConstant.SHAPE_TYPE_POLYLINE, rectAux); |
||
234 | 1073 | vcaballero | |
235 | 2745 | caballero | ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
236 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
237 | 1073 | vcaballero | |
238 | 2745 | caballero | break;
|
239 | 1073 | vcaballero | |
240 | 2745 | caballero | case (Layout.LINE):
|
241 | 1073 | vcaballero | |
242 | 2745 | caballero | Line2D line = new Line2D.Double(); |
243 | line.setLine(new Point2D.Double(rect.x, rect.y), |
||
244 | new Point2D.Double(rect.getMaxX(), rect.getMaxY())); |
||
245 | 1073 | vcaballero | |
246 | 2745 | caballero | GeneralPathX rectA = new GeneralPathX(line);
|
247 | rectA.transform(mT); |
||
248 | m_shape = new FPolyline2D(rectA);
|
||
249 | 1073 | vcaballero | |
250 | 2745 | caballero | ///m_symbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE, Color.red);
|
251 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
252 | 1073 | vcaballero | |
253 | 2745 | caballero | //g.drawString("POLYLINE",(float)rect.getCenterX(),(float)rect.getCenterY());
|
254 | break;
|
||
255 | 1073 | vcaballero | |
256 | 2745 | caballero | case (Layout.POLYLINE):
|
257 | 3115 | caballero | ////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 | 2745 | caballero | (float) rect.getCenterY());
|
263 | 3115 | caballero | |
264 | 2745 | caballero | break;
|
265 | 1073 | vcaballero | |
266 | 2745 | caballero | case (Layout.POLYGON):
|
267 | g.drawString("POLYGON", (float) rect.getCenterX(), |
||
268 | (float) rect.getCenterY());
|
||
269 | 1073 | vcaballero | |
270 | 2745 | caballero | break;
|
271 | 312 | fernando | |
272 | 2745 | caballero | case (Layout.CIRCLE):
|
273 | 312 | fernando | |
274 | 2745 | caballero | Point2D.Double pc = new Point2D.Double((int) rect.getCenterX(), |
275 | (int) rect.getCenterY());
|
||
276 | m_shape = new FPoint2D(pc.x, pc.y);
|
||
277 | 312 | fernando | |
278 | 2745 | caballero | double x = rect.getX();
|
279 | double y = rect.getY();
|
||
280 | double w = rect.getWidth();
|
||
281 | double h = rect.getHeight();
|
||
282 | 312 | fernando | |
283 | 2745 | caballero | 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 | 312 | fernando | |
293 | 2745 | caballero | Shape circle = new Ellipse2D.Double(x, y, w, h); |
294 | m_shape = new FPolygon2D(new GeneralPathX(circle)); |
||
295 | 312 | fernando | |
296 | 2745 | caballero | ///m_symbol = new FSymbol(FConstant.SHAPE_TYPE_POINT, Color.red);
|
297 | FGraphicUtilities.DrawShape(g, mT, m_shape, m_symbol); |
||
298 | 398 | vcaballero | |
299 | 2745 | caballero | break;
|
300 | } |
||
301 | } |
||
302 | 398 | vcaballero | |
303 | 2745 | caballero | g.rotate(Math.toRadians(-getRotation()), rect.x + (rect.width / 2), |
304 | rect.y + (rect.height / 2));
|
||
305 | } |
||
306 | 2183 | fernando | |
307 | 2745 | caballero | /**
|
308 | * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
||
309 | */
|
||
310 | 3185 | caballero | public XMLEntity getXMLEntity() throws SaveException{ |
311 | XMLEntity xml = new XMLEntity();
|
||
312 | try{
|
||
313 | xml.putProperty("className", this.getClass().getName()); |
||
314 | 2745 | caballero | 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 | 3185 | caballero | }catch (Exception e) { |
326 | throw new SaveException(e,this.getClass().getName()); |
||
327 | } |
||
328 | 2745 | caballero | 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 | 3135 | caballero | public void setXMLEntity(XMLEntity xml) { |
370 | 2745 | caballero | 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 | 2847 | caballero | |
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 | 4209 | jaume | public void initialize() { |
420 | // TODO Auto-generated method stub
|
||
421 | |||
422 | } |
||
423 | 312 | fernando | } |