Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameView.java @ 4204

History | View | Annotate | Download (30 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.geom.Rectangle2D.Double;
56
import java.awt.image.BufferedImage;
57
import java.util.ArrayList;
58

    
59
import com.iver.andami.PluginServices;
60
import com.iver.andami.messages.NotificationManager;
61
import com.iver.cit.gvsig.ProjectExtension;
62
import com.iver.cit.gvsig.fmap.ColorEvent;
63
import com.iver.cit.gvsig.fmap.DriverException;
64
import com.iver.cit.gvsig.fmap.ExtentEvent;
65
import com.iver.cit.gvsig.fmap.FMap;
66
import com.iver.cit.gvsig.fmap.ViewPort;
67
import com.iver.cit.gvsig.fmap.ViewPortListener;
68
import com.iver.cit.gvsig.fmap.layers.LegendListener;
69
import com.iver.cit.gvsig.fmap.layers.XMLException;
70
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
71
import com.iver.cit.gvsig.gui.layout.FLayoutFunctions;
72
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
73
import com.iver.cit.gvsig.gui.layout.Layout;
74
import com.iver.cit.gvsig.gui.project.SaveException;
75
import com.iver.cit.gvsig.project.Project;
76
import com.iver.cit.gvsig.project.ProjectView;
77
import com.iver.utiles.XMLEntity;
78

    
79

    
80
/**
81
 * FFrame para introducir una vista en el Layout.
82
 *
83
 * @author Vicente Caballero Navarro
84
 */
85
public class FFrameView extends FFrame implements ViewPortListener,
86
    LegendListener, IFFrameUseProject, IFFrameLayoutDependence,IFFrameUseFMap {
87
    //private static Logger logger = Logger.getLogger(FFrameView.class.getName());
88
    public static final int AUTOMATICO = 0;
89
    public static final int CONSTANTE = 1;
90
    public static final int MANUAL = 2;
91
    public static final int PRESENTACION = 0;
92
    public static final int BORRADOR = 1;
93
    private int m_Mode;
94
    private int m_typeScale = AUTOMATICO;
95
    private int m_extension = 0;
96
    private int m_quality = PRESENTACION;
97
    private int m_viewing = 0;
98
    private boolean m_bLinked = true;
99
    private ProjectView view = null;
100
    private FMap m_fmap = null;
101
    private double m_Scale = 0;
102
    private int m_mapUnits = 1; //Metros.
103

    
104
    private BufferedImage m_image = null;
105
    private AffineTransform at = null;
106
    private Project project = null;
107
    private Layout layout;
108
        private double scaleAnt;
109
        private boolean refresh=false;
110
        private boolean hasViewPort=false;
111
        private Point2D antpoint;
112
    /**
113
     * Creates a new FFrameView object.
114
     */
115
    public FFrameView() {
116
        num++;
117
    }
118

    
119
    /**
120
     * Devuelve una descripci?n del FFrameView.
121
     *
122
     * @return Descripci?n.
123
     */
124
    public String toString() {
125
        if (getView() == null) {
126
            return "FFrameView " + num + ": " + "Vacio";
127
        }
128

    
129
        return "FFrameView " + num + ": " + getView().getName();
130
    }
131

    
132
    /**
133
     * Rellena la escala de la vista que contiene el fframe.
134
     *
135
     * @param d escala de la vista.
136
     */
137
    public void setScale(double d) {
138
        m_Scale = d;
139
    }
140

    
141
    /**
142
     * Inserta el nuevo extent a la FFrameView.
143
     *
144
     * @param r Rect?ngulo a ocupar por el FFrameView.
145
     */
146
    public void setNewExtent(Rectangle2D r) {
147
        getFMap().getViewPort().setExtent(r);
148
        m_Scale = FLayoutUtilities.getScaleView(getFMap().getViewPort(),
149
                getBoundBox().width,
150
                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
192
     * momento esta opci?n esta deshabilitada.
193
     *
194
     * @param v entero que representa la forma de actualizar la vista.
195
     */
196
    public void setViewing(int v) {
197
        m_viewing = v;
198
    }
199

    
200
    /**
201
     * Inserta el ProjectView de donde obtener las propiedades de la vista a
202
     * mostrar.
203
     *
204
     * @param v Modelo de la vista.
205
     */
206
    public void setView(ProjectView v) {
207
        view = v;
208

    
209
        ViewPort vp = v.getMapContext().getViewPort().cloneViewPort();
210

    
211
        vp.setImageSize(new Dimension((int) getBoundingBox(getATMap()).width,
212
                (int) getBoundingBox(null).height));
213

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

    
270
    /**
271
     * Devuelve el modelo de la vista.
272
     *
273
     * @return Modelo de la vista.
274
     */
275
    public ProjectView getView() {
276
        return view;
277
    }
278

    
279
    /**
280
     * Devuelve un Rect?ngulo que representa  el extent de la vista que se
281
     * requiere a partir  de una escala.
282
     *
283
     * @param scale Escala a mostrar.
284
     *
285
     * @return Rect?ngulo.
286
     */
287
    private Rectangle2D.Double getNewExtent(long scale) {
288
        double hview = getBoundBox().getHeight();
289
        double wview = getBoundBox().getWidth();
290
        double hextent = (scale * hview) / 100.0;
291
        double wextent = (scale * wview) / 100.0;
292
        double newx = m_fmap.getViewPort().getExtent().getCenterX() -
293
            (wextent / 2.0);
294
        double newy = m_fmap.getViewPort().getExtent().getCenterY() -
295
            (hextent / 2.0);
296

    
297
        return new Rectangle2D.Double(newx, newy, wextent, hextent);
298
    }
299

    
300
    /**
301
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
302
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
303
     * de dibujar.
304
     *
305
     * @param g Graphics2D
306
     * @param at Transformada af?n.
307
     * @param rv rect?ngulo sobre el que hacer un clip. (el rect?ngulo visible)
308
     * @param imgBase Imagen para acelerar el dibujado.
309
     *
310
     * @throws com.iver.cit.gvsig.fmap.DriverException
311
     */
312
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
313
        BufferedImage imgBase) throws com.iver.cit.gvsig.fmap.DriverException {
314
            Point2D point =null;
315
            if (getATMap()!=null){
316
            point =functions.toMapPoint(new Point2D.Double(layout.getRect().getX(),layout.getRect().getY()), getATMap());
317
            }
318
            /**
319
             * this FFrame's BoundingBox
320
             */
321
            Rectangle2D.Double r = getBoundingBox(at);
322
            if (rv!=null && layout.getAT().getScaleX()==scaleAnt && m_image!=null && !refresh){
323
                if (point.equals(antpoint)) {
324
                                g.translate((int) r.getX(), (int) r.getY());
325
                                g.drawImage(m_image, 0, 0, layout);
326
                                g.translate(-(int) r.getX(), -(int) r.getY());
327
                                scaleAnt = layout.getAT().getScaleX();
328
                                return;
329
                        }
330
        }
331

    
332
            if (getRotation()!=0)
333
        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
334
            r.y + (r.height / 2));
335

    
336
        if (intersects(rv, r)) {
337
            if (getFMap() == null) {
338
                drawEmpty(g);
339
            } else {
340
                if (rv != null) {
341
                    // Dibujamos en pantalla
342
                    Rectangle rclip = g.getClipBounds();
343
                    g.clipRect((int) r.getMinX(), (int) r.getMinY(),
344
                        (int) r.getWidth(), (int) r.getHeight());
345

    
346
                    if (getQuality() == PRESENTACION) {
347
                            if (rv.intersects(r)) {
348
                                    ViewPort viewPort = this.getFMap().getViewPort();
349
                                    Color theBackColor = viewPort.getBackColor();
350

    
351
                                    if (theBackColor != null) {
352
                                            g.setColor(theBackColor);
353
                                            g.fillRect((int) r.x, (int) r.y,
354
                                                            viewPort.getImageWidth(),
355
                                                            viewPort.getImageHeight());
356
                                    }
357
                                    System.err.println("r : "+r);
358
                                    if (r.getWidth()>layout.getWidth() || r.getHeight()>layout.getHeight()){
359
                                            getFMap().getViewPort().setOffset(new Point2D.Double(0,0));
360
                                            if (antpoint!=null && !refresh){
361
                                            Rectangle2D extent=getFMap().getViewPort().getExtent();
362
                                            extent.setRect(extent.getX()+(antpoint.getX()-point.getX()),extent.getY()+(antpoint.getY()-point.getY()),extent.getWidth(),extent.getHeight());
363
                                            setNewExtent(extent);
364
                                            }
365
                                            //if (antViewPort==null)
366
                                            //antViewPort=getFMap().getViewPort().cloneViewPort();
367
                                            getFMap().getViewPort().setImageSize(new Dimension((int) layout.getWidth(), (int)layout.getHeight()));
368
                                            getFMap().draw(imgBase, g, getScale());
369
                                            setATMap((AffineTransform) getFMap()
370
                                                            .getViewPort()
371
                                                            .getAffineTransform()
372
                                                            .clone());
373
                                            //getFMap().setViewPort(antViewPort.cloneViewPort());
374
                                            antpoint=functions.toMapPoint(new Point2D.Double(layout.getRect().getX(),layout.getRect().getY()), getATMap());
375
                                    }else{
376
                                            if (!hasViewPort){
377
                                                    saveAntViewPort();
378
                                                    hasViewPort=true;
379
                                            }else{
380
                                                    getFMap().setViewPort(antViewPort.cloneViewPort());
381
                                            }
382
                                            getFMap().getViewPort().setOffset(new Point2D.Double(
383
                                                            r.x, r.y));
384
                                            getFMap().getViewPort().setImageSize(new Dimension(
385
                                                            (int) r.width, (int) r.height));
386
                                            m_image=new BufferedImage((int)r.getWidth(),
387
                                                            (int) r.getHeight(),
388
                                                            BufferedImage.TYPE_INT_ARGB);
389
                                            Graphics2D gimg=(Graphics2D) m_image.getGraphics();
390
                                            gimg.translate(-((int)r.getX()),-((int)r.getY()));
391
                                            getFMap().draw(m_image,gimg, getScale());
392
                                            gimg.translate(((int)r.getX()),((int)r.getY()));
393
                                            g.drawImage(m_image,(int)r.getX(),(int)r.getY(),layout);
394
                                            setATMap((AffineTransform) getFMap()
395
                                                            .getViewPort()
396
                                                            .getAffineTransform()
397
                                                            .clone());
398
                                             antpoint=null;
399
                                    }
400
                                    scaleAnt=layout.getAT().getScaleX();
401
                                    refresh=false;
402

    
403
                            }
404
                            if (rclip != null) {
405
                                    g.setClip(rclip.x, rclip.y, rclip.width,
406
                                                    rclip.height);
407
                            }
408
                    } else {
409
                            drawDraft(g);
410
                    }
411
                } else {
412
                        printX(g, at);
413
                        setATMap((AffineTransform) getFMap()
414
                                            .getViewPort()
415
                                            .getAffineTransform()
416
                                            .clone());
417
                }
418
            }
419
        }
420

    
421
        if (getRotation()!=0)
422
        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2),
423
            r.y + (r.height / 2));
424
    }
425

    
426
    /**
427
     * DOCUMENT ME!
428
     *
429
     * @param g DOCUMENT ME!
430
     * @param at DOCUMENT ME!
431
     *
432
     * @throws DriverException
433
     *
434
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
435
     *      java.awt.geom.AffineTransform)
436
     */
437
    public void print(Graphics2D g, AffineTransform at)
438
        throws DriverException {
439
        draw(g, at, null, null);
440
    }
441

    
442
    /**
443
     * DOCUMENT ME!
444
     *
445
     * @param g DOCUMENT ME!
446
     * @param at DOCUMENT ME!
447
     */
448
    private void printX(Graphics2D g, AffineTransform at) {
449
        Rectangle2D.Double r = getBoundingBox(at);
450

    
451
        // Dibujamos en impresora
452
        Rectangle rclip = g.getClipBounds();
453
        g.clipRect((int) r.getMinX(), (int) r.getMinY(), (int) r.getWidth(),
454
            (int) r.getHeight());
455
        this.getFMap().getViewPort().setOffset(new Point2D.Double(r.x, r.y));
456
        this.getFMap().getViewPort().setImageSize(new Dimension((int) r.width,
457
                (int) r.height));
458

    
459
        try {
460
            this.getFMap().print(g, getScale());
461
        } catch (com.iver.cit.gvsig.fmap.DriverException e) {
462
            NotificationManager.addError(e.getMessage(), e);
463
        }
464

    
465
        g.setClip(rclip.x, rclip.y, rclip.width, rclip.height);
466
    }
467

    
468
    /**
469
     * Rellena la unidad de medida en la que est? la vista.
470
     *
471
     * @param i entero que representa la unidad de medida de la vista.
472
     */
473
    public void setMapUnits(int i) {
474
        m_mapUnits = i;
475
    }
476

    
477
    /**
478
     * Obtiene la unidad de medida en la que est? la vista.
479
     *
480
     * @return Unidad de medida.
481
     */
482
    public int getMapUnits() {
483
        return m_mapUnits;
484
    }
485

    
486
    /**
487
     * Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
488
     * a?adida la vista.
489
     *
490
     * @return escala.
491
     */
492
    public long getScale() {
493
        /*if (m_bLinked){
494
           return getScaleView1(METROS);
495
               }
496
         */
497
        if (getTypeScale() == AUTOMATICO) {
498
            return FLayoutUtilities.getScaleView(getFMap().getViewPort(),
499
                getBoundBox().width, getBoundingBox(null).width);
500
        } else if (getTypeScale() == CONSTANTE) {
501
            return (long) m_Scale;
502
        } else if (getTypeScale() == MANUAL) {
503
            return (long) m_Scale;
504
        }
505

    
506
        return (long) m_Scale;
507
    }
508

    
509
    /**
510
     * Seleccionar si la vista esta relacionada o no con la original.
511
     *
512
     * @param b true si est? ligada y false si no lo est?.
513
     */
514
    public void setLinked(boolean b) {
515
        m_bLinked = b;
516
    }
517

    
518
    /**
519
     * Devuelve si est? ligada o no el FFrameView con la vista.
520
     *
521
     * @return True si la vista est? ligada.
522
     */
523
    public boolean getLinked() {
524
        return m_bLinked;
525
    }
526

    
527
    /**
528
     * Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
529
     * la vista.
530
     *
531
     * @return entero que representa la opci?n elegida.
532
     */
533
    public int getExtension() {
534
        return m_extension;
535
    }
536

    
537
    /**
538
     * Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
539
     * MANUAL.
540
     *
541
     * @return entero que representa el tipo seleccionado.
542
     */
543
    public int getTypeScale() {
544
        return m_typeScale;
545
    }
546

    
547
    /**
548
     * Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
549
     *
550
     * @param i entero que representa la opci?n elegida.
551
     */
552
    public void setExtension(int i) {
553
        m_extension = i;
554
    }
555

    
556
    /**
557
     * Rellenar el tipo de escala que se desea.
558
     *
559
     * @param i entero que representa el tipo de escala.
560
     */
561
    public void setTypeScale(int i) {
562
        m_typeScale = i;
563
    }
564

    
565
    /**
566
     * DOCUMENT ME!
567
     *
568
     * @return DOCUMENT ME!
569
     *
570
     * @throws SaveException
571
     *
572
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
573
     */
574
    public XMLEntity getXMLEntity() throws SaveException {
575
        XMLEntity xml = super.getXMLEntity();
576

    
577
        try {
578
            xml.putProperty("type", Layout.RECTANGLEVIEW);
579
            xml.putProperty("m_Mode", m_Mode);
580
            xml.putProperty("m_typeScale", m_typeScale);
581
            xml.putProperty("m_extension", m_extension);
582
            xml.putProperty("m_quality", m_quality);
583
            xml.putProperty("m_viewing", m_viewing);
584
            xml.putProperty("m_bLinked", m_bLinked);
585
            xml.putProperty("m_mapUnits", m_mapUnits);
586
            xml.putProperty("m_Scale", m_Scale);
587

    
588
            ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
589
            ArrayList views = pe.getProject().getViews();
590

    
591
            boolean hasIndex = false;
592

    
593
            for (int i = 0; i < views.size(); i++) {
594
                if ((view != null) &&
595
                        view.getName().equals(((ProjectView) views.get(i)).getName())) {
596
                    xml.putProperty("indice", i);
597
                    hasIndex = true;
598
                }
599
            }
600

    
601
            if (!hasIndex) {
602
                xml.putProperty("indice", -1);
603
            }
604

    
605
            if (getFMap() != null) {
606
                xml.putProperty("extentX",
607
                    getFMap().getViewPort().getExtent().getX());
608
                xml.putProperty("extentY",
609
                    getFMap().getViewPort().getExtent().getY());
610
                xml.putProperty("extentW",
611
                    getFMap().getViewPort().getExtent().getWidth());
612
                xml.putProperty("extentH",
613
                    getFMap().getViewPort().getExtent().getHeight());
614

    
615
                xml.addChild(getFMap().getXMLEntity());
616
            }
617
        } catch (Exception e) {
618
            throw new SaveException(e, this.getClass().getName());
619
        }
620

    
621
        return xml;
622
    }
623

    
624
    /**
625
     * Inserta la imagen para repintar el FFrameView.
626
     *
627
     * @param bi Imagen para repintar.
628
     */
629
    public void setBufferedImage(BufferedImage bi) {
630
        m_image = bi;
631
    }
632

    
633
    /**
634
     * Devuelve la imagen para repintar.
635
     *
636
     * @return Imagen para repintar.
637
     */
638
    public BufferedImage getBufferedImage() {
639
        return m_image;
640
    }
641

    
642
    /**
643
     * Devuelve la MAtriz de transformaci?n utilizada por la FFrameView para poder cambiar
644
     * un punto en pixels a coordenadas del mundo real.
645
     *
646
     * @return MAtriz de transformaci?n.
647
     */
648
    public AffineTransform getATMap() {
649
        return at;
650
    }
651

    
652
    /**
653
     * Inserta la matriz de transformaci?n.
654
     *
655
     * @param transform Matriz de transformaci?n.
656
     */
657
    public void setATMap(AffineTransform transform) {
658
        at = transform;
659
    }
660
    /**
661
     * Inserta el proyecto.
662
     *
663
     * @param p Proyecto.
664
     */
665
    public void setProject(Project p) {
666
        project = p;
667
    }
668

    
669
    /**
670
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
671
     *      com.iver.cit.gvsig.project.Project)
672
     */
673
    public void setXMLEntity03(XMLEntity xml, Layout l) {
674
        if (xml.getIntProperty("m_Selected") != 0) {
675
            this.setSelected(true);
676
        } else {
677
            this.setSelected(false);
678
        }
679

    
680
        this.setName(xml.getStringProperty("m_name"));
681
        this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
682
                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
683
                xml.getDoubleProperty("h")));
