Statistics
| Revision:

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

History | View | Annotate | Download (22.1 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
                setAt((AffineTransform)getFMap().getViewPort().getAffineTransform().clone());
369
        }
370

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

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

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

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

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

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

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

    
436
                return (long) m_Scale;
437
        }
438

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

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

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

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

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

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

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

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

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

    
526
                boolean hasIndex = false;
527

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
766
        }
767

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

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