Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / Layout.java @ 2374

History | View | Annotate | Download (37.2 KB)

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

    
47
import com.iver.andami.PluginServices;
48
import com.iver.andami.messages.NotificationManager;
49
import com.iver.andami.ui.mdiManager.SingletonView;
50
import com.iver.andami.ui.mdiManager.ViewInfo;
51
import com.iver.andami.ui.mdiManager.ViewListener;
52

    
53
import com.iver.cit.gvsig.AddLayer;
54
import com.iver.cit.gvsig.fmap.ColorEvent;
55
import com.iver.cit.gvsig.fmap.DriverException;
56
import com.iver.cit.gvsig.fmap.ExtentEvent;
57
import com.iver.cit.gvsig.fmap.ViewPortListener;
58
import com.iver.cit.gvsig.fmap.layers.XMLException;
59
import com.iver.cit.gvsig.gui.layout.dialogs.FConfigLayoutDialog;
60
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
61
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
62
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
63
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
64
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
65
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
66
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
67
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
68
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGraphicsDialog;
69
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameLegendDialog;
70
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFramePictureDialog;
71
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameScaleBarDialog;
72
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameTextDialog;
73
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameViewDialog;
74
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog;
75
import com.iver.cit.gvsig.gui.project.MapProperties;
76
import com.iver.cit.gvsig.project.Project;
77
import com.iver.cit.gvsig.project.ProjectMap;
78

    
79
import com.iver.utiles.GenericFileFilter;
80
import com.iver.utiles.XMLEntity;
81

    
82
import org.apache.log4j.Logger;
83

    
84
import java.awt.Color;
85
import java.awt.Component;
86
import java.awt.Cursor;
87
import java.awt.Graphics;
88
import java.awt.Graphics2D;
89
import java.awt.Image;
90
import java.awt.Point;
91
import java.awt.Rectangle;
92
import java.awt.Toolkit;
93
import java.awt.event.ActionEvent;
94
import java.awt.event.KeyEvent;
95
import java.awt.geom.AffineTransform;
96
import java.awt.geom.Rectangle2D;
97
import java.awt.image.BufferedImage;
98
import java.awt.print.PageFormat;
99
import java.awt.print.Printable;
100
import java.awt.print.PrinterException;
101
import java.awt.print.PrinterJob;
102

    
103
import java.beans.PropertyChangeEvent;
104
import java.beans.PropertyChangeListener;
105

    
106
import java.io.File;
107

    
108
import java.util.ArrayList;
109
import java.util.Hashtable;
110

    
111
import javax.print.Doc;
112
import javax.print.DocFlavor;
113
import javax.print.DocPrintJob;
114
import javax.print.PrintException;
115
import javax.print.PrintService;
116
import javax.print.PrintServiceLookup;
117
import javax.print.ServiceUI;
118
import javax.print.SimpleDoc;
119
import javax.print.attribute.PrintRequestAttributeSet;
120
import javax.print.event.PrintJobAdapter;
121
import javax.print.event.PrintJobEvent;
122
import javax.print.event.PrintJobListener;
123

    
124
import javax.swing.AbstractAction;
125
import javax.swing.Action;
126
import javax.swing.ImageIcon;
127
import javax.swing.JFileChooser;
128
import javax.swing.JPanel;
129
import javax.swing.KeyStroke;
130
import javax.swing.filechooser.FileFilter;
131

    
132

    
133
/**
134
 * Mapa.
135
 *
136
 * @author Vicente Caballero Navarro
137
 */
138
public class Layout extends JPanel implements SingletonView, ViewPortListener,
139
        ViewListener {
140
        private static Logger logger = Logger.getLogger(Layout.class.getName());
141
        public static final int ZOOM_MAS = 1;
142
        public static final int ZOOM_MENOS = 2;
143
        public static final int PAN = 3;
144
        public static final int DESACTUALIZADO = 4;
145
        public static final int RECTANGLEVIEW = 5;
146
        public static final int RECTANGLEPICTURE = 6;
147
        public static final int RECTANGLESCALEBAR = 7;
148
        public static final int RECTANGLELEGEND = 8;
149
        public static final int RECTANGLETEXT = 9;
150
        public static final int RECTANGLE = 10;
151
        public static final int ACTUALIZADO = 11;
152
        public static final int SELECT = 12;
153
        public static final int POINT = 13;
154
        public static final int LINE = 14;
155
        public static final int POLYLINE = 15;
156
        public static final int RECTANGLESIMPLE = 16;
157
        public static final int CIRCLE = 17;
158
        public static final int POLYGON = 18;
159
        public static final int GRAPHICS = 19;
160
        public static final int RECTANGLESYMBOL = 20;
161
        public static final int RECTANGLEGROUP = 21;
162
        public static final int VIEW_ZOOMIN = 22;
163
        public static final int VIEW_ZOOMOUT = 23;
164
        public static final int VIEW_FULL = 24;
165
        public static final int VIEW_PAN = 25;
166
        public static final int SET_TAG = 26;
167
        public static final Image iLayoutpan = new ImageIcon(AddLayer.class.getClassLoader()
168
                                                                                                                                           .getResource("images/LayoutHand.gif")).getImage();
169
        public static final Image ipan = new ImageIcon(AddLayer.class.getClassLoader()
170
                                                                                                                                 .getResource("images/Hand.gif")).getImage();
171
        public static final Image iLayoutzoomin = new ImageIcon(AddLayer.class.getClassLoader()
172
                                                                                                                                                  .getResource("images/LayoutZoomInCursor.gif")).getImage();
173
        public static final Image izoomin = new ImageIcon(AddLayer.class.getClassLoader()
174
                                                                                                                                        .getResource("images/ZoomInCursor.gif")).getImage();
175
        public static final Image iLayoutzoomout = new ImageIcon(AddLayer.class.getClassLoader()
176
                                                                                                                                                   .getResource("images/LayoutZoomOutCursor.gif")).getImage();
177
        public static final Image izoomout = new ImageIcon(AddLayer.class.getClassLoader()
178
                                                                                                                                         .getResource("images/ZoomOutCursor.gif")).getImage();
179
        public static final Image iinfo = new ImageIcon(AddLayer.class.getClassLoader()
180
                                                                                                                                  .getResource("images/InfoCursor.gif")).getImage();
181
        public static final Image icrux = new ImageIcon(AddLayer.class.getClassLoader()
182
                                                                                                                                  .getResource("images/CruxCursor.png")).getImage();
183
        public static final Image itag = new ImageIcon(AddLayer.class.getClassLoader()
184
                                                                                                                                 .getResource("images/tagCursor.gif")).getImage();
185
        public static final Image iPoint = new ImageIcon(AddLayer.class.getClassLoader()
186
                                                                                                                                   .getResource("images/PointCursor.png")).getImage();
187
        public static final Image iRect = new ImageIcon(AddLayer.class.getClassLoader()
188
                                                                                                                                  .getResource("images/RectCursor.png")).getImage();
189
        public static final Image iLine = new ImageIcon(AddLayer.class.getClassLoader()
190
                                                                                                                                  .getResource("images/LineCursor.png")).getImage();
191
        public static final Image iRectangle = new ImageIcon(AddLayer.class.getClassLoader()
192
                                                                                                                                           .getResource("images/RectangleCursor.png")).getImage();
193
        public static final Image iCircle = new ImageIcon(AddLayer.class.getClassLoader()
194
                                                                                                                                        .getResource("images/CircleCursor.png")).getImage();
195
        public static final Image iPoligon = new ImageIcon(AddLayer.class.getClassLoader()
196
                                                                                                                                         .getResource("images/PoligonCursor.png")).getImage();
197
        public static Hashtable nums = new Hashtable();
198
        private Point origin = new Point(50, 50);
199
        private Point rectOrigin = new Point(origin);
200
        private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
201
                        rectOrigin.y, 400, 300);
