Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / Layout.java @ 6711

History | View | Annotate | Download (46.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 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 org.apache.log4j.Logger;
88

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

    
144
/**
145
 * Mapa.
146
 *
147
 * @author Vicente Caballero Navarro
148
 */
149
public class Layout extends JPanel implements SingletonView, ViewPortListener,
150
                ViewListener, CommandListener {
151
        private static Logger logger = Logger.getLogger(Layout.class.getName());
152

    
153
        public static final int ZOOM_MAS = 1;
154

    
155
        public static final int ZOOM_MENOS = 2;
156

    
157
        public static final int PAN = 3;
158

    
159
        public static final int DESACTUALIZADO = 4;
160

    
161
        public static final int ACTUALIZADO = 5;
162

    
163
        public static final int SELECT = 6;
164

    
165
        public static final int RECTANGLE = 10;
166

    
167
        public static final int RECTANGLEVIEW = 11;
168

    
169
        public static final int RECTANGLEPICTURE = 12;
170

    
171
        public static final int RECTANGLESCALEBAR = 13;
172

    
173
        public static final int RECTANGLELEGEND = 14;
174

    
175
        public static final int RECTANGLETEXT = 15;
176

    
177
        public static final int RECTANGLEGROUP = 16;
178

    
179
        public static final int RECTANGLESYMBOL = 17;
180

    
181
        public static final int RECTANGLENORTH = 18;
182

    
183
        public static final int RECTANGLEBOX = 19;
184

    
185
        public static final int GRAPHICS = 20;
186

    
187
        public static final int POINT = 21;
188

    
189
        public static final int LINE = 22;
190

    
191
        public static final int POLYLINE = 23;
192

    
193
        public static final int RECTANGLESIMPLE = 24;
194

    
195
        public static final int CIRCLE = 25;
196

    
197
        public static final int POLYGON = 26;
198

    
199
        public static final int VIEW_ZOOMIN = 30;
200

    
201
        public static final int VIEW_ZOOMOUT = 31;
202

    
203
        public static final int VIEW_FULL = 32;
204

    
205
        public static final int VIEW_PAN = 33;
206

    
207
        public static final int SET_TAG = 34;
208

    
209
        public static final int EDIT = 40;
210

    
211
        public static final Image iLayoutpan = new ImageIcon(AddLayer.class
212
                        .getClassLoader().getResource("images/LayoutHand.gif")).getImage();
213

    
214
        public static final Image ipan = new ImageIcon(AddLayer.class
215
                        .getClassLoader().getResource("images/Hand.gif")).getImage();
216

    
217
        public static final Image iLayoutzoomin = new ImageIcon(AddLayer.class
218
                        .getClassLoader().getResource("images/LayoutZoomInCursor.gif"))
219
                        .getImage();
220

    
221
        public static final Image izoomin = new ImageIcon(AddLayer.class
222
                        .getClassLoader().getResource("images/ZoomInCursor.gif"))
223
                        .getImage();
224

    
225
        public static final Image iLayoutzoomout = new ImageIcon(AddLayer.class
226
                        .getClassLoader().getResource("images/LayoutZoomOutCursor.gif"))
227
                        .getImage();
228

    
229
        public static final Image izoomout = new ImageIcon(AddLayer.class
230
                        .getClassLoader().getResource("images/ZoomOutCursor.gif"))
231
                        .getImage();
232

    
233
        public static final Image iinfo = new ImageIcon(AddLayer.class
234
                        .getClassLoader().getResource("images/InfoCursor.gif")).getImage();
235

    
236
        public static final Image icrux = new ImageIcon(AddLayer.class
237
                        .getClassLoader().getResource("images/CruxCursor.png")).getImage();
238

    
239
        public static final Image itag = new ImageIcon(AddLayer.class
240
                        .getClassLoader().getResource("images/tagCursor.gif")).getImage();
241

    
242
        public static final Image iPoint = new ImageIcon(AddLayer.class
243
                        .getClassLoader().getResource("images/PointCursor.png")).getImage();
244

    
245
        public static final Image iRect = new ImageIcon(AddLayer.class
246
                        .getClassLoader().getResource("images/RectCursor.png")).getImage();
247

    
248
        public static final Image iLine = new ImageIcon(AddLayer.class
249
                        .getClassLoader().getResource("images/LineCursor.png")).getImage();
250

    
251
        public static final Image iRectangle = new ImageIcon(AddLayer.class
252
                        .getClassLoader().getResource("images/RectangleCursor.png"))
253
                        .getImage();
254

    
255
        public static final Image iCircle = new ImageIcon(AddLayer.class
256
                        .getClassLoader().getResource("images/CircleCursor.png"))
257
                        .getImage();
258

    
259
        public static final Image iPoligon = new ImageIcon(AddLayer.class
260
                        .getClassLoader().getResource("images/PoligonCursor.png"))
261
                        .getImage();
262

    
263
        public static Hashtable nums = new Hashtable();
264

    
265
        private Point origin = new Point(50, 50);
266

    
267
        private Point rectOrigin = new Point(origin);
268

    
269
        private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
270
                        rectOrigin.y, 400, 300);
271

    
272
        private Point m_FirstPoint = new Point(0, 0);
273

    
274
        private Point m_PointAnt = new Point(0, 0);
275

    
276
        private Point m_LastPoint = new Point(0, 0);
277

    
278
        private EventsHandler events;
279

    
280
        private int tool = ZOOM_MAS;
281

    
282
        private int status = DESACTUALIZADO;
283

    
284
        private BufferedImage img = null;
285

    
286
        private BufferedImage imgRuler = null;
287

    
288
        private AffineTransform m_MatrizTransf;
289

    
290
        private Rectangle2D rectVisible;
291

    
292
        private IFFrameDialog fframedialog = null;
293

    
294
        private IFFrame[] fframes;
295

    
296
        private MapProperties m_propertiesLayout = null;
297

    
298
        private Attributes m_attributes = null;
299

    
300
        private PrintService[] m_cachePrintServices = null;
301

    
302
        private PrintService m_cachePrintService = null;
303

    
304
        private boolean m_bCancelDrawing = false;
305

    
306
        private boolean isCuadricula = false;
307

    
308
        private boolean initial = true;
309

    
310
        private ProjectMap map = null;
311

    
312
        private Rectangle reSel = null;
313

    
314
        private boolean isReSel = true;
315

    
316
        private boolean m_showRuler = true;
317

    
318
        private FLayoutDraw layoutDraw = null;
319

    
320
        private boolean isDrawCuadricula = true;
321

    
322
        private Doc doc = null;
323

    
324
        private PrintRequestAttributeSet att = null;
325

    
326
        private GeometryAdapter geometryAdapter = new PolyLineAdapter();
327

    
328
        private DefaultEditableFeatureSource efs;
329

    
330
        private boolean isEditable = true;
331

    
332
        private ViewInfo m_viewInfo = null;
333

    
334
        private int numBefore = 0;
335

    
336
        private int numBehind = 0;
337

    
338
        /**
339
         * Lo usamos cuando estamos haciendo una ficha y asignando tags Se pone en
340
         * modo debug cuando hacemos un VIEW_TAGS
341
         */
342
        private boolean bModeDebug = false;
343

    
344
        private boolean editGroup;
345

    
346
        /**
347
         * Creates a new Layout object.
348
         */
349
        public Layout() {
350
                efs = new DefaultEditableFeatureSource();
351
                updateFFrames();
352
                this.setLayout(null);
353
                events = new EventsHandler(this);
354
                layoutDraw = new FLayoutDraw(this);
355
                addComponentListener(events);
356
                addMouseMotionListener(events);
357
                addMouseListener(events);
358
                m_MatrizTransf = new AffineTransform();
359
                m_MatrizTransf.setToIdentity();
360
                this.initComponents();
361
        }
362

    
363
        /**
364
         * Rellena el ProjectMap del Layout.
365
         *
366
         * @param m
367
         *            ProjectMap.
368
         */
369
        public void setProjectMap(ProjectMap m) {
370
                map = m;
371
                this.setName(m.getName());
372
                map.addPropertyChangeListener(new PropertyChangeListener() {
373
                        public void propertyChange(PropertyChangeEvent evt) {
374
                                if (evt.getPropertyName().equals("name")) {
375
                                        PluginServices.getMDIManager().getViewInfo(Layout.this)
376
                                                        .setTitle(
377
                                                                        PluginServices.getText(this, "Mapa")
378
                                                                                        + " : "
379
                                                                                        + (String) evt.getNewValue());
380
                                }
381
                        }
382
                });
383
        }
384

    
385
        /**
386
         * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
387
         *
388
         * @return Rect?ngulo de selecci?n.
389
         */
390
        public Rectangle getReSel() {
391
                return reSel;
392
        }
393

    
394
        /**
395
         * Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar la
396
         * sellecci?n.
397
         *
398
         * @return true si se realiza la selecci?n por rect?ngulo.
399
         */
400
        public boolean isReSel() {
401
                return isReSel;
402
        }
403

    
404
        /**
405
         * Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
406
         * selecci?n.
407
         *
408
         * @param b
409
         *            boolean.
410
         */
411
        public void setIsReSel(boolean b) {
412
                isReSel = b;
413
        }
414

    
415
        /**
416
         * Devuelve true si el dibujado ha sido cancelado.
417
         *
418
         * @return true si el dibujado ha sido cancelado.
419
         */
420
        public synchronized boolean isDrawingCancelled() {
421
                return m_bCancelDrawing;
422
        }
423

    
424
        /**
425
         * Pone el dibuja a cancelado o no seg?n se quiera.
426
         *
427
         * @param b
428
         *            true si se quiere cancelar el dibujado.
429
         */
430
        public synchronized void setCancelDrawing(boolean b) {
431
                m_bCancelDrawing = b;
432

    
433
                for (int i = 0; i < getFFrames().length; i++) {
434
                        IFFrame fframe = getFFrame(i);
435

    
436
                        if (fframe instanceof IFFrameUseFMap
437
                                        && (((IFFrameUseFMap) fframe).getFMap() != null)) {
438
                                // //TODO((FFrameView)
439
                                // getFFrames().get(i)).getFMap().setCancelDrawing(b);
440
                        }
441
                }
442
        }
443

    
444
        /**
445
         * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
446
         *
447
         * @return Array con todos los fframes que contiene el Layout.
448
         */
449
        public IFFrame[] getFFrames() {
450
                return fframes;
451
        }
452

    
453
        public IFFrame getFFrame(int i) {
454
                return fframes[i];
455
        }
456

    
457
        public void updateFFrames() {
458
                ArrayList frames = new ArrayList();
459
                IFFrame[] auxfframes = efs.getFFrames();
460
                for (int j = numBehind; j <= numBefore; j++) {
461
                        for (int i = 0; i < auxfframes.length; i++) {
462
                                if (auxfframes[i].getLevel() == j) {
463
                                        frames.add(auxfframes[i]);
464
                                        continue;
465
                                }
466
                        }
467
                }
468
                fframes = (IFFrame[]) frames.toArray(new IFFrame[0]);
469
        }
470

    
471
        /**
472
         * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
473
         * entero.
474
         */
475
        public void fullRect() {
476
                rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
477
                                getHeight() - (origin.x * 2));
478

    
479
                if (m_attributes.isLandSpace()) {
480
                        rect = m_attributes.getRectangleLandscape(rect, getWidth(),
481
                                        getHeight());
482
                } else {
483
                        rect = m_attributes.getRectanglePortrait(rect, getWidth(),
484
                                        getHeight());
485
                }
486
                refresh();
487
        }
