Statistics
| Revision:

svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameView.java @ 5222

History | View | Annotate | Download (22.2 KB)

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

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.messages.NotificationManager;
49

    
50
import com.iver.cit.gvsig.ProjectExtension;
51
import com.iver.cit.gvsig.fmap.ColorEvent;
52
import com.iver.cit.gvsig.fmap.DriverException;
53
import com.iver.cit.gvsig.fmap.ExtentEvent;
54
import com.iver.cit.gvsig.fmap.FMap;
55
import com.iver.cit.gvsig.fmap.ViewPort;
56
import com.iver.cit.gvsig.fmap.ViewPortListener;
57
import com.iver.cit.gvsig.fmap.layers.LegendListener;
58
import com.iver.cit.gvsig.fmap.layers.XMLException;
59
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent;
60
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
61
import com.iver.cit.gvsig.gui.layout.Layout;
62
import com.iver.cit.gvsig.gui.project.SaveException;
63
import com.iver.cit.gvsig.project.Project;
64
import com.iver.cit.gvsig.project.ProjectView;
65

    
66
import com.iver.utiles.XMLEntity;
67

    
68

    
69
import java.awt.Color;
70
import java.awt.Dimension;
71
import java.awt.Graphics2D;
72
import java.awt.Rectangle;
73
import java.awt.geom.AffineTransform;
74
import java.awt.geom.Point2D;
75
import java.awt.geom.Rectangle2D;
76
import java.awt.image.BufferedImage;
77

    
78
import java.util.ArrayList;
79

    
80

    
81
/**
82
 * FFrame para introducir una vista en el Layout.
83
 *
84
 * @author Vicente Caballero Navarro
85
 */
86
public class FFrameView extends FFrame implements ViewPortListener,LegendListener,IFFrameUseProject  {
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
        //private int num = 0;
104
        private BufferedImage m_image = null;
105
        private AffineTransform at = null;
106
        private Project project = null;
107
        private Layout layout;
108

    
109
        /**
110
         * Creates a new FFrameView object.
111
         */
112
        public FFrameView() {
113
                num++;
114
        }
115

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

    
126
                return "FFrameView " + num + ": " + getView().getName();
127
        }
128

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

    
138
        /**
139
         * Inserta el nuevo extent a la FFrameView.
140
         *
141
         * @param r Rect?ngulo a ocupar por el FFrameView.
142
         */
143
        public void setNewExtent(Rectangle2D r) {
144
                getFMap().getViewPort().setExtent(r);
145
                m_Scale = FLayoutUtilities.getScaleView(getFMap().getViewPort(), getBoundBox().width,getBoundingBox(null).width/getBoundBox().width);
146
        }
147

    
148
        /**
149
         * Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
150
         * escala fija.
151
         *
152
         * @return FMap.
153
         */
154
        public FMap getFMap() {
155
                return m_fmap;
156
        }
157

    
158
        /**
159
         * Rellena la calidad que se quiere aplicar.
160
         *
161
         * @param q entero que representa la calidad a aplicar.
162
         */
163
        public void setQuality(int q) {
164
                m_quality = q;
165
        }
166

    
167
        /**
168
         * Devuelve un entero que representa la calidad que est? seleccionada.
169
         *
170
         * @return tipo de calidad selccionada.
171
         */
172
        public int getQuality() {
173
                return m_quality;
174
        }
175

    
176
        /**
177
         * Devuelve un entero que representa la forma en que se actualiza la vista.
178
         *
179
         * @return forma que se actualiza la vista.
180
         */
181
        public int getViewing() {
182
                return m_viewing;
183
        }
184

    
185
        /**
186
         * Rellena la forma de actualizar la vista(cuando activo o siempre). De momento esta opci?n esta deshabilitada.
187
         *
188
         * @param v entero que representa la forma de actualizar la vista.
189
         */
190
        public void setViewing(int v) {
191
                m_viewing = v;
192
        }
193

    
194
        /**
195
         * Inserta el ProjectView de donde obtener las propiedades de la vista a
196
         * mostrar.
197
         *
198
         * @param v Modelo de la vista.
199
         */
200
        public void setView(ProjectView v) {
201
                view = v;
202

    
203
                ViewPort vp = v.getMapContext().getViewPort().cloneViewPort();
204

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

    
256
                /*
257
                   m_fmap = v.getMapContext();
258

259
                   v.getMapContext().getViewPort();
260
                   ViewPort vp = new ViewPort();
261
                   vp.setExtent(v.getMapContext().getViewPort().getExtent());
262
                   m_fmap = m_fmap.createNewFMap(vp);
263
                   view = v;
264
                 */
265
        }
