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