Statistics
| Revision:

root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameView.java @ 20910

History | View | Annotate | Download (34 KB)

1
/*
2
 * Created on 20-feb-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.gui.layout.fframes;
46

    
47
import java.awt.Color;
48
import java.awt.Dimension;
49
import java.awt.Graphics2D;
50
import java.awt.Point;
51
import java.awt.Rectangle;
52
import java.awt.geom.AffineTransform;
53
import java.awt.geom.Point2D;
54
import java.awt.geom.Rectangle2D;
55
import java.awt.image.BufferedImage;
56
import java.util.ArrayList;
57
import java.util.Iterator;
58

    
59
import org.cresques.cts.IProjection;
60

    
61
import com.iver.andami.PluginServices;
62
import com.iver.andami.messages.NotificationManager;
63
import com.iver.cit.gvsig.ProjectExtension;
64
import com.iver.cit.gvsig.fmap.ColorEvent;
65
import com.iver.cit.gvsig.fmap.DriverException;
66
import com.iver.cit.gvsig.fmap.ExtentEvent;
67
import com.iver.cit.gvsig.fmap.MapContext;
68
import com.iver.cit.gvsig.fmap.ProjectionEvent;
69
import com.iver.cit.gvsig.fmap.ViewPort;
70
import com.iver.cit.gvsig.fmap.ViewPortListener;
71
import com.iver.cit.gvsig.fmap.layers.LegendListener;
72
import com.iver.cit.gvsig.fmap.layers.XMLException;
73
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
74
import com.iver.cit.gvsig.gui.layout.Layout;
75
import com.iver.cit.gvsig.project.Project;
76
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
77
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
78
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
79
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
80
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence;
81
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
82
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseProject;
83
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
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

    
88

    
89
/**
90
 * FFrame para introducir una vista en el Layout.
91
 *
92
 * @author Vicente Caballero Navarro
93
 */
94
public class FFrameView extends FFrame implements ViewPortListener,
95
    LegendListener, IFFrameUseProject, IFFrameLayoutDependence,IFFrameUseFMap {
96
    //private static Logger logger = Logger.getLogger(FFrameView.class.getName());
97
    public static final int PRESENTACION = 0;
98
    public static final int BORRADOR = 1;
99
    protected int m_Mode;
100
    protected int m_typeScale = AUTOMATICO;
101
    protected int m_extension = 0;
102
    protected int m_quality = PRESENTACION;
103
    protected int m_viewing = 0;
104
    protected boolean m_bLinked = true;
105
    protected ProjectView view = null;
106
    protected MapContext m_fmap = null;
107
    protected double m_Scale = 0;
108
    protected int m_mapUnits = 1; //Metros.
109

    
110
    private BufferedImage m_image = null;
111
    private AffineTransform at = null;
112
    private Project project = null;
113
    private Layout layout;
114
        private double scaleAnt;
115
        private boolean refresh=false;
116
        private Point origin;
117
        private Point2D p1;
118
        private Point2D p2;
119
        private IFFrame grid;
120
        private boolean showGrid=false;
121
        /**
122
     * Creates a new FFrameView object.
123
     */
124
    public FFrameView() {
125
        num++;
126
    }
127

    
128
    /**
129
     * Devuelve una descripci?n del FFrameView.
130
     *
131
     * @return Descripci?n.
132
     */
133
    public String toString() {
134
        if (getView() == null) {
135
            return "FFrameView " + num + ": " + "Vacio";
136
        }
137

    
138
        return "FFrameView " + num + ": " + getView().getName();
139
    }
140

    
141
    /**
142
     * Rellena la escala de la vista que contiene el fframe.
143
     *
144
     * @param d escala de la vista.
145
     */
146
    public void setScale(double d) {
147
        m_Scale = d;
148
    }
149

    
150
    /**
151
     * Inserta el nuevo extent a la FFrameView.
152
     *
153
     * @param r Rect?ngulo a ocupar por el FFrameView.
154
     */
155
    public void setNewExtent(Rectangle2D r) {
156
        getMapContext().getViewPort().setExtent(r);
157
        refresh = true;
158
        m_Scale = FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
159
                getBoundBox().width,
160
                getBoundingBox(null).width / getBoundBox().width);
161
    }
162

    
163
    /**
164
     * Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
165
     * escala fija.
166
     *
167
     * @return FMap.
168
     */
169
    public MapContext getMapContext() {
170
            return m_fmap;
171
    }
172

    
173
    /**
174
     * Rellena la calidad que se quiere aplicar.
175
     *
176
     * @param q entero que representa la calidad a aplicar.
177
     */