684

    
685
        this.m_Mode = xml.getIntProperty("m_Mode");
686
        this.m_typeScale = xml.getIntProperty("m_typeScale");
687
        this.m_extension = xml.getIntProperty("m_extension");
688
        this.m_quality = xml.getIntProperty("m_quality");
689
        this.m_viewing = xml.getIntProperty("m_viewing");
690
        this.m_bLinked = xml.getBooleanProperty("m_bLinked");
691
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
692

    
693
        this.m_Scale = xml.getDoubleProperty("m_Scale");
694

    
695
        int indice = xml.getIntProperty("indice");
696

    
697
        if (indice != -1) {
698
            ProjectView view = (ProjectView) project.getViews().get(indice);
699
            this.m_fmap = view.getMapContext();
700
            this.setView((ProjectView) view);
701

    
702
            try {
703
                //this.m_fmap = view.getMapContext();
704

    
705
                /*        this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
706
                   xml.getDoubleProperty("extentX"),
707
                   xml.getDoubleProperty("extentY"),
708
                   xml.getDoubleProperty("extentW"),
709
                   xml.getDoubleProperty("extentH")));
710
                 */
711
                if (m_bLinked) {
712
                    this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
713
                            xml.getDoubleProperty("extentX"),
714
                            xml.getDoubleProperty("extentY"),
715
                            xml.getDoubleProperty("extentW"),
716
                            xml.getDoubleProperty("extentH")));
717
                } else if (!m_bLinked) {
718
                    this.m_fmap = FMap.createFromXML03(xml.getChild(0));
719
                }