488

    
489
        /**
490
         * M?todo para imprimir el Layout sin modificar la matriz de transformaci?n.
491
         *
492
         * @param g2
493
         */
494
        public void drawLayoutPrint(Graphics2D g2) {
495
                setCancelDrawing(false);
496

    
497
                setCursor(Cursor.getDefaultCursor());
498

    
499
                double scale = 0;
500
                scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
501
                AffineTransform escalado = new AffineTransform();
502
                AffineTransform translacion = new AffineTransform();
503
                translacion.setToTranslation(rect.getMinX(), rect.getMinY());
504
                escalado.setToScale(scale, scale);
505
                m_MatrizTransf.setToIdentity();
506
                m_MatrizTransf.concatenate(translacion);
507
                m_MatrizTransf.concatenate(escalado);
508
                m_attributes.setDistanceUnitX(rect);
509
                m_attributes.setDistanceUnitY(rect);
510
                IFFrame[] fframes=getFFrames();
511
                for (int i = 0; i < fframes.length; i++) {
512
                        try {
513
                                fframes[i].print(g2, getAT());
514
                        } catch (DriverException e) {
515
                                NotificationManager.addError(e.getMessage(), e);
516
                        }
517
                }
518

    
519
                // TODO Esto es para ver el rect?ngulo que representa el folio en la
520
                // impresi?n.
521
                g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
522
                // setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
523
        }
524

    
525
        /**
526
         * Clip sobre el rect?ngulo visible.
527
         *
528
         * @param g2d
529
         *            Graphics sobre el que hacer el clip.
530
         */