178
    public void setQuality(int q) {
179
        m_quality = q;
180
    }
181

    
182
    /**
183
     * Devuelve un entero que representa la calidad que est? seleccionada.
184
     *
185
     * @return tipo de calidad selccionada.
186
     */
187
    public int getQuality() {
188
        return m_quality;
189
    }
190

    
191
    /**
192
     * Devuelve un entero que representa la forma en que se actualiza la vista.
193
     *
194
     * @return forma que se actualiza la vista.
195
     */
196
    public int getViewing() {
197
        return m_viewing;
198
    }
199

    
200
    /**
201
     * Rellena la forma de actualizar la vista(cuando activo o siempre). De
202
     * momento esta opci?n esta deshabilitada.
203
     *
204
     * @param v entero que representa la forma de actualizar la vista.
205
     */
206
    public void setViewing(int v) {
207
        m_viewing = v;
208
    }
209

    
210
    /**
211
     * Inserta el ProjectView de donde obtener las propiedades de la vista a
212
     * mostrar.
213
     *
214
     * @param v Modelo de la vista.
215
     */
216
    public void setView(ProjectView v) {
217
            view=v;
218
            ViewPort vp =null;
219
            if (getMapContext()!=null){
220
                vp=getMapContext().getViewPort();
221
        }else{
222
                vp = v.getMapContext().getViewPort().cloneViewPort();
223
        }
224
        vp.setImageSize(new Dimension((int) getBoundingBox(null).width,
225
                (int) getBoundingBox(null).height));
226

    
227
        if (m_bLinked) {
228
                v.getMapContext().addLayerListener(this);
229
            if (getTypeScale() == AUTOMATICO) {
230
                m_fmap = v.getMapContext().createNewFMap(v.getMapContext()
231
                                                          .getViewPort()
232
                                                          .cloneViewPort());
233
                m_fmap.getViewPort().setImageSize(new Dimension(
234
                        (int) getBoundingBox(null).width,
235
                        (int) getBoundingBox(null).height));
236
                v.getMapContext().getViewPort().addViewPortListener(this);
237
            } else if (getTypeScale() == CONSTANTE) {
238
                    m_fmap = v.getMapContext().createNewFMap(vp);
239
                    vp.setExtent(getNewExtent(getScale()));
240
                v.getMapContext().getViewPort().removeViewPortListener(this);
241
            } else if (getTypeScale() == MANUAL) {
242
                m_fmap = v.getMapContext().createNewFMap(vp);
243
                vp.setExtent(getNewExtent(getScale()));
244
                v.getMapContext().getViewPort().removeViewPortListener(this);
245
            }
246
        } else if (!m_bLinked) {
247
                v.getMapContext().removeLayerListener(this);
248
            try {
249
                if (getTypeScale() == AUTOMATICO) {
250
                    m_fmap = v.getMapContext().cloneFMap(); //(v.getMapContext().getViewPort().cloneViewPort());
251
                    m_fmap.setViewPort(v.getMapContext().getViewPort()
252
                                        .cloneViewPort());
253
                    m_fmap.getViewPort().setImageSize(new Dimension(
254
                            (int) getBoundingBox(null).width,
255
                            (int) getBoundingBox(null).height));
256
                    v.getMapContext().getViewPort().addViewPortListener(this);
257
                } else if (getTypeScale() == CONSTANTE) {
258
                        m_fmap = v.getMapContext().cloneFMap();
259
                        vp.setExtent(getNewExtent(getScale()));
260
                    m_fmap.setViewPort(vp);
261
                    v.getMapContext().getViewPort().removeViewPortListener(this);
262
                } else if (getTypeScale() == MANUAL) {
263
                    m_fmap = v.getMapContext().cloneFMap();
264
                    vp.setExtent(getNewExtent(getScale()));
265
                    m_fmap.setViewPort(vp);
266
                    v.getMapContext().getViewPort().removeViewPortListener(this);
267
                }
268
            } catch (XMLException e1) {
269
                NotificationManager.addError("Cuando se a?ade una vista al Layout",
270
                    e1);
271
            }
272
        }
273
    }
274

    
275
    /**
276
     * Devuelve el modelo de la vista.
277
     *
278
     * @return Modelo de la vista.
279
     */
280
    public ProjectView getView() {
281
        return view;
282
    }
283

    
284
    /**
285
     * Devuelve un Rect?ngulo que representa  el extent de la vista que se
286
     * requiere a partir  de una escala.
287
     *
288
     * @param scale Escala a mostrar.
289
     *
290
     * @return Rect?ngulo.
291
     */
