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