Statistics
| Revision:

gvsig-3d / 2.1 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.app / org.gvsig.gvsig3d.app.commons / src / main / java / org / gvsig / gvsig3d / app / layout / fframe / FFrameView3D.java @ 385

History | View | Annotate | Download (33.2 KB)

1
/* gvSIG 3D extension for gvSIG
2
 *
3
 * Copyright (C) 2012 Prodevelop.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Prodevelop, S.L.
22
 *   Pza. Don Juan de Villarrasa, 14 - 5
23
 *   46001 Valencia
24
 *   Spain
25
 *
26
 *   +34 963 510 612
27
 *   +34 963 510 968
28
 *   prode@prodevelop.es
29
 *   http://www.prodevelop.es
30
 */
31
/*
32
 * AUTHORS:
33
 * 2012 AI2 - Instituto Universitario de Automatica e Informatica Industrial.
34
 * Universitat Politecnica de Valencia (UPV)
35
 * http://www.ai2.upv.es
36
 */
37

    
38

    
39
package org.gvsig.gvsig3d.app.layout.fframe;
40

    
41
import java.awt.Dimension;
42
import java.awt.Graphics2D;
43
import java.awt.Point;
44
import java.awt.Rectangle;
45
import java.awt.geom.AffineTransform;
46
import java.awt.geom.Point2D;
47
import java.awt.geom.Rectangle2D;
48
import java.awt.image.BufferedImage;
49

    
50
import javax.print.attribute.PrintRequestAttributeSet;
51

    
52
import org.cresques.cts.IProjection;
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.andami.messages.NotificationManager;
55
import org.gvsig.app.project.Project;
56
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
57
import org.gvsig.app.project.documents.layout.LayoutControl;
58
import org.gvsig.app.project.documents.layout.fframes.FFrame;
59
import org.gvsig.app.project.documents.layout.fframes.FFrameGrid;
60
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
61
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
62
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
63
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseProject;
64
import org.gvsig.app.project.documents.view.BaseViewDocument;
65
import org.gvsig.compat.print.PrintAttributes;
66
import org.gvsig.fmap.dal.exception.ReadException;
67
import org.gvsig.fmap.geom.Geometry;
68
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
69
import org.gvsig.fmap.geom.GeometryLocator;
70
import org.gvsig.fmap.geom.GeometryManager;
71
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
72
import org.gvsig.fmap.geom.primitive.Envelope;
73
import org.gvsig.fmap.geom.primitive.FShape;
74
import org.gvsig.fmap.mapcontext.MapContextException;
75
import org.gvsig.fmap.mapcontext.events.ColorEvent;
76
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
77
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
78
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
79
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent;
80
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener;
81
import org.gvsig.gvsig3d.map3d.MapContext3D;
82
import org.gvsig.osgvp.viewer.ISlaveComponent;
83
import org.slf4j.Logger;
84
import org.slf4j.LoggerFactory;
85

    
86
/**
87
 * @author Jesus Zarzoso- jzarzoso@ai2.upv.es
88
 * @version $Id$
89
 * 
90
 */