292
    protected Rectangle2D getNewExtent(long scale) {
293
        double hview = getBoundBox().getHeight();
294
        double wview = getBoundBox().getWidth();
295
        double hextent = (scale * hview) / 100.0;
296
        double wextent = (scale * wview) / 100.0;
297

    
298
        if (m_fmap.getViewPort().getExtent()==null)
299
                return new Rectangle2D.Double();
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
                 Rectangle2D r = new Rectangle2D.Double(newx, newy, wextent, hextent);
306
                 if (!proj.isProjected()){
307
                          return m_fmap.getViewPort().getProjection().getExtent(r,scale,wview,hview,100,2.54);
308
                 }
309
        return r;
310

    
311

    
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
         *
328
         * @throws com.iver.cit.gvsig.fmap.DriverException
329
         */
330
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
331
                        BufferedImage imgBase)
332
                        throws com.iver.cit.gvsig.fmap.DriverException {
333
                Rectangle2D.Double r = getBoundingBox(at);
334
                if (getRotation() != 0)
335
                        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y
336
                                        + (r.height / 2));
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
                                                        if (origin != null
353
                                                                        && origin.equals(layout.getRectOrigin())
354
                                                                        && layout != null
355
                                                                        && layout.getAT().getScaleX() == scaleAnt
356
                                                                        && m_image != null && !refresh) {
357
                                                                if (theBackColor != null) {
358
                                                                        g.setColor(theBackColor);
359
                                                                        g.fillRect((int) r.x, (int) r.y, viewPort
360
                                                                                        .getImageWidth(), viewPort
361
                                                                                        .getImageHeight());
362
                                                                }
363
                                                                g.translate(r.getX(), r.getY());
364
                                                                g.drawImage(m_image, 0, 0, layout);
365
                                                                g.translate(-r.getX(), -r.getY());
366
                                                                scaleAnt = layout.getAT().getScaleX();
367
                                                                origin = (Point) layout.getRectOrigin().clone();
368
                                                        } else {
369

    
370

    
371
                                                                System.err.println("r : " + r);
372
                                                                if (r.getWidth() > layout.getWidth()
373
                                                                                || r.getHeight() > layout.getHeight()) {
374
                                                                        getMapContext().getViewPort().setOffset(
375
                                                                                        new Point2D.Double(r.getX(), r
376
                                                                                                        .getY()));
377
                                                                        getMapContext().getViewPort().setImageSize(
378
                                                                                        new Dimension((int) r.getWidth(),
379
                                                                                                        (int) r.getHeight()));
380
                                                                        MapContext fmap = getMapContext().cloneToDraw();
381
                                                                        ViewPort viewp = viewPort.cloneViewPort();
382
                                                                        viewp.setImageSize(new Dimension(
383
                                                                                        layout.getWidth(),
384
                                                                                        layout.getHeight()));
385
                                                                        Rectangle2D r1 = calculateExtent();
386
                                                                        double width = layout.getAtributes()
387
                                                                                        .getSizeInUnits().getAncho();
388
                                                                        double scale = FLayoutUtilities
389
                                                                                        .getScaleView(viewp, width, r1
390
                                                                                                        .getWidth()
391
                                                                                                        / width);
392
                                                                        viewp.setExtent(r1);
393

    
394
                                                                        fmap.setViewPort(viewp);
395
                                                                        g.translate(-r.getX(), -r.getY());
396
                                                                        if (theBackColor != null) {
397
                                                                                g.setColor(theBackColor);
398
                                                                                g.fillRect((int) r.x, (int) r.y, viewp
399
                                                                                                .getImageWidth(), viewp
400
                                                                                                .getImageHeight());
401
                                                                        }
402
                                                                        fmap.draw(imgBase, g, scale);
403
                                                                        g.translate(r.getX(), r.getY());
404

    
405
                                                                } else {
406
                                                                        getMapContext().getViewPort().setOffset(
407
                                                                                        new Point2D.Double(r.x, r.y));
408
                                                                        getMapContext().getViewPort().setImageSize(
409
                                                                                        new Dimension((int) r.width,
410
                                                                                                        (int) r.height));
411
                                                                        m_image = new BufferedImage((int) r
412
                                                                                        .getWidth(), (int) r.getHeight(),
413
                                                                                        BufferedImage.TYPE_INT_ARGB);
414
                                                                        Graphics2D gimg = (Graphics2D) m_image
415
                                                                                        .getGraphics();
416
                                                                        gimg.translate(-((int) r.getX()), -((int) r
417
                                                                                        .getY()));
418
                                                                        getMapContext().draw(m_image, gimg, getScale());
419
                                                                        gimg.translate(((int) r.getX()), ((int) r
420
                                                                                        .getY()));
421
                                                                        if (theBackColor != null) {
422
                                                                                g.setColor(theBackColor);
423
                                                                                g.fillRect((int) r.x, (int) r.y, viewPort
424
                                                                                                .getImageWidth(), viewPort
425
                                                                                                .getImageHeight());
426
                                                                        }
427
                                                                        g.drawImage(m_image, (int) r.getX(),
428
                                                                                        (int) r.getY(), layout);
429
                                                                }
430
                                                                scaleAnt = layout.getAT().getScaleX();
431
                                                                origin = (Point) layout.getRectOrigin().clone();
432
                                                                refresh = false;
433
                                                        }