202
        private Point m_FirstPoint = new Point(0, 0);
203
        private Point m_PointAnt = new Point(0, 0);
204
        private Point m_LastPoint = new Point(0, 0);
205
        private EventsHandler events;
206
        private int tool = ZOOM_MAS;
207
        private int status = DESACTUALIZADO;
208
        private BufferedImage img = null;
209
        private AffineTransform m_MatrizTransf;
210
        private Rectangle2D rectVisible;
211
        private IFFrameDialog fframedialog = null;
212
        private ArrayList m_fframes = new ArrayList();
213
        private FConfigLayoutDialog m_configLayout = null;
214
        private MapProperties m_propertiesLayout = null;
215
        private Attributes m_attributes = null;
216
        private PrintService[] m_cachePrintServices = null;
217
        private PrintRequestAttributeSet m_cachePrintRequestAtributeSet = null;
218
        private PrintService m_cachePrintService = null;
219
        private boolean m_bCancelDrawing = false;
220
        private boolean isCuadricula = false;
221
        private boolean initial = true;
222
        private ProjectMap map = null;
223
        private Rectangle reSel = null;
224
        private boolean isReSel = true;
225

    
226
        // private String m_name = null;
227
        private boolean m_showRuler = true;
228
        private FLayoutDraw layoutDraw = null;
229
        private boolean isDrawCuadricula = true;
230
        private Doc doc = null;
231
        private PrintRequestAttributeSet att = null;
232

    
233
        /**
234
         * Creates a new Layout object.
235
         */
236
        public Layout() {
237
                this.setLayout(null);
238
                events = new EventsHandler(this);
239
                layoutDraw = new FLayoutDraw(this);
240
                addComponentListener(events);
241
                addMouseMotionListener(events);
242
                addMouseListener(events);
243
                m_MatrizTransf = new AffineTransform();
244
                m_MatrizTransf.setToIdentity();
245
                this.initComponents();
246
        }
247

    
248
        /**
249
         * Rellena el ProjectMap del Layout.
250
         *
251
         * @param m ProjectMap.
252
         */
253
        public void setProjectMap(ProjectMap m) {
254
                map = m;
255
                map.addPropertyChangeListener(new PropertyChangeListener() {
256
                                public void propertyChange(PropertyChangeEvent evt) {
257
                                        if (evt.getPropertyName().equals("name")) {
258
                                                PluginServices.getMDIManager().getViewInfo(Layout.this)
259
                                                                          .setTitle(PluginServices.getText(this,
260
                                                                "Mapa") + " : " + (String) evt.getNewValue());
261
                                        }
262
                                }
263
                        });
264
        }
265

    
266
        /**
267
         * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
268
         *
269
         * @return Rect?ngulo de selecci?n.
270
         */
271
        public Rectangle getReSel() {
272
                return reSel;
273
        }
274

    
275
        /**
276
         * Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar
277
         * la sellecci?n.
278
         *
279
         * @return true si se realiza la selecci?n por rect?ngulo.
280
         */
281
        public boolean isReSel() {
282
                return isReSel;
283
        }
284

    
285
        /**
286
         * Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
287
         * selecci?n.
288
         *
289
         * @param b boolean.
290
         */
291
        public void setIsReSel(boolean b) {
292
                isReSel = b;
293
        }
294

    
295
        /**
296
         * Devuelve true si el dibujado ha sido cancelado.
297
         *
298
         * @return true si el dibujado ha sido cancelado.
299
         */
300
        public synchronized boolean isDrawingCancelled() {
301
                return m_bCancelDrawing;
302
        }