266

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

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

    
295
                return new Rectangle2D.Double(newx, newy, wextent, hextent);
296
        }
297

    
298
        /**
299
         * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
300
         * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
301
         * de dibujar.
302
         *
303
         * @param g Graphics2D
304
         * @param at Transformada af?n.
305
         * @param rv rect?ngulo sobre el que hacer un clip.
306
         * @param imgBase Imagen para acelerar el dibujado.
307
         *
308
         * @throws com.iver.cit.gvsig.fmap.DriverException
309
         */
310
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
311
                BufferedImage imgBase) throws com.iver.cit.gvsig.fmap.DriverException {
312
                Rectangle2D.Double r = getBoundingBox(at);
313
                g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2),
314
                                r.y + (r.height / 2));
315
                if (intersects(rv, r)) {
316
                        if (getFMap() == null) {
317
                                drawEmpty(g);
318
                        } else {
319
                                if (rv != null) {
320
                                        // Dibujamos en pantalla
321
                                        Rectangle rclip = g.getClipBounds();
322
                                        g.clipRect((int) r.getMinX(), (int) r.getMinY(),
323
                                                (int) r.getWidth(), (int) r.getHeight());
324

    
325
                                        if (getQuality() == PRESENTACION) {
326
                                                /*     this.getFMap().setTransparent(true);
327
                                                   this.getFMap().drawView((Graphics2D) g,
328
                                                       new Rectangle((int) (r.x), (int) (r.y),
329
                                                           (int) (r.width), (int) (r.height)),
330
                                                       (Rectangle) rv, false, imgBase);
331
                                                 */
332
                                                if (rv.intersects(r)) {
333
                                                        this.getFMap().getViewPort().setOffset(new Point2D.Double(
334
                                                                        r.x, r.y));
335
                                                        this.getFMap().getViewPort().setImageSize(new Dimension(
336
                                                                        (int) r.width, (int) r.height));
337

    
338
                                                        try {
339
                                                            ViewPort viewPort = this.getFMap().getViewPort();
340
                                                            Color theBackColor = viewPort.getBackColor();
341
                                                            if (theBackColor != null)
342
                                                            {
343
                                                                g.setColor(theBackColor);
344
                                                                g.fillRect((int) r.x, (int) r.y, viewPort.getImageWidth(), viewPort.getImageHeight());
345
                                                            }
346

    
347
                                                                this.getFMap().draw(imgBase, g,getScale());
348
                                                        } catch (com.iver.cit.gvsig.fmap.DriverException e) {
349
                                                                // TODO Auto-generated catch block
350
                                                                e.printStackTrace();
351
                                                        }
352
                                                }
353

    
354
                                                if (rclip != null) {
355
                                                        g.setClip(rclip.x, rclip.y, rclip.width,
356
                                                                rclip.height);
357
                                                }
358
                                        } else {
359
                                                drawDraft(g);
360
                                        }
361
                                } else {
362
                                        printX(g, at);
363
                                }
364
                        }
365
                }
366
                g.rotate(Math.toRadians(-getRotation()),
367
                                r.x + (r.width / 2), r.y + (r.height / 2));
368
                if (getFMap() != null)
369
                        setAt((AffineTransform)getFMap().getViewPort().getAffineTransform().clone());
370
        }
371

    
372
        /**
373
         * @throws DriverException
374
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
375
         *                 java.awt.geom.AffineTransform)
376
         */
377
        public void print(Graphics2D g, AffineTransform at) throws DriverException {
378
                draw(g, at, null, null);
379
        }
380
        private void printX(Graphics2D g, AffineTransform at){
381
                Rectangle2D.Double r = getBoundingBox(at);
382

    
383
                // Dibujamos en impresora
384
                Rectangle rclip = g.getClipBounds();
385
                g.clipRect((int) r.getMinX(), (int) r.getMinY(), (int) r.getWidth(),
386
                        (int) r.getHeight());
387
                this.getFMap().getViewPort().setOffset(new Point2D.Double(r.x, r.y));
388
                this.getFMap().getViewPort().setImageSize(new Dimension((int) r.width,
389
                                (int) r.height));
390

    
391
                try {
392
                        this.getFMap().print(g,getScale());
393
                } catch (com.iver.cit.gvsig.fmap.DriverException e) {
394
                        NotificationManager.addError(e.getMessage(), e);
395
                }
396

    
397
                g.setClip(rclip.x, rclip.y, rclip.width, rclip.height);
398
        }