531
        private void clipVisibleRect(Graphics2D g2d) {
532
                rectVisible = this.getVisibleRect();
533
                g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
534
                                (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
535
        }
536

    
537
        /**
538
         * Inicializa los componentes.
539
         */
540
        private void initComponents() {
541
                m_attributes = new Attributes();
542
                m_attributes.setDistanceUnitX(rect);
543
                m_attributes.setDistanceUnitY(rect);
544
                //actionDelFFrame();
545
                setDoubleBuffered(true);
546
        }
547

    
548
        /**
549
         * paintComponent del Layout.
550
         *
551
         * @param g
552
         *            Graphics del Layout.
553
         */
554
        protected void paintComponent(Graphics g) {
555
                super.paintComponent(g);
556

    
557
                clipVisibleRect((Graphics2D) g);
558

    
559
                Rectangle rClip = g.getClipBounds();
560

    
561
                if (rClip == null) {
562
                        System.err.println("clip = null");
563
                }
564

    
565
                switch (status) {
566
                case ZOOM_MAS:
567
                        logger.debug("zoom mas");
568
                        layoutDraw.drawRectangle((Graphics2D) g);
569

    
570
                        g.drawImage(img, 0, 0, this);
571

    
572
                        g.setClip(rClip);
573
                        g.drawImage(imgRuler, 0, 0, this);
574
                        g.setColor(Color.black);
575
                        g.setXORMode(Color.white);
576

    
577
                        Rectangle r = new Rectangle();
578

    
579
                        r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
580
                        g.drawRect(r.x, r.y, r.width, r.height);
581

    
582
                        break;
583

    
584
                case RECTANGLE:
585
                        logger.debug("rectangle");
586
                        layoutDraw.drawRectangle((Graphics2D) g);
587

    
588
                        g.drawImage(img, 0, 0, this);
589

    
590
                        g.setClip(rClip);
591
                        g.drawImage(imgRuler, 0, 0, this);
592
                        g.setColor(Color.black);
593
                        g.setXORMode(Color.white);
594

    
595
                        Rectangle re = new Rectangle();
596
                        re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
597

    
598
                        if (isCuadricula()) {
599
                                FLayoutUtilities.setRectGrid(re, m_attributes
600
                                                .getUnitInPixelsX(), m_attributes.getUnitInPixelsY(),
601
                                                m_MatrizTransf);
602
                        }
603

    
604
                        g.drawRect(re.x, re.y, re.width, re.height);
605

    
606
                        break;
607

    
608
                case PAN:
609
                        logger.debug("pan");
610

    
611
                        rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
612
                        rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
613

    
614
                        layoutDraw.drawRectangle((Graphics2D) g);
615

    
616
                        if (img != null) {
617
                                g.drawImage(img, (getLastPoint().x - getPointAnt().x),
618
                                                (getLastPoint().y - getPointAnt().y), this);
619
                        }
620

    
621
                        g.setClip(rClip);
622
                        layoutDraw.drawGrid((Graphics2D) g);
623
                        layoutDraw.drawRuler((Graphics2D) g, Color.black);
624
                        break;
625

    
626
                case VIEW_PAN:
627

    
628
                        logger.debug("View pan");
629
                        layoutDraw.drawRectangle((Graphics2D) g);
630

    
631
                        for (int i = 0; i < getFFrames().length; i++) {
632
                                if (getFFrame(i) instanceof IFFrameUseFMap) {
633
                                        IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
634

    
635
                                        if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
636
                                                Rectangle2D.Double rec = ((IFFrame) fframe)
637
                                                                .getBoundingBox(getAT());
638

    
639
                                                if (img != null) {
640
                                                        rec = (Rectangle2D.Double) rec
641
                                                                        .createIntersection(getVisibleRect());
642
                                                }
643

    
644
                                                if (fframe.getBufferedImage() != null) {
645
                                                        layoutDraw
646
                                                                        .drawHandlers((Graphics2D) g, Color.black);
647
                                                        g.clipRect((int) rec.x, (int) rec.y,
648
                                                                        (int) rec.width, (int) rec.height);
649

    
650
                                                        layoutDraw.drawRectangle((Graphics2D) g);
651
                                                        layoutDraw.drawRuler((Graphics2D) g, Color.black);
652
                                                        Rectangle2D.Double r1 = ((IFFrame) fframe)
653
                                                                        .getBoundingBox(getAT());
654
                                                        g.drawImage(fframe.getBufferedImage(), (int) r1
655
                                                                        .getX()
656
                                                                        + m_LastPoint.x - m_PointAnt.x, (int) r1
657
                                                                        .getY()
658
                                                                        + m_LastPoint.y - m_PointAnt.y, this);
659

    
660
                                                        fframe.refresh();
661
                                                }
662
                                        }
663
                                }
664
                        }
665

    
666
                        g.setClip(rClip);
667
                        g.drawImage(imgRuler, 0, 0, this);
668

    
669
                        break;
670

    
671
                case SELECT:
672
                        logger.debug("select");
673
                        layoutDraw.drawRectangle((Graphics2D) g);
674

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

    
677
                        if (isReSel) {
678
                                reSel = new Rectangle();
679
                                reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
680
                                g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
681
                        }
682
                        IFFrame[] frames = getFFrameSelected();
683
                        for (int i = 0; i < frames.length; i++) {
684
                                g.setColor(Color.black);
685
                                frames[i].drawHandlers((Graphics2D) g);
686
                                int difx = (m_LastPoint.x - m_FirstPoint.x);
687
                                int dify = (m_LastPoint.y - m_FirstPoint.y);
688
                                if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
689
                                        Rectangle2D rectangle = frames[i].getMovieRect(difx, dify);
690
                                        if (rectangle == null)
691
                                                return;
692
                                        ((Graphics2D) g).rotate(Math.toRadians(frames[i]
693
                                                        .getRotation()), rectangle.getX()
694
                                                        + (rectangle.getWidth() / 2), rectangle.getY()
695
                                                        + (rectangle.getHeight() / 2));
696

    
697
                                        if (rectangle != null) {
698
                                                if (isCuadricula) {
699
                                                        FLayoutUtilities.setRectGrid(rectangle,
700
                                                                        m_attributes.getUnitInPixelsX(),
701
                                                                        m_attributes.getUnitInPixelsY(),
702
                                                                        m_MatrizTransf);
703
                                                }
704

    
705
                                                g.drawRect((int) rectangle.getMinX(), (int) rectangle
706
                                                                .getMinY(), (int) rectangle.getWidth(),
707
                                                                (int) rectangle.getHeight());
708
                                        }
709

    
710
                                        ((Graphics2D) g).rotate(Math.toRadians(-frames[i]
711
                                                        .getRotation()), rectangle.getX()
712
                                                        + (rectangle.getWidth() / 2), rectangle.getY()
713
                                                        + (rectangle.getHeight() / 2));
714

    
715
                                }
716
                        }
717

    
718
                        g.setClip(rClip);
719
                        g.drawImage(imgRuler, 0, 0, this);
720

    
721
                        break;
722
                case GRAPHICS:
723
                        logger.debug("graphics");
724
                        layoutDraw.drawRectangle((Graphics2D) g);
725
                        g.drawImage(img, 0, 0, this);
726
                        g.setClip(rClip);
727
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
728

    
729
                        if (getTool() == EDIT) {
730
                                IFFrame[] fframeSelect = getFFrameSelected();
731
                                for (int i = 0; i < fframeSelect.length; i++) {
732
                                        if (fframeSelect[i] instanceof IFFrameEditableVertex) {
733
                                                ((IFFrameEditableVertex) fframeSelect[i]).paint(
734
                                                                (Graphics2D) g, getAT());
735
                                        }
736
                                }
737
                        } else {
738
                                geometryAdapter.paint((Graphics2D) g, getAT(), true);
739
                        }
740
                        g.drawImage(imgRuler, 0, 0, this);
741
                        break;
742

    
743
                case DESACTUALIZADO:
744
                        logger.debug("desactualizado");
745
                        img = new BufferedImage(getWidth(), getHeight(),
746
                                        BufferedImage.TYPE_INT_ARGB);
747
                        imgRuler = new BufferedImage(getWidth(), getHeight(),
748
                                        BufferedImage.TYPE_INT_ARGB);
749
                        Graphics gimag = img.getGraphics();
750
                        Graphics gimgRuler = imgRuler.getGraphics();
751

    
752
                        clipVisibleRect((Graphics2D) gimag);
753

    
754
                        if (initial) {
755
                                fullRect();
756
                                initial = false;
757
                        }
758

    
759
                        try {
760
                                layoutDraw.drawLayout((Graphics2D) gimag, img);
761
                        } catch (DriverException e) {
762
                                e.printStackTrace();
763
                        }
764

    
765
                        g.setClip(rClip);
766
                        layoutDraw.drawRectangle((Graphics2D) g);
767

    
768
                        g.drawImage(img, 0, 0, this);
769
                        g.setClip(rClip);
770

    
771
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
772
                        layoutDraw.drawGrid((Graphics2D) gimgRuler);
773
                        layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
774
                        g.drawImage(imgRuler, 0, 0, this);
775

    
776
                        break;
777

    
778
                case ACTUALIZADO:
779
                        logger.debug("actualizado");
780
                        layoutDraw.drawRectangle((Graphics2D) g);
781

    
782
                        g.drawImage(img, 0, 0, this);
783

    
784
                        g.setClip(rClip);
785
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
786
                        g.drawImage(imgRuler, 0, 0, this);
787
                }