303

    
304
        /**
305
         * Pone el dibuja a cancelado o no seg?n se quiera.
306
         *
307
         * @param b true si se quiere cancelar el dibujado.
308
         */
309
        public synchronized void setCancelDrawing(boolean b) {
310
                m_bCancelDrawing = b;
311

    
312
                for (int i = 0; i < getFFrames().size(); i++) {
313
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
314

    
315
                        if (fframe instanceof FFrameView &&
316
                                        (((FFrameView) fframe).getFMap() != null)) {
317
                                ////TODO((FFrameView) getFFrames().get(i)).getFMap().setCancelDrawing(b);
318
                        }
319
                }
320
        }
321

    
322
        /**
323
         * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
324
         *
325
         * @return Array con todos los fframes que contiene el Layout.
326
         */
327
        public ArrayList getFFrames() {
328
                return m_fframes;
329
        }
330

    
331
        /**
332
         * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
333
         * entero.
334
         */
335
        public void fullRect() {
336
                rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
337
                        getHeight() - (origin.x * 2));
338

    
339
                if (m_attributes.isLandSpace()) {
340
                        rect = m_attributes.getRectangleLandscape(rect, getWidth(),
341
                                        getHeight());
342
                } else {
343
                        rect = m_attributes.getRectanglePortrait(rect, getWidth(),
344
                                        getHeight());
345
                }
346

    
347
                status = DESACTUALIZADO;
348
                repaint();
349
        }
350

    
351
        /**
352
         * M?todo para imprimir el Layout sin modificar la matriz de
353
         * transformaci?n.
354
         *
355
         * @param g2
356
         */
357
        public void drawLayoutPrint(Graphics2D g2) {
358
                setCancelDrawing(false);
359

    
360
                setCursor(Cursor.getDefaultCursor());
361

    
362
                double scale = 0;
363

    
364
                ///if (rect.width > rect.height) {
365
                ///    scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
366
                ///} else {
367
                scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
368

    
369
                ///}
370
                AffineTransform escalado = new AffineTransform();
371
                AffineTransform translacion = new AffineTransform();
372
                translacion.setToTranslation(rect.getMinX(), rect.getMinY());
373
                escalado.setToScale(scale, scale);
374
                m_MatrizTransf.setToIdentity();
375
                m_MatrizTransf.concatenate(translacion);
376
                m_MatrizTransf.concatenate(escalado);
377
                m_attributes.setDistanceUnitX(rect);
378
                m_attributes.setDistanceUnitY(rect);
379

    
380
                for (int i = 0; i < getFFrames().size(); i++) {
381
                        try {
382
                                ((IFFrame) getFFrames().get(i)).print(g2, getAT());
383
                        } catch (DriverException e) {
384
                                NotificationManager.addError(e.getMessage(), e);
385
                        }
386
                }
387

    
388
                //TODO Esto es para ver el rect?ngulo que representa el folio en la impresi?n.
389
                g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
390
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
391
        }
392

    
393
        /**
394
         * Clip sobre el rect?ngulo visible.
395
         *
396
         * @param g2d Graphics sobre el que hacer el clip.
397
         */
398
        private void clipVisibleRect(Graphics2D g2d) {
399
                rectVisible = this.getVisibleRect();
400
                g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
401
                        (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
402
        }
403

    
404
        /**
405
         * Inicializa los componentes.
406
         */
407
        private void initComponents() {
408
                m_attributes = new Attributes();
409
                m_attributes.setDistanceUnitX(rect);
410
                m_attributes.setDistanceUnitY(rect);
411
                actionDelFFrame();
412
        }
413

    
414
        /**
415
         * Crea un ActionEvent para controlar las teclas que se pulsen cuando este
416
         * el Layout Focusable a true.
417
         */
418
        private void actionDelFFrame() {
419
                Action doNothing = new AbstractAction() {
420
                                public void actionPerformed(ActionEvent e) {
421
                                        for (int i = getFFrames().size() - 1; i >= 0; i--) {
422
                                                IFFrame fframe = (IFFrame) getFFrames().get(i);
423

    
424
                                                if (fframe.getSelected() != IFFrame.NOSELECT) {
425
                                                        getFFrames().remove(i);
426
                                                }
427
                                        }
428

    
429
                                        refresh();
430
                                }
431
                        };
432

    
433
                this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
434
                        "doNothing");
435
                this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
436
                        "doNothing");
437
                this.getActionMap().put("doNothing", doNothing);
438
        }
439

    
440
        /**
441
         * paintComponent del Layout.
442
         *
443
         * @param g Graphics del Layout.
444
         */