91
public class FFrameView3D extends FFrame implements ViewPortListener,
92
                LegendListener, IFFrameUseProject, IFFrameUseFMap, ISlaveComponent {
93
        // private static Logger logger =
94
        // Logger.getLogger(FFrameView.class.getName());
95
        public static final int PRESENTACION = 0;
96
        public static final int BORRADOR = 1;
97
  private static final int AUTOMATICO = 0;
98
  private static final int MANUAL = 0;
99
  private static final int CONSTANTE = 0;
100
        protected int m_Mode;
101
        protected int m_typeScale = AUTOMATICO;
102
        protected int m_extension = 0;
103
        protected int m_quality = PRESENTACION;
104
        protected int m_viewing = 0;
105
        protected boolean m_bLinked = true;
106
        protected BaseViewDocument view = null;
107
        protected MapContext3D m_fmap = null;
108
        protected double m_Scale = 0;
109
        protected int m_mapUnits = 1; // Metros.
110

    
111
        private BufferedImage m_image = null;
112
        private AffineTransform at = null;
113
        private Project project = null;
114
        private double scaleAnt;
115
        private boolean refresh = false;
116
        private Point origin;
117
        private Point2D p1;
118
        private Point2D p2;
119
        private String titleWindow;
120
        private String className = this.getClass().getName();
121
        private IFFrame grid;
122

    
123
        private static final GeometryManager geomManager = GeometryLocator
124
                        .getGeometryManager();
125
        private static final Logger logger = LoggerFactory
126
                        .getLogger(FFrameView.class);
127

    
128
        /**
129
         * Creates a new FFrameView object.
130
         */
131
        public FFrameView3D() {
132
                num++;
133
        }
134

    
135
        public String getClassName() {
136
                return className;
137
        }
138

    
139
        /**
140
         * Inserta el nuevo extent a la FFrameView.
141
         * 
142
         * @param r
143
         *            Rect�ngulo a ocupar por el FFrameView.
144
         */
145
        public void setNewEnvelope(Envelope r) {
146
                getMapContext().getViewPort().setEnvelope(r);
147
                refresh = true;
148
//                m_Scale = FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
149
//                                getBoundBox().width, getBoundingBox(null).width
150
//                                                / 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 MapContext3D getMapContext() {
160
                return m_fmap;
161
        }
162

    
163
        /**
164
         * Rellena la calidad que se quiere aplicar.
165
         * 
166
         * @param q
167
         *            entero que representa la calidad a aplicar.
168
         */
169
        public void setQuality(int q) {
170
                m_quality = q;
171
        }
172

    
173
        /**
174
         * Rellena la escala de la vista que contiene el fframe.
175
         * 
176
         * @param d
177
         *            escala de la vista.
178
         */
179
        public void setScale(double d) {
180
                m_Scale = d;
181
        }
182

    
183
        public void setGrid(IFFrame grid) {
184
                this.grid = grid;
185
                this.grid.setRotation(this.getRotation());
186
        }
187

    
188
        public IFFrame getGrid() {
189
                return this.grid;
190
        }
191

    
192
        /**
193
         * Devuelve un entero que representa la calidad que est� seleccionada.
194
         * 
195
         * @return tipo de calidad selccionada.
196
         */
197
        public int getQuality() {
198
                return m_quality;
199
        }
200

    
201
        /**
202
         * Devuelve un entero que representa la forma en que se actualiza la vista.
203
         * 
204
         * @return forma que se actualiza la vista.
205
         */
206
        public int getViewing() {
207
                return m_viewing;
208
        }
209

    
210
        /**
211
         * Rellena la forma de actualizar la vista(cuando activo o siempre). De
212
         * momento esta opci�n esta deshabilitada.
213
         * 
214
         * @param v
215
         *            entero que representa la forma de actualizar la vista.
216
         */
217
        public void setViewing(int v) {
218
                m_viewing = v;
219
        }
220

    
221
        /**
222
         * Inserta el ProjectView de donde obtener las propiedades de la vista a
223
         * mostrar.
224
         * 
225
         * @param v
226
         *            Modelo de la vista.
227
         */
228
        public void setView(BaseViewDocument v) {
229
                view = v;
230
                m_fmap = (MapContext3D) getView().getMapContext();
231
                if (m_fmap.getCanvas3d() != null)
232
                        m_fmap.getCanvas3d().addEventSlaveComponent(this);
233
        }
234

    
235
        /**
236
         * Devuelve el modelo de la vista.
237
         * 
238
         * @return Modelo de la vista.
239
         */
240
        public BaseViewDocument getView() {
241
                return view;
242
        }
243

    
244
        /**
245
         * Devuelve un Rect�ngulo que representa el extent de la vista que se
246
         * requiere a partir de una escala.
247
         * 
248
         * @param scale
249
         *            Escala a mostrar.
250
         * 
251
         * @return Rect�ngulo.
252
         */
253
        protected Envelope getNewEnvelope(long scale) {
254
                double hview = getBoundBox().getHeight();
255
                double wview = getBoundBox().getWidth();
256
                double hextent = (scale * hview) / 100.0;
257
                double wextent = (scale * wview) / 100.0;
258

    
259
                if (m_fmap.getViewPort().getEnvelope() == null) {
260
                        try {
261
                                return geomManager.createEnvelope(0, 0, 0, 0, SUBTYPES.GEOM2D);
262
                        } catch (CreateEnvelopeException e) {
263
                                logger.error("Error creating the envelope", e);
264
                                return null;
265
                        }
266
                }
267
                double newx = m_fmap.getViewPort().getEnvelope()
268
                                .getCenter(Geometry.DIMENSIONS.X)
269
                                - (wextent / 2.0);
270
                double newy = m_fmap.getViewPort().getEnvelope()
271
                                .getCenter(Geometry.DIMENSIONS.Y)
272
                                - (hextent / 2.0);
273
                IProjection proj = m_fmap.getViewPort().getProjection();
274
                Envelope r = null;
275
                try {
276
                        r = geomManager.createEnvelope(newx, newy, newx + wextent, newy
277
                                        + hextent, SUBTYPES.GEOM2D);
278
                } catch (CreateEnvelopeException e) {
279
                        logger.error("Error creating the envelope", e);
280
                }
281
                if (!proj.isProjected()) {
282
                        Rectangle2D auxR = new Rectangle2D.Double(newx, newy, wextent,
283
                                        hextent);
284
                        Rectangle2D aux = m_fmap.getViewPort().getProjection()
285
                                        .getExtent(auxR, scale, wview, hview, 1, 100, 2.54);
286
                        try {
287
                                r = geomManager.createEnvelope(aux.getX(), aux.getY(),
288
                                                aux.getMaxX(), aux.getMaxY(), SUBTYPES.GEOM2D);
289
                        } catch (CreateEnvelopeException e) {
290
                                logger.error("Error creating the envelope", e);
291
                        }
292
                }
293
                return r;
294
        }
295

    
296
        /**
297
         * M�todo que dibuja sobre el graphics que se le pasa como par�metro, seg�n
298
         * la transformada afin que se debe de aplicar y el rect�ngulo que se debe
299
         * de dibujar.
300
         * 
301
         * @param g
302
         *            Graphics2D
303
         * @param at
304
         *            Transformada af�n.
305
         * @param rv
306
         *            rect�ngulo sobre el que hacer un clip.
307
         * @param imgBase
308
         *            Imagen para acelerar el dibujado.
309
         */
310
        public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
311
                        BufferedImage imgBase) {
312

    
313
//                if (getView() != null && m_fmap == null) {
314
//                        m_fmap = (MapContext3D) getView().getMapContext();
315
//                        if (m_fmap.getCanvas3d() != null)
316
//                                m_fmap.getCanvas3d().addEventSlaveComponent(this);
317
//                        // ((ProjectView3D)getView()).getOrCreateView().setModel(model);
318
//                        // m_fmap.setViewer(((ProjectView3D)getView()).getCanvas3d());
319
//                        // m_fmap.getCanvas3d().addEventSlaveComponent(this);
320
//                }
321
//                Rectangle2D.Double r = getBoundingBox(at);
322
//                if (getRotation() != 0)
323
//                        g.rotate(Math.toRadians(getRotation()), r.x + (r.width / 2), r.y
324
//                                        + (r.height / 2));
325
//                if (intersects(rv, r)) {
326
//                        if (getMapContext() == null) {
327
//                                drawEmpty(g);
328
//                        } else {
329
//                                if (rv != null) {
330
//                                        // Dibujamos en pantalla
331
//                                        Rectangle rclip = (Rectangle) g.getClipBounds().clone();
332
//                                        g.clipRect((int) r.getMinX(), (int) r.getMinY(),
333
//                                                        (int) r.getWidth(), (int) r.getHeight());
334
//
335
//                                        if (getQuality() == PRESENTACION) {
336
//                                                if (rv.intersects(r)) {
337
//                                                        ViewPort3D viewPort = (ViewPort3D) this
338
//                                                                        .getMapContext().getViewPort();
339
//                                                        Color theBackColor = viewPort.getBackColor();
340
//
341
//                                                        if (origin != null
342
//                                                                        && origin.equals(getLayoutControl()
343
//                                                                                        .getRectOrigin())
344
//                                                                        && getLayoutControl() != null
345
//                                                                        && getLayoutControl().getAT().getScaleX() == scaleAnt
346
//                                                                        && m_image != null
347
//                                                                        && !refresh
348
//                                                                        && !(r.getWidth() > getLayoutControl()
349
//                                                                                        .getWidth() || r.getHeight() > getLayoutControl()
350
//                                                                                        .getHeight())) {
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
//                                                                g.translate(r.getX(), r.getY());
358
//                                                                // g.drawImage(m_image, 0, 0,
359
//                                                                // getLayoutControl());
360
//                                                                g.translate(-r.getX(), -r.getY());
361
//                                                                scaleAnt = getLayoutControl().getAT()
362
//                                                                                .getScaleX();
363
//                                                                origin = (Point) getLayoutControl()
364
//                                                                                .getRectOrigin().clone();
365
//                                                        } else {
366
//
367
//                                                                if (r.getWidth() > getLayoutControl()
368
//                                                                                .getWidth()
369
//                                                                                || r.getHeight() > getLayoutControl()
370
//                                                                                                .getHeight()) {
371
//                                                                        getMapContext().getViewPort().setOffset(
372
//                                                                                        new Point2D.Double(r.getX(), r
373
//                                                                                                        .getY()));
374
//                                                                        getMapContext().getViewPort().setImageSize(
375
//                                                                                        new Dimension((int) r.getWidth(),
376
//                                                                                                        (int) r.getHeight()));
377
//                                                                        // MapContext3D fmap = (MapContext3D)
378
//                                                                        // getMapContext()
379
//                                                                        // .cloneToDraw();
380
//                                                                        ViewPort3D viewp = (ViewPort3D) this
381
//                                                                                        .getMapContext().getViewPort();// .cloneViewPort();
382
//                                                                        viewp.setImageSize(new Dimension(
383
//                                                                                        getLayoutControl().getWidth(),
384
//                                                                                        getLayoutControl().getHeight()));
385
//                                                                        Rectangle2D r1 = calculateExtent();
386
//                                                                        double width = getLayoutContext()
387
//                                                                                        .getAttributes().getSizeInUnits()
388
//                                                                                        .getAncho();
389
//                                                                        double scale = FLayoutUtilities
390
//                                                                                        .getScaleView(viewp, width,
391
//                                                                                                        r1.getWidth() / width);
392
//                                                                        viewp.setEnvelope(new Envelope2D(r1
393
//                                                                                        .getMinX(), r1.getMinY(), r1
394
//                                                                                        .getMaxX(), r1.getMaxY()));
395
//
396
//                                                                        getMapContext().setViewPort(viewp);
397
//                                                                        g.translate(-r.getX(), -r.getY());
398
//                                                                        if (theBackColor != null) {
399
//                                                                                g.setColor(theBackColor);
400
//                                                                                g.fillRect((int) r.x, (int) r.y,
401
//                                                                                                viewp.getImageWidth(),
402
//                                                                                                viewp.getImageHeight());
403
//                                                                        }
404
//                                                                        try {
405
//                                                                                getMapContext().draw(imgBase, g, scale);
406
//                                                                        } catch (ReadException e) {
407
//                                                                                NotificationManager
408
//                                                                                                .showMessageError(
409
//                                                                                                                "Problems with driver rendering",
410
//                                                                                                                e);
411
//                                                                        } catch (MapContextException e) {
412
//                                                                                // TODO Auto-generated catch block
413
//                                                                                e.printStackTrace();
414
//                                                                        }
415
//                                                                        g.translate(r.getX(), r.getY());
416
//
417
//                                                                } else {
418
//
419
//                                                                        getMapContext().getViewPort().setOffset(
420
//                                                                                        new Point2D.Double(r.x, r.y));
421
//                                                                        getMapContext().getViewPort().setImageSize(
422
//                                                                                        new Dimension((int) r.width,
423
//                                                                                                        (int) r.height));
424
//                                                                        m_image = new BufferedImage(
425
//                                                                                        (int) r.getWidth(),
426
//                                                                                        (int) r.getHeight(),
427
//                                                                                        BufferedImage.TYPE_INT_ARGB);
428
//                                                                        Graphics2D gimg = (Graphics2D) m_image
429
//                                                                                        .getGraphics();
430
//                                                                        gimg.translate(-((int) r.getX()),
431
//                                                                                        -((int) r.getY()));
432
//                                                                        try {
433
//                                                                                getMapContext().draw(m_image, gimg,
434
//                                                                                                getScale());
435
//                                                                        } catch (ReadException e) {
436
//                                                                                NotificationManager
437
//                                                                                                .showMessageError(
438
//                                                                                                                "Problems with driver rendering",
439
//                                                                                                                e);
440
//                                                                        } catch (MapContextException e) {
441
//                                                                                // TODO Auto-generated catch block
442
//                                                                                e.printStackTrace();
443
//                                                                        }
444
//                                                                        gimg.translate(((int) r.getX()),
445
//                                                                                        ((int) r.getY()));
446
//                                                                        if (theBackColor != null) {
447
//                                                                                g.setColor(theBackColor);
448
//                                                                                g.fillRect((int) r.x, (int) r.y,
449
//                                                                                                viewPort.getImageWidth(),
450
//                                                                                                viewPort.getImageHeight());
451
//                                                                        }
452
//                                                                        // g.drawImage(m_image, (int) r.getX(),
453
//                                                                        // (int) r.getY(), getLayout());
454
//
455
//                                                                }
456
//                                                                scaleAnt = getLayoutControl().getAT()
457
//                                                                                .getScaleX();
458
//                                                                origin = (Point) getLayoutControl()
459
//                                                                                .getRectOrigin().clone();
460
//                                                                refresh = false;
461
//                                                        }
462
//                                                }
463
//                                        } else {
464
//                                                drawDraft(g);
465
//                                        }
466
//                                        if (rclip != null) {
467
//                                                g.setClip(rclip.x, rclip.y, rclip.width, rclip.height);
468
//                                        }
469
//                                } else {
470
//                                        printX(g, at);
471
//                                }
472
//                        }
473
//                }
474
//                if (getRotation() != 0)
475
//                        g.rotate(Math.toRadians(-getRotation()), r.x + (r.width / 2), r.y
476
//                                        + (r.height / 2));
477
//
478
//                if (getMapContext() != null) {
479
//                        setATMap(getMapContext().getViewPort().getAffineTransform());
480
//
481
//                }
482
        }