720
            } catch (XMLException e) {
721
                NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
722
                    e);
723
            }
724
        }
725
    }
726

    
727
    /**
728
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
729
     */
730
    public String getNameFFrame() {
731
        return PluginServices.getText(this, "Vista") + num;
732
    }
733

    
734
    /**
735
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
736
     */
737
    public void extentChanged(ExtentEvent e) {
738
        if (getTypeScale() == AUTOMATICO) {
739
            m_fmap.getViewPort().setExtent(e.getNewExtent());
740

    
741
            if (layout != null) {
742
                layout.setStatus(Layout.DESACTUALIZADO);
743
            }
744
        }
745
    }
746

    
747
    /**
748
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
749
     */
750
    public void backColorChanged(ColorEvent e) {
751
        if (getLinked()) {
752
            m_fmap.getViewPort().setBackColor(e.getNewColor());
753
            layout.setStatus(Layout.DESACTUALIZADO);
754
        }
755
    }
756

    
757
    /**
758
     * DOCUMENT ME!
759
     *
760
     * @param l DOCUMENT ME!
761
     */
762
    public void setLayout(Layout l) {
763
        layout = l;
764
    }
765

    
766
    /**
767
     * DOCUMENT ME!
768
     *
769
     * @param e DOCUMENT ME!
770
     */