445
        protected void paintComponent(Graphics g) {
446
                super.paintComponent(g);
447

    
448
                clipVisibleRect((Graphics2D) g);
449

    
450
                Rectangle rClip = g.getClipBounds();
451

    
452
                if (rClip == null) {
453
                        System.err.println("clip = null");
454
                }
455

    
456
                switch (status) {
457
                        case ZOOM_MAS:
458
                                logger.debug("zoom mas");
459
                                layoutDraw.drawRectangle((Graphics2D) g);
460

    
461
                                g.drawImage(img, 0, 0, this);
462

    
463
                                g.setClip(rClip);
464
                                layoutDraw.drawGrid((Graphics2D) g);
465
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
466
                                g.setColor(Color.black);
467
                                g.setXORMode(Color.white);
468

    
469
                                Rectangle r = new Rectangle();
470

    
471
                                r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
472
                                g.drawRect(r.x, r.y, r.width, r.height);
473

    
474
                                break;
475

    
476
                        case RECTANGLE:
477
                                logger.debug("rectangle");
478
                                layoutDraw.drawRectangle((Graphics2D) g);
479

    
480
                                g.drawImage(img, 0, 0, this);
481

    
482
                                g.setClip(rClip);
483
                                layoutDraw.drawGrid((Graphics2D) g);
484
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
485
                                g.setColor(Color.black);
486
                                g.setXORMode(Color.white);
487

    
488
                                Rectangle re = new Rectangle();
489
                                re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
490

    
491
                                if (isCuadricula()) {
492
                                        FLayoutUtilities.setRectGrid(re,
493
                                                m_attributes.getUnitInPixelsX(),
494
                                                m_attributes.getUnitInPixelsY(), m_MatrizTransf);
495
                                }
496

    
497
                                g.drawRect(re.x, re.y, re.width, re.height);
498

    
499
                                break;
500

    
501
                        case PAN:
502
                                logger.debug("pan");
503

    
504
                                //g.setXORMode(Color.black);
505
                                rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
506
                                rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
507

    
508
                                //g.clearRect(0, 0, getWidth(), getHeight());
509
                                layoutDraw.drawRectangle((Graphics2D) g);
510

    
511
                                if (img != null) {
512
                                        g.drawImage(img, (getLastPoint().x - getPointAnt().x),
513
                                                (m_LastPoint.y - m_PointAnt.y), this);
514
                                }
515

    
516
                                g.setClip(rClip);
517
                                layoutDraw.drawGrid((Graphics2D) g);
518
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
519

    
520
                                break;
521

    
522
                        case VIEW_PAN:
523

    
524
                                // logger.debug("View pan");
525
                                layoutDraw.drawRectangle((Graphics2D) g);
526

    
527
                                for (int i = 0; i < getFFrames().size(); i++) {
528
                                        if (getFFrames().get(i) instanceof FFrameView) {
529
                                                FFrameView fframe = (FFrameView) getFFrames().get(i);
530

    
531
                                                if (fframe.getSelected() != IFFrame.NOSELECT) {
532
                                                        Rectangle2D.Double rec = fframe.getBoundingBox(getAT());
533

    
534
                                                        if (img != null) {
535
                                                                //g.drawImage(img, 0, 0, this);
536
                                                                rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
537

    
538
                                                                //((Graphics2D)g).clearRect((int)rec.x,(int)rec.y,(int)rec.width,(int)rec.height);
539
                                                        }
540

    
541
                                                        if (fframe.getBufferedImage() != null) {
542
                                                                layoutDraw.drawHandlers((Graphics2D) g,
543
                                                                        Color.black);
544
                                                                g.clipRect((int) rec.x, (int) rec.y,
545
                                                                        (int) rec.width, (int) rec.height);
546

    
547
                                                                //g.setColor(Color.gray);
548
                                                                //g.fillRect(0,0,getWidth(),getHeight());
549
                                                                layoutDraw.drawRectangle((Graphics2D) g);
550
                                                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
551

    
552
                                                                g.drawImage(fframe.getBufferedImage(),
553
                                                                        m_LastPoint.x - m_PointAnt.x,
554
                                                                        m_LastPoint.y - m_PointAnt.y, this);
555

    
556
                                                                /*System.out.println(
557
                                                                   "m_LastPoint.x - m_PointAnt.x" +
558
                                                                   (m_LastPoint.x - m_PointAnt.x));
559
                                                                   System.out.println(
560
                                                                           "m_LastPoint.y - m_PointAnt.y" +
561
                                                                           (m_LastPoint.y - m_PointAnt.y));
562
                                                                 */
563
                                                        }
564
                                                }
565
                                        }
566
                                }
567

    
568
                                g.setClip(rClip);
569
                                layoutDraw.drawGrid((Graphics2D) g);
570
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
571

    
572
                                //g.setXORMode(Color.black);
573
                                break;
574

    
575
                        case SELECT:
576
                                logger.debug("select");
577
                                layoutDraw.drawRectangle((Graphics2D) g);
578

    
579
                                g.drawImage(img, 0, 0, this);
580

    
581
                                if (isReSel) {
582
                                        reSel = new Rectangle();
583
                                        reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
584
                                        g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
585
                                }
586

    
587
                                for (int i = 0; i < getFFrames().size(); i++) {
588
                                        IFFrame fframe = (IFFrame) getFFrames().get(i);
589

    
590
                                        if (fframe.getSelected() != IFFrame.NOSELECT) {
591
                                                g.setColor(Color.black);
592
                                                fframe.drawHandlers((Graphics2D) g);
593

    
594
                                                int difx = (m_LastPoint.x - m_FirstPoint.x);
595
                                                int dify = (m_LastPoint.y - m_FirstPoint.y);
596

    
597
                                                if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
598
                                                        Rectangle2D rectangle = fframe.getMovieRect(difx,
599
                                                                        dify);
600
                                                        ((Graphics2D) g).rotate(Math.toRadians(
601
                                                                        fframe.getRotation()),
602
                                                                rectangle.getX() + (rectangle.getWidth() / 2),
603
                                                                rectangle.getY() + (rectangle.getHeight() / 2));
604

    
605
                                                        if (rectangle != null) {
606
                                                                if (isCuadricula) {
607
                                                                        FLayoutUtilities.setRectGrid(rectangle,
608
                                                                                m_attributes.getUnitInPixelsX(),
609
                                                                                m_attributes.getUnitInPixelsY(),
610
                                                                                m_MatrizTransf);
611
                                                                }
612

    
613
                                                                g.drawRect((int) rectangle.getMinX(),
614
                                                                        (int) rectangle.getMinY(),
615
                                                                        (int) rectangle.getWidth(),
616
                                                                        (int) rectangle.getHeight());
617
                                                        }
618

    
619
                                                        ((Graphics2D) g).rotate(Math.toRadians(
620
                                                                        -fframe.getRotation()),
621
                                                                rectangle.getX() + (rectangle.getWidth() / 2),
622
                                                                rectangle.getY() + (rectangle.getHeight() / 2));
623
                                                }
624
                                        }
625
                                }
626

    
627
                                g.setClip(rClip);
628
                                layoutDraw.drawGrid((Graphics2D) g);
629
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
630
                                PluginServices.getMainFrame().enableControls();
631

    
632
                                break;
633

    
634
                        case GRAPHICS:
635
                                layoutDraw.drawRectangle((Graphics2D) g);
636
                                g.drawImage(img, 0, 0, this);
637
                                g.setClip(rClip);
638
                                layoutDraw.drawGrid((Graphics2D) g);
639
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
640

    
641
                                break;
642

    
643
                        case DESACTUALIZADO:
644
                                logger.debug("desactualizado");
645
                                img = new BufferedImage(getWidth(), getHeight(),
646
                                                BufferedImage.TYPE_INT_ARGB);
647

    
648
                                Graphics gimag = img.getGraphics();
649
                                clipVisibleRect((Graphics2D) gimag);
650

    
651
                                if (initial) {
652
                                        fullRect();
653
                                        initial = false;
654
                                }
655

    
656
                                try {
657
                                        layoutDraw.drawLayout((Graphics2D) gimag, img);
658
                                } catch (DriverException e) {
659
                                        e.printStackTrace();
660
                                }
661

    
662
                                g.setClip(rClip);
663
                                layoutDraw.drawRectangle((Graphics2D) g);
664

    
665
                                g.drawImage(img, 0, 0, this);
666
                                g.setClip(rClip);
667
                                layoutDraw.drawGrid((Graphics2D) g);
668
                                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
669
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
670

    
671
                                break;
672

    
673
                        case ACTUALIZADO:
674
                                layoutDraw.drawRectangle((Graphics2D) g);
675

    
676
                                g.drawImage(img, 0, 0, this);
677

    
678
                                g.setClip(rClip);
679
                                layoutDraw.drawGrid((Graphics2D) g);
680

    
681
                                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
682
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
683
                }