483

    
484
        private Rectangle2D calculateExtent() {
485
                Rectangle2D.Double r = new Rectangle2D.Double();
486
                if (p1 == null || p2 == null)
487
                        return r;
488
                r.setFrameFromDiagonal(p1, p2);
489
                return r;
490
        }
491

    
492
        public void print(Graphics2D g, AffineTransform at, FShape shape,
493
                        PrintRequestAttributeSet prroperties) {
494
                draw(g, at, null, null);
495
        }
496

    
497
        private void printX(Graphics2D g, AffineTransform at) {
498
                Rectangle2D.Double r = getBoundingBox(at);
499

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

    
509
                Dimension imageSize = this.getMapContext().getViewPort().getImageSize();
510

    
511
                try {
512
                        this.getMapContext().print(g, getScale(), null);
513
                } catch (ReadException e) {
514
                        NotificationManager.addError(e.getMessage(), e);
515
                } catch (MapContextException e) {
516
                        // TODO Auto-generated catch block
517
                        e.printStackTrace();
518
                }
519

    
520
                g.setClip(rclip.x, rclip.y, rclip.width, rclip.height);
521

    
522
                // this.getMapContext().draw(
523
                // g,
524
                // (new Rectangle((int) r.getMinX(), (int) r.getMinY(), (int) r
525
                // .getWidth(), (int) r.getHeight())));
526
                // this.getMapContext().draw(image ,g,null,0);
527

    
528
        }