434
                                                }
435
                                        } else {
436
                                                drawDraft(g);
437
                                        }
438
                                        if (rclip != null) {
439
                                                g.setClip(rclip.x, rclip.y, rclip.width,
440
                                                                rclip.height);
441
                                        }
442
                                } else {
443
                                        printX(g, at);
444
                                }
445
                        }
446
                }
447
                if (getRotation() != 0)
448
                        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y
449
                                        + (r.height / 2));
450

    
451
                if (getMapContext() != null) {
452
                        setATMap(getMapContext().getViewPort()
453
                                        .getAffineTransform());
454

    
455
                }
456
                if (showGrid && grid!=null){
457
                        ((FFrameGrid)grid).setFFrameDependence(this);
458
                        grid.draw(g,at,rv,imgBase);
459
                }
460
        }
461
    private Rectangle2D calculateExtent() {
462
            Rectangle2D.Double r = new Rectangle2D.Double();
463
                if (p1==null||p2==null)
464
                        return r;
465
            r.setFrameFromDiagonal(p1, p2);
466
                return r;
467
    }
468
    /**
469
         * DOCUMENT ME!
470
         *
471
         * @param g
472
         *            DOCUMENT ME!
473
         * @param at
474
         *            DOCUMENT ME!
475
         *
476
         * @throws DriverException
477
         *
478
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
479
         *      java.awt.geom.AffineTransform)
480
         */
481
    public void print(Graphics2D g, AffineTransform at)
482
        throws DriverException {
483
        draw(g, at, null, null);
484
    }
485

    
486
    /**
487
         * DOCUMENT ME!
488
         *
489
         * @param g
490
         *            DOCUMENT ME!
491
         * @param at
492
         *            DOCUMENT ME!
493
         */
494
    private void printX(Graphics2D g, AffineTransform at) {
495
        Rectangle2D.Double r = getBoundingBox(at);
496

    
497
        // Dibujamos en impresora
498
        Rectangle rclip = g.getClipBounds();
499
        g.clipRect((int) r.getMinX(), (int) r.getMinY(), (int) r.getWidth(),
500
            (int) r.getHeight());
501
        this.getMapContext().getViewPort().setOffset(new Point2D.Double(r.x, r.y));
502
        this.getMapContext().getViewPort().setImageSize(new Dimension((int) r.width,
503
                (int) r.height));
504

    
505
        try {
506
                this.getMapContext().print(g, getScale(),layout.getAtributes().toPrintAttributes());
507
        } catch (com.iver.cit.gvsig.fmap.DriverException e) {
508
            NotificationManager.addError(e.getMessage(), e);
509
        }
510

    
511
        g.setClip(rclip.x, rclip.y, rclip.width, rclip.height);
512
    }
513

    
514
    /**
515
     * Rellena la unidad de medida en la que est? la vista.
516
     *
517
     * @param i entero que representa la unidad de medida de la vista.
518
     */
519
    public void setMapUnits(int i) {
520
        m_mapUnits = i;
521
    }
522

    
523
    /**
524
     * Obtiene la unidad de medida en la que est? la vista.
525
     *
526
     * @return Unidad de medida.
527
     */
528
    public int getMapUnits() {
529
        return m_mapUnits;
530
    }
531

    
532
    /**
533
     * Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
534
     * a?adida la vista.
535
     *
536
     * @return escala.
537
     */
538
    public long getScale() {
539
        /*if (m_bLinked){
540
           return getScaleView1(METROS);
541
               }
542
         */
543
            if (getMapContext()==null)
544
                    return 0;
545
        if (getTypeScale() == AUTOMATICO) {
546
            return FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
547
                getBoundBox().width, getBoundingBox(null).width);
548
        } else if (getTypeScale() == CONSTANTE) {
549
            return (long) m_Scale;
550
        } else if (getTypeScale() == MANUAL) {
551
            return (long) m_Scale;
552
        }
553

    
554
        return (long) m_Scale;
555
    }