684
        }
685

    
686
        /**
687
         * A?ade un fframe al Arraylist m_fframes.
688
         *
689
         * @param frame fframe a a?adir.
690
         * @param clearSelection para que se quede seleccionado ?nicamente  el que
691
         *                   a?adimos y false si lo que se pretende es que no se
692
         *                   deseleccionen lo que ya est?n seleccionados.
693
         */
694
        public void addFFrame(IFFrame frame, boolean clearSelection) {
695
                if (clearSelection) {
696
                        for (int i = getFFrames().size() - 1; i >= 0; i--) {
697
                                IFFrame fframe1 = (IFFrame) getFFrames().get(i);
698
                                fframe1.setSelected(false);
699
                        }
700
                }
701

    
702
                if (frame instanceof FFrameView &&
703
                                (((FFrameView) frame).getFMap() != null)) {
704
                        ((FFrameView) frame).getFMap().getViewPort().addViewPortListener(this);
705
                }
706

    
707
                if (nums.containsKey(frame.getClass())) {
708
                        nums.put(frame.getClass(),
709
                                new Integer(Integer.parseInt(nums.get(frame.getClass())
710
                                                                                                 .toString()) + 1));
711
                } else {
712
                        nums.put(frame.getClass(), new Integer(0));
713
                }
714

    
715
                frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
716
                getFFrames().add(frame);
717
                frame.setSelected(true);
718
        }
719

    
720
        /**
721
         * Abre el di?logo de propiedades del folio, pasando como par?metro el
722
         * PrinterJob.
723
         *
724
         * @param job
725
         */
726
        public void showPagePropertiesWindow(PrinterJob job) {
727
                PageFormat pf1; //=new PageFormat();
728

    
729
                pf1 = m_attributes.getPageFormat();
730
                pf1 = job.pageDialog(pf1);
731
                m_attributes.setPageFormat(pf1);
732
                refresh();
733
        }
734

    
735
        /**
736
         * Refresca el Layout.
737
         */
738
        public void refresh() {
739
                //rect = m_attributes.obtainRect(false, rect, getWidth(), getHeight());
740
                status = DESACTUALIZADO;
741
                repaint();
742
        }
743

    
744
        /**
745
         * Obtiene el rect?ngulo que representa el folio con las caracter?sticas
746
         * que contiene attributes y diferenciando si es para visualizar en
747
         * pantalla o para imprimir.
748
         *
749
         * @param isPrint si es para imprimir.
750
         */
751
        public void obtainRect(boolean isPrint) {
752
                m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
753
        }
754

    
755
        /**
756
         * Muestra el di?logo de configuraci?n del Layout.
757
         */
758
        public void showFConfig() {
759
                FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
760
                PluginServices.getMDIManager().addView(m_configLayout);
761
        }
762

    
763
        /**
764
         * Mestra el di?logo de propiedades del Layout.
765
         */
766
        public void showFProperties() {
767
                if (map == null) {
768
                        map = new ProjectMap();
769
                        map.setModel(this);
770
                        map.setName(getName());
771
                }
772

    
773
                m_propertiesLayout = new MapProperties(map);
774
                PluginServices.getMDIManager().addView(m_propertiesLayout);
775
        }
776

    
777
        /**
778
         * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
779
         *
780
         * @param job
781
         */