529

    
530
        /**
531
         * Rellena la unidad de medida en la que est� la vista.
532
         * 
533
         * @param i
534
         *            entero que representa la unidad de medida de la vista.
535
         */
536
        public void setMapUnits(int i) {
537
                m_mapUnits = i;
538
        }
539

    
540
        /**
541
         * Obtiene la unidad de medida en la que est� la vista.
542
         * 
543
         * @return Unidad de medida.
544
         */
545
        public int getMapUnits() {
546
                return m_mapUnits;
547
        }
548

    
549
        /**
550
         * Devuelve la escala seg�n el tipo de escala que se haya seleccionado al
551
         * a�adida la vista.
552
         * 
553
         * @return escala.
554
         */
555
        public long getScale() {
556
                /*
557
                 * if (m_bLinked){ return getScaleView1(METROS); }
558
                 */
559
                if (getMapContext() == null)
560
                        return 0;
561
                if (getTypeScale() == AUTOMATICO) {
562
//                        return FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
563
//                                        getBoundBox().width, getBoundingBox(null).width);
564
                } else if (getTypeScale() == CONSTANTE) {
565
                        return (long) m_Scale;
566
                } else if (getTypeScale() == MANUAL) {
567
                        return (long) m_Scale;
568
                }
569

    
570
                return (long) m_Scale;
571
        }
572

    
573
        /**
574
         * Seleccionar si la vista esta relacionada o no con la original.
575
         * 
576
         * @param b
577
         *            true si est� ligada y false si no lo est�.
578
         */
579
        public void setLinked(boolean b) {
580
                m_bLinked = b;
581
        }
582

    
583
        /**
584
         * Devuelve si est� ligada o no el FFrameView con la vista.
585
         * 
586
         * @return True si la vista est� ligada.
587
         */
588
        public boolean getLinked() {
589
                return m_bLinked;
590
        }