788
        }
789

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

    
812
                if (nums.containsKey(frame.getClass())) {
813
                        nums.put(frame.getClass(), new Integer(Integer.parseInt(nums.get(
814
                                        frame.getClass()).toString()) + 1));
815
                } else {
816
                        nums.put(frame.getClass(), new Integer(0));
817
                }
818

    
819
                frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
820
                efs.addFFrame(frame);
821
                frame.setSelected(select);
822
                frame.setLevel(getNumBefore());
823
                updateFFrames();
824
        }
825

    
826
        /**
827
         * Abre el di?logo de propiedades del folio, pasando como par?metro el
828
         * PrinterJob.
829
         *
830
         * @param job
831
         */
832
        public void showPagePropertiesWindow(PrinterJob job) {
833
                PageFormat pf1;
834

    
835
                pf1 = m_attributes.getPageFormat();
836
                pf1 = job.pageDialog(pf1);
837
                m_attributes.setPageFormat(pf1);
838
                refresh();
839
        }
840

    
841
        /**
842
         * Refresca el Layout.
843
         */
844
        public void refresh() {
845
                setStatus(DESACTUALIZADO);
846
                repaint();
847
        }
848

    
849
        /**
850
         * Obtiene el rect?ngulo que representa el folio con las caracter?sticas que
851
         * contiene attributes y diferenciando si es para visualizar en pantalla o
852
         * para imprimir.
853
         *
854
         * @param isPrint
855
         *            si es para imprimir.
856
         */
857
        public void obtainRect(boolean isPrint) {
858
                m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
859
        }
860

    
861
        /**
862
         * Muestra el di?logo de configuraci?n del Layout.
863
         */
864
        public void showFConfig() {
865
                FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
866
                PluginServices.getMDIManager().addView(m_configLayout);
867
        }
868

    
869
        /**
870
         * Mestra el di?logo de propiedades del Layout.
871
         */
872
        public void showFProperties() {
873
                if (map == null) {
874
                        map = new ProjectMap();
875
                        map.setModel(this);
876
                        map.setName(getName());
877
                }
878

    
879
                m_propertiesLayout = new MapProperties(map);
880
                PluginServices.getMDIManager().addView(m_propertiesLayout);
881
        }
882

    
883
        /**
884
         * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
885
         *
886
         * @param job
887
         */
888
        public void showPrintDialog(PrinterJob job) {
889
                if (job != null) {
890
                        job.printDialog();
891

    
892
                        try {
893
                                job.setPrintable((Printable) PluginServices
894
                                                .getExtension(com.iver.cit.gvsig.Print.class));
895
                                job.print();
896
                        } catch (PrinterException e) {
897
                                e.printStackTrace();
898
                        }
899
                } else {
900
                        // Actualizar attributes
901
                        att = m_attributes.toPrintAttributes();
902

    
903
                        // ------------------ The Printing things --------------------- //
904
                        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
905

    
906
                        // returns the set of printers that support printing a specific
907
                        // document type (such as GIF)
908
                        // with a specific set of attributes (such as two sided).
909
                        // PrintRequestAttributeSet pras = new
910
                        // HashPrintRequestAttributeSet();
911
                        // interestingly, the printer dialog's default behavior has changed
912
                        // with the new API: by default the dialog is not shown.
913
                        // So we must use the ServiceUI class to create a print dialog
914
                        // returns the default print service.
915
                        if (m_cachePrintServices == null) {
916
                                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(
917
                                                flavor, null);
918
                        }
919

    
920
                        PrintService defaultService = null;
921

    
922
                        if (m_cachePrintService == null) {
923
                                defaultService = PrintServiceLookup.lookupDefaultPrintService();
924
                        }
925

    
926
                        if ((defaultService == null) && (m_cachePrintService == null)) {
927
                                JOptionPane.showMessageDialog((Component) PluginServices
928
                                                .getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada"));
929

    
930
                                return;
931
                        }
932

    
933
                        if (m_cachePrintService == null) {
934
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
935
                                                m_cachePrintServices, defaultService, flavor, att);
936

    
937
                                // m_cachePrintRequestAtributeSet = new
938
                                // HashPrintRequestAttributeSet();
939
                                // m_cachePrintRequestAtributeSet.addAll(pras);
940
                        } else {
941
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
942
                                                m_cachePrintServices, m_cachePrintService, flavor, att);
943
                        }
944

    
945
                        if (m_cachePrintService != null) {
946
                                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
947
                                PrintJobListener pjlistener = new PrintJobAdapter() {
948
                                        public void printDataTransferCompleted(PrintJobEvent e) {
949
                                                System.out.println("Fin de impresi?n");
950
                                                fullRect();
951
                                        }
952
                                };
953

    
954
                                jobNuevo.addPrintJobListener(pjlistener);
955

    
956
                                // DocAttributeSet das = new HashDocAttributeSet();
957
                                doc = new SimpleDoc(PluginServices
958
                                                .getExtension(com.iver.cit.gvsig.Print.class), flavor,
959
                                                null);
960

    
961
                                try {
962
                                        jobNuevo.print(doc, att);
963

    
964
                                        // m_attributes.
965
                                } catch (PrintException pe) {
966
                                        pe.printStackTrace();
967
                                }
968
                        }
969
                }