399
        /**
400
         * Rellena la unidad de medida en la que est? la vista.
401
         *
402
         * @param i entero que representa la unidad de medida de la vista.
403
         */
404
        public void setMapUnits(int i) {
405
                m_mapUnits = i;
406
        }
407

    
408
        /**
409
         * Obtiene la unidad de medida en la que est? la vista.
410
         *
411
         * @return Unidad de medida.
412
         */
413
        public int getMapUnits() {
414
                return m_mapUnits;
415
        }
416

    
417
        /**
418
         * Devuelve la escala seg?n el tipo de escala que se haya seleccionado al
419
         * a?adida la vista.
420
         *
421
         * @return escala.
422
         */
423
        public long getScale() {
424
                /*if (m_bLinked){
425
                   return getScaleView1(METROS);
426
                       }
427
                 */
428

    
429
                if (getTypeScale() == AUTOMATICO) {
430
                        return FLayoutUtilities.getScaleView(getFMap().getViewPort(), getBoundBox().width,getBoundingBox(null).width);
431
                } else if (getTypeScale() == CONSTANTE) {
432
                        return (long) m_Scale;
433
                } else if (getTypeScale() == MANUAL) {
434
                        return (long) m_Scale;
435
                }
436

    
437
                return (long) m_Scale;
438
        }
439

    
440
        /**
441
         * Seleccionar si la vista esta relacionada o no con la original.
442
         *
443
         * @param b true si est? ligada y false si no lo est?.
444
         */
445
        public void setLinked(boolean b) {
446
                m_bLinked = b;
447
        }
448

    
449
        /**
450
         * Devuelve si est? ligada o no el FFrameView con la vista.
451
         *
452
         * @return True si la vista est? ligada.
453
         */
454
        public boolean getLinked() {
455
                return m_bLinked;
456
        }
457

    
458
        /**
459
         * Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a
460
         * la vista.
461
         *
462
         * @return entero que representa la opci?n elegida.
463
         */
464
        public int getExtension() {
465
                return m_extension;
466
        }
467

    
468
        /**
469
         * Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o
470
         * MANUAL.
471
         *
472
         * @return entero que representa el tipo seleccionado.
473
         */
474
        public int getTypeScale() {
475
                return m_typeScale;
476
        }
477

    
478
        /**
479
         * Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
480
         *
481
         * @param i entero que representa la opci?n elegida.
482
         */
483
        public void setExtension(int i) {
484
                m_extension = i;
485
        }
486

    
487
        /**
488
         * Rellenar el tipo de escala que se desea.
489
         *
490
         * @param i entero que representa el tipo de escala.
491
         */
492
        public void setTypeScale(int i) {
493
                m_typeScale = i;
494
        }
495

    
496
        /**
497
         * @throws XMLException
498
         * @throws SaveException
499
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
500
         */
501
        public XMLEntity getXMLEntity() throws SaveException {
502
                XMLEntity xml = new XMLEntity();
503
                try{
504
                xml.putProperty("className",this.getClass().getName());
505
                xml.putProperty("m_name", m_name);
506
                xml.putProperty("x", getBoundBox().x);
507
                xml.putProperty("y", getBoundBox().y);
508
                xml.putProperty("w", getBoundBox().width);
509
                xml.putProperty("h", getBoundBox().height);
510
                xml.putProperty("m_Selected", m_Selected);
511
                xml.putProperty("type", Layout.RECTANGLEVIEW);
512
                xml.putProperty("m_Mode", m_Mode);
513
                xml.putProperty("m_typeScale", m_typeScale);
514
                xml.putProperty("m_extension", m_extension);
515
                xml.putProperty("m_quality", m_quality);
516
                xml.putProperty("m_viewing", m_viewing);
517
                xml.putProperty("m_bLinked", m_bLinked);
518
                xml.putProperty("m_mapUnits", m_mapUnits);
519
                xml.putProperty("m_Scale", m_Scale);
520
                xml.putProperty("m_rotation",getRotation());
521

    
522
                xml.putProperty("tag", getTag());
523

    
524
                ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
525
                ArrayList views = pe.getProject().getViews();
526

    
527
                boolean hasIndex = false;
528

    
529
                for (int i = 0; i < views.size(); i++) {
530
                        if (view !=null && view.getName().equals(((ProjectView) views.get(i)).getName())) {
531
                                xml.putProperty("indice", i);
532
                                hasIndex = true;
533
                        }
534
                }
535

    
536
                if (!hasIndex) {
537
                        xml.putProperty("indice", -1);
538
                }
539
                if (getFMap()!=null){
540
                        xml.putProperty("extentX", getFMap().getViewPort().getExtent().getX());
541
                        xml.putProperty("extentY", getFMap().getViewPort().getExtent().getY());
542
                        xml.putProperty("extentW",
543
                                getFMap().getViewPort().getExtent().getWidth());
544
                        xml.putProperty("extentH",
545
                                getFMap().getViewPort().getExtent().getHeight());
546

    
547
                xml.addChild(getFMap().getXMLEntity());
548
                }
549
                }catch (Exception e) {
550
                        throw new SaveException(e,this.getClass().getName());
551
                }
552
                return xml;
553
        }
