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