svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameView.java @ 4203
History | View | Annotate | Download (30.1 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-feb-2004
|
3 |
*
|
4 |
*/
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 |
*
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
8 |
*
|
9 |
* This program is free software; you can redistribute it and/or
|
10 |
* modify it under the terms of the GNU General Public License
|
11 |
* as published by the Free Software Foundation; either version 2
|
12 |
* of the License, or (at your option) any later version.
|
13 |
*
|
14 |
* This program is distributed in the hope that it will be useful,
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
* GNU General Public License for more details.
|
18 |
*
|
19 |
* You should have received a copy of the GNU General Public License
|
20 |
* along with this program; if not, write to the Free Software
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.gui.layout.fframes; |
46 |
|
47 |
import java.awt.Color; |
48 |
import java.awt.Dimension; |
49 |
import java.awt.Graphics2D; |
50 |
import java.awt.Point; |
51 |
import java.awt.Rectangle; |
52 |
import java.awt.geom.AffineTransform; |
53 |
import java.awt.geom.Point2D; |
54 |
import java.awt.geom.Rectangle2D; |
55 |
import java.awt.geom.Rectangle2D.Double; |
56 |
import java.awt.image.BufferedImage; |
57 |
import java.util.ArrayList; |
58 |
|
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.DriverException; |
64 |
import com.iver.cit.gvsig.fmap.ExtentEvent; |
65 |
import com.iver.cit.gvsig.fmap.FMap; |
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.gui.layout.FLayoutFunctions; |
72 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
73 |
import com.iver.cit.gvsig.gui.layout.Layout; |
74 |
import com.iver.cit.gvsig.gui.project.SaveException; |
75 |
import com.iver.cit.gvsig.project.Project; |
76 |
import com.iver.cit.gvsig.project.ProjectView; |
77 |
import com.iver.utiles.XMLEntity; |
78 |
|
79 |
|
80 |
/**
|
81 |
* FFrame para introducir una vista en el Layout.
|
82 |
*
|
83 |
* @author Vicente Caballero Navarro
|
84 |
*/
|
85 |
public class FFrameView extends FFrame implements ViewPortListener, |
86 |
LegendListener, IFFrameUseProject, IFFrameLayoutDependence,IFFrameUseFMap { |
87 |
//private static Logger logger = Logger.getLogger(FFrameView.class.getName());
|
88 |
public static final int AUTOMATICO = 0; |
89 |
public static final int CONSTANTE = 1; |
90 |
public static final int MANUAL = 2; |
91 |
public static final int PRESENTACION = 0; |
92 |
public static final int BORRADOR = 1; |
93 |
private int m_Mode; |
94 |
private int m_typeScale = AUTOMATICO; |
95 |
private int m_extension = 0; |
96 |
private int m_quality = PRESENTACION; |
97 |
private int m_viewing = 0; |
98 |
private boolean m_bLinked = true; |
99 |
private ProjectView view = null; |
100 |
private FMap m_fmap = null; |
101 |
private double m_Scale = 0; |
102 |
private int m_mapUnits = 1; //Metros. |
103 |
|
104 |
private BufferedImage m_image = null; |
105 |
private AffineTransform at = null; |
106 |
private Project project = null; |
107 |
private Layout layout;
|
108 |
private double scaleAnt; |
109 |
private boolean refresh=false; |
110 |
private boolean hasViewPort=false; |
111 |
private Point2D antpoint; |
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 |
getFMap().getViewPort().setExtent(r); |
148 |
m_Scale = FLayoutUtilities.getScaleView(getFMap().getViewPort(), |
149 |
getBoundBox().width, |
150 |
getBoundingBox(null).width / getBoundBox().width);
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
|
155 |
* escala fija.
|
156 |
*
|
157 |
* @return FMap.
|
158 |
*/
|
159 |
public FMap getFMap() {
|
160 |
return m_fmap;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Rellena la calidad que se quiere aplicar.
|
165 |
*
|
166 |
* @param q entero que representa la calidad a aplicar.
|
167 |
*/
|
168 |
public void setQuality(int q) { |
169 |
m_quality = q; |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Devuelve un entero que representa la calidad que est? seleccionada.
|
174 |
*
|
175 |
* @return tipo de calidad selccionada.
|
176 |
*/
|
177 |
public int getQuality() { |
178 |
return m_quality;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
183 |
*
|
184 |
* @return forma que se actualiza la vista.
|
185 |
*/
|
186 |
public int getViewing() { |
187 |
return m_viewing;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* Rellena la forma de actualizar la vista(cuando activo o siempre). De
|
192 |
* momento esta opci?n esta deshabilitada.
|
193 |
*
|
194 |
* @param v entero que representa la forma de actualizar la vista.
|
195 |
*/
|
196 |
public void setViewing(int v) { |
197 |
m_viewing = v; |
198 |
} |
199 |
|
200 |
/**
|
201 |
* Inserta el ProjectView de donde obtener las propiedades de la vista a
|
202 |
* mostrar.
|
203 |
*
|
204 |
* @param v Modelo de la vista.
|
205 |
*/
|
206 |
public void setView(ProjectView v) { |
207 |
view = v; |
208 |
|
209 |
ViewPort vp = v.getMapContext().getViewPort().cloneViewPort(); |
210 |
|
211 |
vp.setImageSize(new Dimension((int) getBoundingBox(getATMap()).width, |
212 |
(int) getBoundingBox(null).height)); |
213 |
|
214 |
if (m_bLinked) {
|
215 |
if (getTypeScale() == AUTOMATICO) {
|
216 |
m_fmap = v.getMapContext().createNewFMap(v.getMapContext() |
217 |
.getViewPort() |
218 |
.cloneViewPort()); |
219 |
m_fmap.getViewPort().setImageSize(new Dimension( |
220 |
(int) getBoundingBox(null).width, |
221 |
(int) getBoundingBox(null).height)); |
222 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
223 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
224 |
v.getMapContext().removeLayerListener(this);
|
225 |
v.getMapContext().addLayerListener(this);
|
226 |
} else if (getTypeScale() == CONSTANTE) { |
227 |
vp.setExtent((Rectangle2D) v.getMapContext().getViewPort()
|
228 |
.getExtent().clone()); |
229 |
m_fmap = v.getMapContext().createNewFMap(vp); |
230 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
231 |
v.getMapContext().removeLayerListener(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().removeLayerListener(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().removeViewPortListener(this);
|
250 |
v.getMapContext().getViewPort().addViewPortListener(this);
|
251 |
} else if (getTypeScale() == CONSTANTE) { |
252 |
vp.setExtent((Rectangle2D) v.getMapContext().getViewPort()
|
253 |
.getExtent().clone()); |
254 |
m_fmap = v.getMapContext().cloneFMap(); |
255 |
m_fmap.setViewPort(vp); |
256 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
257 |
} else if (getTypeScale() == MANUAL) { |
258 |
m_fmap = v.getMapContext().cloneFMap(); |
259 |
vp.setExtent(getNewExtent(getScale())); |
260 |
m_fmap.setViewPort(vp); |
261 |
v.getMapContext().getViewPort().removeViewPortListener(this);
|
262 |
} |
263 |
} catch (XMLException e1) {
|
264 |
NotificationManager.addError("Cuando se a?ade una vista al Layout",
|
265 |
e1); |
266 |
} |
267 |
} |
268 |
} |
269 |
|
270 |
/**
|
271 |
* Devuelve el modelo de la vista.
|
272 |
*
|
273 |
* @return Modelo de la vista.
|
274 |
*/
|
275 |
public ProjectView getView() {
|
276 |
return view;
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* Devuelve un Rect?ngulo que representa el extent de la vista que se
|
281 |
* requiere a partir de una escala.
|
282 |
*
|
283 |
* @param scale Escala a mostrar.
|
284 |
*
|
285 |
* @return Rect?ngulo.
|
286 |
*/
|
287 |
private Rectangle2D.Double getNewExtent(long scale) { |
288 |
double hview = getBoundBox().getHeight();
|
289 |
double wview = getBoundBox().getWidth();
|
290 |
double hextent = (scale * hview) / 100.0; |
291 |
double wextent = (scale * wview) / 100.0; |
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 Graphics2D
|
306 |
* @param at Transformada af?n.
|
307 |
* @param rv rect?ngulo sobre el que hacer un clip. (el rect?ngulo visible)
|
308 |
* @param imgBase Imagen para acelerar el dibujado.
|
309 |
*
|
310 |
* @throws com.iver.cit.gvsig.fmap.DriverException
|
311 |
*/
|
312 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
313 |
BufferedImage imgBase) throws com.iver.cit.gvsig.fmap.DriverException { |
314 |
System.out.println("Tama?o del imgBase= "+ imgBase.getWidth()+","+imgBase.getHeight()); |
315 |
Point2D point =null; |
316 |
if (getATMap()!=null){ |
317 |
point =functions.toMapPoint(new Point2D.Double(layout.getRect().getX(),layout.getRect().getY()), getATMap()); |
318 |
} |
319 |
/**
|
320 |
* this FFrame's BoundingBox
|
321 |
*/
|
322 |
Rectangle2D.Double r = getBoundingBox(at);
|
323 |
if (rv!=null && layout.getAT().getScaleX()==scaleAnt && m_image!=null && !refresh){ |
324 |
if (point.equals(antpoint)) {
|
325 |
g.translate((int) r.getX(), (int) r.getY()); |
326 |
g.drawImage(m_image, 0, 0, layout); |
327 |
g.translate(-(int) r.getX(), -(int) r.getY()); |
328 |
scaleAnt = layout.getAT().getScaleX(); |
329 |
return;
|
330 |
} |
331 |
} |
332 |
|
333 |
if (getRotation()!=0) |
334 |
g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), |
335 |
r.y + (r.height / 2));
|
336 |
|
337 |
if (intersects(rv, r)) {
|
338 |
if (getFMap() == null) { |
339 |
drawEmpty(g); |
340 |
} else {
|
341 |
if (rv != null) { |
342 |
// Dibujamos en pantalla
|
343 |
Rectangle rclip = g.getClipBounds();
|
344 |
g.clipRect((int) r.getMinX(), (int) r.getMinY(), |
345 |
(int) r.getWidth(), (int) r.getHeight()); |
346 |
|
347 |
if (getQuality() == PRESENTACION) {
|
348 |
if (rv.intersects(r)) {
|
349 |
ViewPort viewPort = this.getFMap().getViewPort();
|
350 |
Color theBackColor = viewPort.getBackColor();
|
351 |
|
352 |
if (theBackColor != null) { |
353 |
g.setColor(theBackColor); |
354 |
g.fillRect((int) r.x, (int) r.y, |
355 |
viewPort.getImageWidth(), |
356 |
viewPort.getImageHeight()); |
357 |
} |
358 |
System.err.println("r : "+r); |
359 |
if (r.getWidth()>layout.getWidth() || r.getHeight()>layout.getHeight()){
|
360 |
getFMap().getViewPort().setOffset(new Point2D.Double(0,0)); |
361 |
if (antpoint!=null && !refresh){ |
362 |
Rectangle2D extent=getFMap().getViewPort().getExtent();
|
363 |
extent.setRect(extent.getX()+(antpoint.getX()-point.getX()),extent.getY()+(antpoint.getY()-point.getY()),extent.getWidth(),extent.getHeight()); |
364 |
setNewExtent(extent); |
365 |
} |
366 |
//if (antViewPort==null)
|
367 |
//antViewPort=getFMap().getViewPort().cloneViewPort();
|
368 |
getFMap().getViewPort().setImageSize(new Dimension((int) layout.getWidth(), (int)layout.getHeight())); |
369 |
getFMap().draw(imgBase, g, getScale()); |
370 |
setATMap((AffineTransform) getFMap()
|
371 |
.getViewPort() |
372 |
.getAffineTransform() |
373 |
.clone()); |
374 |
//getFMap().setViewPort(antViewPort.cloneViewPort());
|
375 |
antpoint=functions.toMapPoint(new Point2D.Double(layout.getRect().getX(),layout.getRect().getY()), getATMap()); |
376 |
}else{
|
377 |
if (!hasViewPort){
|
378 |
saveAntViewPort(); |
379 |
hasViewPort=true;
|
380 |
}else{
|
381 |
getFMap().setViewPort(antViewPort.cloneViewPort()); |
382 |
} |
383 |
getFMap().getViewPort().setOffset(new Point2D.Double( |
384 |
r.x, r.y)); |
385 |
getFMap().getViewPort().setImageSize(new Dimension( |
386 |
(int) r.width, (int) r.height)); |
387 |
m_image=new BufferedImage((int)r.getWidth(), |
388 |
(int) r.getHeight(),
|
389 |
BufferedImage.TYPE_INT_ARGB);
|
390 |
Graphics2D gimg=(Graphics2D) m_image.getGraphics(); |
391 |
gimg.translate(-((int)r.getX()),-((int)r.getY())); |
392 |
getFMap().draw(m_image,gimg, getScale()); |
393 |
gimg.translate(((int)r.getX()),((int)r.getY())); |
394 |
g.drawImage(m_image,(int)r.getX(),(int)r.getY(),layout); |
395 |
setATMap((AffineTransform) getFMap()
|
396 |
.getViewPort() |
397 |
.getAffineTransform() |
398 |
.clone()); |
399 |
antpoint=null;
|
400 |
} |
401 |
scaleAnt=layout.getAT().getScaleX(); |
402 |
refresh=false;
|
403 |
|
404 |
} |
405 |
if (rclip != null) { |
406 |
g.setClip(rclip.x, rclip.y, rclip.width, |
407 |
rclip.height); |
408 |
} |
409 |
} else {
|
410 |
drawDraft(g); |
411 |
} |
412 |
} else {
|
413 |
printX(g, at); |
414 |
setATMap((AffineTransform) getFMap()
|
415 |
.getViewPort() |
416 |
.getAffineTransform() |
417 |
.clone()); |
418 |
} |
419 |
} |
420 |
} |
421 |
|
422 |
if (getRotation()!=0) |
423 |
g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), |
424 |
r.y + (r.height / 2));
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* DOCUMENT ME!
|
429 |
*
|
430 |
* @param g DOCUMENT ME!
|
431 |
* @param at DOCUMENT ME!
|
432 |
*
|
433 |
* @throws DriverException
|
434 |
*
|
435 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
436 |
* java.awt.geom.AffineTransform)
|
437 |
*/
|
438 |
public void print(Graphics2D g, AffineTransform at) |
439 |
throws DriverException {
|
440 |
draw(g, at, null, null); |
441 |
} |
442 |
|
443 |
/**
|
444 |
* DOCUMENT ME!
|
445 |
*
|
446 |
* @param g DOCUMENT ME!
|
447 |
* @param at DOCUMENT ME!
|
448 |
*/
|
449 |
private void printX(Graphics2D g, AffineTransform at) { |
450 |
Rectangle2D.Double r = getBoundingBox(at);
|
451 |
|
452 |
// Dibujamos en impresora
|
453 |
Rectangle rclip = g.getClipBounds();
|
454 |
g.clipRect((int) r.getMinX(), (int) r.getMinY(), (int) r.getWidth(), |
455 |
(int) r.getHeight());
|
456 |
this.getFMap().getViewPort().setOffset(new Point2D.Double(r.x, r.y)); |
457 |
this.getFMap().getViewPort().setImageSize(new Dimension((int) r.width, |
458 |
(int) r.height));
|
459 |
|
460 |
try {
|
461 |
this.getFMap().print(g, getScale());
|
462 |
} catch (com.iver.cit.gvsig.fmap.DriverException e) {
|
463 |
NotificationManager.addError(e.getMessage(), e); |
464 |
} |
465 |
|
466 |
g.setClip(rclip.x, rclip.y, rclip.width, rclip.height); |
467 |
} |
468 |
|
469 |
/**
|
470 |
* Rellena la unidad de medida en la que est? la vista.
|
471 |
*
|
472 |
* @param i entero que representa la unidad de medida de la vista.
|
473 |
*/
|
474 |
public void setMapUnits(int i) { |
475 |
m_mapUnits = i; |
476 |
} |
477 |
|
478 |
/**
|
479 |
* Obtiene la unidad de medida en la que est? la vista.
|
480 |
*
|
481 |
* @return Unidad de medida.
|
482 |
*/
|
483 |
public int getMapUnits() { |
484 |
return m_mapUnits;
|
485 |
} |
486 |
|
487 |
/**
|
488 |
* Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
|
489 |
* a?adida la vista.
|
490 |
*
|
491 |
* @return escala.
|
492 |
*/
|
493 |
public long getScale() { |
494 |
/*if (m_bLinked){
|
495 |
return getScaleView1(METROS);
|
496 |
}
|
497 |
*/
|
498 |
if (getTypeScale() == AUTOMATICO) {
|
499 |
return FLayoutUtilities.getScaleView(getFMap().getViewPort(),
|
500 |
getBoundBox().width, getBoundingBox(null).width);
|
501 |
} else if (getTypeScale() == CONSTANTE) { |
502 |
return (long) m_Scale; |
503 |
} else if (getTypeScale() == MANUAL) { |
504 |
return (long) m_Scale; |
505 |
} |
506 |
|
507 |
return (long) m_Scale; |
508 |
} |
509 |
|
510 |
/**
|
511 |
* Seleccionar si la vista esta relacionada o no con la original.
|
512 |
*
|
513 |
* @param b true si est? ligada y false si no lo est?.
|
514 |
*/
|
515 |
public void setLinked(boolean b) { |
516 |
m_bLinked = b; |
517 |
} |
518 |
|
519 |
/**
|
520 |
* Devuelve si est? ligada o no el FFrameView con la vista.
|
521 |
*
|
522 |
* @return True si la vista est? ligada.
|
523 |
*/
|
524 |
public boolean getLinked() { |
525 |
return m_bLinked;
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
|
530 |
* la vista.
|
531 |
*
|
532 |
* @return entero que representa la opci?n elegida.
|
533 |
*/
|
534 |
public int getExtension() { |
535 |
return m_extension;
|
536 |
} |
537 |
|
538 |
/**
|
539 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
|
540 |
* MANUAL.
|
541 |
*
|
542 |
* @return entero que representa el tipo seleccionado.
|
543 |
*/
|
544 |
public int getTypeScale() { |
545 |
return m_typeScale;
|
546 |
} |
547 |
|
548 |
/**
|
549 |
* Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
|
550 |
*
|
551 |
* @param i entero que representa la opci?n elegida.
|
552 |
*/
|
553 |
public void setExtension(int i) { |
554 |
m_extension = i; |
555 |
} |
556 |
|
557 |
/**
|
558 |
* Rellenar el tipo de escala que se desea.
|
559 |
*
|
560 |
* @param i entero que representa el tipo de escala.
|
561 |
*/
|
562 |
public void setTypeScale(int i) { |
563 |
m_typeScale = i; |
564 |
} |
565 |
|
566 |
/**
|
567 |
* DOCUMENT ME!
|
568 |
*
|
569 |
* @return DOCUMENT ME!
|
570 |
*
|
571 |
* @throws SaveException
|
572 |
*
|
573 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
574 |
*/
|
575 |
public XMLEntity getXMLEntity() throws SaveException { |
576 |
XMLEntity xml = super.getXMLEntity();
|
577 |
|
578 |
try {
|
579 |
xml.putProperty("type", Layout.RECTANGLEVIEW);
|
580 |
xml.putProperty("m_Mode", m_Mode);
|
581 |
xml.putProperty("m_typeScale", m_typeScale);
|
582 |
xml.putProperty("m_extension", m_extension);
|
583 |
xml.putProperty("m_quality", m_quality);
|
584 |
xml.putProperty("m_viewing", m_viewing);
|
585 |
xml.putProperty("m_bLinked", m_bLinked);
|
586 |
xml.putProperty("m_mapUnits", m_mapUnits);
|
587 |
xml.putProperty("m_Scale", m_Scale);
|
588 |
|
589 |
ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class); |
590 |
ArrayList views = pe.getProject().getViews();
|
591 |
|
592 |
boolean hasIndex = false; |
593 |
|
594 |
for (int i = 0; i < views.size(); i++) { |
595 |
if ((view != null) && |
596 |
view.getName().equals(((ProjectView) views.get(i)).getName())) { |
597 |
xml.putProperty("indice", i);
|
598 |
hasIndex = true;
|
599 |
} |
600 |
} |
601 |
|
602 |
if (!hasIndex) {
|
603 |
xml.putProperty("indice", -1); |
604 |
} |
605 |
|
606 |
if (getFMap() != null) { |
607 |
xml.putProperty("extentX",
|
608 |
getFMap().getViewPort().getExtent().getX()); |
609 |
xml.putProperty("extentY",
|
610 |
getFMap().getViewPort().getExtent().getY()); |
611 |
xml.putProperty("extentW",
|
612 |
getFMap().getViewPort().getExtent().getWidth()); |
613 |
xml.putProperty("extentH",
|
614 |
getFMap().getViewPort().getExtent().getHeight()); |
615 |
|
616 |
xml.addChild(getFMap().getXMLEntity()); |
617 |
} |
618 |
} catch (Exception e) { |
619 |
throw new SaveException(e, this.getClass().getName()); |
620 |
} |
621 |
|
622 |
return xml;
|
623 |
} |
624 |
|
625 |
/**
|
626 |
* Inserta la imagen para repintar el FFrameView.
|
627 |
*
|
628 |
* @param bi Imagen para repintar.
|
629 |
*/
|
630 |
public void setBufferedImage(BufferedImage bi) { |
631 |
m_image = bi; |
632 |
} |
633 |
|
634 |
/**
|
635 |
* Devuelve la imagen para repintar.
|
636 |
*
|
637 |
* @return Imagen para repintar.
|
638 |
*/
|
639 |
public BufferedImage getBufferedImage() { |
640 |
return m_image;
|
641 |
} |
642 |
|
643 |
/**
|
644 |
* Devuelve la MAtriz de transformaci?n utilizada por la FFrameView para poder cambiar
|
645 |
* un punto en pixels a coordenadas del mundo real.
|
646 |
*
|
647 |
* @return MAtriz de transformaci?n.
|
648 |
*/
|
649 |
public AffineTransform getATMap() { |
650 |
return at;
|
651 |
} |
652 |
|
653 |
/**
|
654 |
* Inserta la matriz de transformaci?n.
|
655 |
*
|
656 |
* @param transform Matriz de transformaci?n.
|
657 |
*/
|
658 |
public void setATMap(AffineTransform transform) { |
659 |
at = transform; |
660 |
} |
661 |
/**
|
662 |
* Inserta el proyecto.
|
663 |
*
|
664 |
* @param p Proyecto.
|
665 |
*/
|
666 |
public void setProject(Project p) { |
667 |
project = p; |
668 |
} |
669 |
|
670 |
/**
|
671 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
672 |
* com.iver.cit.gvsig.project.Project)
|
673 |
*/
|
674 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
675 |
if (xml.getIntProperty("m_Selected") != 0) { |
676 |
this.setSelected(true); |
677 |
} else {
|
678 |
this.setSelected(false); |
679 |
} |
680 |
|
681 |
this.setName(xml.getStringProperty("m_name")); |
682 |
this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
683 |
xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
684 |
xml.getDoubleProperty("h")));
|
685 |
|
686 |
this.m_Mode = xml.getIntProperty("m_Mode"); |
687 |
this.m_typeScale = xml.getIntProperty("m_typeScale"); |
688 |
this.m_extension = xml.getIntProperty("m_extension"); |
689 |
this.m_quality = xml.getIntProperty("m_quality"); |
690 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
691 |
this.m_bLinked = xml.getBooleanProperty("m_bLinked"); |
692 |
this.m_mapUnits = xml.getIntProperty("m_mapUnits"); |
693 |
|
694 |
this.m_Scale = xml.getDoubleProperty("m_Scale"); |
695 |
|
696 |
int indice = xml.getIntProperty("indice"); |
697 |
|
698 |
if (indice != -1) { |
699 |
ProjectView view = (ProjectView) project.getViews().get(indice); |
700 |
this.m_fmap = view.getMapContext();
|
701 |
this.setView((ProjectView) view);
|
702 |
|
703 |
try {
|
704 |
//this.m_fmap = view.getMapContext();
|
705 |
|
706 |
/* this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
|
707 |
xml.getDoubleProperty("extentX"),
|
708 |
xml.getDoubleProperty("extentY"),
|
709 |
xml.getDoubleProperty("extentW"),
|
710 |
xml.getDoubleProperty("extentH")));
|
711 |
*/
|
712 |
if (m_bLinked) {
|
713 |
this.getFMap().getViewPort().setExtent(new Rectangle2D.Double( |
714 |
xml.getDoubleProperty("extentX"),
|
715 |
xml.getDoubleProperty("extentY"),
|
716 |
xml.getDoubleProperty("extentW"),
|
717 |
xml.getDoubleProperty("extentH")));
|
718 |
} else if (!m_bLinked) { |
719 |
this.m_fmap = FMap.createFromXML03(xml.getChild(0)); |
720 |
} |
721 |
} catch (XMLException e) {
|
722 |
NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
|
723 |
e); |
724 |
} |
725 |
} |
726 |
} |
727 |
|
728 |
/**
|
729 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
|
730 |
*/
|
731 |
public String getNameFFrame() { |
732 |
return PluginServices.getText(this, "Vista") + num; |
733 |
} |
734 |
|
735 |
/**
|
736 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
737 |
*/
|
738 |
public void extentChanged(ExtentEvent e) { |
739 |
if (getTypeScale() == AUTOMATICO) {
|
740 |
m_fmap.getViewPort().setExtent(e.getNewExtent()); |
741 |
|
742 |
if (layout != null) { |
743 |
layout.setStatus(Layout.DESACTUALIZADO); |
744 |
} |
745 |
} |
746 |
} |
747 |
|
748 |
/**
|
749 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
750 |
*/
|
751 |
public void backColorChanged(ColorEvent e) { |
752 |
if (getLinked()) {
|
753 |
m_fmap.getViewPort().setBackColor(e.getNewColor()); |
754 |
layout.setStatus(Layout.DESACTUALIZADO); |
755 |
} |
756 |
} |
757 |
|
758 |
/**
|
759 |
* DOCUMENT ME!
|
760 |
*
|
761 |
* @param l DOCUMENT ME!
|
762 |
*/
|
763 |
public void setLayout(Layout l) { |
764 |
layout = l; |
765 |
} |
766 |
|
767 |
/**
|
768 |
* DOCUMENT ME!
|
769 |
*
|
770 |
* @param e DOCUMENT ME!
|
771 |
*/
|
772 |
public void legendChanged(LegendChangedEvent e) { |
773 |
if (getLinked()) {
|
774 |
layout.setStatus(Layout.DESACTUALIZADO); |
775 |
} |
776 |
} |
777 |
|
778 |
/**
|
779 |
* DOCUMENT ME!
|
780 |
*
|
781 |
* @param xml DOCUMENT ME!
|
782 |
*/
|
783 |
public void setXMLEntity(XMLEntity xml) { |
784 |
if (xml.getIntProperty("m_Selected") != 0) { |
785 |
this.setSelected(true); |
786 |
} else {
|
787 |
this.setSelected(false); |
788 |
} |
789 |
|
790 |
this.setName(xml.getStringProperty("m_name")); |
791 |
this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), |
792 |
xml.getDoubleProperty("y"), xml.getDoubleProperty("w"), |
793 |
xml.getDoubleProperty("h")));
|
794 |
|
795 |
this.m_Mode = xml.getIntProperty("m_Mode"); |
796 |
this.m_typeScale = xml.getIntProperty("m_typeScale"); |
797 |
this.m_extension = xml.getIntProperty("m_extension"); |
798 |
this.m_quality = xml.getIntProperty("m_quality"); |
799 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
800 |
this.m_bLinked = xml.getBooleanProperty("m_bLinked"); |
801 |
this.m_mapUnits = xml.getIntProperty("m_mapUnits"); |
802 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
803 |
this.m_Scale = xml.getDoubleProperty("m_Scale"); |
804 |
|
805 |
int indice = xml.getIntProperty("indice"); |
806 |
|
807 |
if (indice != -1) { |
808 |
try {
|
809 |
ProjectView view = (ProjectView) project.getViews().get(indice); |
810 |
this.m_fmap = view.getMapContext();
|
811 |
this.setView((ProjectView) view);
|
812 |
|
813 |
try {
|
814 |
//this.m_fmap = view.getMapContext();
|
815 |
|
816 |
/* this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
|
817 |
xml.getDoubleProperty("extentX"),
|
818 |
xml.getDoubleProperty("extentY"),
|
819 |
xml.getDoubleProperty("extentW"),
|
820 |
xml.getDoubleProperty("extentH")));
|
821 |
*/
|
822 |
if (xml.contains("extentX")) { |
823 |
if (m_bLinked) {
|
824 |
this.getFMap().getViewPort().setExtent(new Rectangle2D.Double( |
825 |
xml.getDoubleProperty("extentX"),
|
826 |
xml.getDoubleProperty("extentY"),
|
827 |
xml.getDoubleProperty("extentW"),
|
828 |
xml.getDoubleProperty("extentH")));
|
829 |
} else if (!m_bLinked) { |
830 |
this.m_fmap = FMap.createFromXML(xml.getChild(0)); |
831 |
} |
832 |
} |
833 |
} catch (XMLException e) {
|
834 |
NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
|
835 |
e); |
836 |
} |
837 |
} catch (IndexOutOfBoundsException e) { |
838 |
} |
839 |
} else if (!m_bLinked) { |
840 |
try {
|
841 |
this.m_fmap = FMap.createFromXML(xml.getChild(0)); |
842 |
} catch (XMLException e) {
|
843 |
// TODO Auto-generated catch block
|
844 |
e.printStackTrace(); |
845 |
} |
846 |
} |
847 |
} |
848 |
|
849 |
/**
|
850 |
* DOCUMENT ME!
|
851 |
*
|
852 |
* @return DOCUMENT ME!
|
853 |
*/
|
854 |
public Layout getLayout() {
|
855 |
return layout;
|
856 |
} |
857 |
|
858 |
/**
|
859 |
* DOCUMENT ME!
|
860 |
*
|
861 |
* @param arg0 DOCUMENT ME!
|
862 |
*
|
863 |
* @return DOCUMENT ME!
|
864 |
*/
|
865 |
public boolean compare(Object arg0) { |
866 |
if (!(arg0 instanceof FFrameView)) { |
867 |
return false; |
868 |
} |
869 |
|
870 |
if (!this.getName().equals(((FFrameView) arg0).getName())) { |
871 |
return false; |
872 |
} |
873 |
|
874 |
if (!this.getBoundBox().equals(((FFrameView) arg0).getBoundBox())) { |
875 |
return false; |
876 |
} |
877 |
|
878 |
if (!this.toString().equals(((FFrameView) arg0).toString())) { |
879 |
return false; |
880 |
} |
881 |
|
882 |
if (!this.getFMap().equals(((FFrameView) arg0).getFMap())) { |
883 |
return false; |
884 |
} |
885 |
|
886 |
return true; |
887 |
} |
888 |
|
889 |
/**
|
890 |
* DOCUMENT ME!
|
891 |
*
|
892 |
* @param arg0 DOCUMENT ME!
|
893 |
*
|
894 |
* @return DOCUMENT ME!
|
895 |
*/
|
896 |
public boolean equals(Object arg0) { |
897 |
return this.compare(arg0); |
898 |
} |
899 |
|
900 |
public void refresh() { |
901 |
refresh=true;
|
902 |
} |
903 |
private FLayoutFunctions functions=new FLayoutFunctions(layout); |
904 |
private ViewPort antViewPort;
|
905 |
|
906 |
public void saveAntViewPort() { |
907 |
antViewPort=getFMap().getViewPort().cloneViewPort(); |
908 |
|
909 |
} |
910 |
|
911 |
public void initialize() { |
912 |
setView(view); |
913 |
} |
914 |
} |