782
        public void showPrintDialog(PrinterJob job) {
783
                if (job != null) {
784
                        job.printDialog();
785

    
786
                        try {
787
                                job.setPrintable((Printable) PluginServices.getExtension(
788
                                                com.iver.cit.gvsig.Print.class));
789
                                job.print();
790
                        } catch (PrinterException e) {
791
                                e.printStackTrace();
792
                        }
793
                } else {
794
                        boolean print = false;
795

    
796
                        //Actualizar attributes
797
                        att = m_attributes.toPrintAttributes();
798

    
799
                        //------------------ The Printing things --------------------- //
800
                        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
801

    
802
                        // returns the set of printers that support printing a specific document type (such as GIF)
803
                        // with a specific set of attributes (such as two sided).
804
                        // PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
805
                        // interestingly, the printer dialog's default behavior has changed with the new API: by default the dialog is not shown.
806
                        // So we must use the ServiceUI class to create a print dialog
807
                        // returns the default print service.
808
                        if (m_cachePrintServices == null) {
809
                                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
810
                                                null);
811
                        }
812

    
813
                        PrintService defaultService = null;
814

    
815
                        if (m_cachePrintService == null) {
816
                                defaultService = PrintServiceLookup.lookupDefaultPrintService();
817
                        }
818

    
819
                        if (m_cachePrintService == null) {
820
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
821
                                                m_cachePrintServices, defaultService, flavor, att);
822

    
823
                                // m_cachePrintRequestAtributeSet = new HashPrintRequestAttributeSet();
824
                                // m_cachePrintRequestAtributeSet.addAll(pras);
825
                        } else {
826
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
827
                                                m_cachePrintServices, m_cachePrintService, flavor, att);
828
                        }
829

    
830
                        if (m_cachePrintService != null) {
831
                                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
832
                                PrintJobListener pjlistener = new PrintJobAdapter() {
833
                                                public void printDataTransferCompleted(PrintJobEvent e) {
834
                                                        System.out.println("Fin de impresi?n");
835
                                                }
836
                                        };
837

    
838
                                jobNuevo.addPrintJobListener(pjlistener);
839

    
840
                                // DocAttributeSet das = new HashDocAttributeSet();
841
                                doc = new SimpleDoc((Printable) PluginServices.getExtension(
842
                                                        com.iver.cit.gvsig.Print.class), flavor, null);
843

    
844
                                try {
845
                                        jobNuevo.print(doc, att);
846

    
847
                                        // m_attributes.
848
                                } catch (PrintException pe) {
849
                                        pe.printStackTrace();
850
                                }
851
                        }
852
                }
853

    
854
                /* try {
855
                   print = job.printDialog(att);
856
                   } catch (Exception e) {
857
                       logger.error("Abriendo el Di?logo de imprimir"); //System.out.println("Excepci?n "+e);
858
                   }
859
                   if (print) {
860
                       job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
861
                       try {
862
                           job.print(att);
863
                       } catch (Exception ex) {
864
                           ex.printStackTrace();
865
                       }
866
                   } */
867
                fullRect();
868
        }
869

    
870
        /**
871
         * Sustituye el puntero del rat?n por la imagen que se le pasa como
872
         * par?metro.
873
         *
874
         * @param image
875
         */
876
        public void setMapCursor(Image image) {
877
                Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
878
                                new Point(16, 16), "");
879
                setCursor(cur);
880
        }
881

    
882
        /**
883
         * Cambia el puntero del raton al cusor que se le introduce como par?metro.
884
         *
885
         * @param cursor cursor a mostrar en el puntero del rat?n.
886
         */
887
        public void setMapCursor(Cursor cursor) {
888
                setCursor(cursor);
889
        }
890

    
891
        /**
892
         * Pone como seleccionada a la herramienta a partir de su n?mero.
893
         *
894
         * @param i
895
         */
896
        public void setTool(int i) {
897
                tool = i;
898

    
899
                if (getTool() == PAN) {
900
                        setMapCursor(ipan);
901
                } else if (getTool() == ZOOM_MAS) {
902
                        setMapCursor(izoomin);
903
                } else if (getTool() == ZOOM_MENOS) {
904
                        setMapCursor(izoomout);
905
                } else if (getTool() == RECTANGLEVIEW) {
906
                        setMapCursor(icrux);
907
                } else if (getTool() == RECTANGLEPICTURE) {
908
                        setMapCursor(icrux);
909
                } else if (getTool() == RECTANGLESCALEBAR) {
910
                        setMapCursor(icrux);
911
                } else if (getTool() == RECTANGLELEGEND) {
912
                        setMapCursor(icrux);
913
                } else if (getTool() == RECTANGLETEXT) {
914
                        setMapCursor(icrux);
915
                } else if (getTool() == SELECT) {
916
                        setCursor(Cursor.getDefaultCursor());
917
                } else if (getTool() == SET_TAG) {
918
                        setMapCursor(itag);
919
                } else if (getTool() == POINT) {
920
                        setMapCursor(iPoint);
921
                } else if (getTool() == LINE) {
922
                        setMapCursor(iRect);
923
                } else if (getTool() == RECTANGLESIMPLE) {
924
                        setMapCursor(iRectangle);
925
                } else if (getTool() == POLYLINE) {
926
                        setMapCursor(iLine);
927
                } else if (getTool() == POLYGON) {
928
                        setMapCursor(iPoligon);
929
                } else if (getTool() == CIRCLE) {
930
                        setMapCursor(iCircle);
931
                }
932
        }
933

    
934
        /**
935
         * Se crean aqu? los dialogos cada vez que se necesitan.
936
         *
937
         * @param fframe Rectangle que representa el lugar que ocupara el elemento
938
         *                   a?adido.
939
         *
940
         * @return true si se debe de a?adir el fframe.
941
         */
