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