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