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