Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / Layout.java @ 9300

History | View | Annotate | Download (50 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 java.awt.Color;
48
import java.awt.Component;
49
import java.awt.Cursor;
50
import java.awt.Graphics;
51
import java.awt.Graphics2D;
52
import java.awt.Image;
53
import java.awt.Point;
54
import java.awt.Rectangle;
55
import java.awt.Toolkit;
56
import java.awt.geom.AffineTransform;
57
import java.awt.geom.Rectangle2D;
58
import java.awt.image.BufferedImage;
59
import java.awt.print.PageFormat;
60
import java.awt.print.Printable;
61
import java.awt.print.PrinterException;
62
import java.awt.print.PrinterJob;
63
import java.beans.PropertyChangeEvent;
64
import java.beans.PropertyChangeListener;
65
import java.io.File;
66
import java.util.ArrayList;
67
import java.util.Hashtable;
68

    
69
import javax.print.Doc;
70
import javax.print.DocFlavor;
71
import javax.print.DocPrintJob;
72
import javax.print.PrintException;
73
import javax.print.PrintService;
74
import javax.print.PrintServiceLookup;
75
import javax.print.ServiceUI;
76
import javax.print.SimpleDoc;
77
import javax.print.attribute.PrintRequestAttributeSet;
78
import javax.print.event.PrintJobAdapter;
79
import javax.print.event.PrintJobEvent;
80
import javax.print.event.PrintJobListener;
81
import javax.swing.ImageIcon;
82
import javax.swing.JFileChooser;
83
import javax.swing.JOptionPane;
84
import javax.swing.JPanel;
85
import javax.swing.filechooser.FileFilter;
86

    
87
import com.iver.andami.PluginServices;
88
import com.iver.andami.messages.NotificationManager;
89
import com.iver.andami.ui.mdiManager.IWindowListener;
90
import com.iver.andami.ui.mdiManager.SingletonWindow;
91
import com.iver.andami.ui.mdiManager.WindowInfo;
92
import com.iver.cit.gvsig.AddLayer;
93
import com.iver.cit.gvsig.fmap.ColorEvent;
94
import com.iver.cit.gvsig.fmap.DriverException;
95
import com.iver.cit.gvsig.fmap.ExtentEvent;
96
import com.iver.cit.gvsig.fmap.ProjectionEvent;
97
import com.iver.cit.gvsig.fmap.ViewPortListener;
98
import com.iver.cit.gvsig.fmap.core.adapter.CircleAdapter;
99
import com.iver.cit.gvsig.fmap.core.adapter.GeometryAdapter;
100
import com.iver.cit.gvsig.fmap.core.adapter.PointAdapter;
101
import com.iver.cit.gvsig.fmap.core.adapter.PolyLineAdapter;
102
import com.iver.cit.gvsig.fmap.core.adapter.PolygonAdapter;
103
import com.iver.cit.gvsig.fmap.core.adapter.RectangleAdapter;
104
import com.iver.cit.gvsig.fmap.edition.commands.CommandListener;
105
import com.iver.cit.gvsig.fmap.layers.XMLException;
106
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
107
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
108
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup;
109
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
110
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth;
111
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
112
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
113
import com.iver.cit.gvsig.gui.layout.fframes.FFrameTable;
114
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
115
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
116
import com.iver.cit.gvsig.project.Project;
117
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
118
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
119
import com.iver.cit.gvsig.project.documents.layout.EventsHandler;
120
import com.iver.cit.gvsig.project.documents.layout.FLayoutDraw;
121
import com.iver.cit.gvsig.project.documents.layout.FLayoutFunctions;
122
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
123
import com.iver.cit.gvsig.project.documents.layout.ProjectMap;
124
import com.iver.cit.gvsig.project.documents.layout.commands.DefaultEditableFeatureSource;
125
import com.iver.cit.gvsig.project.documents.layout.commands.EditableFeatureSource;
126
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
127
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameEditableVertex;
128
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence;
129
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
130
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
131
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameBoxDialog;
132
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameGraphicsDialog;
133
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameGroupDialog;
134
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameLegendDialog;
135
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameNorthDialog;
136
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameOverViewDialog;
137
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFramePictureDialog;
138
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
139
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameTextDialog;
140
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameViewDialog;
141
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
142
import com.iver.cit.gvsig.project.documents.layout.gui.MapProperties;
143
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
144
import com.iver.utiles.GenericFileFilter;
145
import com.iver.utiles.XMLEntity;
146

    
147
/**
148
 * Mapa.
149
 *
150
 * @author Vicente Caballero Navarro
151
 */
152
public class Layout extends JPanel implements SingletonWindow, ViewPortListener,
153
                IWindowListener, CommandListener {
154
        //private static Logger logger = Logger.getLogger(Layout.class.getName());
155

    
156
        public static final int ZOOM_MAS = 1;
157

    
158
        public static final int ZOOM_MENOS = 2;
159

    
160
        public static final int PAN = 3;
161

    
162
        public static final int DESACTUALIZADO = 4;
163

    
164
        public static final int ACTUALIZADO = 5;
165

    
166
        public static final int SELECT = 6;
167

    
168
        public static final int RECTANGLE = 10;
169

    
170
        public static final int RECTANGLEVIEW = 11;
171

    
172
        public static final int RECTANGLEPICTURE = 12;
173

    
174
        public static final int RECTANGLESCALEBAR = 13;
175

    
176
        public static final int RECTANGLELEGEND = 14;
177

    
178
        public static final int RECTANGLETEXT = 15;
179

    
180
        public static final int RECTANGLEGROUP = 16;
181

    
182
        public static final int RECTANGLESYMBOL = 17;
183

    
184
        public static final int RECTANGLENORTH = 18;
185

    
186
        public static final int RECTANGLEBOX = 19;
187

    
188
        public static final int GRAPHICS = 20;
189

    
190
        public static final int POINT = 21;
191

    
192
        public static final int LINE = 22;
193

    
194
        public static final int POLYLINE = 23;
195

    
196
        public static final int RECTANGLESIMPLE = 24;
197

    
198
        public static final int CIRCLE = 25;
199

    
200
        public static final int POLYGON = 26;
201

    
202
         public static final int RECTANGLEOVERVIEW = 27;
203

    
204
        public static final int VIEW_ZOOMIN = 30;
205

    
206
        public static final int VIEW_ZOOMOUT = 31;
207

    
208
        public static final int VIEW_FULL = 32;
209

    
210
        public static final int VIEW_PAN = 33;
211

    
212
        public static final int SET_TAG = 34;
213

    
214
        public static final int EDIT = 40;
215

    
216
        public static final Image iLayoutpan = new ImageIcon(AddLayer.class
217
                        .getClassLoader().getResource("images/LayoutHand.gif")).getImage();
218

    
219
        public static final Image ipan = new ImageIcon(AddLayer.class
220
                        .getClassLoader().getResource("images/Hand.gif")).getImage();
221

    
222
        public static final Image iLayoutzoomin = new ImageIcon(AddLayer.class
223
                        .getClassLoader().getResource("images/LayoutZoomInCursor.gif"))
224
                        .getImage();
225

    
226
        public static final Image izoomin = new ImageIcon(AddLayer.class
227
                        .getClassLoader().getResource("images/ZoomInCursor.gif"))
228
                        .getImage();
229

    
230
        public static final Image iLayoutzoomout = new ImageIcon(AddLayer.class
231
                        .getClassLoader().getResource("images/LayoutZoomOutCursor.gif"))
232
                        .getImage();
233

    
234
        public static final Image izoomout = new ImageIcon(AddLayer.class
235
                        .getClassLoader().getResource("images/ZoomOutCursor.gif"))
236
                        .getImage();
237

    
238
        public static final Image iinfo = new ImageIcon(AddLayer.class
239
                        .getClassLoader().getResource("images/InfoCursor.gif")).getImage();
240

    
241
        public static final Image icrux = new ImageIcon(AddLayer.class
242
                        .getClassLoader().getResource("images/CruxCursor.png")).getImage();
243

    
244
        public static final Image itag = new ImageIcon(AddLayer.class
245
                        .getClassLoader().getResource("images/tagCursor.gif")).getImage();
246

    
247
        public static final Image iPoint = new ImageIcon(AddLayer.class
248
                        .getClassLoader().getResource("images/PointCursor.png")).getImage();
249

    
250
        public static final Image iRect = new ImageIcon(AddLayer.class
251
                        .getClassLoader().getResource("images/RectCursor.png")).getImage();
252

    
253
        public static final Image iLine = new ImageIcon(AddLayer.class
254
                        .getClassLoader().getResource("images/LineCursor.png")).getImage();
255

    
256
        public static final Image iRectangle = new ImageIcon(AddLayer.class
257
                        .getClassLoader().getResource("images/RectangleCursor.png"))
258
                        .getImage();
259

    
260
        public static final Image iCircle = new ImageIcon(AddLayer.class
261
                        .getClassLoader().getResource("images/CircleCursor.png"))
262
                        .getImage();
263

    
264
        public static final Image iPoligon = new ImageIcon(AddLayer.class
265
                        .getClassLoader().getResource("images/PoligonCursor.png"))
266
                        .getImage();
267

    
268
        public static Hashtable nums = new Hashtable();
269

    
270
        private static Boolean defaultShowGrid = null;
271

    
272
        private static Boolean defaultAdjustToGrid = null;
273

    
274
        private static Boolean defaultShowRulers = null;
275

    
276
        private Point origin = new Point(50, 50);
277

    
278
        private Point rectOrigin = new Point(origin);
279

    
280
        private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
281
                        rectOrigin.y, 400, 300);
282

    
283
        private Point m_FirstPoint = new Point(0, 0);
284

    
285
        private Point m_PointAnt = new Point(0, 0);
286

    
287
        private Point m_LastPoint = new Point(0, 0);
288

    
289
        private EventsHandler events;
290

    
291
        private int tool = ZOOM_MAS;
292

    
293
        private int status = DESACTUALIZADO;
294

    
295
        private BufferedImage img = null;
296

    
297
        private BufferedImage imgRuler = null;
298

    
299
        private AffineTransform m_MatrizTransf;
300

    
301
        private Rectangle2D rectVisible;
302

    
303
        private IFFrameDialog fframedialog = null;
304

    
305
        private IFFrame[] fframes;
306

    
307
        private MapProperties m_propertiesLayout = null;
308

    
309
        private Attributes m_attributes = null;
310

    
311
        private PrintService[] m_cachePrintServices = null;
312

    
313
        private PrintService m_cachePrintService = null;
314

    
315
        private boolean m_bCancelDrawing = false;
316

    
317
        private Boolean adjustToGrid = null;
318

    
319
        private boolean initial = true;
320

    
321
        private ProjectMap map = null;
322

    
323
        private Rectangle reSel = null;
324

    
325
        private boolean isReSel = true;
326

    
327
        private Boolean m_showRuler;
328

    
329
        private FLayoutDraw layoutDraw = null;
330

    
331
        private Boolean isGridVisible = null;
332

    
333
        private Doc doc = null;
334

    
335
        private PrintRequestAttributeSet att = null;
336

    
337
        private GeometryAdapter geometryAdapter = new PolyLineAdapter();
338

    
339
        private DefaultEditableFeatureSource efs;
340

    
341
        private boolean isEditable = true;
342

    
343
        private WindowInfo m_viewInfo = null;
344

    
345
        private int numBefore = 0;
346

    
347
        private int numBehind = 0;
348

    
349
        /**
350
         * Lo usamos cuando estamos haciendo una ficha y asignando tags Se pone en
351
         * modo debug cuando hacemos un VIEW_TAGS
352
         */
353
        private boolean bShowIconTag = false;
354

    
355
        private boolean editGroup;
356

    
357
        /**
358
         * Creates a new Layout object.
359
         */
360
        public Layout() {
361
                efs = new DefaultEditableFeatureSource();
362
                updateFFrames();
363
                this.setLayout(null);
364
                events = new EventsHandler(this);
365
                layoutDraw = new FLayoutDraw(this);
366
                addComponentListener(events);
367
                addMouseMotionListener(events);
368
                addMouseListener(events);
369
                m_MatrizTransf = new AffineTransform();
370
                m_MatrizTransf.setToIdentity();
371
                this.initComponents();
372
        }
373

    
374
        /**
375
         * Rellena el ProjectMap del Layout.
376
         *
377
         * @param m
378
         *            ProjectMap.
379
         */
380
        public void setProjectMap(ProjectMap m) {
381
                map = m;
382
                this.setName(m.getName());
383
                map.addPropertyChangeListener(new PropertyChangeListener() {
384
                        public void propertyChange(PropertyChangeEvent evt) {
385
                                if (evt.getPropertyName().equals("name")) {
386
                                        PluginServices.getMDIManager().getWindowInfo(Layout.this)
387
                                                        .setTitle(
388
                                                                        PluginServices.getText(this, "Mapa")
389
                                                                                        + " : "
390
                                                                                        + (String) evt.getNewValue());
391
                                }
392
                        }
393
                });
394
        }
395

    
396
        /**
397
         * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
398
         *
399
         * @return Rect?ngulo de selecci?n.
400
         */
401
        public Rectangle getReSel() {
402
                return reSel;
403
        }
404

    
405
        /**
406
         * Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar la
407
         * sellecci?n.
408
         *
409
         * @return true si se realiza la selecci?n por rect?ngulo.
410
         */
411
        public boolean isReSel() {
412
                return isReSel;
413
        }
414

    
415
        /**
416
         * Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
417
         * selecci?n.
418
         *
419
         * @param b
420
         *            boolean.
421
         */
422
        public void setIsReSel(boolean b) {
423
                isReSel = b;
424
        }
425

    
426
        /**
427
         * Devuelve true si el dibujado ha sido cancelado.
428
         *
429
         * @return true si el dibujado ha sido cancelado.
430
         */
431
        public synchronized boolean isDrawingCancelled() {
432
                return m_bCancelDrawing;
433
        }
434

    
435
        /**
436
         * Pone el dibuja a cancelado o no seg?n se quiera.
437
         *
438
         * @param b
439
         *            true si se quiere cancelar el dibujado.
440
         */
441
        public synchronized void setCancelDrawing(boolean b) {
442
                m_bCancelDrawing = b;
443

    
444
                for (int i = 0; i < getFFrames().length; i++) {
445
                        IFFrame fframe = getFFrame(i);
446

    
447
                        if (fframe instanceof IFFrameUseFMap
448
                                        && (((IFFrameUseFMap) fframe).getMapContext() != null)) {
449
                                // //TODO((FFrameView)
450
                                // getFFrames().get(i)).getFMap().setCancelDrawing(b);
451
                        }
452
                }
453
        }
454

    
455
        /**
456
         * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
457
         *
458
         * @return Array con todos los fframes que contiene el Layout.
459
         */
460
        public IFFrame[] getFFrames() {
461
                return fframes;
462
        }
463

    
464
        public IFFrame getFFrame(int i) {
465
                return fframes[i];
466
        }
467

    
468
        public void updateFFrames() {
469
                ArrayList frames = new ArrayList();
470
                IFFrame[] auxfframes = efs.getFFrames();
471
                for (int j = numBehind; j <= numBefore; j++) {
472
                        for (int i = 0; i < auxfframes.length; i++) {
473
                                if (auxfframes[i].getLevel() == j) {
474
                                        frames.add(auxfframes[i]);
475
                                        continue;
476
                                }
477
                        }
478
                }
479
                fframes = (IFFrame[]) frames.toArray(new IFFrame[0]);
480
        }
481

    
482
        /**
483
         * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
484
         * entero.
485
         */
486
        public void fullRect() {
487
                rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
488
                                getHeight() - (origin.x * 2));
489

    
490
                if (m_attributes.isLandSpace()) {
491
                        rect = m_attributes.getRectangleLandscape(rect, getWidth(),
492
                                        getHeight());
493
                } else {
494
                        rect = m_attributes.getRectanglePortrait(rect, getWidth(),
495
                                        getHeight());
496
                }
497
                refresh();
498
        }