970

    
971
                /*
972
                 * try { print = job.printDialog(att); } catch (Exception e) {
973
                 * logger.error("Abriendo el Di?logo de imprimir");
974
                 * //System.out.println("Excepci?n "+e); } if (print) {
975
                 * job.setPrintable((Printable)
976
                 * App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
977
                 * try { job.print(att); } catch (Exception ex) { ex.printStackTrace(); } }
978
                 */
979
        }
980

    
981
        /**
982
         * Sustituye el puntero del rat?n por la imagen que se le pasa como
983
         * par?metro.
984
         *
985
         * @param image
986
         */
987
        public void setMapCursor(Image image) {
988
                Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
989
                                new Point(16, 16), "");
990
                setCursor(cur);
991
        }
992

    
993
        /**
994
         * Cambia el puntero del raton al cusor que se le introduce como par?metro.
995
         *
996
         * @param cursor
997
         *            cursor a mostrar en el puntero del rat?n.
998
         */
999
        public void setMapCursor(Cursor cursor) {
1000
                setCursor(cursor);
1001
        }
1002

    
1003
        /**
1004
         * Pone como seleccionada a la herramienta a partir de su n?mero.
1005
         *
1006
         * @param i
1007
         */
1008
        public void setTool(int i) {
1009
                tool = i;
1010

    
1011
                if (getTool() == PAN) {
1012
                        setMapCursor(ipan);
1013
                } else if (getTool() == ZOOM_MAS) {
1014
                        setMapCursor(izoomin);
1015
                } else if (getTool() == ZOOM_MENOS) {
1016
                        setMapCursor(izoomout);
1017
                } else if (getTool() == RECTANGLEVIEW) {
1018
                        setMapCursor(icrux);
1019
                } else if (getTool() == RECTANGLEPICTURE) {
1020
                        setMapCursor(icrux);
1021
                } else if (getTool() == RECTANGLESCALEBAR) {
1022
                        setMapCursor(icrux);
1023
                } else if (getTool() == RECTANGLELEGEND) {
1024
                        setMapCursor(icrux);
1025
                } else if (getTool() == RECTANGLETEXT) {
1026
                        setMapCursor(icrux);
1027
                } else if (getTool() == RECTANGLENORTH) {
1028
                        setMapCursor(icrux);
1029
                } else if (getTool() == RECTANGLEBOX) {
1030
                        setMapCursor(icrux);
1031
                } else if (getTool() == SELECT) {
1032
                        setCursor(Cursor.getDefaultCursor());
1033
                } else if (getTool() == SET_TAG) {
1034
                        setMapCursor(itag);
1035
                } else if (getTool() == POINT) {
1036
                        setMapCursor(iPoint);
1037
                } else if (getTool() == LINE) {
1038
                        setMapCursor(iRect);
1039
                } else if (getTool() == RECTANGLESIMPLE) {
1040
                        setMapCursor(iRectangle);
1041
                } else if (getTool() == POLYLINE) {
1042
                        setMapCursor(iLine);
1043
                } else if (getTool() == POLYGON) {
1044
                        setMapCursor(iPoligon);
1045
                } else if (getTool() == CIRCLE) {
1046
                        setMapCursor(iCircle);
1047
                }
1048
                if (getTool() == EDIT) {
1049
                        setMapCursor(icrux);
1050
                        startEdit();
1051
                } else {
1052
                        stopEdit();
1053
                }
1054
                initGeometryAdapter();
1055
        }
1056

    
1057
        /**
1058
         * Se crean aqu? los dialogos cada vez que se necesitan.
1059
         *
1060
         * @param fframe
1061
         *            Rectangle que representa el lugar que ocupara el elemento
1062
         *            a?adido.
1063
         *
1064
         * @return true si se debe de a?adir el fframe.
1065
         */
1066
        public boolean openFFrameDialog(IFFrame fframe) {
1067
                switch (tool) {
1068
                case RECTANGLEVIEW:
1069
                        fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
1070

    
1071
                        break;
1072

    
1073
                case RECTANGLEPICTURE:
1074
                        fframedialog = new FFramePictureDialog(this, (FFramePicture) fframe);
1075

    
1076
                        break;
1077

    
1078
                case RECTANGLESCALEBAR:
1079
                        fframedialog = new FFrameScaleBarDialog(this,
1080
                                        (FFrameScaleBar) fframe);
1081

    
1082
                        break;
1083

    
1084
                case RECTANGLELEGEND:
1085
                        fframedialog = new FFrameLegendDialog(this, (FFrameLegend) fframe);
1086

    
1087
                        break;
1088

    
1089
                case RECTANGLETEXT:
1090
                        fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
1091

    
1092
                        break;
1093

    
1094
                case GRAPHICS:
1095
                        fframedialog = new FFrameGraphicsDialog(this,
1096
                                        (FFrameGraphics) fframe);
1097

    
1098
                        break;
1099

    
1100
                case RECTANGLEGROUP:
1101
                        fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe);
1102

    
1103
                        break;
1104
                case RECTANGLENORTH:
1105
                        fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe);
1106

    
1107
                        break;
1108
                case RECTANGLEBOX:
1109
                        fframedialog = new FFrameBoxDialog(this, (FFrameTable) fframe);
1110

    
1111
                        break;
1112
                default:
1113
                        return true;
1114
                }
1115

    
1116
                if (fframedialog != null) {
1117
                        fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
1118
                        PluginServices.getMDIManager().addView(fframedialog);
1119
                }
1120

    
1121
                return fframedialog.getIsAcepted();
1122
        }
1123

    
1124
        /**
1125
         * Devuelve el Rectangle2D que representa en pixels al folio.
1126
         *
1127
         * @return Rectangle2D.Double
1128
         */
1129
        public Rectangle2D.Double getRect() {
1130
                return rect;
1131
        }
1132

    
1133
        public void setRect(Rectangle2D r) {
1134
                rect.setRect(r);
1135
        }
1136

    
1137
        /**
1138
         * Obtiene un entero que representa la herramienta seleccionada.
1139
         *
1140
         * @return entero.
1141
         */
1142
        public int getTool() {
1143
                return tool;
1144
        }
1145

    
1146
        /**
1147
         * Devuelve la Matriz transformada que se esta plicando al Layout.
1148
         *
1149
         * @return AffineTransform
1150
         */
1151
        public AffineTransform getAT() {
1152
                return m_MatrizTransf;
1153
        }