554

    
555
        /**
556
         * Inserta la imagen para repintar el FFrameView.
557
         *
558
         * @param bi Imagen para repintar.
559
         */
560
        public void setBufferedImage(BufferedImage bi) {
561
                m_image = bi;
562
        }
563

    
564
        /**
565
         * Devuelve la imagen para repintar.
566
         *
567
         * @return Imagen para repintar.
568
         */
569
        public BufferedImage getBufferedImage() {
570
                return m_image;
571
        }
572

    
573
        /**
574
         * Devuelve la MAtriz de transformaci?n utilizada por la FFrameView.
575
         *
576
         * @return MAtriz de transformaci?n.
577
         */
578
        public AffineTransform getAt() {
579
                return at;
580
        }
581

    
582
        /**
583
         * Inserta la matriz de transformaci?n.
584
         *
585
         * @param transform Matriz de transformaci?n.
586
         */
587
        public void setAt(AffineTransform transform) {
588
                at = transform;
589
        }
590

    
591
        /**
592
         * Inserta el proyecto.
593
         *
594
         * @param p Proyecto.
595
         */
596
        public void setProject(Project p) {
597
                project = p;
598
        }
599
        /**
600
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
601
         *                 com.iver.cit.gvsig.project.Project)
602
         */
603
        public void setXMLEntity03(XMLEntity xml, Layout l) {
604
                if (xml.getIntProperty("m_Selected") != 0) {
605
                        this.setSelected(true);
606
                } else {
607
                        this.setSelected(false);
608
                }
609

    
610
                this.setName(xml.getStringProperty("m_name"));
611
                this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
612
                                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
613
                                xml.getDoubleProperty("h")));
614

    
615
                this.m_Mode = xml.getIntProperty("m_Mode");
616
                this.m_typeScale = xml.getIntProperty("m_typeScale");
617
                this.m_extension = xml.getIntProperty("m_extension");
618
                this.m_quality = xml.getIntProperty("m_quality");
619
                this.m_viewing = xml.getIntProperty("m_viewing");
620
                this.m_bLinked = xml.getBooleanProperty("m_bLinked");
621
                this.m_mapUnits = xml.getIntProperty("m_mapUnits");
622

    
623
                //ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
624
                this.m_Scale = xml.getDoubleProperty("m_Scale");
625

    
626
                int indice = xml.getIntProperty("indice");
627

    
628
                if (indice != -1) {
629
                        ProjectView view = (ProjectView) project.getViews().get(indice);
630
                        this.m_fmap = view.getMapContext();
631
                        this.setView((ProjectView) view);
632

    
633
                        try {
634
                                //this.m_fmap = view.getMapContext();
635

    
636
                                /*        this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
637
                                   xml.getDoubleProperty("extentX"),
638
                                   xml.getDoubleProperty("extentY"),
639
                                   xml.getDoubleProperty("extentW"),
640
                                   xml.getDoubleProperty("extentH")));
641
                                 */
642
                                if (m_bLinked) {
643
                                        this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
644
                                                        xml.getDoubleProperty("extentX"),
645
                                                        xml.getDoubleProperty("extentY"),
646
                                                        xml.getDoubleProperty("extentW"),
647
                                                        xml.getDoubleProperty("extentH")));
648
                                } else if (!m_bLinked) {
649
                                        this.m_fmap = FMap.createFromXML03(xml.getChild(0));
650
                                }
651
                        } catch (XMLException e) {
652
                                NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
653
                                        e);
654
                        }
655
                }
656
        }
657

    
658
        /**
659
         * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
660
         */
661
        public String getNameFFrame() {
662
                return PluginServices.getText(this, "Vista") + num;
663
        }