591

    
592
        /**
593
         * Devuelve la opci�n seleccionada:Rellenar marco de la vista o recorte a la
594
         * vista.
595
         * 
596
         * @return entero que representa la opci�n elegida.
597
         */
598
        public int getExtension() {
599
                return m_extension;
600
        }
601

    
602
        /**
603
         * Devuelve el tipo de escala que est� seleccionada AUTOMATICO,CONSTANTE o
604
         * MANUAL.
605
         * 
606
         * @return entero que representa el tipo seleccionado.
607
         */
608
        public int getTypeScale() {
609
                return m_typeScale;
610
        }
611

    
612
        /**
613
         * Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista.
614
         * 
615
         * @param i
616
         *            entero que representa la opci�n elegida.
617
         */
618
        public void setExtension(int i) {
619
                m_extension = i;
620
        }
621

    
622
        /**
623
         * Rellenar el tipo de escala que se desea.
624
         * 
625
         * @param i
626
         *            entero que representa el tipo de escala.
627
         */
628
        public void setTypeScale(int i) {
629
                m_typeScale = i;
630
        }
631

    
632
        /**
633
         * DOCUMENT ME!
634
         * 
635
         * @return DOCUMENT ME!
636
         * 
637
         * @throws SaveException
638
         * 
639
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
640
         */
641
        // public XMLEntity getXMLEntity() throws SaveException {
642
        // XMLEntity xml = super.getXMLEntity();
643
        //
644
        // try {
645
        // // xml.putProperty("type", Layout.RECTANGLEVIEW);
646
        // // xml.putProperty("className", this.getClassName());
647
        //
648
        // xml.putProperty("m_Mode", m_Mode);
649
        // xml.putProperty("m_typeScale", m_typeScale);
650
        // xml.putProperty("m_extension", m_extension);
651
        // xml.putProperty("m_quality", m_quality);
652
        // xml.putProperty("m_viewing", m_viewing);
653
        // xml.putProperty("m_bLinked", m_bLinked);
654
        // xml.putProperty("m_mapUnits", m_mapUnits);
655
        // xml.putProperty("m_Scale", m_Scale);
656
        //
657
        // ProjectExtension pe = (ProjectExtension) PluginServices
658
        // .getExtension(ProjectExtension.class);
659
        // ArrayList views = pe.getProject().getDocumentsByType(
660
        // ProjectView3DFactory._registerName);
661
        //
662
        // boolean hasIndex = false;
663
        //
664
        // if (view != null) {
665
        // xml.putProperty("viewName", view.getName());
666
        // for (int i = 0; i < views.size(); i++) {
667
        // if (view.getName().equals(
668
        // ((ProjectViewBase) views.get(i)).getName())) {
669
        // xml.putProperty("indice", i);
670
        // hasIndex = true;
671
        // break;
672
        // }
673
        // }
674
        //
675
        // }
676
        //
677
        // // titleWindow = ((ProjectView3D)
678
        // // view).getView().getWindowInfo().getTitle();
679
        // // xml.putProperty("titleWindow", titleWindow);
680
        //
681
        // if (!hasIndex) {
682
        // xml.putProperty("indice", -1);
683
        // }
684
        //
685
        // if (getMapContext() != null
686
        // && getMapContext().getViewPort().getExtent() != null) {
687
        // xml.putProperty("extentX", getMapContext().getViewPort()
688
        // .getExtent().getX());
689
        // xml.putProperty("extentY", getMapContext().getViewPort()
690
        // .getExtent().getY());
691
        // xml.putProperty("extentW", getMapContext().getViewPort()
692
        // .getExtent().getWidth());
693
        // xml.putProperty("extentH", getMapContext().getViewPort()
694
        // .getExtent().getHeight());
695
        //
696
        // xml.addChild(getMapContext().getXMLEntity());
697
        // }
698
        // } catch (Exception e) {
699
        // throw new SaveException(e, this.getClass().getName());
700
        // }
701
        //
702
        // return xml;
703
        // }
704

    
705
        /**
706
         * Inserta la imagen para repintar el FFrameView.
707
         * 
708
         * @param bi
709
         *            Imagen para repintar.
710
         */
711
        public void setBufferedImage(BufferedImage bi) {
712
                m_image = bi;
713
        }
714

    
715
        /**
716
         * Devuelve la imagen para repintar.
717
         * 
718
         * @return Imagen para repintar.
719
         */
720
        public BufferedImage getBufferedImage() {
721
                return m_image;
722
        }
723

    
724
        /**
725
         * Devuelve la MAtriz de transformaci�n utilizada por la FFrameView.
726
         * 
727
         * @return MAtriz de transformaci�n.
728
         */
729
        public AffineTransform getATMap() {
730
                return at;
731
        }
732

    
733
        /**
734
         * Inserta la matriz de transformaci�n.
735
         * 
736
         * @param transform
737
         *            Matriz de transformaci�n.
738
         */
739
        public void setATMap(AffineTransform transform) {
740
                at = transform;
741
        }
742

    
743
        /**
744
         * Inserta el proyecto.
745
         * 
746
         * @param p
747
         *            Proyecto.
748
         */
749
        public void setProject(Project p) {
750
                project = p;
751
        }
752

    
753
        /**
754
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
755
         *      com.iver.cit.gvsig.project.Project)
756
         */
757
        // public void setXMLEntity03(XMLEntity xml, Layout l) {
758
        // if (xml.getIntProperty("m_Selected") != 0) {
759
        // this.setSelected(true);
760
        // } else {
761
        // this.setSelected(false);