1154

    
1155
        /**
1156
         * Devuelve los atributos del Mapa.
1157
         *
1158
         * @return Attributes.
1159
         */
1160
        public Attributes getAtributes() {
1161
                return m_attributes;
1162
        }
1163

    
1164
        /**
1165
         * Pone el estado que se quiera.
1166
         *
1167
         * @param s
1168
         *            estado.
1169
         */
1170
        public void setStatus(int s) {
1171
                status = s;
1172
        }
1173

    
1174
        /**
1175
         * Devuelve el punto que representa la esquina noroeste del mapa.
1176
         *
1177
         * @return un punto.
1178
         */
1179
        public Point getRectOrigin() {
1180
                return rectOrigin;
1181
        }
1182

    
1183
        /**
1184
         * Devuelve el punto del primer click de rat?n.
1185
         *
1186
         * @return un punto.
1187
         */
1188
        public Point getFirstPoint() {
1189
                return m_FirstPoint;
1190
        }
1191

    
1192
        /**
1193
         * Devuelve el punto de click de rat?n anterior.
1194
         *
1195
         * @return un punto.
1196
         */
1197
        public Point getPointAnt() {
1198
                return m_PointAnt;
1199
        }
1200

    
1201
        /**
1202
         * Devuelve el punto donde se solt? el bot?n del rat?n.
1203
         *
1204
         * @return un punto.
1205
         */
1206
        public Point getLastPoint() {
1207
                return m_LastPoint;
1208
        }
1209

    
1210
        /**
1211
         * Rellena el primer punto de click de rat?n.
1212
         *
1213
         * @param p
1214
         *            punto.
1215
         */
1216
        public void setFirstPoint(Point p) {
1217
                m_FirstPoint = p;
1218
        }
1219

    
1220
        /**
1221
         * Rellena el punto de click de rat?n anterior.
1222
         *
1223
         * @param p
1224
         *            punto.
1225
         */
1226
        public void setPointAnt(Point p) {
1227
                m_PointAnt = p;
1228
        }
1229

    
1230
        /**
1231
         * Rellena el punto donde se solto el bot?n del rat?n.
1232
         *
1233
         * @param p
1234
         *            punto.
1235
         */
1236
        public void setLastPoint(Point p) {
1237
                m_LastPoint = p;
1238
        }
1239

    
1240
        /**
1241
         * This method is used to get <strong>an initial</strong> ViewInfo object
1242
         * for this Map. It is not intended to retrieve the ViewInfo object in a
1243
         * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
1244
         * to retrieve the ViewInfo object at any time after the creation of the
1245
         * object.
1246
         *
1247
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1248
         */
1249
        public ViewInfo getViewInfo() {
1250
                if (m_viewInfo == null) {
1251
                        m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE
1252
                                        | ViewInfo.MAXIMIZABLE);
1253
                        m_viewInfo.setWidth(500);
1254
                        m_viewInfo.setHeight(400);
1255

    
1256
                        m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : "
1257
                                        + getName());
1258
                }
1259
                return m_viewInfo;
1260
        }
1261

    
1262
        /**
1263
         * Inserta si se muestra o no la regla del Layout.
1264
         *
1265
         * @param b
1266
         *            True si se muestra la regla.
1267
         */
1268
        public void setRuler(boolean b) {
1269
                m_showRuler = b;
1270
        }
1271

    
1272
        /**
1273
         * Devuelve si se muestra la regla del Layout.
1274
         *
1275
         * @return True si se muestra la regla.
1276
         */
1277
        public boolean getRuler() {
1278
                return m_showRuler;
1279
        }
1280

    
1281
        /**
1282
         * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1283
         * cuadr?cula, o no.
1284
         *
1285
         * @return true si se esta aplicando la cuadr?cula.
1286
         */
1287
        public boolean isCuadricula() {
1288
                return isCuadricula;
1289
        }
1290

    
1291
        /**
1292
         * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1293
         *
1294
         * @param b
1295
         *            true si se aplica la cuadr?cula.
1296
         */
1297
        public void setIsCuadricula(boolean b) {
1298
                isCuadricula = b;
1299
        }
1300

    
1301
        /**
1302
         * Realiza una exteni?n completa de las capas que contiene la vista del
1303
         * FFrameView.
1304
         *
1305
         * @throws DriverException
1306
         */
1307
        public void viewFull() throws DriverException {
1308
                IFFrame[] fframes = getFFrameSelected();
1309
                for (int i = 0; i < fframes.length; i++) {
1310
                        if (fframes[i] instanceof IFFrameUseFMap) {
1311
                                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
1312

    
1313
                                if (fframe.getFMap() != null) {
1314
                                        fframe.fullExtent();
1315
                                }
1316
                                fframe.refresh();
1317
                        }
1318
                }
1319
                refresh();
1320
        }
1321

    
1322
        /**
1323
         * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1324
         * para poder despu?s volver a crear el objeto original.
1325
         *
1326
         * @return XMLEntity.
1327
         *
1328
         * @throws XMLException
1329
         */
1330
        public XMLEntity getXMLEntity() {
1331
                XMLEntity xml = new XMLEntity();
1332
                xml.putProperty("className", this.getClass().getName());
1333
                xml.setName("layout");
1334
                xml.putProperty("isCuadricula", isCuadricula());
1335
                xml.putProperty("m_name", this.getName());
1336
                xml.putProperty("isEditable", isEditable);
1337
                xml.putProperty("numBehind", numBehind);
1338
                xml.putProperty("numBefore", numBefore);
1339
                xml.addChild(getAtributes().getXMLEntity());
1340
                IFFrame[] fframes=getFFrames();
1341
                for (int i = 0; i < fframes.length; i++) {
1342
                        try {
1343
                                XMLEntity xmlAux = fframes[i].getXMLEntity();
1344
                                xml.addChild(xmlAux);
1345
                        } catch (SaveException e) {
1346
                                e.showError();
1347
                        }
1348
                }
1349
                return xml;
1350
        }
1351

    
1352
        /**
1353
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1354
         *
1355
         * @param xml
1356
         *            XMLEntity
1357
         * @param p
1358
         *            Proyecto.
1359
         *
1360
         * @return Objeto de esta clase.
1361
         * @throws OpenException
1362
         */
1363
        public static Layout createLayout(XMLEntity xml, Project p)