771
    public void legendChanged(LegendChangedEvent e) {
772
        if (getLinked()) {
773
            layout.setStatus(Layout.DESACTUALIZADO);
774
        }
775
    }
776

    
777
    /**
778
     * DOCUMENT ME!
779
     *
780
     * @param xml DOCUMENT ME!
781
     */
782
    public void setXMLEntity(XMLEntity xml) {
783
        if (xml.getIntProperty("m_Selected") != 0) {
784
            this.setSelected(true);
785
        } else {
786
            this.setSelected(false);
787
        }
788

    
789
        this.setName(xml.getStringProperty("m_name"));
790
        this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
791
                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
792
                xml.getDoubleProperty("h")));
793

    
794
        this.m_Mode = xml.getIntProperty("m_Mode");
795
        this.m_typeScale = xml.getIntProperty("m_typeScale");
796
        this.m_extension = xml.getIntProperty("m_extension");
797
        this.m_quality = xml.getIntProperty("m_quality");
798
        this.m_viewing = xml.getIntProperty("m_viewing");
799
        this.m_bLinked = xml.getBooleanProperty("m_bLinked");
800
        this.m_mapUnits = xml.getIntProperty("m_mapUnits");
801
        setRotation(xml.getDoubleProperty("m_rotation"));
802
        this.m_Scale = xml.getDoubleProperty("m_Scale");