499

    
500
        /**
501
         * M?todo para imprimir el Layout sin modificar la matriz de transformaci?n.
502
         *
503
         * @param g2
504
         */
505
        public void drawLayoutPrint(Graphics2D g2) {
506
                setCancelDrawing(false);
507

    
508
                setCursor(Cursor.getDefaultCursor());
509

    
510
                double scale = 0;
511
                scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
512
                AffineTransform escalado = new AffineTransform();
513
                AffineTransform translacion = new AffineTransform();
514
                translacion.setToTranslation(rect.getMinX(), rect.getMinY());
515
                escalado.setToScale(scale, scale);
516
                m_MatrizTransf.setToIdentity();
517
                m_MatrizTransf.concatenate(translacion);
518
                m_MatrizTransf.concatenate(escalado);
519
                m_attributes.setDistanceUnitX(rect);
520
                m_attributes.setDistanceUnitY(rect);
521
                IFFrame[] fframes=getFFrames();
522
                for (int i = 0; i < fframes.length; i++) {
523
                        try {
524
                                fframes[i].print(g2, getAT());
525
                        } catch (DriverException e) {
526
                                NotificationManager.addError(e.getMessage(), e);
527
                        }
528
                }
529

    
530
                // TODO Esto es para ver el rect?ngulo que representa el folio en la
531
                // impresi?n.
532
                //g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
533
                // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
534
        }