1364
                        throws OpenException {
1365
                Layout layout = new Layout();
1366
                try {
1367
                        layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1368
                        layout.setName(xml.getStringProperty("m_name"));
1369
                        layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1370
                        if (xml.contains("isEditable")) {
1371
                                layout.setEditable(xml.getBooleanProperty("isEditable"));
1372
                        }
1373
                        if (xml.contains("numBehind")) {
1374
                                layout.numBehind = xml.getIntProperty("numBehind");
1375
                                layout.numBefore = xml.getIntProperty("numBefore");
1376
                        }
1377
                        layout.getEFS().startComplexCommand();
1378
                        for (int i = 1; i < xml.getNumChild(); i++) {
1379
                                try {
1380
                                        layout.addFFrame(FFrame.createFFrame(xml.getChild(i), p,
1381
                                                        layout), true, false);
1382
                                } catch (OpenException e) {
1383
                                        e.showError();
1384
                                }
1385
                        }
1386
                        layout.getEFS().endComplexCommand(PluginServices.getText(layout,"Inicializando"));
1387
                        IFFrame[] fframes = layout.getAllFFrames();
1388
                        for (int i = 0; i < fframes.length; i++) {
1389
                                if (fframes[i] instanceof IFFrameLayoutDependence) {
1390
                                        ((IFFrameLayoutDependence) fframes[i]).setLayout(layout);
1391
                                }
1392
                                if (fframes[i] instanceof IFFrameViewDependence) {
1393
                                        ((IFFrameViewDependence) fframes[i])
1394
                                                        .initDependence(fframes);
1395
                                }
1396
                        }
1397
                } catch (Exception e) {
1398
                        throw new OpenException(e, layout.getClass().getName());
1399
                }
1400
                return layout;
1401
        }
1402

    
1403
        /**
1404
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1405
         *
1406
         * @param xml
1407
         *            XMLEntity
1408
         * @param p
1409
         *            Proyecto.
1410
         *
1411
         * @return Objeto de esta clase.
1412
         */
1413
        public static Layout createLayout03(XMLEntity xml, Project p) {
1414
                Layout layout = new Layout();
1415
                layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1416
                layout.setName(xml.getStringProperty("m_name"));
1417
                layout.m_attributes = Attributes.createAtributes03(xml.getChild(0));
1418

    
1419
                for (int i = 1; i < xml.getNumChild(); i++) {
1420
                        if (xml.getChild(i).getStringProperty("className").equals(
1421
                                        "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1422
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1423
                                                p), true, false);
1424
                        }
1425
                }
1426

    
1427
                for (int i = 1; i < xml.getNumChild(); i++) {
1428
                        if (!xml.getChild(i).getStringProperty("className").equals(
1429
                                        "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1430
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1431
                                                p), true, false);
1432
                        }
1433
                }
1434

    
1435
                return layout;
1436
        }
1437

    
1438
        /**
1439
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1440
         */
1441
        public void viewActivated() {
1442
                //fullRect();
1443
                refresh();
1444
                PluginServices.getMainFrame().getStatusBar().setMessage("units",
1445
                                getAtributes().getNameUnit());
1446
        }
1447

    
1448
        /**
1449
         * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1450
         */
1451
        public Object getViewModel() {
1452
                return map;
1453
        }
1454

    
1455
        /**
1456
         * Devuelve si se dibuja el Grid en el Layout o no.
1457
         *
1458
         * @return True si se dibuja el Grid en el Layout.
1459
         */
1460
        public boolean getIsDrawGrid() {
1461
                return isDrawCuadricula;
1462
        }
1463

    
1464
        /**
1465
         * Inserta si se muestra el Grid del Layout.
1466
         *
1467
         * @param b
1468
         *            True si se muestra el Grid del Layout.
1469
         */
1470
        public void setIsDrawGrid(boolean b) {
1471
                isDrawCuadricula = b;
1472
        }
1473

    
1474
        /**
1475
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1476
         */
1477
        public void extentChanged(ExtentEvent e) {
1478
        }
1479

    
1480
        /**
1481
         * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
1482
         */
1483
        public void viewClosed() {
1484
                // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1485
        }
1486

    
1487
        /**
1488
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1489
         */
1490
        public void backColorChanged(ColorEvent e) {
1491
                // refresh();
1492
        }
1493

    
1494
        /**
1495
         * Devuelve un array con los FFrames seleccionados.
1496
         *
1497
         * @return Array con los FFrames seleccionados.
1498
         */
1499
        public IFFrame[] getFFrameSelected() {
1500
                ArrayList selecList = new ArrayList();
1501
                IFFrame[] fframes=getFFrames();
1502
                for (int i = fframes.length - 1; i >= 0; i--) {
1503
                        IFFrame fframe = fframes[i];
1504

    
1505
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1506
                                selecList.add(fframe);
1507
                        }
1508
                }
1509

    
1510
                return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1511
        }
1512

    
1513
        /**
1514
         * Opens a dialog where to pick a PDF-file to save the current Layout
1515
         * suggesting a name for the file given by the first argument
1516
         *
1517
         * @param suggestedName
1518
         */
1519
        public void layoutToPDF(String suggestedName) {
1520
                FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices
1521
                                .getText(this, "pdf"));
1522

    
1523
                JFileChooser jfc = new JFileChooser();
1524
                if (suggestedName != null)
1525
                        jfc.setSelectedFile(new File(suggestedName));
1526
                jfc.addChoosableFileFilter(pdfFilter);
1527
                jfc.setFileFilter(pdfFilter);
1528

    
1529
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1530
                        File f = jfc.getSelectedFile();
1531
                        File faux = null;
1532

    
1533
                        if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
1534
                                faux = f;
1535
                        } else {
1536
                                faux = new File(f.getPath() + ".pdf");
1537
                        }
1538

    
1539
                        layoutDraw.toPDF(faux);
1540
                }
1541
        }
1542
        /**
1543
         * Opens a dialog where to pick a PS-file to save the current Layout
1544
         * suggesting a name for the file given by the first argument
1545
         *
1546
         * @param suggestedName
1547
         */
1548
        public void layoutToPS(String suggestedName) {
1549
                FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices
1550
                                .getText(this, "ps"));
1551

    
1552
                JFileChooser jfc = new JFileChooser();
1553
                if (suggestedName != null)
1554
                        jfc.setSelectedFile(new File(suggestedName));
1555
                jfc.addChoosableFileFilter(pdfFilter);
1556
                jfc.setFileFilter(pdfFilter);
1557

    
1558
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1559
                        File f = jfc.getSelectedFile();
1560
                        File faux = null;
1561

    
1562
                        if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
1563
                                faux = f;
1564
                        } else {
1565
                                faux = new File(f.getPath() + ".ps");
1566
                        }
1567

    
1568
                        layoutDraw.toPS(faux);
1569
                }
1570
        }
1571
        /**
1572
         * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1573
         * en este formato.
1574
         */
1575
        public void layoutToPDF() {
1576
                layoutToPDF(null);
1577
        }
1578
        /**
1579
         * Abre un di?logo para seleccionar un fichero ps donde guardar el Layout
1580
         * en este formato.
1581
         */
1582
        public void layoutToPS() {
1583
                layoutToPS(null);
1584
        }
1585
        /**
1586
         * @return Returns the bModeDebug.
1587
         */
1588
        public boolean isModeDebug() {
1589
                return bModeDebug;
1590
        }
1591

    
1592
        /**
1593
         * @param modeDebug
1594
         *            The bModeDebug to set.
1595
         */