556

    
557
    /**
558
     * Seleccionar si la vista esta relacionada o no con la original.
559
     *
560
     * @param b true si est? ligada y false si no lo est?.
561
     */
562
    public void setLinked(boolean b) {
563
        m_bLinked = b;
564
    }
565

    
566
    /**
567
     * Devuelve si est? ligada o no el FFrameView con la vista.
568
     *
569
     * @return True si la vista est? ligada.
570
     */
571
    public boolean getLinked() {
572
        return m_bLinked;
573
    }
574

    
575
    /**
576
     * Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
577
     * la vista.
578
     *
579
     * @return entero que representa la opci?n elegida.
580
     */
581
    public int getExtension() {
582
        return m_extension;
583
    }
584

    
585
    /**
586
     * Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
587
     * MANUAL.
588
     *
589
     * @return entero que representa el tipo seleccionado.
590
     */
591
    public int getTypeScale() {
592
        return m_typeScale;
593
    }
594

    
595
    /**
596
     * Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
597
     *
598
     * @param i entero que representa la opci?n elegida.
599
     */
600
    public void setExtension(int i) {
601
        m_extension = i;
602
    }
603

    
604
    /**
605
     * Rellenar el tipo de escala que se desea.
606
     *
607
     * @param i entero que representa el tipo de escala.
608
     */
609
    public void setTypeScale(int i) {
610
        m_typeScale = i;
611
    }
612

    
613
    /**
614
     * DOCUMENT ME!
615
     *
616
     * @return DOCUMENT ME!
617
     *
618
     * @throws SaveException
619
     *
620
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
621
     */
622
    public XMLEntity getXMLEntity() throws SaveException {
623
        XMLEntity xml = super.getXMLEntity();
624

    
625
        try {
626
            xml.putProperty("type", Layout.RECTANGLEVIEW);
627
            xml.putProperty("m_Mode", m_Mode);
628
            xml.putProperty("m_typeScale", m_typeScale);
629
            xml.putProperty("m_extension", m_extension);
630
            xml.putProperty("m_quality", m_quality);
631
            xml.putProperty("m_viewing", m_viewing);
632
            xml.putProperty("m_bLinked", m_bLinked);
633
            xml.putProperty("m_mapUnits", m_mapUnits);
634
            xml.putProperty("m_Scale", m_Scale);
635

    
636
            ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
637
            ArrayList views = pe.getProject().getDocumentsByType(ProjectViewFactory.registerName);
638

    
639
            boolean hasIndex = false;
640

    
641

    
642
            if (view != null) {
643
                    xml.putProperty("viewName",view.getName());
644
                    for (int i = 0; i < views.size(); i++) {
645
                        if (view.getName().equals(((ProjectView) views.get(i)).getName())) {
646
                            xml.putProperty("indice", i);
647
                            hasIndex = true;
648
                            break;
649
                        }
650
                    }
651
            }
652

    
653
            if (!hasIndex) {
654
                xml.putProperty("indice", -1);
655
            }
656

    
657
            if (getMapContext() != null && getMapContext().getViewPort().getExtent()!=null) {
658
                xml.putProperty("extentX",
659
                    getMapContext().getViewPort().getExtent().getX());
660
                xml.putProperty("extentY",
661
                    getMapContext().getViewPort().getExtent().getY());
662
                xml.putProperty("extentW",
663
                    getMapContext().getViewPort().getExtent().getWidth());
664
                xml.putProperty("extentH",
665
                    getMapContext().getViewPort().getExtent().getHeight());
666

    
667
                xml.addChild(getMapContext().getXMLEntity());
668
            }
669
            if (grid!=null)
670
                    xml.addChild(grid.getXMLEntity());
671
        } catch (Exception e) {
672
            throw new SaveException(e, this.getClass().getName());
673
        }
674

    
675
        return xml;
676
    }
677

    
678
    /**
679
     * Inserta la imagen para repintar el FFrameView.
680
     *
681
     * @param bi Imagen para repintar.
682
     */
683
    public void setBufferedImage(BufferedImage bi) {
684
        m_image = bi;
685
    }
686

    
687
    /**
688
     * Devuelve la imagen para repintar.
689
     *
690
     * @return Imagen para repintar.
691
     */
692
    public BufferedImage getBufferedImage() {
693
        return m_image;
694
    }
695

    
696
    /**
697
     * Devuelve la MAtriz de transformaci?n utilizada por la FFrameView.
698
     *
699
     * @return MAtriz de transformaci?n.
700
     */
701
    public AffineTransform getATMap() {
702
        return at;
703
    }
704

    
705
    /**
706
     * Inserta la matriz de transformaci?n.
707
     *
708
     * @param transform Matriz de transformaci?n.
709
     */