535

    
536
        /**
537
         * Clip sobre el rect?ngulo visible.
538
         *
539
         * @param g2d
540
         *            Graphics sobre el que hacer el clip.
541
         */
542
        private void clipVisibleRect(Graphics2D g2d) {
543
                rectVisible = this.getVisibleRect();
544
                g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
545
                                (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
546
        }
547

    
548
        /**
549
         * Inicializa los componentes.
550
         */
551
        private void initComponents() {
552
                m_attributes = new Attributes();
553
                m_attributes.setDistanceUnitX(rect);
554
                m_attributes.setDistanceUnitY(rect);
555
                //actionDelFFrame();
556
                setDoubleBuffered(true);
557
        }
558

    
559
        /**
560
         * paintComponent del Layout.
561
         *
562
         * @param g
563
         *            Graphics del Layout.
564
         */
565
        protected void paintComponent(Graphics g) {
566
                super.paintComponent(g);
567

    
568
                clipVisibleRect((Graphics2D) g);
569

    
570
                Rectangle rClip = g.getClipBounds();
571

    
572
                if (rClip == null) {
573
                        System.err.println("clip = null");
574
                }
575

    
576
                switch (status) {
577
                case ZOOM_MAS:
578
                        //logger.debug("zoom mas");
579
                        layoutDraw.drawRectangle((Graphics2D) g);
580

    
581
                        g.drawImage(img, 0, 0, this);
582

    
583
                        g.setClip(rClip);
584
                        g.drawImage(imgRuler, 0, 0, this);
585
                        g.setColor(Color.black);
586
                        g.setXORMode(Color.white);
587

    
588
                        Rectangle r = new Rectangle();
589

    
590
                        r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
591
                        g.drawRect(r.x, r.y, r.width, r.height);
592

    
593
                        break;
594

    
595
                case RECTANGLE:
596
                        //logger.debug("rectangle");
597
                        layoutDraw.drawRectangle((Graphics2D) g);
598

    
599
                        g.drawImage(img, 0, 0, this);
600

    
601
                        g.setClip(rClip);
602
                        g.drawImage(imgRuler, 0, 0, this);
603
                        g.setColor(Color.black);
604
                        g.setXORMode(Color.white);
605

    
606
                        Rectangle re = new Rectangle();
607
                        re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
608

    
609
                        if (isAdjustingToGrid()) {
610
                                FLayoutUtilities.setRectGrid(re, m_attributes
611
                                                .getUnitInPixelsX(), m_attributes.getUnitInPixelsY(),
612
                                                m_MatrizTransf);
613
                        }
614

    
615
                        g.drawRect(re.x, re.y, re.width, re.height);
616

    
617
                        break;
618

    
619
                case PAN:
620
                        //logger.debug("pan");
621

    
622
                        rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
623
                        rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
624

    
625
                        layoutDraw.drawRectangle((Graphics2D) g);
626

    
627
                        if (img != null) {
628
                                g.drawImage(img, (getLastPoint().x - getPointAnt().x),
629
                                                (getLastPoint().y - getPointAnt().y), this);
630
                        }
631

    
632
                        g.setClip(rClip);
633
                        layoutDraw.drawGrid((Graphics2D) g);
634
                        layoutDraw.drawRuler((Graphics2D) g, Color.black);
635
                        break;
636

    
637
                case VIEW_PAN:
638

    
639
                        //logger.debug("View pan");
640
                        layoutDraw.drawRectangle((Graphics2D) g);
641

    
642
                        for (int i = 0; i < getFFrames().length; i++) {
643
                                if (getFFrame(i) instanceof IFFrameUseFMap) {
644
                                        IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
645

    
646
                                        if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
647
                                                Rectangle2D.Double rec = ((IFFrame) fframe)
648
                                                                .getBoundingBox(getAT());
649

    
650
                                                if (img != null) {
651
                                                        rec = (Rectangle2D.Double) rec
652
                                                                        .createIntersection(getVisibleRect());
653
                                                }
654

    
655
                                                if (fframe.getBufferedImage() != null) {
656
                                                        layoutDraw
657
                                                                        .drawHandlers((Graphics2D) g, Color.black);
658
                                                        g.clipRect((int) rec.x, (int) rec.y,
659
                                                                        (int) rec.width, (int) rec.height);
660

    
661
                                                        layoutDraw.drawRectangle((Graphics2D) g);
662
                                                        layoutDraw.drawRuler((Graphics2D) g, Color.black);
663
                                                        Rectangle2D.Double r1 = ((IFFrame) fframe)
664
                                                                        .getBoundingBox(getAT());
665
                                                        g.drawImage(fframe.getBufferedImage(), (int) r1
666
                                                                        .getX()
667
                                                                        + m_LastPoint.x - m_PointAnt.x, (int) r1
668
                                                                        .getY()
669
                                                                        + m_LastPoint.y - m_PointAnt.y, this);
670

    
671
                                                        fframe.refresh();
672
                                                }
673
                                        }
674
                                }
675
                        }
676

    
677
                        g.setClip(rClip);
678
                        g.drawImage(imgRuler, 0, 0, this);
679

    
680
                        break;
681

    
682
                case SELECT:
683
                        //logger.debug("select");
684
                        layoutDraw.drawRectangle((Graphics2D) g);
685

    
686
                        g.drawImage(img, 0, 0, this);
687

    
688
                        if (isReSel) {
689
                                reSel = new Rectangle();
690
                                reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
691
                                g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
692
                        }
693
                        IFFrame[] frames = getFFrameSelected();
694
                        for (int i = 0; i < frames.length; i++) {
695
                                g.setColor(Color.black);
696
                                frames[i].drawHandlers((Graphics2D) g);
697
                                int difx = (m_LastPoint.x - m_FirstPoint.x);
698
                                int dify = (m_LastPoint.y - m_FirstPoint.y);
699
                                if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
700
                                        Rectangle2D rectangle = frames[i].getMovieRect(difx, dify);
701
                                        if (rectangle == null)
702
                                                return;
703
                                        ((Graphics2D) g).rotate(Math.toRadians(frames[i]
704
                                                        .getRotation()), rectangle.getX()
705
                                                        + (rectangle.getWidth() / 2), rectangle.getY()
706
                                                        + (rectangle.getHeight() / 2));
707

    
708
                                        if (rectangle != null) {
709
                                                if (isAdjustingToGrid()) {
710
                                                        FLayoutUtilities.setRectGrid(rectangle,
711
                                                                        m_attributes.getUnitInPixelsX(),
712
                                                                        m_attributes.getUnitInPixelsY(),
713
                                                                        m_MatrizTransf);
714
                                                }
715

    
716
                                                g.drawRect((int) rectangle.getMinX(), (int) rectangle
717
                                                                .getMinY(), (int) rectangle.getWidth(),
718
                                                                (int) rectangle.getHeight());
719
                                        }
720

    
721
                                        ((Graphics2D) g).rotate(Math.toRadians(-frames[i]
722
                                                        .getRotation()), rectangle.getX()
723
                                                        + (rectangle.getWidth() / 2), rectangle.getY()
724
                                                        + (rectangle.getHeight() / 2));
725

    
726
                                }
727
                        }
728

    
729
                        g.setClip(rClip);
730
                        g.drawImage(imgRuler, 0, 0, this);
731

    
732
                        break;
733
                case GRAPHICS:
734
                        //logger.debug("graphics");
735
                        layoutDraw.drawRectangle((Graphics2D) g);
736
                        g.drawImage(img, 0, 0, this);
737
                        g.setClip(rClip);
738
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
739

    
740
                        if (getTool() == EDIT) {
741
                                IFFrame[] fframeSelect = getFFrameSelected();
742
                                for (int i = 0; i < fframeSelect.length; i++) {
743
                                        if (fframeSelect[i] instanceof IFFrameEditableVertex) {
744
                                                ((IFFrameEditableVertex) fframeSelect[i]).paint(
745
                                                                (Graphics2D) g, getAT());
746
                                        }
747
                                }
748
                        } else {
749
                                geometryAdapter.paint((Graphics2D) g, getAT(), true);
750
                        }
751
                        g.drawImage(imgRuler, 0, 0, this);
752
                        break;
753

    
754
                case DESACTUALIZADO:
755
                        //logger.debug("desactualizado");
756
                        img = new BufferedImage(getWidth(), getHeight(),
757
                                        BufferedImage.TYPE_INT_ARGB);
758
                        imgRuler = new BufferedImage(getWidth(), getHeight(),
759
                                        BufferedImage.TYPE_INT_ARGB);
760
                        Graphics gimag = img.getGraphics();
761
                        Graphics gimgRuler = imgRuler.getGraphics();
762

    
763
                        clipVisibleRect((Graphics2D) gimag);
764

    
765
                        if (initial) {
766
                                fullRect();
767
                                initial = false;
768
                        }
769

    
770
                        try {
771
                                layoutDraw.drawLayout((Graphics2D) gimag, img);
772
                        } catch (DriverException e) {
773
                                e.printStackTrace();
774
                        }
775

    
776
                        g.setClip(rClip);
777
                        layoutDraw.drawRectangle((Graphics2D) g);
778

    
779
                        g.drawImage(img, 0, 0, this);
780
                        g.setClip(rClip);
781

    
782
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
783
                        layoutDraw.drawGrid((Graphics2D) gimgRuler);
784
                        layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
785
                        g.drawImage(imgRuler, 0, 0, this);
786

    
787
                        break;
788

    
789
                case ACTUALIZADO:
790
                        layoutDraw.drawRectangle((Graphics2D) g);
791

    
792
                        g.drawImage(img, 0, 0, this);
793

    
794
                        g.setClip(rClip);
795
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
796
                        g.drawImage(imgRuler, 0, 0, this);
797
                }
