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