root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameView.java @ 24962
History | View | Annotate | Download (31.4 KB)
1 | 9392 | caballero | /*
|
---|---|---|---|
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 | 10911 | jaume | import javax.print.attribute.PrintRequestAttributeSet; |
59 | |||
60 | 11971 | caballero | import org.cresques.cts.IProjection; |
61 | 24759 | jmvivo | import org.gvsig.fmap.dal.exception.ReadException; |
62 | 21154 | vcaballero | import org.gvsig.fmap.geom.Geometry; |
63 | 21530 | vcaballero | import org.gvsig.fmap.geom.primitive.DefaultEnvelope; |
64 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
65 | 20994 | jmvivo | 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 | 11971 | caballero | |
74 | 9392 | caballero | 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 | 23176 | vcaballero | import com.iver.utiles.XMLException; |
88 | 9392 | caballero | |
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 | 21530 | vcaballero | public void setNewEnvelope(Envelope r) { |
154 | 21501 | vcaballero | getMapContext().getViewPort().setEnvelope(r); |
155 | 9392 | caballero | 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 | 21530 | vcaballero | vp.setEnvelope(getNewEnvelope(getScale())); |
238 | 9392 | caballero | v.getMapContext().getViewPort().removeViewPortListener(this);
|
239 | v.getMapContext().addLayerListener(this);
|
||
240 | } else if (getTypeScale() == MANUAL) { |
||
241 | m_fmap = v.getMapContext().createNewFMap(vp); |
||
242 | 21530 | vcaballero | vp.setEnvelope(getNewEnvelope(getScale())); |
243 | 9392 | caballero | v.getMapContext().getViewPort().removeViewPortListener(this);
|
244 | v.getMapContext().addLayerListener(this);
|
||
245 | } |
||
246 | } else if (!m_bLinked) { |
||
247 | 23176 | vcaballero | // try {
|
248 | 9392 | caballero | 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 | 21530 | vcaballero | vp.setEnvelope(getNewEnvelope(getScale())); |
259 | 9392 | caballero | m_fmap.setViewPort(vp); |
260 | v.getMapContext().getViewPort().removeViewPortListener(this);
|
||
261 | } else if (getTypeScale() == MANUAL) { |
||
262 | m_fmap = v.getMapContext().cloneFMap(); |
||
263 | 21530 | vcaballero | vp.setEnvelope(getNewEnvelope(getScale())); |
264 | 9392 | caballero | m_fmap.setViewPort(vp); |
265 | v.getMapContext().getViewPort().removeViewPortListener(this);
|
||
266 | } |
||
267 | 23176 | vcaballero | // } catch (XMLException e1) {
|
268 | // NotificationManager.addError("Cuando se a?ade una vista al Layout",
|
||
269 | // e1);
|
||
270 | // }
|
||
271 | 9392 | caballero | } |
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 | 21530 | vcaballero | protected Envelope getNewEnvelope(long scale) { |
292 | 9392 | caballero | 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 | 24759 | jmvivo | if (m_fmap.getViewPort().getExtent()==null) { |
298 | return new DefaultEnvelope(2,new double[]{0,0},new double[]{0,0}); |
||
299 | } |
||
300 | 9392 | caballero | double newx = m_fmap.getViewPort().getExtent().getCenterX() -
|
301 | (wextent / 2.0);
|
||
302 | double newy = m_fmap.getViewPort().getExtent().getCenterY() -
|
||
303 | (hextent / 2.0);
|
||
304 | 11971 | caballero | IProjection proj=m_fmap.getViewPort().getProjection(); |
305 | 21530 | vcaballero | Envelope r = new DefaultEnvelope(2,new double[]{newx, newy},new double[]{newx+ wextent,newy+ hextent}); |
306 | 11971 | caballero | if (!proj.isProjected()){
|
307 | 21530 | vcaballero | 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=new DefaultEnvelope(2,new double[]{aux.getX(),aux.getY()},new double[]{aux.getMaxX(),aux.getMaxY()}); |
||
310 | } |
||
311 | 11971 | caballero | return r;
|
312 | 9392 | caballero | } |
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 | 21299 | vcaballero | * @throws ReadException
|
328 | 9392 | caballero | */
|
329 | public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
||
330 | BufferedImage imgBase)
|
||
331 | 21299 | vcaballero | throws ReadException {
|
332 | 9392 | caballero | Rectangle2D.Double r = getBoundingBox(at);
|
333 | 24759 | jmvivo | if (getRotation() != 0) { |
334 | 9392 | caballero | g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y |
335 | + (r.height / 2));
|
||
336 | 24759 | jmvivo | } |
337 | 9392 | caballero | 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 | 9435 | caballero | ViewPort viewPort = this.getMapContext()
|
350 | .getViewPort(); |
||
351 | Color theBackColor = viewPort.getBackColor();
|
||
352 | |||
353 | 9392 | caballero | 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 | 9435 | caballero | if (theBackColor != null) { |
360 | g.setColor(theBackColor); |
||
361 | g.fillRect((int) r.x, (int) r.y, viewPort |
||
362 | .getImageWidth(), viewPort |
||
363 | .getImageHeight()); |
||
364 | } |
||
365 | 9392 | caballero | 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 | 12323 | caballero | // System.err.println("r : " + r);
|
373 | 9392 | caballero | 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 | 21530 | vcaballero | Envelope r1 = calculateEnvelope(); |
387 | 23069 | vcaballero | double width = getLayout().getLayoutContext().getAttributes()
|
388 | 9392 | caballero | .getSizeInUnits().getAncho(); |
389 | double scale = FLayoutUtilities
|
||
390 | .getScaleView(viewp, width, r1 |
||
391 | 21530 | vcaballero | .getLength(0)
|
392 | 9392 | caballero | / width); |
393 | 21501 | vcaballero | viewp.setEnvelope(r1); |
394 | 9392 | caballero | |
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 | 24759 | jmvivo | if (getRotation() != 0) { |
449 | 9392 | caballero | g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y |
450 | + (r.height / 2));
|
||
451 | 24759 | jmvivo | } |
452 | 9392 | caballero | |
453 | if (getMapContext() != null) { |
||
454 | setATMap(getMapContext().getViewPort() |
||
455 | .getAffineTransform()); |
||
456 | |||
457 | } |
||
458 | } |
||
459 | 21299 | vcaballero | |
460 | 21530 | vcaballero | private Envelope calculateEnvelope() {
|
461 | 24759 | jmvivo | if (p1==null||p2==null) { |
462 | 21530 | vcaballero | return new DefaultEnvelope(2,new double[]{0,0},new double[]{0,0}); |
463 | 24759 | jmvivo | } |
464 | 21530 | vcaballero | Envelope r=new DefaultEnvelope(2,new double[]{p1.getX(),p1.getY()},new double[]{p2.getX(),p2.getY()}); |
465 | 9392 | caballero | return r;
|
466 | } |
||
467 | 18623 | jdominguez | |
468 | 21154 | vcaballero | public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintRequestAttributeSet prroperties) |
469 | 21299 | vcaballero | throws ReadException {
|
470 | 9392 | caballero | 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 | 23069 | vcaballero | this.getMapContext().print(g, getScale(),getLayout().getLayoutContext().getAttributes().toPrintAttributes());
|
486 | 21299 | vcaballero | } catch (ReadException e) {
|
487 | 9392 | caballero | 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 | 24759 | jmvivo | if (getMapContext()==null) { |
523 | return 0; |
||
524 | } |
||
525 | 9392 | caballero | 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 | 20994 | jmvivo | * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(org.gvsig.fmap.mapcontext.events.ExtentEvent)
|
710 | 9392 | caballero | */
|
711 | public void extentChanged(ExtentEvent e) { |
||
712 | if (getTypeScale() == AUTOMATICO) {
|
||
713 | 21501 | vcaballero | m_fmap.getViewPort().setEnvelope(e.getNewExtent()); |
714 | 9392 | caballero | if (getLayout() != null) { |
715 | getLayout().getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO); |
||
716 | } |
||
717 | } |
||
718 | refresh=true;
|
||
719 | } |
||
720 | |||
721 | /**
|
||
722 | 20994 | jmvivo | * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
|
723 | 9392 | caballero | */
|
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 | 20994 | jmvivo | * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#projectionChanged(org.gvsig.fmap.mapcontext.events.ProjectionEvent)
|
735 | 9392 | caballero | */
|
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 | 21530 | vcaballero | 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(new DefaultEnvelope(2, |
||
818 | new double[]{x,y}, |
||
819 | new double[]{x+w,y+h})); |
||
820 | 9392 | caballero | } else if (!m_bLinked) { |
821 | this.m_fmap = MapContext.createFromXML(xml.getChild(0)); |
||
822 | } |
||
823 | } |
||
824 | } catch (XMLException e) {
|
||
825 | NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
|
||
826 | e); |
||
827 | } |
||
828 | } else if (!m_bLinked) { |
||
829 | try {
|
||
830 | this.m_fmap = MapContext.createFromXML(xml.getChild(0)); |
||
831 | } catch (XMLException e) {
|
||
832 | e.printStackTrace(); |
||
833 | } |
||
834 | } |
||
835 | } |
||
836 | |||
837 | /**
|
||
838 | * DOCUMENT ME!
|
||
839 | *
|
||
840 | * @param arg0 DOCUMENT ME!
|
||
841 | *
|
||
842 | * @return DOCUMENT ME!
|
||
843 | */
|
||
844 | public boolean compare(Object arg0) { |
||
845 | if (!(arg0 instanceof FFrameView)) { |
||
846 | return false; |
||
847 | } |
||
848 | |||
849 | if (!this.getName().equals(((FFrameView) arg0).getName())) { |
||
850 | return false; |
||
851 | } |
||
852 | |||
853 | if (Math.abs(this.getBoundBox().getWidth()-(((FFrameView) arg0).getBoundBox().getWidth()))>0.05) { |
||
854 | return false; |
||
855 | } |
||
856 | if (Math.abs(this.getBoundBox().getHeight()-(((FFrameView) arg0).getBoundBox().getHeight()))>0.05) { |
||
857 | return false; |
||
858 | } |
||
859 | |||
860 | if (!this.toString().equals(((FFrameView) arg0).toString())) { |
||
861 | return false; |
||
862 | } |
||
863 | |||
864 | if (this.getMapContext()!=null && !this.getMapContext().equals(((FFrameView) arg0).getMapContext())) { |
||
865 | return false; |
||
866 | } |
||
867 | |||
868 | 12145 | caballero | if (this.getRotation()!=((FFrameView)arg0).getRotation()){ |
869 | return false; |
||
870 | } |
||
871 | 9392 | caballero | return true; |
872 | } |
||
873 | |||
874 | /**
|
||
875 | * DOCUMENT ME!
|
||
876 | *
|
||
877 | * @param arg0 DOCUMENT ME!
|
||
878 | *
|
||
879 | * @return DOCUMENT ME!
|
||
880 | */
|
||
881 | public boolean equals(Object arg0) { |
||
882 | return this.compare(arg0); |
||
883 | } |
||
884 | |||
885 | public void refresh() { |
||
886 | 24759 | jmvivo | if (view!=null && (getTypeScale() == MANUAL || getTypeScale() == CONSTANTE )) { |
887 | 21530 | vcaballero | getMapContext().getViewPort().setEnvelope(getNewEnvelope(getScale())); |
888 | 24759 | jmvivo | } |
889 | 9392 | caballero | refresh=true;
|
890 | } |
||
891 | |||
892 | 21299 | vcaballero | public void fullExtent() throws ReadException { |
893 | 21530 | vcaballero | setNewEnvelope(getMapContext().getFullEnvelope()); |
894 | 9392 | caballero | } |
895 | |||
896 | public void setPointsToZoom(Point2D px1, Point2D px2) { |
||
897 | p1=px1; |
||
898 | p2=px2; |
||
899 | } |
||
900 | |||
901 | public void movePoints(Point2D px1, Point2D px2) { |
||
902 | double difX=-px2.getX()+px1.getX();
|
||
903 | double difY=-px2.getY()+px1.getY();
|
||
904 | if (p1!=null) { |
||
905 | p1.setLocation(p1.getX()+difX,p1.getY()+difY); |
||
906 | p2.setLocation(p2.getX()+difX,p2.getY()+difY); |
||
907 | } |
||
908 | } |
||
909 | |||
910 | public void cloneActions(IFFrame frame) { |
||
911 | 24759 | jmvivo | if (view ==null || view.getMapContext()==null) { |
912 | 9392 | caballero | return;
|
913 | 24759 | jmvivo | } |
914 | 9392 | caballero | if (m_bLinked) {
|
915 | if (getTypeScale() == AUTOMATICO) {
|
||
916 | view.getMapContext().getViewPort().addViewPortListener(this);
|
||
917 | view.getMapContext().addLayerListener(this);
|
||
918 | } else if (getTypeScale() == CONSTANTE) { |
||
919 | view.getMapContext().getViewPort().removeViewPortListener(this);
|
||
920 | view.getMapContext().addLayerListener(this);
|
||
921 | } else if (getTypeScale() == MANUAL) { |
||
922 | view.getMapContext().getViewPort().removeViewPortListener(this);
|
||
923 | view.getMapContext().addLayerListener(this);
|
||
924 | } |
||
925 | } else if (!m_bLinked) { |
||
926 | if (getTypeScale() == AUTOMATICO) {
|
||
927 | view.getMapContext().getViewPort().addViewPortListener(this);
|
||
928 | } else if (getTypeScale() == CONSTANTE) { |
||
929 | view.getMapContext().getViewPort().removeViewPortListener(this);
|
||
930 | } else if (getTypeScale() == MANUAL) { |
||
931 | view.getMapContext().getViewPort().removeViewPortListener(this);
|
||
932 | } |
||
933 | } |
||
934 | ((FFrameView)frame).view.getMapContext().removeLayerListener((FFrameView)frame); |
||
935 | ((FFrameView)frame).view.getMapContext().getViewPort().removeViewPortListener((FFrameView)frame); |
||
936 | |||
937 | |||
938 | } |
||
939 | public IFFrame cloneFFrame(Layout layout) {
|
||
940 | 9516 | caballero | FFrameView frame =(FFrameView)FrameFactory.createFrameFromName(FFrameViewFactory.registerName); |
941 | 9392 | caballero | frame.setLevel(this.getLevel());
|
942 | frame.setNum(this.num);
|
||
943 | frame.setName(this.getName());
|
||
944 | frame.setBoundBox(this.getBoundBox());
|
||
945 | frame.setTag(this.getTag());
|
||
946 | frame.m_Mode = this.m_Mode;
|
||
947 | frame.m_typeScale = this.m_typeScale;
|
||
948 | frame.m_extension = this.m_extension;
|
||
949 | frame.m_quality = this.m_quality;
|
||
950 | frame.m_viewing = this.m_viewing;
|
||
951 | frame.m_bLinked = this.m_bLinked;
|
||
952 | frame.m_mapUnits = this.m_mapUnits;
|
||
953 | frame.setRotation(this.getRotation());
|
||
954 | |||
955 | frame.m_Scale = this.m_Scale;
|
||
956 | frame.view=this.getView();
|
||
957 | frame.m_fmap = this.getMapContext();
|
||
958 | frame.setSelected(this.getSelected()!=IFFrame.NOSELECT);
|
||
959 | frame.setLayout(layout); |
||
960 | 23642 | vcaballero | frame.origin=this.origin;
|
961 | frame.scaleAnt=this.scaleAnt;
|
||
962 | frame.m_image=this.m_image;
|
||
963 | frame.refresh=this.refresh;
|
||
964 | 9392 | caballero | |
965 | if (frame instanceof IFFrameViewDependence) { |
||
966 | ((IFFrameViewDependence) frame).initDependence(layout.getLayoutContext().getAllFFrames()); |
||
967 | } |
||
968 | cloneActions(frame); |
||
969 | return frame;
|
||
970 | } |
||
971 | |||
972 | public IFFrameDialog getPropertyDialog() {
|
||
973 | return new FFrameViewDialog(getLayout(),this); |
||
974 | } |
||
975 | } |