798
        }
799

    
800
        /**
801
         * A?ade un fframe al Arraylist m_fframes.
802
         *
803
         * @param frame
804
         *            fframe a a?adir.
805
         * @param clearSelection
806
         *            para que se quede seleccionado ?nicamente el que a?adimos y
807
         *            false si lo que se pretende es que no se deseleccionen lo que
808
         *            ya est?n seleccionados.
809
         * @param select
810
         *            Booleano que indica si se tiene que quedar seleccionado el
811
         *            FFrame que se a?ade o no.
812
         */
813
        public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) {
814
                IFFrame[] fframes = getFFrames();
815
                if (clearSelection) {
816
                        for (int i = fframes.length - 1; i >= 0; i--) {
817
                                IFFrame fframe1 = fframes[i];
818
                                fframe1.setSelected(false);
819
                        }
820
                }
821

    
822
                if (nums.containsKey(frame.getClass())) {
823
                        nums.put(frame.getClass(), new Integer(Integer.parseInt(nums.get(
824
                                        frame.getClass()).toString()) + 1));
825
                } else {
826
                        nums.put(frame.getClass(), new Integer(0));
827
                }
828

    
829
                frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
830
                efs.addFFrame(frame);
831
                frame.setSelected(select);
832
                frame.setLevel(getNumBefore());
833
                updateFFrames();
834
        }
835

    
836
        /**
837
         * Abre el di?logo de propiedades del folio, pasando como par?metro el
838
         * PrinterJob.
839
         *
840
         * @param job
841
         */
842
        public void showPagePropertiesWindow(PrinterJob job) {
843
                PageFormat pf1;
844

    
845
                pf1 = m_attributes.getPageFormat();
846
                pf1 = job.pageDialog(pf1);
847
                m_attributes.setPageFormat(pf1);
848
                refresh();
849
        }
850

    
851
        /**
852
         * Refresca el Layout.
853
         */
854
        public void refresh() {
855
                setStatus(DESACTUALIZADO);
856
                repaint();
857
        }
858
        public void fullRefresh() {
859
                IFFrame[] fframes = getFFrames();
860
                for (int i = 0; i < fframes.length; i++) {
861
                        if (fframes[i] instanceof IFFrameUseFMap) {
862
                                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
863
                                fframe.refresh();
864
                        }
865
                }
866
                refresh();
867
        }
868
        /**
869
         * Obtiene el rect?ngulo que representa el folio con las caracter?sticas que
870
         * contiene attributes y diferenciando si es para visualizar en pantalla o
871
         * para imprimir.
872
         *
873
         * @param isPrint
874
         *            si es para imprimir.
875
         */
876
        public void obtainRect(boolean isPrint) {
877
                m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
878
        }
879

    
880
        /**
881
         * Muestra el di?logo de configuraci?n del Layout.
882
         */
883
        public void showFConfig() {
884
                FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
885
                PluginServices.getMDIManager().addWindow(m_configLayout);
886
        }
887

    
888
        /**
889
         * Mestra el di?logo de propiedades del Layout.
890
         */
891
        public void showFProperties() {
892
                if (map == null) {
893
                        map = new ProjectMap();
894
                        map.setModel(this);
895
                        map.setName(getName());
896
                }
897

    
898
                m_propertiesLayout = new MapProperties(map);
899
                PluginServices.getMDIManager().addWindow(m_propertiesLayout);
900
        }
901

    
902
        /**
903
         * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
904
         *
905
         * @param job
906
         */