942
        public boolean openFFrameDialog(IFFrame fframe) {
943
                switch (tool) {
944
                        case RECTANGLEVIEW:
945
                                fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
946

    
947
                                break;
948

    
949
                        case RECTANGLEPICTURE:
950
                                fframedialog = new FFramePictureDialog(this,
951
                                                (FFramePicture) fframe);
952

    
953
                                break;
954

    
955
                        case RECTANGLESCALEBAR:
956
                                fframedialog = new FFrameScaleBarDialog(this,
957
                                                (FFrameScaleBar) fframe);
958

    
959
                                break;
960

    
961
                        case RECTANGLELEGEND:
962
                                fframedialog = new FFrameLegendDialog(this,
963
                                                (FFrameLegend) fframe);
964

    
965
                                break;
966

    
967
                        case RECTANGLETEXT:
968
                                fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
969

    
970
                                break;
971

    
972
                        case GRAPHICS:
973
                                fframedialog = new FFrameGraphicsDialog(this,
974
                                                (FFrameGraphics) fframe);
975

    
976
                                break;
977

    
978
                        default:
979
                                return true;
980
                }
981

    
982
                if (fframedialog != null) {
983
                        fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
984
                        PluginServices.getMDIManager().addView(fframedialog);
985
                }
986

    
987
                return fframedialog.getIsAcepted();
988
        }
989

    
990
        /**
991
         * Devuelve el Rectangle2D que representa en pixels al folio.
992
         *
993
         * @return Rectangle2D.Double
994
         */
995
        public Rectangle2D.Double getRect() {
996
                return rect;
997
        }
998

    
999
        /**
1000
         * Obtiene un entero que representa la herramienta seleccionada.
1001
         *
1002
         * @return entero.
1003
         */
1004
        public int getTool() {
1005
                return tool;
1006
        }
1007

    
1008
        /**
1009
         * Devuelve la Matriz transformada que se esta plicando al Layout.
1010
         *
1011
         * @return AffineTransform
1012
         */
1013
        public AffineTransform getAT() {
1014
                return m_MatrizTransf;
1015
        }
1016

    
1017
        /**
1018
         * Devuelve los atributos del Mapa.
1019
         *
1020
         * @return Attributes.
1021
         */
1022
        public Attributes getAtributes() {
1023
                return m_attributes;
1024
        }
1025

    
1026
        /**
1027
         * Pone el estado que se quiera.
1028
         *
1029
         * @param s estado.
1030
         */
1031
        public void setStatus(int s) {
1032
                status = s;
1033
        }
1034

    
1035
        /**
1036
         * Devuelve el punto que representa la esquina noroeste del mapa.
1037
         *
1038
         * @return un punto.
1039
         */
1040
        public Point getRectOrigin() {
1041
                return rectOrigin;
1042
        }
1043

    
1044
        /**
1045
         * Devuelve el punto del primer click de rat?n.
1046
         *
1047
         * @return un punto.
1048
         */
1049
        public Point getFirstPoint() {
1050
                return m_FirstPoint;
1051
        }
1052

    
1053
        /**
1054
         * Devuelve el punto de click de rat?n anterior.
1055
         *
1056
         * @return un punto.
1057
         */
1058
        public Point getPointAnt() {
1059
                return m_PointAnt;
1060
        }
1061

    
1062
        /**
1063
         * Devuelve el punto donde se solt? el bot?n del rat?n.
1064
         *
1065
         * @return un punto.
1066
         */
1067
        public Point getLastPoint() {
1068
                return m_LastPoint;
1069
        }
1070

    
1071
        /**
1072
         * Rellena el primer punto de click de rat?n.
1073
         *
1074
         * @param p punto.
1075
         */
1076
        public void setFirstPoint(Point p) {
1077
                m_FirstPoint = p;
1078
        }
1079

    
1080
        /**
1081
         * Rellena el punto de click de rat?n anterior.
1082
         *
1083
         * @param p punto.
1084
         */
1085
        public void setPointAnt(Point p) {
1086
                m_PointAnt = p;
1087
        }
1088

    
1089
        /**
1090
         * Rellena el punto donde se solto el bot?n del rat?n.
1091
         *
1092
         * @param p punto.
1093
         */
1094
        public void setLastPoint(Point p) {
1095
                m_LastPoint = p;
1096
        }
1097

    
1098
        /**
1099
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1100
         */
1101
        public ViewInfo getViewInfo() {
1102
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.ICONIFIABLE |
1103
                                ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE);
1104

    
1105
                m_viewinfo.setWidth(500);
1106
                m_viewinfo.setHeight(400);
1107

    
1108
                m_viewinfo.setTitle(PluginServices.getText(this, "Mapa") + " : " +
1109
                        getName());
1110

    
1111
                return m_viewinfo;
1112
        }
1113

    
1114
        /**
1115
         * Inserta si se muestra o no la regla del Layout.
1116
         *
1117
         * @param b True si se muestra la regla.
1118
         */
1119
        public void setRuler(boolean b) {
1120
                m_showRuler = b;
1121
        }
1122

    
1123
        /**
1124
         * Devuelve si se muestra la regla del Layout.
1125
         *
1126
         * @return True si se muestra la regla.
1127
         */
1128
        public boolean getRuler() {
1129
                return m_showRuler;
1130
        }
1131

    
1132
        /**
1133
         * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1134
         * cuadr?cula, o no.
1135
         *
1136
         * @return true si se esta aplicando la cuadr?cula.
1137
         */
1138
        public boolean isCuadricula() {
1139
                return isCuadricula;
1140
        }
1141

    
1142
        /**
1143
         * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1144
         *
1145
         * @param b true si se aplica la cuadr?cula.
1146
         */
1147
        public void setIsCuadricula(boolean b) {
1148
                isCuadricula = b;
1149
        }
1150

    
1151
        /**
1152
         * Realiza una exteni?n completa de las capas que contiene la vista del
1153
         * FFrameView.
1154
         *
1155
         * @throws DriverException
1156
         */
1157
        public void viewFull() throws DriverException {
1158
                for (int i = 0; i < getFFrames().size(); i++) {
1159
                        if (getFFrames().get(i) instanceof FFrameView) {
1160
                                FFrameView fframe = (FFrameView) getFFrames().get(i);
1161

    
1162
                                if (fframe.getSelected() != IFFrame.NOSELECT) {
1163
                                        fframe.getFMap().getViewPort().setExtent(fframe.getFMap()
1164
                                                                                                                                   .getFullExtent());
1165
                                }
1166
                        }
1167
                }
1168

    
1169
                setStatus(DESACTUALIZADO);
1170
                repaint();
1171
        }