803

    
804
        int indice = xml.getIntProperty("indice");
805

    
806
        if (indice != -1) {
807
            try {
808
                ProjectView view = (ProjectView) project.getViews().get(indice);
809
                this.m_fmap = view.getMapContext();
810
                this.setView((ProjectView) view);
811

    
812
                try {
813
                    //this.m_fmap = view.getMapContext();
814

    
815
                    /*        this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
816
                       xml.getDoubleProperty("extentX"),
817
                       xml.getDoubleProperty("extentY"),
818
                       xml.getDoubleProperty("extentW"),
819
                       xml.getDoubleProperty("extentH")));
820
                     */
821
                    if (xml.contains("extentX")) {
822
                        if (m_bLinked) {
823
                            this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
824
                                    xml.getDoubleProperty("extentX"),
825
                                    xml.getDoubleProperty("extentY"),
826
                                    xml.getDoubleProperty("extentW"),
827
                                    xml.getDoubleProperty("extentH")));
828
                        } else if (!m_bLinked) {
829
                            this.m_fmap = FMap.createFromXML(xml.getChild(0));
830
                        }
831
                    }
832
                } catch (XMLException e) {
833
                    NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
834
                        e);
835
                }
836
            } catch (IndexOutOfBoundsException e) {
837
            }
838
        } else if (!m_bLinked) {
839
            try {
840
                this.m_fmap = FMap.createFromXML(xml.getChild(0));
841
            } catch (XMLException e) {
842
                // TODO Auto-generated catch block
843
                e.printStackTrace();
844
            }
845
        }