762
        // }
763
        //
764
        // this.setName(xml.getStringProperty("m_name"));
765
        // this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), xml
766
        // .getDoubleProperty("y"), xml.getDoubleProperty("w"), xml
767
        // .getDoubleProperty("h")));
768
        //
769
        // this.m_Mode = xml.getIntProperty("m_Mode");
770
        // this.m_typeScale = xml.getIntProperty("m_typeScale");
771
        // this.m_extension = xml.getIntProperty("m_extension");
772
        // this.m_quality = xml.getIntProperty("m_quality");
773
        // this.m_viewing = xml.getIntProperty("m_viewing");
774
        // this.m_bLinked = xml.getBooleanProperty("m_bLinked");
775
        // this.m_mapUnits = xml.getIntProperty("m_mapUnits");
776
        //
777
        // // ProjectExtension pe = (ProjectExtension)
778
        // // PluginServices.getExtension(ProjectExtension.class);
779
        // this.m_Scale = xml.getDoubleProperty("m_Scale");
780
        //
781
        // int indice = xml.getIntProperty("indice");
782
        //
783
        // if (indice != -1) {
784
        // ArrayList views = project
785
        // .getDocumentsByType(ProjectView3DFactory._registerName);
786
        //
787
        // ProjectViewBase view = (ProjectViewBase) views.get(indice);
788
        // this.m_fmap = (MapContext3D) view.getMapContext();
789
        // this.setView(view);
790
        //
791
        // try {
792
        // if (m_bLinked) {
793
        // this.getMapContext()
794
        // .getViewPort()
795
        // .setExtent(
796
        // new Rectangle2D.Double(xml
797
        // .getDoubleProperty("extentX"), xml
798
        // .getDoubleProperty("extentY"), xml
799
        // .getDoubleProperty("extentW"), xml
800
        // .getDoubleProperty("extentH")));
801
        // } else if (!m_bLinked) {
802
        // this.m_fmap = (MapContext3D) MapContext.createFromXML03(xml
803
        // .getChild(0));
804
        // }
805
        // } catch (XMLException e) {
806
        // NotificationManager.addError(
807
        // "Pasando las propiedades del XMLEntity al objeto", e);
808
        // }
809
        // }
810
        // }
811

    
812
        /**
813
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
814
         */
815
        public String getNameFFrame() {
816
                return PluginServices.getText(this, "Vista") + num;
817
        }
818

    
819
        /**
820
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(org.gvsig.fmap.mapcontext.events.ExtentEvent)
821
         */
822
        public void extentChanged(ExtentEvent e) {
823
//                if (getTypeScale() == AUTOMATICO) {
824
//                        m_fmap.getViewPort().setEnvelope(e.getNewExtent());
825
//                        if (getLayoutControl() != null) {
826
//                                getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO);
827
//                        }
828
//                } else if (getTypeScale() == MANUAL) {
829
//                        Envelope oldExtent = m_fmap.getViewPort().getEnvelope();
830
//                        Envelope newExtent = e.getNewExtent();
831
//                        double xDif = newExtent.getCenter(0) - oldExtent.getCenter(0);
832
//                        double yDif = newExtent.getCenter(1) - oldExtent.getCenter(1);
833
//                        try {
834
//                                m_fmap.getViewPort()
835
//                                                .setEnvelope(
836
//                                                                geomManager.createEnvelope(
837
//                                                                                oldExtent.getMinimum(0) + xDif,
838
//                                                                                oldExtent.getMinimum(1) + yDif,
839
//                                                                                oldExtent.getMaximum(0) + xDif,
840
//                                                                                oldExtent.getMaximum(1) + yDif,
841
//                                                                                SUBTYPES.GEOM2D));
842
//                        } catch (CreateEnvelopeException e1) {
843
//                                e1.printStackTrace();
844
//                        }
845
//                        if (getLayoutControl() != null) {
846
//                                getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO);
847
//                        }
848
//                }
849
//                refresh = true;
850
        }
851

    
852
        /**
853
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
854
         */
855
        public void backColorChanged(ColorEvent e) {
856
//                if (getLinked()) {
857
//                        m_fmap.getViewPort().setBackColor(e.getNewColor());
858
//                        getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO);
859
//
860
//                        // setBufferedImage(null);
861
//                }
862
        }
863

    
864
        /**
865
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#projectionChanged(com.iver.cit.gvsig.fmap.ProjectionEvent)
866
         */
867
        public void projectionChanged(ProjectionEvent e) {
868
//                if (getTypeScale() == AUTOMATICO) {
869
//                        m_fmap.getViewPort().setProjection(e.getNewProjection());
870
//
871
//                        if (getLayoutControl() != null) {
872
//                                getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO);
873
//                        }
874
//                }
875
        }
876

    
877
        /**
878
         * DOCUMENT ME!
879
         * 
880
         * @param e
881
         *            DOCUMENT ME!
882
         */
883
        public void legendChanged(LegendChangedEvent e) {
884
//                if (getLinked()) {
885
//                        getLayoutControl().setStatus(LayoutControl.DESACTUALIZADO);
886
//                        refresh = true;
887
//                        // setBufferedImage(null);
888
//                }
889
        }
890

    
891
        /**
892
         * DOCUMENT ME!
893
         * 
894
         * @param xml
895
         *            DOCUMENT ME!
896
         */
897
        // public void setXMLEntity(XMLEntity xml) {
898
        //
899
        // //
900
        // if (xml.getIntProperty("m_Selected") != 0) {
901
        // this.setSelected(true);
902
        // } else {