1172

    
1173
        /**
1174
         * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1175
         * para poder despu?s volver a crear el objeto original.
1176
         *
1177
         * @return XMLEntity.
1178
         *
1179
         * @throws XMLException
1180
         */
1181
        public XMLEntity getXMLEntity() throws XMLException {
1182
                XMLEntity xml = new XMLEntity();
1183
                xml.putProperty("className", this.getClass().getName());
1184
                xml.setName("layout");
1185
                xml.putProperty("isCuadricula", isCuadricula());
1186
                xml.putProperty("m_name", this.getName());
1187
                xml.addChild(getAtributes().getXMLEntity());
1188

    
1189
                for (int i = 0; i < getFFrames().size(); i++) {
1190
                        xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity());
1191
                }
1192

    
1193
                return xml;
1194
        }
1195

    
1196
        /**
1197
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1198
         *
1199
         * @param xml XMLEntity
1200
         * @param p Proyecto.
1201
         *
1202
         * @return Objeto de esta clase.
1203
         */
1204
        public static Layout createLayout(XMLEntity xml, Project p) {
1205
                Layout layout = new Layout();
1206
                layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1207
                layout.setName(xml.getStringProperty("m_name"));
1208
                layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1209

    
1210
                for (int i = 1; i < xml.getNumChild(); i++) {
1211
                        if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1212
                                layout.addFFrame(FFrame.createFFrame(xml.getChild(i), layout, p),
1213
                                        true);
1214
                        }
1215
                }
1216

    
1217
                for (int i = 1; i < xml.getNumChild(); i++) {
1218
                        if (!xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1219
                                layout.addFFrame(FFrame.createFFrame(xml.getChild(i), layout, p),
1220
                                        true);
1221
                        }
1222
                }
1223

    
1224
                return layout;
1225
        }
1226

    
1227
        /**
1228
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1229
         *
1230
         * @param xml XMLEntity
1231
         * @param p Proyecto.
1232
         *
1233
         * @return Objeto de esta clase.
1234
         */
1235
        public static Layout createLayout03(XMLEntity xml, Project p) {
1236
                Layout layout = new Layout();
1237
                layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1238
                layout.setName(xml.getStringProperty("m_name"));
1239
                layout.m_attributes = Attributes.createAtributes03(xml.getChild(0));
1240

    
1241
                for (int i = 1; i < xml.getNumChild(); i++) {
1242
                        if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1243
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1244
                                                p), true);
1245
                        }
1246
                }
1247

    
1248
                for (int i = 1; i < xml.getNumChild(); i++) {
1249
                        if (!xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1250
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1251
                                                p), true);
1252
                        }
1253
                }
1254

    
1255
                return layout;
1256
        }
1257

    
1258
        /**
1259
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1260
         */
1261
        public void viewActivated() {
1262
                PluginServices.getMainFrame().getStatusBar().setMessage("1",
1263
                        getAtributes().getNameUnit());
1264

    
1265
                ///System.out.println("---------- 1 "+ getAtributes().getNameUnit());
1266
        }
1267

    
1268
        /**
1269
         * @see com.iver.cit.gvsig.fmap.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
1270
         */
1271
        public void extentChanged(Rectangle2D newExtent) {
1272
        }
1273

    
1274
        /**
1275
         * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1276
         */
1277
        public Object getViewModel() {
1278
                return map;
1279
        }
1280

    
1281
        /**
1282
         * Devuelve si se dibuja el Grid en el Layout o no.
1283
         *
1284
         * @return True si se dibuja el Grid en el Layout.
1285
         */
1286
        public boolean getIsDrawGrid() {
1287
                return isDrawCuadricula;
1288
        }
1289

    
1290
        /**
1291
         * Inserta si se muestra el Grid del Layout.
1292
         *
1293
         * @param b True si se muestra el Grid del Layout.
1294
         */
1295
        public void setIsDrawGrid(boolean b) {
1296
                isDrawCuadricula = b;
1297
        }
1298

    
1299
        /**
1300
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1301
         */
1302
        public void extentChanged(ExtentEvent e) {
1303
        }
1304

    
1305
        /**
1306
         * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
1307
         */
1308
        public void viewClosed() {
1309
                ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1310
        }
1311

    
1312
        /**
1313
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1314
         */
1315
        public void backColorChanged(ColorEvent e) {
1316
        }
1317

    
1318
        /**
1319
         * Devuelve un array con los FFrames seleccionados.
1320
         *
1321
         * @return Array con los FFrames seleccionados.
1322
         */
1323
        public IFFrame[] getFFrameSelected() {
1324
                ArrayList selecList = new ArrayList();
1325

    
1326
                for (int i = getFFrames().size() - 1; i >= 0; i--) {
1327
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
1328

    
1329
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1330
                                selecList.add(fframe);
1331
                        }
1332
                }
1333

    
1334
                return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1335
        }
1336

    
1337
        /**
1338
         * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1339
         * en este formato.
1340
         */
1341
        public void layoutToPDF() {
1342
                FileFilter pdfFilter = new GenericFileFilter("pdf",
1343
                                PluginServices.getText(this, "pdf"));
1344

    
1345
                JFileChooser jfc = new JFileChooser();
1346
                jfc.addChoosableFileFilter(pdfFilter);
1347
                jfc.setFileFilter(pdfFilter);
1348

    
1349
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1350
                        File f = jfc.getSelectedFile();
1351
                        layoutDraw.toPDF(f);
1352
                }
1353
        }
1354
}