svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameView.java @ 12320
History | View | Annotate | Download (32.8 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-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 java.awt.Color; |
48 |
import java.awt.Dimension; |
49 |
import java.awt.Graphics2D; |
50 |
import java.awt.Point; |
51 |
import java.awt.Rectangle; |
52 |
import java.awt.geom.AffineTransform; |
53 |
import java.awt.geom.Point2D; |
54 |
import java.awt.geom.Rectangle2D; |
55 |
import java.awt.image.BufferedImage; |
56 |
import java.util.ArrayList; |
57 |
|
58 |
import org.cresques.cts.IProjection; |
59 |
|
60 |
import com.iver.andami.PluginServices; |
61 |
import com.iver.andami.messages.NotificationManager; |
62 |
import com.iver.cit.gvsig.ProjectExtension; |
63 |
import com.iver.cit.gvsig.fmap.ColorEvent; |
64 |
import com.iver.cit.gvsig.fmap.DriverException; |
65 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
66 |
import com.iver.cit.gvsig.fmap.MapContext; |
67 |
import com.iver.cit.gvsig.fmap.ProjectionEvent; |
68 |
import com.iver.cit.gvsig.fmap.ViewPort; |
69 |
import com.iver.cit.gvsig.fmap.ViewPortListener; |
70 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
71 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
72 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
73 |
import com.iver.cit.gvsig.gui.layout.Layout; |
74 |
import com.iver.cit.gvsig.project.Project; |
75 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
76 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
77 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
78 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence; |
79 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap; |
80 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseProject; |
81 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence; |
82 |
import com.iver.cit.gvsig.project.documents.view.ProjectView; |
83 |
import com.iver.cit.gvsig.project.documents.view.ProjectViewFactory; |
84 |
import com.iver.utiles.XMLEntity; |
85 |
|
86 |
|
87 |
/**
|
88 |
* FFrame para introducir una vista en el Layout.
|
89 |
*
|
90 |
* @author Vicente Caballero Navarro
|
91 |
*/
|
92 |
public class FFrameView extends FFrame implements ViewPortListener, |
93 |
LegendListener, IFFrameUseProject, IFFrameLayoutDependence,IFFrameUseFMap { |
94 |
//private static Logger logger = Logger.getLogger(FFrameView.class.getName());
|
95 |
public static final int PRESENTACION = 0; |
96 |
public static final int BORRADOR = 1; |
97 |
protected int m_Mode; |
98 |
protected int m_typeScale = AUTOMATICO; |
99 |
protected int m_extension = 0; |
100 |
protected int m_quality = PRESENTACION; |
101 |
protected int m_viewing = 0; |
102 |
protected boolean m_bLinked = true; |
103 |
protected ProjectView view = null; |
104 |
protected MapContext m_fmap = null; |
105 |
protected double m_Scale = 0; |
106 |
protected int m_mapUnits = 1; //Metros. |
107 |
|
108 |
private BufferedImage m_image = null; |
109 |
private AffineTransform at = null; |
110 |
private Project project = null; |
111 |
private Layout layout;
|
112 |
private double scaleAnt; |
113 |
private boolean refresh=false; |
114 |
private Point origin; |
115 |
private Point2D p1; |
116 |
private Point2D p2; |
117 |
/**
|
118 |
* Creates a new FFrameView object.
|
119 |
*/
|
120 |
public FFrameView() {
|
121 |
num++; |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Devuelve una descripci?n del FFrameView.
|
126 |
*
|
127 |
* @return Descripci?n.
|
128 |
*/
|
129 |
public String toString() { |
130 |
if (getView() == null) { |
131 |
return "FFrameView " + num + ": " + "Vacio"; |
132 |
} |
133 |
|
134 |
return "FFrameView " + num + ": " + getView().getName(); |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Rellena la escala de la vista que contiene el fframe.
|
139 |
*
|
140 |
* @param d escala de la vista.
|
141 |
*/
|
142 |
public void setScale(double d) { |
143 |
m_Scale = d; |
144 |
} |
145 |
|
146 |
/**
|
147 |
* Inserta el nuevo extent a la FFrameView.
|
148 |
*
|
149 |
* @param r Rect?ngulo a ocupar por el FFrameView.
|
150 |
*/
|
151 |
public void setNewExtent(Rectangle2D r) { |
152 |
getMapContext().getViewPort().setExtent(r); |
153 |
refresh = true;
|
154 |
m_Scale = FLayoutUtilities.getScaleView(getMapContext().getViewPort(), |
155 |
getBoundBox().width, |
156 |
getBoundingBox(null).width / getBoundBox().width);
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
|
161 |
* escala fija.
|
162 |
*
|
163 |
* @return FMap.
|
164 |
*/
|
165 |
public MapContext getMapContext() {
|
166 |
return m_fmap;
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Rellena la calidad que se quiere aplicar.
|
171 |
*
|
172 |
* @param q entero que representa la calidad a aplicar.
|
173 |
*/
|
174 |
public void setQuality(int q) { |
175 |
m_quality = q; |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Devuelve un entero que representa la calidad que est? seleccionada.
|
180 |
*
|
181 |
* @return tipo de calidad selccionada.
|
182 |
*/
|
183 |
public int getQuality() { |
184 |
return m_quality;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
189 |
*
|
190 |
* @return forma que se actualiza la vista.
|
191 |
*/
|
192 |
public int getViewing() { |
193 |
return m_viewing;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Rellena la forma de actualizar la vista(cuando activo o siempre). De
|
198 |
* momento esta opci?n esta deshabilitada.
|
199 |
*
|
200 |
* @param v entero que representa la forma de actualizar la vista.
|
201 |
*/
|
202 |
public void setViewing(int v) { |
203 |
m_viewing = v; |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Inserta el ProjectView de donde obtener las propiedades de la vista a
|
208 |
* mostrar.
|
209 |
*
|
210 |
* @param v Modelo de la vista.
|
211 |
*/
|
212 |
public void setView(ProjectView v) { |
213 |
view=v; |
214 |
ViewPort vp =null;
|
215 |
if (getMapContext()!=null){ |
216 |
vp=getMapContext().getViewPort(); |
217 |
}else{
|
218 |
vp = v.getMapContext().getViewPort().cloneViewPort(); |
219 |
} |
220 |
vp.setImageSize(new Dimension((int) getBoundingBox(null).width, |
221 |
(int) getBoundingBox(null).height)); |
222 |
|
223 |
if (m_bLinked) {
|
224 |
v.getMapContext().addLayerListener(this);
|
225 |
if (getTypeScale() == AUTOMATICO) {
|
226 |
m_fmap = v.getMapContext().createNewFMap(v.getMapContext() |
227 |
.getViewPort() |
228 |
.cloneViewPort()); |
229 |
m_fmap.getViewPort().setImageSize(new Dimension( |
230 |
(int) getBoundingBox(null).width, |
231 |
(int) getBoundingBox(null).height)); |
232 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
233 |
} else if (getTypeScale() == CONSTANTE) { |
234 |
m_fmap = v.getMapContext().createNewFMap(vp); |
235 |
vp.setExtent(getNewExtent(getScale())); |
236 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
237 |
} else if (getTypeScale() == MANUAL) { |
238 |
m_fmap = v.getMapContext().createNewFMap(vp); |
239 |
vp.setExtent(getNewExtent(getScale())); |
240 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
241 |
} |
242 |
} else if (!m_bLinked) { |
243 |
v.getMapContext().removeLayerListener(this);
|
244 |
try {
|
245 |
if (getTypeScale() == AUTOMATICO) {
|
246 |
m_fmap = v.getMapContext().cloneFMap(); //(v.getMapContext().getViewPort().cloneViewPort());
|
247 |
m_fmap.setViewPort(v.getMapContext().getViewPort() |
248 |
.cloneViewPort()); |
249 |
m_fmap.getViewPort().setImageSize(new Dimension( |
250 |
(int) getBoundingBox(null).width, |
251 |
(int) getBoundingBox(null).height)); |
252 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
253 |
} else if (getTypeScale() == CONSTANTE) { |
254 |
m_fmap = v.getMapContext().cloneFMap(); |
255 |
vp.setExtent(getNewExtent(getScale())); |
256 |
m_fmap.setViewPort(vp); |
257 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
258 |
} else if (getTypeScale() == MANUAL) { |
259 |
m_fmap = v.getMapContext().cloneFMap(); |
260 |
vp.setExtent(getNewExtent(getScale())); |
261 |
m_fmap.setViewPort(vp); |
262 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
263 |
} |
264 |
} catch (XMLException e1) {
|
265 |
NotificationManager.addError("Cuando se a?ade una vista al Layout",
|
266 |
e1); |
267 |
} |
268 |
} |
269 |
} |
270 |
|
271 |
/**
|
272 |
* Devuelve el modelo de la vista.
|
273 |
*
|
274 |
* @return Modelo de la vista.
|
275 |
*/
|
276 |
public ProjectView getView() {
|
277 |
return view;
|
278 |
} |
279 |
|
280 |
/**
|
281 |
* Devuelve un Rect?ngulo que representa el extent de la vista que se
|
282 |
* requiere a partir de una escala.
|
283 |
*
|
284 |
* @param scale Escala a mostrar.
|
285 |
*
|
286 |
* @return Rect?ngulo.
|
287 |
*/
|
288 |
protected Rectangle2D getNewExtent(long scale) { |
289 |
double hview = getBoundBox().getHeight();
|
290 |
double wview = getBoundBox().getWidth();
|
291 |
double hextent = (scale * hview) / 100.0; |
292 |
double wextent = (scale * wview) / 100.0; |
293 |
|
294 |
if (m_fmap.getViewPort().getExtent()==null) |
295 |
return new Rectangle2D.Double(); |
296 |
double newx = m_fmap.getViewPort().getExtent().getCenterX() -
|
297 |
(wextent / 2.0);
|
298 |
double newy = m_fmap.getViewPort().getExtent().getCenterY() -
|
299 |
(hextent / 2.0);
|
300 |
IProjection proj=m_fmap.getViewPort().getProjection(); |
301 |
Rectangle2D r = new Rectangle2D.Double(newx, newy, wextent, hextent); |
302 |
if (!proj.isProjected()){
|
303 |
return m_fmap.getViewPort().getProjection().getExtent(r,scale,wview,hview,100,2.54); |
304 |
} |
305 |
return r;
|
306 |
|
307 |
|
308 |
} |
309 |
|
310 |
/**
|
311 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
312 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
313 |
* de dibujar.
|
314 |
*
|
315 |
* @param g
|
316 |
* Graphics2D
|
317 |
* @param at
|
318 |
* Transformada af?n.
|
319 |
* @param rv
|
320 |
* rect?ngulo sobre el que hacer un clip.
|
321 |
* @param imgBase
|
322 |
* Imagen para acelerar el dibujado.
|
323 |
*
|
324 |
* @throws com.iver.cit.gvsig.fmap.DriverException
|
325 |
*/
|
326 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
327 |
BufferedImage imgBase)
|
328 |
throws com.iver.cit.gvsig.fmap.DriverException {
|
329 |
Rectangle2D.Double r = getBoundingBox(at);
|
330 |
if (getRotation() != 0) |
331 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
332 |
+ (r.height / 2));
|
333 |
if (intersects(rv, r)) {
|
334 |
if (getMapContext() == null) { |
335 |
drawEmpty(g); |
336 |
} else {
|
337 |
if (rv != null) { |
338 |
// Dibujamos en pantalla
|
339 |
Rectangle rclip = (Rectangle)g.getClipBounds().clone(); |
340 |
g.clipRect((int) r.getMinX(), (int) r.getMinY(), (int) r |
341 |
.getWidth(), (int) r.getHeight());
|
342 |
|
343 |
if (getQuality() == PRESENTACION) {
|
344 |
if (rv.intersects(r)) {
|
345 |
ViewPort viewPort = this.getMapContext()
|
346 |
.getViewPort(); |
347 |
Color theBackColor = viewPort.getBackColor();
|
348 |
if (origin != null |
349 |
&& origin.equals(layout.getRectOrigin()) |
350 |
&& layout != null
|
351 |
&& layout.getAT().getScaleX() == scaleAnt |
352 |
&& m_image != null && !refresh) {
|
353 |
if (theBackColor != null) { |
354 |
g.setColor(theBackColor); |
355 |
g.fillRect((int) r.x, (int) r.y, viewPort |
356 |
.getImageWidth(), viewPort |
357 |
.getImageHeight()); |
358 |
} |
359 |
g.translate(r.getX(), r.getY()); |
360 |
g.drawImage(m_image, 0, 0, layout); |
361 |
g.translate(-r.getX(), -r.getY()); |
362 |
scaleAnt = layout.getAT().getScaleX(); |
363 |
origin = (Point) layout.getRectOrigin().clone();
|
364 |
} else {
|
365 |
|
366 |
|
367 |
System.err.println("r : " + r); |
368 |
if (r.getWidth() > layout.getWidth()
|
369 |
|| r.getHeight() > layout.getHeight()) { |
370 |
getMapContext().getViewPort().setOffset( |
371 |
new Point2D.Double(r.getX(), r |
372 |
.getY())); |
373 |
getMapContext().getViewPort().setImageSize( |
374 |
new Dimension((int) r.getWidth(), |
375 |
(int) r.getHeight()));
|
376 |
MapContext fmap = getMapContext().cloneToDraw(); |
377 |
ViewPort viewp = viewPort.cloneViewPort(); |
378 |
viewp.setImageSize(new Dimension( |
379 |
layout.getWidth(), |
380 |
layout.getHeight())); |
381 |
Rectangle2D r1 = calculateExtent();
|
382 |
double width = layout.getAtributes()
|
383 |
.getSizeInUnits().getAncho(); |
384 |
double scale = FLayoutUtilities
|
385 |
.getScaleView(viewp, width, r1 |
386 |
.getWidth() |
387 |
/ width); |
388 |
viewp.setExtent(r1); |
389 |
|
390 |
fmap.setViewPort(viewp); |
391 |
g.translate(-r.getX(), -r.getY()); |
392 |
if (theBackColor != null) { |
393 |
g.setColor(theBackColor); |
394 |
g.fillRect((int) r.x, (int) r.y, viewp |
395 |
.getImageWidth(), viewp |
396 |
.getImageHeight()); |
397 |
} |
398 |
fmap.draw(imgBase, g, scale); |
399 |
g.translate(r.getX(), r.getY()); |
400 |
|
401 |
} else {
|
402 |
getMapContext().getViewPort().setOffset( |
403 |
new Point2D.Double(r.x, r.y)); |
404 |
getMapContext().getViewPort().setImageSize( |
405 |
new Dimension((int) r.width, |
406 |
(int) r.height));
|
407 |
m_image = new BufferedImage((int) r |
408 |
.getWidth(), (int) r.getHeight(),
|
409 |
BufferedImage.TYPE_INT_ARGB);
|
410 |
Graphics2D gimg = (Graphics2D) m_image |
411 |
.getGraphics(); |
412 |
gimg.translate(-((int) r.getX()), -((int) r |
413 |
.getY())); |
414 |
getMapContext().draw(m_image, gimg, getScale()); |
415 |
gimg.translate(((int) r.getX()), ((int) r |
416 |
.getY())); |
417 |
if (theBackColor != null) { |
418 |
g.setColor(theBackColor); |
419 |
g.fillRect((int) r.x, (int) r.y, viewPort |
420 |
.getImageWidth(), viewPort |
421 |
.getImageHeight()); |
422 |
} |
423 |
g.drawImage(m_image, (int) r.getX(),
|
424 |
(int) r.getY(), layout);
|
425 |
} |
426 |
scaleAnt = layout.getAT().getScaleX(); |
427 |
origin = (Point) layout.getRectOrigin().clone();
|
428 |
refresh = false;
|
429 |
} |
430 |
} |
431 |
} else {
|
432 |
drawDraft(g); |
433 |
} |
434 |
if (rclip != null) { |
435 |
g.setClip(rclip.x, rclip.y, rclip.width, |
436 |
rclip.height); |
437 |
} |
438 |
} else {
|
439 |
printX(g, at); |
440 |
} |
441 |
} |
442 |
} |
443 |
if (getRotation() != 0) |
444 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
445 |
+ (r.height / 2));
|
446 |
|
447 |
if (getMapContext() != null) { |
448 |
setATMap(getMapContext().getViewPort() |
449 |
.getAffineTransform()); |
450 |
|
451 |
} |
452 |
} |
453 |
private Rectangle2D calculateExtent() { |
454 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
455 |
if (p1==null||p2==null) |
456 |
return r;
|
457 |
r.setFrameFromDiagonal(p1, p2); |
458 |
return r;
|
459 |
} |
460 |
/**
|
461 |
* DOCUMENT ME!
|
462 |
*
|
463 |
* @param g
|
464 |
* DOCUMENT ME!
|
465 |
* @param at
|
466 |
* DOCUMENT ME!
|
467 |
*
|
468 |
* @throws DriverException
|
469 |
*
|
470 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
471 |
* java.awt.geom.AffineTransform)
|
472 |
*/
|
473 |
public void print(Graphics2D g, AffineTransform at) |
474 |
throws DriverException {
|
475 |
draw(g, at, null, null); |
476 |
} |
477 |
|
478 |
/**
|
479 |
* DOCUMENT ME!
|
480 |
*
|
481 |
* @param g
|
482 |
* DOCUMENT ME!
|
483 |
* @param at
|
484 |
* DOCUMENT ME!
|
485 |
*/
|
486 |
private void printX(Graphics2D g, AffineTransform at) { |
487 |
Rectangle2D.Double r = getBoundingBox(at);
|
488 |
|
489 |
// Dibujamos en impresora
|
490 |
Rectangle rclip = g.getClipBounds();
|
491 |
g.clipRect((int) r.getMinX(), (int) r.getMinY(), (int) r.getWidth(), |
492 |
(int) r.getHeight());
|
493 |
this.getMapContext().getViewPort().setOffset(new Point2D.Double(r.x, r.y)); |
494 |
this.getMapContext().getViewPort().setImageSize(new Dimension((int) r.width, |
495 |
(int) r.height));
|
496 |
|
497 |
try {
|
498 |
this.getMapContext().print(g, getScale(),layout.getAtributes().toPrintAttributes());
|
499 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
500 |
NotificationManager.addError(e.getMessage(), e); |
501 |
} |
502 |
|
503 |
g.setClip(rclip.x, rclip.y, rclip.width, rclip.height); |
504 |
} |
505 |
|
506 |
/**
|
507 |
* Rellena la unidad de medida en la que est? la vista.
|
508 |
*
|
509 |
* @param i entero que representa la unidad de medida de la vista.
|
510 |
*/
|
511 |
public void setMapUnits(int i) { |
512 |
m_mapUnits = i; |
513 |
} |
514 |
|
515 |
/**
|
516 |
* Obtiene la unidad de medida en la que est? la vista.
|
517 |
*
|
518 |
* @return Unidad de medida.
|
519 |
*/
|
520 |
public int getMapUnits() { |
521 |
return m_mapUnits;
|
522 |
} |
523 |
|
524 |
/**
|
525 |
* Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
|
526 |
* a?adida la vista.
|
527 |
*
|
528 |
* @return escala.
|
529 |
*/
|
530 |
public long getScale() { |
531 |
/*if (m_bLinked){
|
532 |
return getScaleView1(METROS);
|
533 |
}
|
534 |
*/
|
535 |
if (getMapContext()==null) |
536 |
return 0; |
537 |
if (getTypeScale() == AUTOMATICO) {
|
538 |
return FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
|
539 |
getBoundBox().width, getBoundingBox(null).width);
|
540 |
} else if (getTypeScale() == CONSTANTE) { |
541 |
return (long) m_Scale; |
542 |
} else if (getTypeScale() == MANUAL) { |
543 |
return (long) m_Scale; |
544 |
} |
545 |
|
546 |
return (long) m_Scale; |
547 |
} |
548 |
|
549 |
/**
|
550 |
* Seleccionar si la vista esta relacionada o no con la original.
|
551 |
*
|
552 |
* @param b true si est? ligada y false si no lo est?.
|
553 |
*/
|
554 |
public void setLinked(boolean b) { |
555 |
m_bLinked = b; |
556 |
} |
557 |
|
558 |
/**
|
559 |
* Devuelve si est? ligada o no el FFrameView con la vista.
|
560 |
*
|
561 |
* @return True si la vista est? ligada.
|
562 |
*/
|
563 |
public boolean getLinked() { |
564 |
return m_bLinked;
|
565 |
} |
566 |
|
567 |
/**
|
568 |
* Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
|
569 |
* la vista.
|
570 |
*
|
571 |
* @return entero que representa la opci?n elegida.
|
572 |
*/
|
573 |
public int getExtension() { |
574 |
return m_extension;
|
575 |
} |
576 |
|
577 |
/**
|
578 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
|
579 |
* MANUAL.
|
580 |
*
|
581 |
* @return entero que representa el tipo seleccionado.
|
582 |
*/
|
583 |
public int getTypeScale() { |
584 |
return m_typeScale;
|
585 |
} |
586 |
|
587 |
/**
|
588 |
* Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
|
589 |
*
|
590 |
* @param i entero que representa la opci?n elegida.
|
591 |
*/
|
592 |
public void setExtension(int i) { |
593 |
m_extension = i; |
594 |
} |
595 |
|
596 |
/**
|
597 |
* Rellenar el tipo de escala que se desea.
|
598 |
*
|
599 |
* @param i entero que representa el tipo de escala.
|
600 |
*/
|
601 |
public void setTypeScale(int i) { |
602 |
m_typeScale = i; |
603 |
} |
604 |
|
605 |
/**
|
606 |
* DOCUMENT ME!
|
607 |
*
|
608 |
* @return DOCUMENT ME!
|
609 |
*
|
610 |
* @throws SaveException
|
611 |
*
|
612 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
|
613 |
*/
|
614 |
public XMLEntity getXMLEntity() throws SaveException { |
615 |
XMLEntity xml = super.getXMLEntity();
|
616 |
|
617 |
try {
|
618 |
xml.putProperty("type", Layout.RECTANGLEVIEW);
|
619 |
xml.putProperty("m_Mode", m_Mode);
|
620 |
xml.putProperty("m_typeScale", m_typeScale);
|
621 |
xml.putProperty("m_extension", m_extension);
|
622 |
xml.putProperty("m_quality", m_quality);
|
623 |
xml.putProperty("m_viewing", m_viewing);
|
624 |
xml.putProperty("m_bLinked", m_bLinked);
|
625 |
xml.putProperty("m_mapUnits", m_mapUnits);
|
626 |
xml.putProperty("m_Scale", m_Scale);
|
627 |
|
628 |
ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
629 |
ArrayList views = pe.getProject().getDocumentsByType(ProjectViewFactory.registerName);
|
630 |
|
631 |
boolean hasIndex = false; |
632 |
|
633 |
|
634 |
if (view != null) { |
635 |
xml.putProperty("viewName",view.getName());
|
636 |
for (int i = 0; i < views.size(); i++) { |
637 |
if (view.getName().equals(((ProjectView) views.get(i)).getName())) {
|
638 |
xml.putProperty("indice", i);
|
639 |
hasIndex = true;
|
640 |
break;
|
641 |
} |
642 |
} |
643 |
} |
644 |
|
645 |
if (!hasIndex) {
|
646 |
xml.putProperty("indice", -1); |
647 |
} |
648 |
|
649 |
if (getMapContext() != null && getMapContext().getViewPort().getExtent()!=null) { |
650 |
xml.putProperty("extentX",
|
651 |
getMapContext().getViewPort().getExtent().getX()); |
652 |
xml.putProperty("extentY",
|
653 |
getMapContext().getViewPort().getExtent().getY()); |
654 |
xml.putProperty("extentW",
|
655 |
getMapContext().getViewPort().getExtent().getWidth()); |
656 |
xml.putProperty("extentH",
|
657 |
getMapContext().getViewPort().getExtent().getHeight()); |
658 |
|
659 |
xml.addChild(getMapContext().getXMLEntity()); |
660 |
} |
661 |
} catch (Exception e) { |
662 |
throw new SaveException(e, this.getClass().getName()); |
663 |
} |
664 |
|
665 |
return xml;
|
666 |
} |
667 |
|
668 |
/**
|
669 |
* Inserta la imagen para repintar el FFrameView.
|
670 |
*
|
671 |
* @param bi Imagen para repintar.
|
672 |
*/
|
673 |
public void setBufferedImage(BufferedImage bi) { |
674 |
m_image = bi; |
675 |
} |
676 |
|
677 |
/**
|
678 |
* Devuelve la imagen para repintar.
|
679 |
*
|
680 |
* @return Imagen para repintar.
|
681 |
*/
|
682 |
public BufferedImage getBufferedImage() { |
683 |
return m_image;
|
684 |
} |
685 |
|
686 |
/**
|
687 |
* Devuelve la MAtriz de transformaci?n utilizada por la FFrameView.
|
688 |
*
|
689 |
* @return MAtriz de transformaci?n.
|
690 |
*/
|
691 |
public AffineTransform getATMap() { |
692 |
return at;
|
693 |
} |
694 |
|
695 |
/**
|
696 |
* Inserta la matriz de transformaci?n.
|
697 |
*
|
698 |
* @param transform Matriz de transformaci?n.
|
699 |
*/
|
700 |
public void setATMap(AffineTransform transform) { |
701 |
at = transform; |
702 |
} |
703 |
/**
|
704 |
* Inserta el proyecto.
|
705 |
*
|
706 |
* @param p Proyecto.
|
707 |
*/
|
708 |
public void setProject(Project p) { |
709 |
project = p; |
710 |
} |
711 |
|
712 |
/**
|
713 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
714 |
* com.iver.cit.gvsig.project.Project)
|
715 |
*/
|
716 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
717 |
if (xml.getIntProperty("m_Selected") != 0) { |
718 |
this.setSelected(true); |
719 |
} else {
|
720 |
this.setSelected(false); |
721 |
} |
722 |
|
723 |
this.setName(xml.getStringProperty("m_name")); |
724 |
this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
725 |
xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
726 |
xml.getDoubleProperty("h")));
|
727 |
|
728 |
this.m_Mode = xml.getIntProperty("m_Mode"); |
729 |
this.m_typeScale = xml.getIntProperty("m_typeScale"); |
730 |
this.m_extension = xml.getIntProperty("m_extension"); |
731 |
this.m_quality = xml.getIntProperty("m_quality"); |
732 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
733 |
this.m_bLinked = xml.getBooleanProperty("m_bLinked"); |
734 |
this.m_mapUnits = xml.getIntProperty("m_mapUnits"); |
735 |
|
736 |
//ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
|
737 |
this.m_Scale = xml.getDoubleProperty("m_Scale"); |
738 |
|
739 |
int indice = xml.getIntProperty("indice"); |
740 |
|
741 |
if (indice != -1) { |
742 |
ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
|
743 |
|
744 |
ProjectView view = (ProjectView) views.get(indice); |
745 |
this.m_fmap = view.getMapContext();
|
746 |
this.setView(view);
|
747 |
|
748 |
try {
|
749 |
if (m_bLinked) {
|
750 |
this.getMapContext().getViewPort().setExtent(new Rectangle2D.Double( |
751 |
xml.getDoubleProperty("extentX"),
|
752 |
xml.getDoubleProperty("extentY"),
|
753 |
xml.getDoubleProperty("extentW"),
|
754 |
xml.getDoubleProperty("extentH")));
|
755 |
} else if (!m_bLinked) { |
756 |
this.m_fmap = MapContext.createFromXML03(xml.getChild(0)); |
757 |
} |
758 |
} catch (XMLException e) {
|
759 |
NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
|
760 |
e); |
761 |
} |
762 |
} |
763 |
} |
764 |
|
765 |
/**
|
766 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
767 |
*/
|
768 |
public String getNameFFrame() { |
769 |
return PluginServices.getText(this, "Vista")+ num; |
770 |
} |
771 |
|
772 |
/**
|
773 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
774 |
*/
|
775 |
public void extentChanged(ExtentEvent e) { |
776 |
if (getTypeScale() == AUTOMATICO) {
|
777 |
m_fmap.getViewPort().setExtent(e.getNewExtent()); |
778 |
if (layout != null) { |
779 |
layout.setStatus(Layout.DESACTUALIZADO); |
780 |
} |
781 |
|
782 |
} |
783 |
refresh=true;
|
784 |
} |
785 |
|
786 |
/**
|
787 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
788 |
*/
|
789 |
public void backColorChanged(ColorEvent e) { |
790 |
if (getLinked()) {
|
791 |
m_fmap.getViewPort().setBackColor(e.getNewColor()); |
792 |
layout.setStatus(Layout.DESACTUALIZADO); |
793 |
|
794 |
//setBufferedImage(null);
|
795 |
} |
796 |
} |
797 |
|
798 |
/**
|
799 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#projectionChanged(com.iver.cit.gvsig.fmap.ProjectionEvent)
|
800 |
*/
|
801 |
public void projectionChanged(ProjectionEvent e) { |
802 |
if (getTypeScale() == AUTOMATICO) {
|
803 |
m_fmap.getViewPort().setProjection(e.getNewProjection()); |
804 |
|
805 |
if (layout != null) { |
806 |
layout.setStatus(Layout.DESACTUALIZADO); |
807 |
} |
808 |
} |
809 |
} |
810 |
|
811 |
/**
|
812 |
* DOCUMENT ME!
|
813 |
*
|
814 |
* @param l DOCUMENT ME!
|
815 |
*/
|
816 |
public void setLayout(Layout l) { |
817 |
layout = l; |
818 |
} |
819 |
|
820 |
/**
|
821 |
* DOCUMENT ME!
|
822 |
*
|
823 |
* @param e DOCUMENT ME!
|
824 |
*/
|
825 |
public void legendChanged(LegendChangedEvent e) { |
826 |
if (getLinked()) {
|
827 |
layout.setStatus(Layout.DESACTUALIZADO); |
828 |
refresh=true;
|
829 |
//setBufferedImage(null);
|
830 |
} |
831 |
} |
832 |
|
833 |
/**
|
834 |
* DOCUMENT ME!
|
835 |
*
|
836 |
* @param xml DOCUMENT ME!
|
837 |
*/
|
838 |
public void setXMLEntity(XMLEntity xml) { |
839 |
if (xml.getIntProperty("m_Selected") != 0) { |
840 |
this.setSelected(true); |
841 |
} else {
|
842 |
this.setSelected(false); |
843 |
} |
844 |
|
845 |
this.setName(xml.getStringProperty("m_name")); |
846 |
this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
847 |
xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
848 |
xml.getDoubleProperty("h")));
|
849 |
|
850 |
this.m_Mode = xml.getIntProperty("m_Mode"); |
851 |
this.m_typeScale = xml.getIntProperty("m_typeScale"); |
852 |
this.m_extension = xml.getIntProperty("m_extension"); |
853 |
this.m_quality = xml.getIntProperty("m_quality"); |
854 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
855 |
this.m_bLinked = xml.getBooleanProperty("m_bLinked"); |
856 |
this.m_mapUnits = xml.getIntProperty("m_mapUnits"); |
857 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
858 |
|
859 |
this.m_Scale = xml.getDoubleProperty("m_Scale"); |
860 |
|
861 |
int indice = xml.getIntProperty("indice"); |
862 |
|
863 |
ProjectView view = null;
|
864 |
|
865 |
if (xml.contains("viewName")){ |
866 |
view = (ProjectView)project.getProjectDocumentByName(xml.getStringProperty("viewName"),ProjectViewFactory.registerName);
|
867 |
}else {
|
868 |
if (indice != -1) { |
869 |
try {
|
870 |
ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
|
871 |
|
872 |
view = (ProjectView) views.get(indice); |
873 |
} catch (IndexOutOfBoundsException e) { |
874 |
NotificationManager.addError("No se ha encontrado la vista de indice "+ indice,
|
875 |
e); |
876 |
} |
877 |
} |
878 |
} |
879 |
|
880 |
|
881 |
if (view != null) { |
882 |
this.setView(view);
|
883 |
|
884 |
try {
|
885 |
if (xml.contains("extentX")) { |
886 |
if (m_bLinked) {
|
887 |
this.getMapContext().getViewPort().setExtent(new Rectangle2D.Double( |
888 |
xml.getDoubleProperty("extentX"),
|
889 |
xml.getDoubleProperty("extentY"),
|
890 |
xml.getDoubleProperty("extentW"),
|
891 |
xml.getDoubleProperty("extentH")));
|
892 |
} else if (!m_bLinked) { |
893 |
this.m_fmap = MapContext.createFromXML(xml.getChild(0)); |
894 |
} |
895 |
} |
896 |
} catch (XMLException e) {
|
897 |
NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
|
898 |
e); |
899 |
} |
900 |
} else if (!m_bLinked) { |
901 |
try {
|
902 |
this.m_fmap = MapContext.createFromXML(xml.getChild(0)); |
903 |
} catch (XMLException e) {
|
904 |
e.printStackTrace(); |
905 |
} |
906 |
} |
907 |
} |
908 |
|
909 |
/**
|
910 |
* DOCUMENT ME!
|
911 |
*
|
912 |
* @return DOCUMENT ME!
|
913 |
*/
|
914 |
public Layout getLayout() {
|
915 |
return layout;
|
916 |
} |
917 |
|
918 |
/**
|
919 |
* DOCUMENT ME!
|
920 |
*
|
921 |
* @param arg0 DOCUMENT ME!
|
922 |
*
|
923 |
* @return DOCUMENT ME!
|
924 |
*/
|
925 |
public boolean compare(Object arg0) { |
926 |
if (!(arg0 instanceof FFrameView)) { |
927 |
return false; |
928 |
} |
929 |
|
930 |
if (!this.getName().equals(((FFrameView) arg0).getName())) { |
931 |
return false; |
932 |
} |
933 |
|
934 |
if (Math.abs(this.getBoundBox().getWidth()-(((FFrameView) arg0).getBoundBox().getWidth()))>0.05) { |
935 |
return false; |
936 |
} |
937 |
if (Math.abs(this.getBoundBox().getHeight()-(((FFrameView) arg0).getBoundBox().getHeight()))>0.05) { |
938 |
return false; |
939 |
} |
940 |
|
941 |
if (!this.toString().equals(((FFrameView) arg0).toString())) { |
942 |
return false; |
943 |
} |
944 |
|
945 |
if (this.getMapContext()!=null && !this.getMapContext().equals(((FFrameView) arg0).getMapContext())) { |
946 |
return false; |
947 |
} |
948 |
|
949 |
if (this.getRotation()!=((FFrameView)arg0).getRotation()){ |
950 |
return false; |
951 |
} |
952 |
|
953 |
return true; |
954 |
} |
955 |
|
956 |
/**
|
957 |
* DOCUMENT ME!
|
958 |
*
|
959 |
* @param arg0 DOCUMENT ME!
|
960 |
*
|
961 |
* @return DOCUMENT ME!
|
962 |
*/
|
963 |
public boolean equals(Object arg0) { |
964 |
return this.compare(arg0); |
965 |
} |
966 |
|
967 |
public void refresh() { |
968 |
if (view!=null && (getTypeScale() == MANUAL || getTypeScale() == CONSTANTE )) |
969 |
getMapContext().getViewPort().setExtent(getNewExtent(getScale())); |
970 |
refresh=true;
|
971 |
} |
972 |
|
973 |
public void fullExtent() throws DriverException { |
974 |
setNewExtent(getMapContext().getFullExtent()); |
975 |
} |
976 |
|
977 |
public void setPointsToZoom(Point2D px1, Point2D px2) { |
978 |
p1=px1; |
979 |
p2=px2; |
980 |
} |
981 |
|
982 |
public void movePoints(Point2D px1, Point2D px2) { |
983 |
double difX=-px2.getX()+px1.getX();
|
984 |
double difY=-px2.getY()+px1.getY();
|
985 |
if (p1!=null) { |
986 |
p1.setLocation(p1.getX()+difX,p1.getY()+difY); |
987 |
p2.setLocation(p2.getX()+difX,p2.getY()+difY); |
988 |
} |
989 |
} |
990 |
|
991 |
public void cloneActions(IFFrame frame) { |
992 |
if (view ==null || view.getMapContext()==null) |
993 |
return;
|
994 |
if (m_bLinked) {
|
995 |
if (getTypeScale() == AUTOMATICO) {
|
996 |
view.getMapContext().getViewPort().addViewPortListener(this);
|
997 |
view.getMapContext().addLayerListener(this);
|
998 |
} else if (getTypeScale() == CONSTANTE) { |
999 |
view.getMapContext().getViewPort().removeViewPortListener(this);
|
1000 |
view.getMapContext().addLayerListener(this);
|
1001 |
} else if (getTypeScale() == MANUAL) { |
1002 |
view.getMapContext().getViewPort().removeViewPortListener(this);
|
1003 |
view.getMapContext().addLayerListener(this);
|
1004 |
} |
1005 |
} else if (!m_bLinked) { |
1006 |
if (getTypeScale() == AUTOMATICO) {
|
1007 |
view.getMapContext().getViewPort().addViewPortListener(this);
|
1008 |
} else if (getTypeScale() == CONSTANTE) { |
1009 |
view.getMapContext().getViewPort().removeViewPortListener(this);
|
1010 |
} else if (getTypeScale() == MANUAL) { |
1011 |
view.getMapContext().getViewPort().removeViewPortListener(this);
|
1012 |
} |
1013 |
} |
1014 |
((FFrameView)frame).view.getMapContext().removeLayerListener((FFrameView)frame); |
1015 |
((FFrameView)frame).view.getMapContext().getViewPort().removeViewPortListener((FFrameView)frame); |
1016 |
|
1017 |
|
1018 |
} |
1019 |
public IFFrame cloneFFrame(Layout layout) {
|
1020 |
FFrameView frame = new FFrameView();
|
1021 |
frame.setLevel(this.getLevel());
|
1022 |
frame.setNum(this.num);
|
1023 |
frame.setName(this.getName());
|
1024 |
frame.setBoundBox(this.getBoundBox());
|
1025 |
frame.setTag(this.getTag());
|
1026 |
frame.m_Mode = this.m_Mode;
|
1027 |
frame.m_typeScale = this.m_typeScale;
|
1028 |
frame.m_extension = this.m_extension;
|
1029 |
frame.m_quality = this.m_quality;
|
1030 |
frame.m_viewing = this.m_viewing;
|
1031 |
frame.m_bLinked = this.m_bLinked;
|
1032 |
frame.m_mapUnits = this.m_mapUnits;
|
1033 |
frame.setRotation(this.getRotation());
|
1034 |
|
1035 |
frame.m_Scale = this.m_Scale;
|
1036 |
frame.view=this.getView();
|
1037 |
frame.m_fmap = this.getMapContext();
|
1038 |
frame.setSelected(this.getSelected()!=IFFrame.NOSELECT);
|
1039 |
frame.setLayout(layout); |
1040 |
|
1041 |
if (frame instanceof IFFrameViewDependence) { |
1042 |
((IFFrameViewDependence) frame).initDependence(layout.getAllFFrames()); |
1043 |
} |
1044 |
cloneActions(frame); |
1045 |
return frame;
|
1046 |
} |
1047 |
} |