903
        // this.setSelected(false);
904
        // }
905
        //
906
        // this.setName(xml.getStringProperty("m_name"));
907
        // this.setBoundBox(new Rectangle2D.Double(xml.getDoubleProperty("x"), xml
908
        // .getDoubleProperty("y"), xml.getDoubleProperty("w"), xml
909
        // .getDoubleProperty("h")));
910
        //
911
        // this.m_Mode = xml.getIntProperty("m_Mode");
912
        // this.m_typeScale = xml.getIntProperty("m_typeScale");
913
        // this.m_extension = xml.getIntProperty("m_extension");
914
        // this.m_quality = xml.getIntProperty("m_quality");
915
        // this.m_viewing = xml.getIntProperty("m_viewing");
916
        // this.m_bLinked = xml.getBooleanProperty("m_bLinked");
917
        // this.m_mapUnits = xml.getIntProperty("m_mapUnits");
918
        // setRotation(xml.getDoubleProperty("m_rotation"));
919
        //
920
        // this.m_Scale = xml.getDoubleProperty("m_Scale");
921
        //
922
        // int indice = xml.getIntProperty("indice");
923
        //
924
        // ProjectViewBase view = null;
925
        //
926
        // if (xml.contains("viewName")) {
927
        // view = (ProjectViewBase) project.getProjectDocumentByName(
928
        // xml.getStringProperty("viewName"),
929
        // ProjectView3DFactory._registerName);
930
        //
931
        // // if (xml.contains("className"))
932
        // // this.className= xml.getStringProperty("className");
933
        //
934
        // } else {
935
        // if (indice != -1) {
936
        // try {
937
        // ArrayList views = project
938
        // .getDocumentsByType(ProjectView3DFactory._registerName);
939
        //
940
        // view = (ProjectViewBase) views.get(indice);
941
        // } catch (IndexOutOfBoundsException e) {
942
        // NotificationManager.addError(
943
        // "No se ha encontrado la vista de indice " + indice,
944
        // e);
945
        // }
946
        // }
947
        // }
948
        //
949
        // // if (xml.contains("titleWindow"))
950
        // // this.titleWindow = xml.getStringProperty("titleWindow");
951
        //
952
        // if (view != null) {
953
        // this.setView(view);
954
        //
955
        // try {
956
        // if (xml.contains("extentX")) {
957
        // if (m_bLinked) {
958
        // this.getMapContext()
959
        // .getViewPort()
960
        // .setExtent(
961
        // new Rectangle2D.Double(
962
        // xml.getDoubleProperty("extentX"),
963
        // xml.getDoubleProperty("extentY"),
964
        // xml.getDoubleProperty("extentW"),
965
        // xml.getDoubleProperty("extentH")));
966
        // } else if (!m_bLinked) {
967
        // this.m_fmap = (MapContext3D) MapContext
968
        // .createFromXML(xml.getChild(0));
969
        // }
970
        // }
971
        // } catch (XMLException e) {
972
        // NotificationManager.addError(
973
        // "Pasando las propiedades del XMLEntity al objeto", e);
974
        // }
975
        // } else if (!m_bLinked) {
976
        // try {
977
        // this.m_fmap = (MapContext3D) MapContext.createFromXML(xml
978
        // .getChild(0));
979
        // } catch (XMLException e) {
980
        // e.printStackTrace();
981
        // }
982
        // }
983
        // }
984

    
985
        /**
986
         * DOCUMENT ME!
987
         * 
988
         * @param arg0
989
         *            DOCUMENT ME!
990
         * 
991
         * @return DOCUMENT ME!
992
         */
993
        public boolean compare(Object arg0) {
994
                if (!(arg0 instanceof FFrameView3D)) {
995
                        return false;
996
                }
997

    
998
                if (!this.getName().equals(((FFrameView3D) arg0).getName())) {
999
                        return false;
1000
                }
1001

    
1002
                if (Math.abs(this.getBoundBox().getWidth()
1003
                                - (((FFrameView3D) arg0).getBoundBox().getWidth())) > 0.05) {
1004
                        return false;
1005
                }
1006
                if (Math.abs(this.getBoundBox().getHeight()
1007
                                - (((FFrameView3D) arg0).getBoundBox().getHeight())) > 0.05) {
1008
                        return false;
1009
                }
1010

    
1011
                if (!this.toString().equals(((FFrameView3D) arg0).toString())) {
1012
                        return false;
1013
                }
1014

    
1015
                if (this.getMapContext() != null
1016
                                && !this.getMapContext().equals(
1017
                                                ((FFrameView3D) arg0).getMapContext())) {
1018
                        return false;
1019
                }
1020

    
1021
                if (this.getRotation() != ((FFrameView3D) arg0).getRotation()) {
1022
                        return false;
1023
                }
1024
                return true;
1025
        }
1026

    
1027
        /**
1028
         * DOCUMENT ME!
1029
         * 
1030
         * @param arg0
1031
         *            DOCUMENT ME!
1032
         * 
1033
         * @return DOCUMENT ME!
1034
         */
1035
        public boolean equals(Object arg0) {
1036
                return this.compare(arg0);
1037
        }
1038

    
1039
        public void refresh() {
1040
                if (view != null
1041
                                && (getTypeScale() == MANUAL || getTypeScale() == CONSTANTE)) {
1042
                        getMapContext().getViewPort().setEnvelope(
1043
                                        getNewEnvelope(getScale()));
1044
                }
1045
                refresh = true;
1046
        }
1047

    
1048
           public void fullExtent() throws ReadException {
1049
                setNewEnvelope(getMapContext().getFullEnvelope());
1050
            }