710
    public void setATMap(AffineTransform transform) {
711
        at = transform;
712
    }
713
    /**
714
     * Inserta el proyecto.
715
     *
716
     * @param p Proyecto.
717
     */
718
    public void setProject(Project p) {
719
        project = p;
720
    }
721

    
722
    /**
723
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
724
     *      com.iver.cit.gvsig.project.Project)
725
     */
726
    public void setXMLEntity03(XMLEntity xml, Layout l) {
727
        if (xml.getIntProperty("m_Selected") != 0) {
728
            this.setSelected(true);
729
        } else {
730
            this.setSelected(false);
731
        }
732

    
733
        this.setName(xml.getStringProperty("m_name"));
734
        this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
735
                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
736
                xml.getDoubleProperty("h")));
737

    
738
        this.m_Mode = xml.getIntProperty("m_Mode");
739
        this.m_typeScale = xml.getIntProperty("m_typeScale");
740
        this.m_extension = xml.getIntProperty("m_extension");
741
        this.m_quality = xml.getIntProperty("m_quality");
742
        this.m_viewing = xml.getIntProperty("m_viewing");
743
        this.m_bLinked = xml.getBooleanProperty("m_bLinked");
744
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
745

    
746
        //ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
747
        this.m_Scale = xml.getDoubleProperty("m_Scale");
748

    
749
        int indice = xml.getIntProperty("indice");
750

    
751
        if (indice != -1) {
752
                ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
753

    
754
            ProjectView view = (ProjectView) views.get(indice);
755
            this.m_fmap = view.getMapContext();
756
            this.setView(view);
757

    
758
            try {
759
                if (m_bLinked) {
760
                    this.getMapContext().getViewPort().setExtent(new Rectangle2D.Double(
761
                            xml.getDoubleProperty("extentX"),
762
                            xml.getDoubleProperty("extentY"),
763
                            xml.getDoubleProperty("extentW"),
764
                            xml.getDoubleProperty("extentH")));
765
                } else if (!m_bLinked) {
766
                    this.m_fmap = MapContext.createFromXML03(xml.getChild(0));
767
                }
768
            } catch (XMLException e) {
769
                NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
770
                    e);
771
            }
772
        }
773
    }
774

    
775
    /**
776
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
777
     */
778
    public String getNameFFrame() {
779
        return PluginServices.getText(this, "Vista")+ num;
780
    }
781

    
782
    /**
783
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
784
     */
785
    public void extentChanged(ExtentEvent e) {
786
        if (getTypeScale() == AUTOMATICO) {
787
            m_fmap.getViewPort().setExtent(e.getNewExtent());
788
            if (layout != null) {
789
                layout.setStatus(Layout.DESACTUALIZADO);
790
            }
791

    
792
        }
793
        refresh=true;
794
    }
795

    
796
    /**
797
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
798
     */
799
    public void backColorChanged(ColorEvent e) {
800
        if (getLinked()) {
801
            m_fmap.getViewPort().setBackColor(e.getNewColor());
802
            layout.setStatus(Layout.DESACTUALIZADO);
803

    
804
            //setBufferedImage(null);
805
        }
806
    }
807

    
808
    /**
809
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#projectionChanged(com.iver.cit.gvsig.fmap.ProjectionEvent)
810
     */
811
        public void projectionChanged(ProjectionEvent e) {
812
        if (getTypeScale() == AUTOMATICO) {
813
            m_fmap.getViewPort().setProjection(e.getNewProjection());
814

    
815
            if (layout != null) {
816
                layout.setStatus(Layout.DESACTUALIZADO);
817
            }
818
        }
819
        }
820

    
821
    /**
822
     * DOCUMENT ME!
823
     *
824
     * @param l DOCUMENT ME!
825
     */
826
    public void setLayout(Layout l) {
827
        layout = l;
828
    }
829

    
830
    /**
831
     * DOCUMENT ME!
832
     *
833
     * @param e DOCUMENT ME!
834
     */
835
    public void legendChanged(LegendChangedEvent e) {
836
        if (getLinked()) {
837
            layout.setStatus(Layout.DESACTUALIZADO);
838
            refresh=true;
839
            //setBufferedImage(null);
840
        }
841
    }
842

    
843
    /**
844
     * DOCUMENT ME!
845
     *
846
     * @param xml DOCUMENT ME!
847
     */
848
    public void setXMLEntity(XMLEntity xml) {
849
        if (xml.getIntProperty("m_Selected") != 0) {
850
            this.setSelected(true);
851
        } else {
852
            this.setSelected(false);
853
        }
854

    
855
        this.setName(xml.getStringProperty("m_name"));
856
        this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
857
                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
858
                xml.getDoubleProperty("h")));