907
        public void showPrintDialog(PrinterJob job) {
908
                if (job != null) {
909
                        job.printDialog();
910

    
911
                        try {
912
                                job.setPrintable((Printable) PluginServices
913
                                                .getExtension(com.iver.cit.gvsig.Print.class));
914
                                job.print();
915
                        } catch (PrinterException e) {
916
                                e.printStackTrace();
917
                        }
918
                } else {
919
                        // Actualizar attributes
920
                        att = m_attributes.toPrintAttributes();
921

    
922
                        // ------------------ The Printing things --------------------- //
923
                        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
924

    
925
                        // returns the set of printers that support printing a specific
926
                        // document type (such as GIF)
927
                        // with a specific set of attributes (such as two sided).
928
                        // PrintRequestAttributeSet pras = new
929
                        // HashPrintRequestAttributeSet();
930
                        // interestingly, the printer dialog's default behavior has changed
931
                        // with the new API: by default the dialog is not shown.
932
                        // So we must use the ServiceUI class to create a print dialog
933
                        // returns the default print service.
934
                        if (m_cachePrintServices == null) {
935
                                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(
936
                                                flavor, null);
937
                        }
938

    
939
                        PrintService defaultService = null;
940

    
941
                        if (m_cachePrintService == null) {
942
                                defaultService = PrintServiceLookup.lookupDefaultPrintService();
943
                        }
944

    
945
                        if ((defaultService == null) && (m_cachePrintService == null)) {
946
                                JOptionPane.showMessageDialog((Component) PluginServices
947
                                                .getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada"));
948

    
949
                                return;
950
                        }
951

    
952
                        if (m_cachePrintService == null) {
953
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
954
                                                m_cachePrintServices, defaultService, flavor, att);
955

    
956
                                // m_cachePrintRequestAtributeSet = new
957
                                // HashPrintRequestAttributeSet();
958
                                // m_cachePrintRequestAtributeSet.addAll(pras);
959
                        } else {
960
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
961
                                                m_cachePrintServices, m_cachePrintService, flavor, att);
962
                        }
963

    
964
                        if (m_cachePrintService != null) {
965
                                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
966
                                PrintJobListener pjlistener = new PrintJobAdapter() {
967
                                        public void printDataTransferCompleted(PrintJobEvent e) {
968
                                                System.out.println("Fin de impresi?n");
969
                                                fullRect();
970
                                        }
971
                                };
972

    
973
                                jobNuevo.addPrintJobListener(pjlistener);
974

    
975
                                // DocAttributeSet das = new HashDocAttributeSet();
976
                                doc = new SimpleDoc(PluginServices
977
                                                .getExtension(com.iver.cit.gvsig.Print.class), flavor,
978
                                                null);
979

    
980
                                try {
981
                                        jobNuevo.print(doc, att);
982

    
983
                                        // m_attributes.
984
                                } catch (PrintException pe) {
985
                                        pe.printStackTrace();
986
                                }
987
                        }
988
                }
989

    
990
                /*
991
                 * try { print = job.printDialog(att); } catch (Exception e) {
992
                 * logger.error("Abriendo el Di?logo de imprimir");
993
                 * //System.out.println("Excepci?n "+e); } if (print) {
994
                 * job.setPrintable((Printable)
995
                 * App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
996
                 * try { job.print(att); } catch (Exception ex) { ex.printStackTrace(); } }
997
                 */
998
        }
999

    
1000
        /**
1001
         * Sustituye el puntero del rat?n por la imagen que se le pasa como
1002
         * par?metro.
1003
         *
1004
         * @param image
1005
         */
1006
        public void setMapCursor(Image image) {
1007
                Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
1008
                                new Point(16, 16), "");
1009
                setCursor(cur);
1010
        }
1011

    
1012
        /**
1013
         * Cambia el puntero del raton al cusor que se le introduce como par?metro.
1014
         *
1015
         * @param cursor
1016
         *            cursor a mostrar en el puntero del rat?n.
1017
         */
1018
        public void setMapCursor(Cursor cursor) {
1019
                setCursor(cursor);
1020
        }
1021

    
1022
        /**
1023
         * Pone como seleccionada a la herramienta a partir de su n?mero.
1024
         *
1025
         * @param i
1026
         */
1027
        public void setTool(int i) {
1028
                tool = i;
1029

    
1030
                if (getTool() == PAN) {
1031
                        setMapCursor(ipan);
1032
                } else if (getTool() == ZOOM_MAS) {
1033
                        setMapCursor(izoomin);
1034
                } else if (getTool() == ZOOM_MENOS) {
1035
                        setMapCursor(izoomout);
1036
                } else if (getTool() == RECTANGLEVIEW) {
1037
                        setMapCursor(icrux);
1038
                } else if (getTool() == RECTANGLEOVERVIEW) {
1039
            setMapCursor(icrux);
1040
        } else if (getTool() == RECTANGLEPICTURE) {
1041
                        setMapCursor(icrux);
1042
                } else if (getTool() == RECTANGLESCALEBAR) {
1043
                        setMapCursor(icrux);
1044
                } else if (getTool() == RECTANGLELEGEND) {
1045
                        setMapCursor(icrux);
1046
                } else if (getTool() == RECTANGLETEXT) {
1047
                        setMapCursor(icrux);
1048
                } else if (getTool() == RECTANGLENORTH) {
1049
                        setMapCursor(icrux);
1050
                } else if (getTool() == RECTANGLEBOX) {
1051
                        setMapCursor(icrux);
1052
                } else if (getTool() == SELECT) {
1053
                        setCursor(Cursor.getDefaultCursor());
1054
                } else if (getTool() == SET_TAG) {
1055
                        setMapCursor(itag);
1056
                } else if (getTool() == POINT) {
1057
                        setMapCursor(iPoint);
1058
                } else if (getTool() == LINE) {
1059
                        setMapCursor(iRect);
1060
                } else if (getTool() == RECTANGLESIMPLE) {
1061
                        setMapCursor(iRectangle);
1062
                } else if (getTool() == POLYLINE) {
1063
                        setMapCursor(iLine);
1064
                } else if (getTool() == POLYGON) {
1065
                        setMapCursor(iPoligon);
1066
                } else if (getTool() == CIRCLE) {
1067
                        setMapCursor(iCircle);
1068
                }
1069
                if (getTool() == EDIT) {
1070
                        setMapCursor(icrux);
1071
                        startEdit();
1072
                } else {
1073
                        stopEdit();
1074
                }
1075
                initGeometryAdapter();
1076
        }
1077

    
1078
        /**
1079
         * Se crean aqu? los dialogos cada vez que se necesitan.
1080
         *
1081
         * @param fframe
1082
         *            Rectangle que representa el lugar que ocupara el elemento
1083
         *            a?adido.
1084
         *
1085
         * @return true si se debe de a?adir el fframe.
1086
         */
1087
        public IFFrame openFFrameDialog(IFFrame fframe) {
1088
                switch (tool) {
1089
                case RECTANGLEVIEW:
1090
                        fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
1091

    
1092
                        break;
1093
                case RECTANGLEOVERVIEW:
1094
            fframedialog = new FFrameOverViewDialog(this, (FFrameView) fframe);
1095

    
1096
            break;
1097

    
1098
                case RECTANGLEPICTURE:
1099
                        fframedialog = new FFramePictureDialog(this, (FFramePicture) fframe);
1100

    
1101
                        break;
1102

    
1103
                case RECTANGLESCALEBAR:
1104
                        fframedialog = new FFrameScaleBarDialog(this,
1105
                                        (FFrameScaleBar) fframe);
1106

    
1107
                        break;
1108

    
1109
                case RECTANGLELEGEND:
1110
                        fframedialog = new FFrameLegendDialog(this, (FFrameLegend) fframe);
1111

    
1112
                        break;
1113

    
1114
                case RECTANGLETEXT:
1115
                        fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
1116

    
1117
                        break;
1118

    
1119
                case GRAPHICS:
1120
                        fframedialog = new FFrameGraphicsDialog(this,
1121
                                        (FFrameGraphics) fframe);
1122

    
1123
                        break;
1124

    
1125
                case RECTANGLEGROUP:
1126
                        fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe);
1127

    
1128
                        break;
1129
                case RECTANGLENORTH:
1130
                        fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe);
1131

    
1132
                        break;
1133
                case RECTANGLEBOX:
1134
                        fframedialog = new FFrameBoxDialog(this, (FFrameTable) fframe);
1135

    
1136
                        break;
1137
                default:
1138
                        return null;
1139
                }
1140

    
1141
                if (fframedialog != null) {
1142
                        fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
1143
                        PluginServices.getMDIManager().addWindow(fframedialog);
1144
                }
1145

    
1146
                return fframedialog.getFFrame();
1147
        }
1148

    
1149
        /**
1150
         * Devuelve el Rectangle2D que representa en pixels al folio.
1151
         *
1152
         * @return Rectangle2D.Double
1153
         */
1154
        public Rectangle2D.Double getRect() {
1155
                return rect;
1156
        }
1157

    
1158
        public void setRect(Rectangle2D r) {
1159
                rect.setRect(r);
1160
        }
1161

    
1162
        /**
1163
         * Obtiene un entero que representa la herramienta seleccionada.
1164
         *
1165
         * @return entero.
1166
         */
1167
        public int getTool() {
1168
                return tool;
1169
        }