664

    
665
        /**
666
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
667
         */
668
        public void extentChanged(ExtentEvent e) {
669
                if (getTypeScale() == AUTOMATICO) {
670
                        m_fmap.getViewPort().setExtent(e.getNewExtent());
671
                        if (layout!=null){
672
                                layout.setStatus(Layout.DESACTUALIZADO);
673
                                //setBufferedImage(null);
674
                        }
675
                }
676
        }
677

    
678
        /**
679
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
680
         */
681
        public void backColorChanged(ColorEvent e) {
682
                if (getLinked()){
683
            m_fmap.getViewPort().setBackColor(e.getNewColor());
684
                layout.setStatus(Layout.DESACTUALIZADO);
685
                //setBufferedImage(null);
686
                }
687
        }
688
        public void setLayout(Layout l){
689
                layout=l;
690
        }
691

    
692
        public void legendChanged(LegendChangedEvent e) {
693
                if (getLinked()){
694
                        layout.setStatus(Layout.DESACTUALIZADO);
695
                        //setBufferedImage(null);
696
                }
697
        }
698

    
699
        public void setXMLEntity(XMLEntity xml) {
700
                if (xml.getIntProperty("m_Selected") != 0) {
701
                        this.setSelected(true);
702
                } else {
703
                        this.setSelected(false);
704
                }
705

    
706
                this.setName(xml.getStringProperty("m_name"));
707
                this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"),
708
                                xml.getDoubleProperty("y"), xml.getDoubleProperty("w"),
709
                                xml.getDoubleProperty("h")));
710

    
711
                this.m_Mode = xml.getIntProperty("m_Mode");
712
                this.m_typeScale = xml.getIntProperty("m_typeScale");
713
                this.m_extension = xml.getIntProperty("m_extension");
714
                this.m_quality = xml.getIntProperty("m_quality");
715
                this.m_viewing = xml.getIntProperty("m_viewing");
716
                this.m_bLinked = xml.getBooleanProperty("m_bLinked");
717
                this.m_mapUnits = xml.getIntProperty("m_mapUnits");
718
                setRotation(xml.getDoubleProperty("m_rotation"));
719
                //ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
720
                this.m_Scale = xml.getDoubleProperty("m_Scale");
721

    
722
                int indice = xml.getIntProperty("indice");
723

    
724
                if (indice != -1) {
725
                        try{
726
                        ProjectView view = (ProjectView) project.getViews().get(indice);
727
                        this.m_fmap = view.getMapContext();
728
                        this.setView((ProjectView) view);
729

    
730
                        try {
731
                                //this.m_fmap = view.getMapContext();
732

    
733
                                /*        this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
734
                                   xml.getDoubleProperty("extentX"),
735
                                   xml.getDoubleProperty("extentY"),
736
                                   xml.getDoubleProperty("extentW"),
737
                                   xml.getDoubleProperty("extentH")));
738
                                 */
739
                                if (xml.contains("extentX")){
740
                                if (m_bLinked) {
741
                                        this.getFMap().getViewPort().setExtent(new Rectangle2D.Double(
742
                                                        xml.getDoubleProperty("extentX"),
743
                                                        xml.getDoubleProperty("extentY"),
744
                                                        xml.getDoubleProperty("extentW"),
745
                                                        xml.getDoubleProperty("extentH")));
746
                                } else if (!m_bLinked) {
747
                                        this.m_fmap = FMap.createFromXML(xml.getChild(0));
748
                                }
749
                                }
750
                        } catch (XMLException e) {
751
                                NotificationManager.addError("Pasando las propiedades del XMLEntity al objeto",
752
                                        e);
753
                        }
754
        }catch (IndexOutOfBoundsException e) {
755

    
756
                }
757
                }
758
        else if (!m_bLinked) {
759
            try {
760
                this.m_fmap = FMap.createFromXML(xml.getChild(0));
761
            } catch (XMLException e) {
762
                // TODO Auto-generated catch block
763
                e.printStackTrace();
764
            }
765
        }
766

    
767
        }
768

    
769
        public Layout getLayout() {
770
                return layout;
771
        }
772

    
773
        /*public boolean equals(Object arg0) {
774
                if (!this.getName().equals(((FFrameView)arg0).getName())){
775
                        return false;
776
                } if (!this.getLayout().equals(((FFrameView)arg0).getLayout())){
777
                        return false;
778
                }
779
                return super.equals(arg0);
780
}*/
781
}