859

    
860
        this.m_Mode = xml.getIntProperty("m_Mode");
861
        this.m_typeScale = xml.getIntProperty("m_typeScale");
862
        this.m_extension = xml.getIntProperty("m_extension");
863
        this.m_quality = xml.getIntProperty("m_quality");
864
        this.m_viewing = xml.getIntProperty("m_viewing");
865
        this.m_bLinked = xml.getBooleanProperty("m_bLinked");
866
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
867
        setRotation(xml.getDoubleProperty("m_rotation"));
868

    
869
        this.m_Scale = xml.getDoubleProperty("m_Scale");
870

    
871
        int indice = xml.getIntProperty("indice");
872

    
873
        ProjectView view = null;
874

    
875
        if (xml.contains("viewName")){
876
                view = (ProjectView)project.getProjectDocumentByName(xml.getStringProperty("viewName"),ProjectViewFactory.registerName);
877
        }else {
878
                if (indice != -1) {
879
                        try {
880
                                ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
881

    
882
                                view = (ProjectView) views.get(indice);
883
                        } catch (IndexOutOfBoundsException e) {
884
                                NotificationManager.addError("No se ha encontrado la vista de indice "+ indice,
885
                                            e);
886
                        }
887
                }
888
        }
889

    
890

    
891
        if (view != null) {
892
                this.setView(view);
893

    
894
                try {
895
                        if (xml.contains("extentX")) {
896
                                if (m_bLinked) {
897
                                        this.getMapContext().getViewPort().setExtent(new Rectangle2D.Double(
898
                                                        xml.getDoubleProperty("extentX"),
899
                                                        xml.getDoubleProperty("extentY"),
900
                                                        xml.getDoubleProperty("extentW"),
901
                                                        xml.getDoubleProperty("extentH")));
902
                                } else if (!m_bLinked) {
903
                                        this.m_fmap = MapContext.createFromXML(xml.getChild(0));
904
                                }
905
                        }
906
                } catch (XMLException e) {
907
                        NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
908
                                        e);
909
                }
910
        } else if (!m_bLinked) {
911
            try {
912
                this.m_fmap = MapContext.createFromXML(xml.getChild(0));
913
            } catch (XMLException e) {
914
                e.printStackTrace();
915
            }
916
        }
917
        Iterator iterator=xml.findChildren("fframegrid","fframegrid");
918
        while (iterator.hasNext()) {
919
                        XMLEntity element = (XMLEntity) iterator.next();
920
                        try {
921
                                grid=createFFrame(element,project,layout);
922
                        } catch (OpenException e) {
923
                                NotificationManager.addError("Creando el grid asociado a la vista",
924
                                        e);
925
                        }
926
                }
927
    }
928

    
929
    /**
930
     * DOCUMENT ME!
931
     *
932
     * @return DOCUMENT ME!
933
     */
934
    public Layout getLayout() {
935
        return layout;
936
    }
937

    
938
    /**
939
     * DOCUMENT ME!
940
     *
941
     * @param arg0 DOCUMENT ME!
942
     *
943
     * @return DOCUMENT ME!
944
     */
945
    public boolean compare(Object arg0) {
946
        if (!(arg0 instanceof FFrameView)) {
947
            return false;
948
        }
949

    
950
        if (!this.getName().equals(((FFrameView) arg0).getName())) {
951
            return false;
952
        }
953

    
954
        if (Math.abs(this.getBoundBox().getWidth()-(((FFrameView) arg0).getBoundBox().getWidth()))>0.05) {
955
            return false;
956
        }
957
        if (Math.abs(this.getBoundBox().getHeight()-(((FFrameView) arg0).getBoundBox().getHeight()))>0.05) {
958
            return false;
959
        }
960

    
961
        if (!this.toString().equals(((FFrameView) arg0).toString())) {
962
            return false;
963
        }
964

    
965
        if (this.getMapContext()!=null && !this.getMapContext().equals(((FFrameView) arg0).getMapContext())) {
966
            return false;
967
        }
968

    
969
        if (this.getRotation()!=((FFrameView)arg0).getRotation()){
970
            return false;
971
        }
972

    
973
        return true;
974
    }
975

    
976
    /**
977
     * DOCUMENT ME!
978
     *
979
     * @param arg0 DOCUMENT ME!
980
     *
981
     * @return DOCUMENT ME!
982
     */
983
    public boolean equals(Object arg0) {
984
        return this.compare(arg0);
985
    }