1170

    
1171
        /**
1172
         * Devuelve la Matriz transformada que se esta plicando al Layout.
1173
         *
1174
         * @return AffineTransform
1175
         */
1176
        public AffineTransform getAT() {
1177
                return m_MatrizTransf;
1178
        }
1179

    
1180
        /**
1181
         * Devuelve los atributos del Mapa.
1182
         *
1183
         * @return Attributes.
1184
         */
1185
        public Attributes getAtributes() {
1186
                return m_attributes;
1187
        }
1188

    
1189
        /**
1190
         * Pone el estado que se quiera.
1191
         *
1192
         * @param s
1193
         *            estado.
1194
         */
1195
        public void setStatus(int s) {
1196
                status = s;
1197
        }
1198

    
1199
        /**
1200
         * Devuelve el punto que representa la esquina noroeste del mapa.
1201
         *
1202
         * @return un punto.
1203
         */
1204
        public Point getRectOrigin() {
1205
                return rectOrigin;
1206
        }
1207

    
1208
        /**
1209
         * Devuelve el punto del primer click de rat?n.
1210
         *
1211
         * @return un punto.
1212
         */
1213
        public Point getFirstPoint() {
1214
                return m_FirstPoint;
1215
        }
1216

    
1217
        /**
1218
         * Devuelve el punto de click de rat?n anterior.
1219
         *
1220
         * @return un punto.
1221
         */
1222
        public Point getPointAnt() {
1223
                return m_PointAnt;
1224
        }
1225

    
1226
        /**
1227
         * Devuelve el punto donde se solt? el bot?n del rat?n.
1228
         *
1229
         * @return un punto.
1230
         */
1231
        public Point getLastPoint() {
1232
                return m_LastPoint;
1233
        }
1234

    
1235
        /**
1236
         * Rellena el primer punto de click de rat?n.
1237
         *
1238
         * @param p
1239
         *            punto.
1240
         */
1241
        public void setFirstPoint(Point p) {
1242
                m_FirstPoint = p;
1243
        }
1244

    
1245
        /**
1246
         * Rellena el punto de click de rat?n anterior.
1247
         *
1248
         * @param p
1249
         *            punto.
1250
         */
1251
        public void setPointAnt(Point p) {
1252
                m_PointAnt = p;
1253
        }
1254

    
1255
        /**
1256
         * Rellena el punto donde se solto el bot?n del rat?n.
1257
         *
1258
         * @param p
1259
         *            punto.
1260
         */
1261
        public void setLastPoint(Point p) {
1262
                m_LastPoint = p;
1263
        }
1264

    
1265
        /**
1266
         * This method is used to get <strong>an initial</strong> ViewInfo object
1267
         * for this Map. It is not intended to retrieve the ViewInfo object in a
1268
         * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
1269
         * to retrieve the ViewInfo object at any time after the creation of the
1270
         * object.
1271
         *
1272
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
1273
         */
1274
        public WindowInfo getWindowInfo() {
1275
                if (m_viewInfo == null) {
1276
                        m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
1277
                                        | WindowInfo.MAXIMIZABLE);
1278
                        m_viewInfo.setWidth(500);
1279
                        m_viewInfo.setHeight(400);
1280

    
1281
                        m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : "
1282
                                        + map.getName());
1283
                }
1284
                return m_viewInfo;
1285
        }
1286

    
1287
        /**
1288
         * Inserta si se muestra o no la regla del Layout.
1289
         *
1290
         * @param b
1291
         *            True si se muestra la regla.
1292
         */
1293
        public void setRuler(boolean b) {
1294
                m_showRuler = new Boolean(b);
1295
        }
1296

    
1297
        /**
1298
         * Devuelve si se muestra la regla del Layout.
1299
         *
1300
         * @return True si se muestra la regla.
1301
         */
1302
        public boolean getRuler() {
1303
                if (m_showRuler == null) {
1304
                        m_showRuler = new Boolean(getDefaultShowRulers());
1305
                }
1306
                return m_showRuler.booleanValue();
1307
        }
1308

    
1309

    
1310

    
1311
        /**
1312
         * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1313
         * cuadr?cula, o no.
1314
         *
1315
         * @return true si se esta aplicando la cuadr?cula.
1316
         */
1317
        public boolean isAdjustingToGrid() {
1318
                if (adjustToGrid == null) {
1319
                        adjustToGrid = new Boolean(getDefaultAdjustToGrid());
1320
                }
1321
                return adjustToGrid.booleanValue();
1322
        }
1323

    
1324
        /**
1325
         * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1326
         * cuadr?cula, o no.
1327
         *
1328
         * @return true si se esta aplicando la cuadr?cula.
1329
         */
1330
        public boolean isGridVisible() {
1331
                if (isGridVisible== null) {
1332
                        isGridVisible = new Boolean(getDefaultShowGrid());
1333
                }
1334
                return isGridVisible.booleanValue();
1335
        }
1336

    
1337
        /**
1338
         * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1339
         *
1340
         * @param b
1341
         *            true si se aplica la cuadr?cula.
1342
         */
1343
        public void setAdjustToGrid(boolean b) {
1344
                adjustToGrid = new Boolean(b);
1345
        }
1346

    
1347
        /**
1348
         * Realiza una exteni?n completa de las capas que contiene la vista del
1349
         * FFrameView.
1350
         *
1351
         * @throws DriverException
1352
         */
1353
        public void viewFull() throws DriverException {
1354
                IFFrame[] fframes = getFFrameSelected();
1355
                for (int i = 0; i < fframes.length; i++) {
1356
                        if (fframes[i] instanceof IFFrameUseFMap) {
1357
                                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
1358

    
1359
                                if (fframe.getMapContext() != null) {
1360
                                        fframe.fullExtent();
1361
                                }
1362
                                fframe.refresh();
1363
                        }
1364
                }
1365
                refresh();
1366
        }
1367

    
1368
        /**
1369
         * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1370
         * para poder despu?s volver a crear el objeto original.
1371
         *
1372
         * @return XMLEntity.
1373
         *
1374
         * @throws XMLException
1375
         */
1376
        public XMLEntity getXMLEntity() {
1377
                XMLEntity xml = new XMLEntity();
1378
                xml.putProperty("className", this.getClass().getName());
1379
                xml.setName("layout");
1380
                xml.putProperty("isCuadricula", isAdjustingToGrid());
1381
                xml.putProperty("m_name", this.getName());
1382
                xml.putProperty("isEditable", isEditable);
1383
                xml.putProperty("numBehind", numBehind);
1384
                xml.putProperty("numBefore", numBefore);
1385
                xml.addChild(getAtributes().getXMLEntity());
1386
                IFFrame[] fframes=getFFrames();
1387
                for (int i = 0; i < fframes.length; i++) {
1388
                        try {
1389
                                XMLEntity xmlAux = fframes[i].getXMLEntity();
1390
                                xml.addChild(xmlAux);
1391
                        } catch (SaveException e) {
1392
                                e.showError();
1393
                        }
1394
                }
1395
                return xml;
1396
        }
1397

    
1398
        /**
1399
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1400
         *
1401
         * @param xml
1402
         *            XMLEntity
1403
         * @param p
1404
         *            Proyecto.
1405
         *
1406
         * @return Objeto de esta clase.
1407
         * @throws OpenException
1408
         */
1409
        public static Layout createLayout(XMLEntity xml, Project p)
