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