986

    
987
        public void refresh() {
988
                if (view!=null && (getTypeScale() == MANUAL || getTypeScale() == CONSTANTE ))
989
                        getMapContext().getViewPort().setExtent(getNewExtent(getScale()));
990
                refresh=true;
991
        }
992

    
993
        public void fullExtent() throws DriverException {
994
                setNewExtent(getMapContext().getFullExtent());
995
        }
996

    
997
        public void setPointsToZoom(Point2D px1, Point2D px2) {
998
                p1=px1;
999
                p2=px2;
1000
        }
1001

    
1002
        public void movePoints(Point2D px1, Point2D px2) {
1003
                double difX=-px2.getX()+px1.getX();
1004
                double difY=-px2.getY()+px1.getY();
1005
                if (p1!=null) {
1006
                        p1.setLocation(p1.getX()+difX,p1.getY()+difY);
1007
                        p2.setLocation(p2.getX()+difX,p2.getY()+difY);
1008
                }
1009
        }
1010

    
1011
        public void cloneActions(IFFrame frame) {
1012
                if (view ==null || view.getMapContext()==null)
1013
                        return;
1014
                if (m_bLinked) {
1015
            if (getTypeScale() == AUTOMATICO) {
1016
                    view.getMapContext().getViewPort().addViewPortListener(this);
1017
                view.getMapContext().addLayerListener(this);
1018
            } else if (getTypeScale() == CONSTANTE) {
1019
                view.getMapContext().getViewPort().removeViewPortListener(this);
1020
                view.getMapContext().addLayerListener(this);
1021
            } else if (getTypeScale() == MANUAL) {
1022
                view.getMapContext().getViewPort().removeViewPortListener(this);
1023
                view.getMapContext().addLayerListener(this);
1024
            }
1025
        } else if (!m_bLinked) {
1026
                if (getTypeScale() == AUTOMATICO) {
1027
                view.getMapContext().getViewPort().addViewPortListener(this);
1028
            } else if (getTypeScale() == CONSTANTE) {
1029
                view.getMapContext().getViewPort().removeViewPortListener(this);
1030
            } else if (getTypeScale() == MANUAL) {
1031
                view.getMapContext().getViewPort().removeViewPortListener(this);
1032
            }
1033
        }
1034
                ((FFrameView)frame).view.getMapContext().removeLayerListener((FFrameView)frame);
1035
            ((FFrameView)frame).view.getMapContext().getViewPort().removeViewPortListener((FFrameView)frame);
1036
    }
1037
        public IFFrame cloneFFrame(Layout layout) {
1038
        FFrameView frame = new FFrameView();
1039
        frame.setLevel(this.getLevel());
1040
        frame.setNum(this.num);
1041
        frame.setName(this.getName());
1042
        frame.setBoundBox(this.getBoundBox());
1043
        frame.setTag(this.getTag());
1044
        frame.m_Mode = this.m_Mode;
1045
        frame.m_typeScale = this.m_typeScale;
1046
        frame.m_extension = this.m_extension;
1047
        frame.m_quality = this.m_quality;
1048
        frame.m_viewing = this.m_viewing;
1049
        frame.m_bLinked = this.m_bLinked;
1050
        frame.m_mapUnits = this.m_mapUnits;
1051
        frame.setRotation(this.getRotation());
1052

    
1053
        frame.m_Scale = this.m_Scale;
1054
        frame.view=this.getView();
1055
        frame.m_fmap = this.getMapContext();
1056
        frame.setSelected(this.getSelected()!=IFFrame.NOSELECT);
1057
        frame.setLayout(layout);
1058

    
1059
        if (frame instanceof IFFrameViewDependence) {
1060
            ((IFFrameViewDependence) frame).initDependence(layout.getAllFFrames());
1061
        }
1062
        if (grid!=null){
1063
                FFrameGrid newGrid=(FFrameGrid)this.grid.cloneFFrame(layout);
1064
                newGrid.setFFrameDependence(frame);
1065
                frame.setGrid(newGrid);
1066
        }
1067
        cloneActions(frame);
1068
        return frame;
1069
    }
1070

    
1071
        public void setGrid(IFFrame grid) {
1072
                this.grid=grid;
1073
                this.grid.setRotation(this.getRotation());
1074
        }
1075

    
1076
        public void setRotation(double rotation) {
1077
                super.setRotation(rotation);
1078
                if (grid!=null)
1079
                        grid.setRotation(rotation);
1080
        }
1081
        public void showGrid(boolean b){
1082
                showGrid=b;
1083
        }
1084

    
1085
        public boolean isShowGrid() {
1086
                return showGrid;
1087
        }
1088
}