1410
                        throws OpenException {
1411
                Layout layout = new Layout();
1412
                try {
1413
                        layout.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
1414
                        layout.setName(xml.getStringProperty("m_name"));
1415
                        layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1416
                        if (xml.contains("isEditable")) {
1417
                                layout.setEditable(xml.getBooleanProperty("isEditable"));
1418
                        }
1419
                        if (xml.contains("numBehind")) {
1420
                                layout.numBehind = xml.getIntProperty("numBehind");
1421
                                layout.numBefore = xml.getIntProperty("numBefore");
1422
                        }
1423
                        layout.getEFS().startComplexCommand();
1424
                        for (int i = 1; i < xml.getChildrenCount(); i++) {
1425
                                try {
1426
                                        layout.addFFrame(FFrame.createFFrame(xml.getChild(i), p,
1427
                                                        layout), true, false);
1428
                                } catch (OpenException e) {
1429
                                        e.showError();
1430
                                }
1431
                        }
1432
                        layout.getEFS().endComplexCommand(PluginServices.getText(layout,"Inicializando"));
1433
                        IFFrame[] fframes = layout.getAllFFrames();
1434
                        for (int i = 0; i < fframes.length; i++) {
1435
                                if (fframes[i] instanceof IFFrameLayoutDependence) {
1436
                                        ((IFFrameLayoutDependence) fframes[i]).setLayout(layout);
1437
                                }
1438
                                if (fframes[i] instanceof IFFrameViewDependence) {
1439
                                        ((IFFrameViewDependence) fframes[i])
1440
                                                        .initDependence(fframes);
1441
                                }
1442
                        }
1443
                } catch (Exception e) {
1444
                        throw new OpenException(e, layout.getClass().getName());
1445
                }
1446
                return layout;
1447
        }
1448

    
1449
        /**
1450
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1451
         *
1452
         * @param xml
1453
         *            XMLEntity
1454
         * @param p
1455
         *            Proyecto.
1456
         *
1457
         * @return Objeto de esta clase.
1458
         */
1459
        public static Layout createLayout03(XMLEntity xml, Project p) {
1460
                Layout layout = new Layout();
1461
                layout.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
1462
                layout.setName(xml.getStringProperty("m_name"));
1463
                layout.m_attributes = Attributes.createAtributes03(xml.getChild(0));
1464

    
1465
                for (int i = 1; i < xml.getChildrenCount(); i++) {
1466
                        if (xml.getChild(i).getStringProperty("className").equals(
1467
                                        "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1468
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1469
                                                p), true, false);
1470
                        }
1471
                }
1472

    
1473
                for (int i = 1; i < xml.getChildrenCount(); i++) {
1474
                        if (!xml.getChild(i).getStringProperty("className").equals(
1475
                                        "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1476
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1477
                                                p), true, false);
1478
                        }
1479
                }
1480

    
1481
                return layout;
1482
        }
1483

    
1484
        /**
1485
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
1486
         */
1487
        public void windowActivated() {
1488
                //fullRect();
1489
                refresh();
1490
                PluginServices.getMainFrame().getStatusBar().setMessage("units",
1491
                                PluginServices.getText(this, getAtributes().getNameUnit()));
1492
        }
1493

    
1494
        /**
1495
         * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
1496
         */
1497
        public Object getWindowModel() {
1498
                return map;
1499
        }
1500

    
1501
        /**
1502
         * Devuelve si se dibuja el Grid en el Layout o no.
1503
         *
1504
         * @return True si se dibuja el Grid en el Layout.
1505
         */
1506
        public boolean getGridVisible() {
1507
                if (isGridVisible== null) {
1508
                        isGridVisible = new Boolean(getDefaultShowGrid());
1509
                }
1510
                return isGridVisible.booleanValue();
1511
        }
1512

    
1513
        /**
1514
         * Inserta si se muestra el Grid del Layout.
1515
         *
1516
         * @param b
1517
         *            True si se muestra el Grid del Layout.
1518
         */
1519
        public void setGridVisible(boolean b) {
1520
                isGridVisible = new Boolean(b);
1521
        }
1522

    
1523
        /**
1524
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1525
         */
1526
        public void extentChanged(ExtentEvent e) {
1527
        }
1528

    
1529
        /**
1530
         * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
1531
         */
1532
        public void windowClosed() {
1533
                // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1534
        }
1535

    
1536
        /**
1537
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1538
         */
1539
        public void backColorChanged(ColorEvent e) {
1540
                // refresh();
1541
        }
1542

    
1543
        /**
1544
         * Devuelve un array con los FFrames seleccionados.
1545
         *
1546
         * @return Array con los FFrames seleccionados.
1547
         */
1548
        public IFFrame[] getFFrameSelected() {
1549
                ArrayList selecList = new ArrayList();
1550
                IFFrame[] fframes=getFFrames();
1551
                for (int i = fframes.length - 1; i >= 0; i--) {
1552
                        IFFrame fframe = fframes[i];
1553

    
1554
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1555
                                selecList.add(fframe);
1556
                        }
1557
                }
1558

    
1559
                return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1560
        }
1561

    
1562
        /**
1563
         * Opens a dialog where to pick a PDF-file to save the current Layout
1564
         * suggesting a name for the file given by the first argument
1565
         *
1566
         * @param suggestedName
1567
         */
1568
        public void layoutToPDF(String suggestedName) {
1569
                FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices
1570
                                .getText(this, "pdf"));
1571

    
1572
                JFileChooser jfc = new JFileChooser();
1573
                if (suggestedName != null)
1574
                        jfc.setSelectedFile(new File(suggestedName));
1575
                jfc.addChoosableFileFilter(pdfFilter);
1576
                jfc.setFileFilter(pdfFilter);
1577

    
1578
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1579
                        File f = jfc.getSelectedFile();
1580
                        File faux = null;
1581

    
1582
                        if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
1583
                                faux = f;
1584
                        } else {
1585
                                faux = new File(f.getPath() + ".pdf");
1586
                        }
1587

    
1588
                        layoutDraw.toPDF(faux);
1589
                }
1590
        }
1591
        /**
1592
         * Opens a dialog where to pick a PS-file to save the current Layout
1593
         * suggesting a name for the file given by the first argument
1594
         *
1595
         * @param suggestedName
1596
         */
1597
        public void layoutToPS(String suggestedName) {
1598
                FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices
1599
                                .getText(this, "ps"));
1600

    
1601
                JFileChooser jfc = new JFileChooser();
1602
                if (suggestedName != null)
1603
                        jfc.setSelectedFile(new File(suggestedName));
1604
                jfc.addChoosableFileFilter(pdfFilter);
1605
                jfc.setFileFilter(pdfFilter);
1606

    
1607
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1608
                        File f = jfc.getSelectedFile();
1609
                        File faux = null;
1610

    
1611
                        if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
1612
                                faux = f;
1613
                        } else {
1614
                                faux = new File(f.getPath() + ".ps");
1615
                        }
1616

    
1617
                        layoutDraw.toPS(faux);
1618
                }
1619
        }
1620
        /**
1621
         * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1622
         * en este formato.
1623
         */
1624
        public void layoutToPDF() {
1625
                layoutToPDF(null);
1626
        }
1627
        /**
1628
         * Abre un di?logo para seleccionar un fichero ps donde guardar el Layout
1629
         * en este formato.
1630
         */
1631
        public void layoutToPS() {
1632
                layoutToPS(null);
1633
        }
1634
        /**
1635
         * @return Returns the bModeDebug.
1636
         */
1637
        public boolean showIconTag() {
1638
                return bShowIconTag;
1639
        }
1640

    
1641
        /**
1642
         * @param modeDebug
1643
         *            The bModeDebug to set.
1644
         */
1645
        public void setShowIconTag(boolean modeDebug) {
1646
                bShowIconTag = modeDebug;
1647
        }
1648

    
1649
        private ArrayList allFFrames(IFFrame[] fframes, ArrayList all) {
1650
                for (int i = 0; i < fframes.length; i++) {
1651
                        if (fframes[i] instanceof FFrameGroup) {
1652
                                return allFFrames(((FFrameGroup) fframes[i]).getFFrames(), all);
1653

    
1654
                        }
1655
                                all.add(fframes[i]);
1656
                }
1657
                return all;
1658
        }
1659

    
1660
        public IFFrame[] getAllFFrames() {
1661
                ArrayList all = new ArrayList();
1662
                return (IFFrame[]) allFFrames(getFFrames(), all)
1663
                                .toArray(new IFFrame[0]);
1664
        }
1665

    
1666
        public GeometryAdapter getGeometryAdapter() {
1667
                return geometryAdapter;
1668
        }
1669

    
1670
        public boolean isEditable() {
1671
                return isEditable;
1672
        }