1051

    
1052
        public void setPointsToZoom(Point2D px1, Point2D px2) {
1053
                p1 = px1;
1054
                p2 = px2;
1055
        }
1056

    
1057
        public void movePoints(Point2D px1, Point2D px2) {
1058
                double difX = -px2.getX() + px1.getX();
1059
                double difY = -px2.getY() + px1.getY();
1060
                if (p1 != null) {
1061
                        p1.setLocation(p1.getX() + difX, p1.getY() + difY);
1062
                        p2.setLocation(p2.getX() + difX, p2.getY() + difY);
1063
                }
1064
        }
1065

    
1066
        public void cloneActions(IFFrame frame) {
1067
                if (view == null || view.getMapContext() == null)
1068
                        return;
1069
                if (m_bLinked) {
1070
                        if (getTypeScale() == AUTOMATICO) {
1071
                                view.getMapContext().getViewPort().addViewPortListener(this);
1072
                                view.getMapContext().addLayerListener(this);
1073
                        } else if (getTypeScale() == CONSTANTE) {
1074
                                view.getMapContext().getViewPort().removeViewPortListener(this);
1075
                                view.getMapContext().addLayerListener(this);
1076
                        } else if (getTypeScale() == MANUAL) {
1077
                                view.getMapContext().getViewPort().removeViewPortListener(this);
1078
                                view.getMapContext().addLayerListener(this);
1079
                        }
1080
                } else if (!m_bLinked) {
1081
                        if (getTypeScale() == AUTOMATICO) {
1082
                                view.getMapContext().getViewPort().addViewPortListener(this);
1083
                        } else if (getTypeScale() == CONSTANTE) {
1084
                                view.getMapContext().getViewPort().removeViewPortListener(this);
1085
                        } else if (getTypeScale() == MANUAL) {
1086
                                view.getMapContext().getViewPort().removeViewPortListener(this);
1087
                        }
1088
                }
1089
                ((FFrameView3D) frame).view.getMapContext().removeLayerListener(
1090
                                (FFrameView3D) frame);
1091
                ((FFrameView3D) frame).view.getMapContext().getViewPort()
1092
                                .removeViewPortListener((FFrameView3D) frame);
1093

    
1094
        }
1095

    
1096
        public Object clone() throws CloneNotSupportedException {
1097
                FFrameView frame = (FFrameView) super.clone();
1098

    
1099
                frame.setSelected(this.getSelected() != IFFrame.NOSELECT);
1100

    
1101
                if (grid != null) {
1102
                        FFrameGrid newGrid = (FFrameGrid) this.grid.clone();
1103
                        newGrid.setFFrameDependence(frame);
1104
                        frame.setGrid(newGrid);
1105
                }
1106
                cloneActions(frame);
1107
                return frame;
1108
        }
1109

    
1110
//        public IFFrameDialog getPropertyDialog() {
1111
//                return new FFrameView3DDialog(getLayout(), this);
1112
//        }
1113

    
1114
        public void repaint() {
1115
//                refresh = true;
1116
//                this.getLayoutControl().refresh();
1117
        }
1118

    
1119
        public void refreshOriginalExtent() {
1120
                if (getTypeScale() == AUTOMATICO) {
1121
                        view.getMapContext().getViewPort()
1122
                                        .setEnvelope(getMapContext().getViewPort().getEnvelope());
1123
                        view.getMapContext().getViewPort().refreshExtent();
1124
                } else if (getTypeScale() == MANUAL) {
1125
                        Envelope oldExtent = view.getMapContext().getViewPort()
1126
                                        .getEnvelope();
1127
                        Envelope newExtent = getMapContext().getViewPort().getEnvelope();
1128
                        double xDif = newExtent.getCenter(0) - oldExtent.getCenter(0);
1129
                        double yDif = newExtent.getCenter(1) - oldExtent.getCenter(1);
1130
                        try {
1131
                                view.getMapContext()
1132
                                                .getViewPort()
1133
                                                .setEnvelope(
1134
                                                                geomManager.createEnvelope(
1135
                                                                                oldExtent.getMinimum(0) + xDif,
1136
                                                                                oldExtent.getMinimum(1) + yDif,
1137
                                                                                oldExtent.getMaximum(0) + xDif,
1138
                                                                                oldExtent.getMaximum(1) + yDif,
1139
                                                                                SUBTYPES.GEOM2D));
1140
                        } catch (CreateEnvelopeException e) {
1141
                                e.printStackTrace();
1142
                        }
1143
                        view.getMapContext().getViewPort().refreshExtent();
1144
                }
1145

    
1146
        }
1147

    
1148
        public String getName() {
1149
                // TODO Auto-generated method stub
1150
                return null;
1151
        }
1152

    
1153
        public void print(Graphics2D g, AffineTransform at, Geometry shape,
1154
                        PrintAttributes properties) {
1155
                // TODO Auto-generated method stub
1156
                
1157
        }
1158

    
1159
  public boolean getLayerSynced() {
1160
    // TODO Auto-generated method stub
1161
    return false;
1162
  }
1163

    
1164
  public void setLayerSynced(boolean synced) {
1165
    // TODO Auto-generated method stub
1166
    
1167
  }
1168

    
1169
  public boolean getExtentSynced() {
1170
    // TODO Auto-generated method stub
1171
    return false;
1172
  }
1173

    
1174
  public void setExtentSynced(boolean synced) {
1175
    // TODO Auto-generated method stub
1176
    
1177
  }
1178
}