846
    }
847

    
848
    /**
849
     * DOCUMENT ME!
850
     *
851
     * @return DOCUMENT ME!
852
     */
853
    public Layout getLayout() {
854
        return layout;
855
    }
856

    
857
    /**
858
     * DOCUMENT ME!
859
     *
860
     * @param arg0 DOCUMENT ME!
861
     *
862
     * @return DOCUMENT ME!
863
     */
864
    public boolean compare(Object arg0) {
865
        if (!(arg0 instanceof FFrameView)) {
866
            return false;
867
        }
868

    
869
        if (!this.getName().equals(((FFrameView) arg0).getName())) {
870
            return false;
871
        }
872

    
873
        if (!this.getBoundBox().equals(((FFrameView) arg0).getBoundBox())) {
874
            return false;
875
        }
876

    
877
        if (!this.toString().equals(((FFrameView) arg0).toString())) {
878
            return false;
879
        }
880

    
881
        if (!this.getFMap().equals(((FFrameView) arg0).getFMap())) {
882
            return false;
883
        }
884

    
885
        return true;
886
    }
887

    
888
    /**
889
     * DOCUMENT ME!
890
     *
891
     * @param arg0 DOCUMENT ME!
892
     *
893
     * @return DOCUMENT ME!
894
     */
895
    public boolean equals(Object arg0) {
896
        return this.compare(arg0);
897
    }
898

    
899
        public void refresh() {
900
                refresh=true;
901
        }
902
        private FLayoutFunctions functions=new FLayoutFunctions(layout);
903
        private ViewPort antViewPort;
904

    
905
        public void saveAntViewPort() {
906
                antViewPort=getFMap().getViewPort().cloneViewPort();
907

    
908
        }
909

    
910
        public void initialize() {
911
                setView(view);
912
        }
913
}