1673

    
1674
        public void setEditable(boolean b) {
1675
                if (!b) {
1676
                        clearSelection();
1677
                        setTool(Layout.ZOOM_MAS);
1678
                        PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
1679
                }
1680
                isEditable = b;
1681

    
1682
        }
1683

    
1684
        public void initGeometryAdapter() {
1685
                if (getTool() == LINE) {
1686
                        geometryAdapter = new PolyLineAdapter();
1687
                } else if (getTool() == RECTANGLESIMPLE) {
1688
                        geometryAdapter = new RectangleAdapter();
1689
                } else if (getTool() == POLYLINE) {
1690
                        geometryAdapter = new PolyLineAdapter();
1691
                } else if (getTool() == POLYGON) {
1692
                        geometryAdapter = new PolygonAdapter();
1693
                } else if (getTool() == CIRCLE) {
1694
                        geometryAdapter = new CircleAdapter();
1695
                } else if (getTool() == POINT) {
1696
                        geometryAdapter = new PointAdapter();
1697
                }
1698
        }
1699

    
1700
        public void startEdit() {
1701
                IFFrame[] fframes=getFFrames();
1702
                for (int i = 0; i < fframes.length; i++) {
1703
                        IFFrame frame = fframes[i];
1704
                        if (frame instanceof IFFrameEditableVertex) {
1705
                                if (frame.getSelected() != IFFrame.NOSELECT) {
1706
                                        ((IFFrameEditableVertex) frame).startEditing();
1707
                                } else {
1708
                                        ((IFFrameEditableVertex) frame).stopEditing();
1709
                                }
1710
                        }
1711

    
1712
                }
1713
                refresh();
1714
        }
1715

    
1716
        public void stopEdit() {
1717
                boolean refresh = false;
1718
                IFFrame[] fframes=getFFrames();
1719
                for (int i = 0; i < fframes.length; i++) {
1720
                        IFFrame frame = fframes[i];
1721
                        if (frame instanceof IFFrameEditableVertex) {
1722
                                if (((IFFrameEditableVertex) frame).isEditing()) {
1723
                                        ((IFFrameEditableVertex) fframes[i]).stopEditing();
1724
                                        refresh = true;
1725
                                }
1726
                        }
1727
                }
1728
                if (refresh)
1729
                        refresh();
1730
        }
1731

    
1732
        public void delFFrameSelected() {
1733
                efs.startComplexCommand();
1734
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1735
                        IFFrame fframe = efs.getFFrame(i);
1736

    
1737
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1738
                                efs.removeFFrame(i);
1739
                        }
1740
                }
1741
                efs.endComplexCommand(PluginServices.getText(this,"remove_elements"));
1742
                updateFFrames();
1743
        }
1744

    
1745
        public void clearSelection() {
1746
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1747
                        IFFrame fframe = efs.getFFrame(i);
1748
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1749
                                fframe.setSelected(false);
1750
                        }
1751
                }
1752
        }
1753
        public void delFFrame(int index) {
1754
                for (int i = 0; i < getEFS().getAllFFrames().length; i++) {
1755
                        if (getEFS().getFFrame(i).equals(getFFrame(index))) {
1756
                                getEFS().removeFFrame(i);
1757
                        }
1758
                }
1759
                updateFFrames();
1760
        }
1761

    
1762
        public void delFFrame(IFFrame frame) {
1763
                for (int i = 0; i < getEFS().getAllFFrames().length; i++) {
1764
                        if (getEFS().getFFrame(i).equals(frame)) {
1765
                                getEFS().removeFFrame(i);
1766
                        }
1767
                }
1768
                updateFFrames();
1769
        }
1770

    
1771
        public EditableFeatureSource getEFS() {
1772
                return efs;
1773
        }
1774

    
1775
        public void commandRepaint() {
1776
                this.updateFFrames();
1777
                this.refresh();
1778
        }
1779

    
1780
        public void commandRefresh() {
1781
                commandRepaint();
1782

    
1783
        }
1784

    
1785
        /**
1786
         * Introduce la posibilidad de establecer que los cambios que se hacen a
1787
         * partir de ese momento hasta que se vuelva a poner a false, que todas las
1788
         * operaciones que realices son sobre los fframes que implementen
1789
         * IFFrameGroupSelectable.
1790
         *
1791
         * @param b
1792
         */
1793
        public void setEditGroup(boolean b) {
1794
                editGroup = b;
1795
        }
1796

    
1797
        /**
1798
         * Devuelve true si se est? en modo de edici?n de los fframes que
1799
         * implementen IFFrameGroupSelectable.
1800
         *
1801
         * @return
1802
         */
1803
        public boolean isEditGroup() {
1804
                return editGroup;
1805
        }
1806

    
1807
        public int getNumBehind() {
1808
                return --numBehind;
1809
        }
1810

    
1811
        public int getNumBefore() {
1812
                return ++numBefore;
1813
        }
1814

    
1815
        public void projectionChanged(ProjectionEvent e) {
1816
                // TODO Auto-generated method stub
1817

    
1818
        }
1819

    
1820
         public void endGraphic() {
1821
                if ((getTool() == Layout.LINE)
1822
                                || (getTool() == Layout.POLYLINE)
1823
                                || (getTool() == Layout.POLYGON)
1824
                                || (getTool() == Layout.CIRCLE)
1825
                                || (getTool() == Layout.RECTANGLESIMPLE)
1826
                                || (getTool() == Layout.POINT)) {
1827
                        getGeometryAdapter().end();
1828
                        PluginServices.getMainFrame().enableControls();
1829
                        FLayoutFunctions lf=new FLayoutFunctions(this);
1830
                        lf.addFFrame();
1831
                        initGeometryAdapter();
1832
                        refresh();
1833
                }
1834
        }
1835

    
1836
        public void delLastPoint() {
1837
                getGeometryAdapter().delLastPoint();
1838
        }
1839

    
1840
        public static boolean getDefaultShowGrid() {
1841
                if (defaultShowGrid == null) {
1842
                        XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
1843
                        if (xml.contains("DefaultShowLayoutGrid")) {
1844
                                defaultShowGrid = new Boolean(xml.getBooleanProperty("DefaultShowLayoutGrid"));
1845
                        }
1846
                        else {
1847
                                // factory default is true
1848
                                defaultShowGrid = new Boolean(true);
1849
                        }
1850
                }
1851
                return defaultShowGrid.booleanValue();
1852
        }
1853

    
1854
        public static boolean getDefaultAdjustToGrid() {
1855
                if (defaultAdjustToGrid == null) {
1856
                        XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
1857
                        if (xml.contains("DefaultEnableLayoutGrid")) {
1858
                                defaultAdjustToGrid = new Boolean(xml.getBooleanProperty("DefaultEnableLayoutGrid"));
1859
                        }
1860
                        else {
1861
                                // factory default is false
1862
                                defaultAdjustToGrid = new Boolean(false);
1863
                        }
1864
                }
1865
                return defaultAdjustToGrid.booleanValue();
1866
        }
1867

    
1868
        private static boolean getDefaultShowRulers() {
1869
                if (defaultShowRulers == null){
1870
                        XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
1871
                        if (xml.contains("DefaultShowLayoutRules")) {
1872
                                defaultShowRulers = new Boolean(xml.getBooleanProperty("DefaultShowLayoutRules"));
1873
                        }
1874
                        else {
1875
                                // factory default is true
1876
                                defaultShowRulers = new Boolean(true);
1877
                        }
1878
                }
1879
                return defaultShowRulers.booleanValue();
1880
        }
1881

    
1882
        public static void setDefaultShowGrid(boolean showGrid) {
1883
                defaultShowGrid = new Boolean(showGrid);
1884
        }
1885

    
1886
        public static void setDefaultAdjustToGrid(boolean gridEnabled) {
1887
                defaultAdjustToGrid = new Boolean(gridEnabled);
1888
        }
1889

    
1890
        public static void setDefaultShowRulers(boolean showRules) {
1891
                defaultShowRulers  = new Boolean(showRules);
1892
        }
1893

    
1894
}