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