1596
        public void setModeDebug(boolean modeDebug) {
1597
                bModeDebug = modeDebug;
1598
        }
1599

    
1600
        private ArrayList allFFrames(IFFrame[] fframes, ArrayList all) {
1601
                for (int i = 0; i < fframes.length; i++) {
1602
                        if (fframes[i] instanceof FFrameGroup) {
1603
                                return allFFrames(((FFrameGroup) fframes[i]).getFFrames(), all);
1604

    
1605
                        }
1606
                                all.add(fframes[i]);
1607
                }
1608
                return all;
1609
        }
1610

    
1611
        public IFFrame[] getAllFFrames() {
1612
                ArrayList all = new ArrayList();
1613
                return (IFFrame[]) allFFrames(getFFrames(), all)
1614
                                .toArray(new IFFrame[0]);
1615
        }
1616

    
1617
        public GeometryAdapter getGeometryAdapter() {
1618
                return geometryAdapter;
1619
        }
1620

    
1621
        public boolean isEditable() {
1622
                return isEditable;
1623
        }
1624

    
1625
        public void setEditable(boolean b) {
1626
                if (!b) {
1627
                        clearSelection();
1628
                        setTool(Layout.ZOOM_MAS);
1629
                        PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
1630
                }
1631
                isEditable = b;
1632

    
1633
        }
1634

    
1635
        public void initGeometryAdapter() {
1636
                if (getTool() == LINE) {
1637
                        geometryAdapter = new PolyLineAdapter();
1638
                } else if (getTool() == RECTANGLESIMPLE) {
1639
                        geometryAdapter = new RectangleAdapter();
1640
                } else if (getTool() == POLYLINE) {
1641
                        geometryAdapter = new PolyLineAdapter();
1642
                } else if (getTool() == POLYGON) {
1643
                        geometryAdapter = new PolygonAdapter();
1644
                } else if (getTool() == CIRCLE) {
1645
                        geometryAdapter = new CircleAdapter();
1646
                } else if (getTool() == POINT) {
1647
                        geometryAdapter = new PointAdapter();
1648
                }
1649
        }
1650

    
1651
        public void startEdit() {
1652
                IFFrame[] fframes=getFFrames();
1653
                for (int i = 0; i < fframes.length; i++) {
1654
                        IFFrame frame = fframes[i];
1655
                        if (frame instanceof IFFrameEditableVertex) {
1656
                                if (frame.getSelected() != IFFrame.NOSELECT) {
1657
                                        ((IFFrameEditableVertex) frame).startEditing();
1658
                                } else {
1659
                                        ((IFFrameEditableVertex) frame).stopEditing();
1660
                                }
1661
                        }
1662

    
1663
                }
1664
                refresh();
1665
        }
1666

    
1667
        public void stopEdit() {
1668
                boolean refresh = false;
1669
                IFFrame[] fframes=getFFrames();
1670
                for (int i = 0; i < fframes.length; i++) {
1671
                        IFFrame frame = fframes[i];
1672
                        if (frame instanceof IFFrameEditableVertex) {
1673
                                if (((IFFrameEditableVertex) frame).isEditing()) {
1674
                                        ((IFFrameEditableVertex) fframes[i]).stopEditing();
1675
                                        refresh = true;
1676
                                }
1677
                        }
1678
                }
1679
                if (refresh)
1680
                        refresh();
1681
        }
1682

    
1683
        public void delFFrameSelected() {
1684
                efs.startComplexCommand();
1685
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1686
                        IFFrame fframe = efs.getFFrame(i);
1687

    
1688
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1689
                                efs.removeFFrame(i);
1690
                        }
1691
                }
1692
                efs.endComplexCommand(PluginServices.getText(this,"remove_elements"));
1693
                updateFFrames();
1694
        }
1695

    
1696
        public void clearSelection() {
1697
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1698
                        IFFrame fframe = efs.getFFrame(i);
1699
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1700
                                fframe.setSelected(false);
1701
                        }
1702
                }
1703
        }
1704
        public void delFFrame(int index) {
1705
                for (int i = 0; i < getEFS().getAllFFrames().length; i++) {
1706
                        if (getEFS().getFFrame(i).equals(getFFrame(index))) {
1707
                                getEFS().removeFFrame(i);
1708
                        }
1709
                }
1710
                updateFFrames();
1711
        }
1712

    
1713
        public void delFFrame(IFFrame frame) {
1714
                for (int i = 0; i < getEFS().getAllFFrames().length; i++) {
1715
                        if (getEFS().getFFrame(i).equals(frame)) {
1716
                                getEFS().removeFFrame(i);
1717
                        }
1718
                }
1719
                updateFFrames();
1720
        }
1721

    
1722
        public EditableFeatureSource getEFS() {
1723
                return efs;
1724
        }
1725

    
1726
        public void commandRepaint() {
1727
                this.updateFFrames();
1728
                this.refresh();
1729
        }
1730

    
1731
        public void commandRefresh() {
1732
                commandRepaint();
1733

    
1734
        }
1735

    
1736
        /**
1737
         * Introduce la posibilidad de establecer que los cambios que se hacen a
1738
         * partir de ese momento hasta que se vuelva a poner a false, que todas las
1739
         * operaciones que realices son sobre los fframes que implementen
1740
         * IFFrameGroupSelectable.
1741
         *
1742
         * @param b
1743
         */
1744
        public void setEditGroup(boolean b) {
1745
                editGroup = b;
1746
        }
1747

    
1748
        /**
1749
         * Devuelve true si se est? en modo de edici?n de los fframes que
1750
         * implementen IFFrameGroupSelectable.
1751
         *
1752
         * @return
1753
         */
1754
        public boolean isEditGroup() {
1755
                return editGroup;
1756
        }
1757

    
1758
        public int getNumBehind() {
1759
                return --numBehind;
1760
        }
1761

    
1762
        public int getNumBefore() {
1763
                return ++numBefore;
1764
        }
1765

    
1766
        public void projectionChanged(ProjectionEvent e) {
1767
                // TODO Auto-generated method stub
1768

    
1769
        }
1770

    
1771
         public void endGraphic() {
1772
                if ((getTool() == Layout.LINE)
1773
                                || (getTool() == Layout.POLYLINE)
1774
                                || (getTool() == Layout.POLYGON)
1775
                                || (getTool() == Layout.CIRCLE)
1776
                                || (getTool() == Layout.RECTANGLESIMPLE)
1777
                                || (getTool() == Layout.POINT)) {
1778
                        getGeometryAdapter().end();
1779
                        PluginServices.getMainFrame().enableControls();
1780
                        FLayoutFunctions lf=new FLayoutFunctions(this);
1781
                        lf.addFFrame();
1782
                        initGeometryAdapter();
1783
                        refresh();
1784
                }
1785
        }
1786

    
1787
        public void delLastPoint() {
1788
                getGeometryAdapter().delLastPoint();
1789
        }
1790
}