Statistics
| Revision:

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

History | View | Annotate | Download (47.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.SingletonWindow;
92
import com.iver.andami.ui.mdiManager.WindowInfo;
93
import com.iver.andami.ui.mdiManager.IWindowListener;
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.fframes.FFrame;
109
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
110
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGroup;
111
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
112
import com.iver.cit.gvsig.gui.layout.fframes.FFrameNorth;
113
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
114
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
115
import com.iver.cit.gvsig.gui.layout.fframes.FFrameTable;
116
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
117
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
118
import com.iver.cit.gvsig.project.Project;
119
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
120
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
121
import com.iver.cit.gvsig.project.documents.layout.EventsHandler;
122
import com.iver.cit.gvsig.project.documents.layout.FLayoutDraw;
123
import com.iver.cit.gvsig.project.documents.layout.FLayoutFunctions;
124
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
125
import com.iver.cit.gvsig.project.documents.layout.ProjectMap;
126
import com.iver.cit.gvsig.project.documents.layout.commands.DefaultEditableFeatureSource;
127
import com.iver.cit.gvsig.project.documents.layout.commands.EditableFeatureSource;
128
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
129
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameEditableVertex;
130
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameLayoutDependence;
131
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameUseFMap;
132
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
133
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameBoxDialog;
134
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameGraphicsDialog;
135
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameGroupDialog;
136
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameLegendDialog;
137
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameNorthDialog;
138
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFramePictureDialog;
139
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameScaleBarDialog;
140
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameTextDialog;
141
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameViewDialog;
142
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
143
import com.iver.cit.gvsig.project.documents.layout.gui.MapProperties;
144
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
145
import com.iver.utiles.GenericFileFilter;
146
import com.iver.utiles.XMLEntity;
147

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

    
157
        public static final int ZOOM_MAS = 1;
158

    
159
        public static final int ZOOM_MENOS = 2;
160

    
161
        public static final int PAN = 3;
162

    
163
        public static final int DESACTUALIZADO = 4;
164

    
165
        public static final int ACTUALIZADO = 5;
166

    
167
        public static final int SELECT = 6;
168

    
169
        public static final int RECTANGLE = 10;
170

    
171
        public static final int RECTANGLEVIEW = 11;
172

    
173
        public static final int RECTANGLEPICTURE = 12;
174

    
175
        public static final int RECTANGLESCALEBAR = 13;
176

    
177
        public static final int RECTANGLELEGEND = 14;
178

    
179
        public static final int RECTANGLETEXT = 15;
180

    
181
        public static final int RECTANGLEGROUP = 16;
182

    
183
        public static final int RECTANGLESYMBOL = 17;
184

    
185
        public static final int RECTANGLENORTH = 18;
186

    
187
        public static final int RECTANGLEBOX = 19;
188

    
189
        public static final int GRAPHICS = 20;
190

    
191
        public static final int POINT = 21;
192

    
193
        public static final int LINE = 22;
194

    
195
        public static final int POLYLINE = 23;
196

    
197
        public static final int RECTANGLESIMPLE = 24;
198

    
199
        public static final int CIRCLE = 25;
200

    
201
        public static final int POLYGON = 26;
202

    
203
        public static final int VIEW_ZOOMIN = 30;
204

    
205
        public static final int VIEW_ZOOMOUT = 31;
206

    
207
        public static final int VIEW_FULL = 32;
208

    
209
        public static final int VIEW_PAN = 33;
210

    
211
        public static final int SET_TAG = 34;
212

    
213
        public static final int EDIT = 40;
214

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
269
        private Point origin = new Point(50, 50);
270

    
271
        private Point rectOrigin = new Point(origin);
272

    
273
        private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
274
                        rectOrigin.y, 400, 300);
275

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

    
278
        private Point m_PointAnt = new Point(0, 0);
279

    
280
        private Point m_LastPoint = new Point(0, 0);
281

    
282
        private EventsHandler events;
283

    
284
        private int tool = ZOOM_MAS;
285

    
286
        private int status = DESACTUALIZADO;
287

    
288
        private BufferedImage img = null;
289

    
290
        private BufferedImage imgRuler = null;
291

    
292
        private AffineTransform m_MatrizTransf;
293

    
294
        private Rectangle2D rectVisible;
295

    
296
        private IFFrameDialog fframedialog = null;
297

    
298
        private IFFrame[] fframes;
299

    
300
        private MapProperties m_propertiesLayout = null;
301

    
302
        private Attributes m_attributes = null;
303

    
304
        private PrintService[] m_cachePrintServices = null;
305

    
306
        private PrintService m_cachePrintService = null;
307

    
308
        private boolean m_bCancelDrawing = false;
309

    
310
        private boolean isCuadricula = false;
311

    
312
        private boolean initial = true;
313

    
314
        private ProjectMap map = null;
315

    
316
        private Rectangle reSel = null;
317

    
318
        private boolean isReSel = true;
319

    
320
        private boolean m_showRuler = true;
321

    
322
        private FLayoutDraw layoutDraw = null;
323

    
324
        private boolean isDrawCuadricula = true;
325

    
326
        private Doc doc = null;
327

    
328
        private PrintRequestAttributeSet att = null;
329

    
330
        private GeometryAdapter geometryAdapter = new PolyLineAdapter();
331

    
332
        private DefaultEditableFeatureSource efs;
333

    
334
        private boolean isEditable = true;
335

    
336
        private WindowInfo m_viewInfo = null;
337

    
338
        private int numBefore = 0;
339

    
340
        private int numBehind = 0;
341

    
342
        /**
343
         * Lo usamos cuando estamos haciendo una ficha y asignando tags Se pone en
344
         * modo debug cuando hacemos un VIEW_TAGS
345
         */
346
        private boolean bModeDebug = false;
347

    
348
        private boolean editGroup;
349

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

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

    
389
        /**
390
         * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
391
         *
392
         * @return Rect?ngulo de selecci?n.
393
         */
394
        public Rectangle getReSel() {
395
                return reSel;
396
        }
397

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

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

    
419
        /**
420
         * Devuelve true si el dibujado ha sido cancelado.
421
         *
422
         * @return true si el dibujado ha sido cancelado.
423
         */
424
        public synchronized boolean isDrawingCancelled() {
425
                return m_bCancelDrawing;
426
        }
427

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

    
437
                for (int i = 0; i < getFFrames().length; i++) {
438
                        IFFrame fframe = getFFrame(i);
439

    
440
                        if (fframe instanceof IFFrameUseFMap
441
                                        && (((IFFrameUseFMap) fframe).getMapContext() != null)) {
442
                                // //TODO((FFrameView)
443
                                // getFFrames().get(i)).getFMap().setCancelDrawing(b);
444
                        }
445
                }
446
        }
447

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

    
457
        public IFFrame getFFrame(int i) {
458
                return fframes[i];
459
        }
460

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

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

    
483
                if (m_attributes.isLandSpace()) {
484
                        rect = m_attributes.getRectangleLandscape(rect, getWidth(),
485
                                        getHeight());
486
                } else {
487
                        rect = m_attributes.getRectanglePortrait(rect, getWidth(),
488
                                        getHeight());
489
                }
490
                refresh();
491
        }
492

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

    
501
                setCursor(Cursor.getDefaultCursor());
502

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

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

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

    
541
        /**
542
         * Inicializa los componentes.
543
         */
544
        private void initComponents() {
545
                m_attributes = new Attributes();
546
                m_attributes.setDistanceUnitX(rect);
547
                m_attributes.setDistanceUnitY(rect);
548
                //actionDelFFrame();
549
                setDoubleBuffered(true);
550
        }
551

    
552
        /**
553
         * paintComponent del Layout.
554
         *
555
         * @param g
556
         *            Graphics del Layout.
557
         */
558
        protected void paintComponent(Graphics g) {
559
                super.paintComponent(g);
560

    
561
                clipVisibleRect((Graphics2D) g);
562

    
563
                Rectangle rClip = g.getClipBounds();
564

    
565
                if (rClip == null) {
566
                        System.err.println("clip = null");
567
                }
568

    
569
                switch (status) {
570
                case ZOOM_MAS:
571
                        logger.debug("zoom mas");
572
                        layoutDraw.drawRectangle((Graphics2D) g);
573

    
574
                        g.drawImage(img, 0, 0, this);
575

    
576
                        g.setClip(rClip);
577
                        g.drawImage(imgRuler, 0, 0, this);
578
                        g.setColor(Color.black);
579
                        g.setXORMode(Color.white);
580

    
581
                        Rectangle r = new Rectangle();
582

    
583
                        r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
584
                        g.drawRect(r.x, r.y, r.width, r.height);
585

    
586
                        break;
587

    
588
                case RECTANGLE:
589
                        logger.debug("rectangle");
590
                        layoutDraw.drawRectangle((Graphics2D) g);
591

    
592
                        g.drawImage(img, 0, 0, this);
593

    
594
                        g.setClip(rClip);
595
                        g.drawImage(imgRuler, 0, 0, this);
596
                        g.setColor(Color.black);
597
                        g.setXORMode(Color.white);
598

    
599
                        Rectangle re = new Rectangle();
600
                        re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
601

    
602
                        if (isCuadricula()) {
603
                                FLayoutUtilities.setRectGrid(re, m_attributes
604
                                                .getUnitInPixelsX(), m_attributes.getUnitInPixelsY(),
605
                                                m_MatrizTransf);
606
                        }
607

    
608
                        g.drawRect(re.x, re.y, re.width, re.height);
609

    
610
                        break;
611

    
612
                case PAN:
613
                        logger.debug("pan");
614

    
615
                        rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
616
                        rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
617

    
618
                        layoutDraw.drawRectangle((Graphics2D) g);
619

    
620
                        if (img != null) {
621
                                g.drawImage(img, (getLastPoint().x - getPointAnt().x),
622
                                                (getLastPoint().y - getPointAnt().y), this);
623
                        }
624

    
625
                        g.setClip(rClip);
626
                        layoutDraw.drawGrid((Graphics2D) g);
627
                        layoutDraw.drawRuler((Graphics2D) g, Color.black);
628
                        break;
629

    
630
                case VIEW_PAN:
631

    
632
                        logger.debug("View pan");
633
                        layoutDraw.drawRectangle((Graphics2D) g);
634

    
635
                        for (int i = 0; i < getFFrames().length; i++) {
636
                                if (getFFrame(i) instanceof IFFrameUseFMap) {
637
                                        IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
638

    
639
                                        if (((IFFrame) fframe).getSelected() != IFFrame.NOSELECT) {
640
                                                Rectangle2D.Double rec = ((IFFrame) fframe)
641
                                                                .getBoundingBox(getAT());
642

    
643
                                                if (img != null) {
644
                                                        rec = (Rectangle2D.Double) rec
645
                                                                        .createIntersection(getVisibleRect());
646
                                                }
647

    
648
                                                if (fframe.getBufferedImage() != null) {
649
                                                        layoutDraw
650
                                                                        .drawHandlers((Graphics2D) g, Color.black);
651
                                                        g.clipRect((int) rec.x, (int) rec.y,
652
                                                                        (int) rec.width, (int) rec.height);
653

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

    
664
                                                        fframe.refresh();
665
                                                }
666
                                        }
667
                                }
668
                        }
669

    
670
                        g.setClip(rClip);
671
                        g.drawImage(imgRuler, 0, 0, this);
672

    
673
                        break;
674

    
675
                case SELECT:
676
                        logger.debug("select");
677
                        layoutDraw.drawRectangle((Graphics2D) g);
678

    
679
                        g.drawImage(img, 0, 0, this);
680

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

    
701
                                        if (rectangle != null) {
702
                                                if (isCuadricula) {
703
                                                        FLayoutUtilities.setRectGrid(rectangle,
704
                                                                        m_attributes.getUnitInPixelsX(),
705
                                                                        m_attributes.getUnitInPixelsY(),
706
                                                                        m_MatrizTransf);
707
                                                }
708

    
709
                                                g.drawRect((int) rectangle.getMinX(), (int) rectangle
710
                                                                .getMinY(), (int) rectangle.getWidth(),
711
                                                                (int) rectangle.getHeight());
712
                                        }
713

    
714
                                        ((Graphics2D) g).rotate(Math.toRadians(-frames[i]
715
                                                        .getRotation()), rectangle.getX()
716
                                                        + (rectangle.getWidth() / 2), rectangle.getY()
717
                                                        + (rectangle.getHeight() / 2));
718

    
719
                                }
720
                        }
721

    
722
                        g.setClip(rClip);
723
                        g.drawImage(imgRuler, 0, 0, this);
724

    
725
                        break;
726
                case GRAPHICS:
727
                        logger.debug("graphics");
728
                        layoutDraw.drawRectangle((Graphics2D) g);
729
                        g.drawImage(img, 0, 0, this);
730
                        g.setClip(rClip);
731
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
732

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

    
747
                case DESACTUALIZADO:
748
                        logger.debug("desactualizado");
749
                        img = new BufferedImage(getWidth(), getHeight(),
750
                                        BufferedImage.TYPE_INT_ARGB);
751
                        imgRuler = new BufferedImage(getWidth(), getHeight(),
752
                                        BufferedImage.TYPE_INT_ARGB);
753
                        Graphics gimag = img.getGraphics();
754
                        Graphics gimgRuler = imgRuler.getGraphics();
755

    
756
                        clipVisibleRect((Graphics2D) gimag);
757

    
758
                        if (initial) {
759
                                fullRect();
760
                                initial = false;
761
                        }
762

    
763
                        try {
764
                                layoutDraw.drawLayout((Graphics2D) gimag, img);
765
                        } catch (DriverException e) {
766
                                e.printStackTrace();
767
                        }
768

    
769
                        g.setClip(rClip);
770
                        layoutDraw.drawRectangle((Graphics2D) g);
771

    
772
                        g.drawImage(img, 0, 0, this);
773
                        g.setClip(rClip);
774

    
775
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
776
                        layoutDraw.drawGrid((Graphics2D) gimgRuler);
777
                        layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
778
                        g.drawImage(imgRuler, 0, 0, this);
779

    
780
                        break;
781

    
782
                case ACTUALIZADO:
783
                        logger.debug("actualizado");
784
                        layoutDraw.drawRectangle((Graphics2D) g);
785

    
786
                        g.drawImage(img, 0, 0, this);
787

    
788
                        g.setClip(rClip);
789
                        layoutDraw.drawHandlers((Graphics2D) g, Color.black);
790
                        g.drawImage(imgRuler, 0, 0, this);
791
                }
792
        }
793

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

    
816
                if (nums.containsKey(frame.getClass())) {
817
                        nums.put(frame.getClass(), new Integer(Integer.parseInt(nums.get(
818
                                        frame.getClass()).toString()) + 1));
819
                } else {
820
                        nums.put(frame.getClass(), new Integer(0));
821
                }
822

    
823
                frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
824
                efs.addFFrame(frame);
825
                frame.setSelected(select);
826
                frame.setLevel(getNumBefore());
827
                updateFFrames();
828
        }
829

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

    
839
                pf1 = m_attributes.getPageFormat();
840
                pf1 = job.pageDialog(pf1);
841
                m_attributes.setPageFormat(pf1);
842
                refresh();
843
        }
844

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

    
874
        /**
875
         * Muestra el di?logo de configuraci?n del Layout.
876
         */
877
        public void showFConfig() {
878
                FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
879
                PluginServices.getMDIManager().addWindow(m_configLayout);
880
        }
881

    
882
        /**
883
         * Mestra el di?logo de propiedades del Layout.
884
         */
885
        public void showFProperties() {
886
                if (map == null) {
887
                        map = new ProjectMap();
888
                        map.setModel(this);
889
                        map.setName(getName());
890
                }
891

    
892
                m_propertiesLayout = new MapProperties(map);
893
                PluginServices.getMDIManager().addWindow(m_propertiesLayout);
894
        }
895

    
896
        /**
897
         * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
898
         *
899
         * @param job
900
         */
901
        public void showPrintDialog(PrinterJob job) {
902
                if (job != null) {
903
                        job.printDialog();
904

    
905
                        try {
906
                                job.setPrintable((Printable) PluginServices
907
                                                .getExtension(com.iver.cit.gvsig.Print.class));
908
                                job.print();
909
                        } catch (PrinterException e) {
910
                                e.printStackTrace();
911
                        }
912
                } else {
913
                        // Actualizar attributes
914
                        att = m_attributes.toPrintAttributes();
915

    
916
                        // ------------------ The Printing things --------------------- //
917
                        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
918

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

    
933
                        PrintService defaultService = null;
934

    
935
                        if (m_cachePrintService == null) {
936
                                defaultService = PrintServiceLookup.lookupDefaultPrintService();
937
                        }
938

    
939
                        if ((defaultService == null) && (m_cachePrintService == null)) {
940
                                JOptionPane.showMessageDialog((Component) PluginServices
941
                                                .getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada"));
942

    
943
                                return;
944
                        }
945

    
946
                        if (m_cachePrintService == null) {
947
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
948
                                                m_cachePrintServices, defaultService, flavor, att);
949

    
950
                                // m_cachePrintRequestAtributeSet = new
951
                                // HashPrintRequestAttributeSet();
952
                                // m_cachePrintRequestAtributeSet.addAll(pras);
953
                        } else {
954
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
955
                                                m_cachePrintServices, m_cachePrintService, flavor, att);
956
                        }
957

    
958
                        if (m_cachePrintService != null) {
959
                                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
960
                                PrintJobListener pjlistener = new PrintJobAdapter() {
961
                                        public void printDataTransferCompleted(PrintJobEvent e) {
962
                                                System.out.println("Fin de impresi?n");
963
                                                fullRect();
964
                                        }
965
                                };
966

    
967
                                jobNuevo.addPrintJobListener(pjlistener);
968

    
969
                                // DocAttributeSet das = new HashDocAttributeSet();
970
                                doc = new SimpleDoc(PluginServices
971
                                                .getExtension(com.iver.cit.gvsig.Print.class), flavor,
972
                                                null);
973

    
974
                                try {
975
                                        jobNuevo.print(doc, att);
976

    
977
                                        // m_attributes.
978
                                } catch (PrintException pe) {
979
                                        pe.printStackTrace();
980
                                }
981
                        }
982
                }
983

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

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

    
1006
        /**
1007
         * Cambia el puntero del raton al cusor que se le introduce como par?metro.
1008
         *
1009
         * @param cursor
1010
         *            cursor a mostrar en el puntero del rat?n.
1011
         */
1012
        public void setMapCursor(Cursor cursor) {
1013
                setCursor(cursor);
1014
        }
1015

    
1016
        /**
1017
         * Pone como seleccionada a la herramienta a partir de su n?mero.
1018
         *
1019
         * @param i
1020
         */
1021
        public void setTool(int i) {
1022
                tool = i;
1023

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

    
1070
        /**
1071
         * Se crean aqu? los dialogos cada vez que se necesitan.
1072
         *
1073
         * @param fframe
1074
         *            Rectangle que representa el lugar que ocupara el elemento
1075
         *            a?adido.
1076
         *
1077
         * @return true si se debe de a?adir el fframe.
1078
         */
1079
        public boolean openFFrameDialog(IFFrame fframe) {
1080
                switch (tool) {
1081
                case RECTANGLEVIEW:
1082
                        fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
1083

    
1084
                        break;
1085

    
1086
                case RECTANGLEPICTURE:
1087
                        fframedialog = new FFramePictureDialog(this, (FFramePicture) fframe);
1088

    
1089
                        break;
1090

    
1091
                case RECTANGLESCALEBAR:
1092
                        fframedialog = new FFrameScaleBarDialog(this,
1093
                                        (FFrameScaleBar) fframe);
1094

    
1095
                        break;
1096

    
1097
                case RECTANGLELEGEND:
1098
                        fframedialog = new FFrameLegendDialog(this, (FFrameLegend) fframe);
1099

    
1100
                        break;
1101

    
1102
                case RECTANGLETEXT:
1103
                        fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
1104

    
1105
                        break;
1106

    
1107
                case GRAPHICS:
1108
                        fframedialog = new FFrameGraphicsDialog(this,
1109
                                        (FFrameGraphics) fframe);
1110

    
1111
                        break;
1112

    
1113
                case RECTANGLEGROUP:
1114
                        fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe);
1115

    
1116
                        break;
1117
                case RECTANGLENORTH:
1118
                        fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe);
1119

    
1120
                        break;
1121
                case RECTANGLEBOX:
1122
                        fframedialog = new FFrameBoxDialog(this, (FFrameTable) fframe);
1123

    
1124
                        break;
1125
                default:
1126
                        return true;
1127
                }
1128

    
1129
                if (fframedialog != null) {
1130
                        fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
1131
                        PluginServices.getMDIManager().addWindow(fframedialog);
1132
                }
1133

    
1134
                return fframedialog.getIsAcepted();
1135
        }
1136

    
1137
        /**
1138
         * Devuelve el Rectangle2D que representa en pixels al folio.
1139
         *
1140
         * @return Rectangle2D.Double
1141
         */
1142
        public Rectangle2D.Double getRect() {
1143
                return rect;
1144
        }
1145

    
1146
        public void setRect(Rectangle2D r) {
1147
                rect.setRect(r);
1148
        }
1149

    
1150
        /**
1151
         * Obtiene un entero que representa la herramienta seleccionada.
1152
         *
1153
         * @return entero.
1154
         */
1155
        public int getTool() {
1156
                return tool;
1157
        }
1158

    
1159
        /**
1160
         * Devuelve la Matriz transformada que se esta plicando al Layout.
1161
         *
1162
         * @return AffineTransform
1163
         */
1164
        public AffineTransform getAT() {
1165
                return m_MatrizTransf;
1166
        }
1167

    
1168
        /**
1169
         * Devuelve los atributos del Mapa.
1170
         *
1171
         * @return Attributes.
1172
         */
1173
        public Attributes getAtributes() {
1174
                return m_attributes;
1175
        }
1176

    
1177
        /**
1178
         * Pone el estado que se quiera.
1179
         *
1180
         * @param s
1181
         *            estado.
1182
         */
1183
        public void setStatus(int s) {
1184
                status = s;
1185
        }
1186

    
1187
        /**
1188
         * Devuelve el punto que representa la esquina noroeste del mapa.
1189
         *
1190
         * @return un punto.
1191
         */
1192
        public Point getRectOrigin() {
1193
                return rectOrigin;
1194
        }
1195

    
1196
        /**
1197
         * Devuelve el punto del primer click de rat?n.
1198
         *
1199
         * @return un punto.
1200
         */
1201
        public Point getFirstPoint() {
1202
                return m_FirstPoint;
1203
        }
1204

    
1205
        /**
1206
         * Devuelve el punto de click de rat?n anterior.
1207
         *
1208
         * @return un punto.
1209
         */
1210
        public Point getPointAnt() {
1211
                return m_PointAnt;
1212
        }
1213

    
1214
        /**
1215
         * Devuelve el punto donde se solt? el bot?n del rat?n.
1216
         *
1217
         * @return un punto.
1218
         */
1219
        public Point getLastPoint() {
1220
                return m_LastPoint;
1221
        }
1222

    
1223
        /**
1224
         * Rellena el primer punto de click de rat?n.
1225
         *
1226
         * @param p
1227
         *            punto.
1228
         */
1229
        public void setFirstPoint(Point p) {
1230
                m_FirstPoint = p;
1231
        }
1232

    
1233
        /**
1234
         * Rellena el punto de click de rat?n anterior.
1235
         *
1236
         * @param p
1237
         *            punto.
1238
         */
1239
        public void setPointAnt(Point p) {
1240
                m_PointAnt = p;
1241
        }
1242

    
1243
        /**
1244
         * Rellena el punto donde se solto el bot?n del rat?n.
1245
         *
1246
         * @param p
1247
         *            punto.
1248
         */
1249
        public void setLastPoint(Point p) {
1250
                m_LastPoint = p;
1251
        }
1252

    
1253
        /**
1254
         * This method is used to get <strong>an initial</strong> ViewInfo object
1255
         * for this Map. It is not intended to retrieve the ViewInfo object in a
1256
         * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
1257
         * to retrieve the ViewInfo object at any time after the creation of the
1258
         * object.
1259
         *
1260
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
1261
         */
1262
        public WindowInfo getWindowInfo() {
1263
                if (m_viewInfo == null) {
1264
                        m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
1265
                                        | WindowInfo.MAXIMIZABLE);
1266
                        m_viewInfo.setWidth(500);
1267
                        m_viewInfo.setHeight(400);
1268

    
1269
                        m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : "
1270
                                        + map.getName());
1271
                }
1272
                return m_viewInfo;
1273
        }
1274

    
1275
        /**
1276
         * Inserta si se muestra o no la regla del Layout.
1277
         *
1278
         * @param b
1279
         *            True si se muestra la regla.
1280
         */
1281
        public void setRuler(boolean b) {
1282
                m_showRuler = b;
1283
        }
1284

    
1285
        /**
1286
         * Devuelve si se muestra la regla del Layout.
1287
         *
1288
         * @return True si se muestra la regla.
1289
         */
1290
        public boolean getRuler() {
1291
                return m_showRuler;
1292
        }
1293

    
1294
        /**
1295
         * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1296
         * cuadr?cula, o no.
1297
         *
1298
         * @return true si se esta aplicando la cuadr?cula.
1299
         */
1300
        public boolean isCuadricula() {
1301
                return isCuadricula;
1302
        }
1303

    
1304
        /**
1305
         * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1306
         *
1307
         * @param b
1308
         *            true si se aplica la cuadr?cula.
1309
         */
1310
        public void setIsCuadricula(boolean b) {
1311
                isCuadricula = b;
1312
        }
1313

    
1314
        /**
1315
         * Realiza una exteni?n completa de las capas que contiene la vista del
1316
         * FFrameView.
1317
         *
1318
         * @throws DriverException
1319
         */
1320
        public void viewFull() throws DriverException {
1321
                IFFrame[] fframes = getFFrameSelected();
1322
                for (int i = 0; i < fframes.length; i++) {
1323
                        if (fframes[i] instanceof IFFrameUseFMap) {
1324
                                IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i];
1325

    
1326
                                if (fframe.getMapContext() != null) {
1327
                                        fframe.fullExtent();
1328
                                }
1329
                                fframe.refresh();
1330
                        }
1331
                }
1332
                refresh();
1333
        }
1334

    
1335
        /**
1336
         * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1337
         * para poder despu?s volver a crear el objeto original.
1338
         *
1339
         * @return XMLEntity.
1340
         *
1341
         * @throws XMLException
1342
         */
1343
        public XMLEntity getXMLEntity() {
1344
                XMLEntity xml = new XMLEntity();
1345
                xml.putProperty("className", this.getClass().getName());
1346
                xml.setName("layout");
1347
                xml.putProperty("isCuadricula", isCuadricula());
1348
                xml.putProperty("m_name", this.getName());
1349
                xml.putProperty("isEditable", isEditable);
1350
                xml.putProperty("numBehind", numBehind);
1351
                xml.putProperty("numBefore", numBefore);
1352
                xml.addChild(getAtributes().getXMLEntity());
1353
                IFFrame[] fframes=getFFrames();
1354
                for (int i = 0; i < fframes.length; i++) {
1355
                        try {
1356
                                XMLEntity xmlAux = fframes[i].getXMLEntity();
1357
                                xml.addChild(xmlAux);
1358
                        } catch (SaveException e) {
1359
                                e.showError();
1360
                        }
1361
                }
1362
                return xml;
1363
        }
1364

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

    
1416
        /**
1417
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1418
         *
1419
         * @param xml
1420
         *            XMLEntity
1421
         * @param p
1422
         *            Proyecto.
1423
         *
1424
         * @return Objeto de esta clase.
1425
         */
1426
        public static Layout createLayout03(XMLEntity xml, Project p) {
1427
                Layout layout = new Layout();
1428
                layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1429
                layout.setName(xml.getStringProperty("m_name"));
1430
                layout.m_attributes = Attributes.createAtributes03(xml.getChild(0));
1431

    
1432
                for (int i = 1; i < xml.getChildrenCount(); i++) {
1433
                        if (xml.getChild(i).getStringProperty("className").equals(
1434
                                        "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1435
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1436
                                                p), true, false);
1437
                        }
1438
                }
1439

    
1440
                for (int i = 1; i < xml.getChildrenCount(); i++) {
1441
                        if (!xml.getChild(i).getStringProperty("className").equals(
1442
                                        "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1443
                                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1444
                                                p), true, false);
1445
                        }
1446
                }
1447

    
1448
                return layout;
1449
        }
1450

    
1451
        /**
1452
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
1453
         */
1454
        public void windowActivated() {
1455
                //fullRect();
1456
                refresh();
1457
                PluginServices.getMainFrame().getStatusBar().setMessage("units",
1458
                                getAtributes().getNameUnit());
1459
        }
1460

    
1461
        /**
1462
         * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
1463
         */
1464
        public Object getWindowModel() {
1465
                return map;
1466
        }
1467

    
1468
        /**
1469
         * Devuelve si se dibuja el Grid en el Layout o no.
1470
         *
1471
         * @return True si se dibuja el Grid en el Layout.
1472
         */
1473
        public boolean getIsDrawGrid() {
1474
                return isDrawCuadricula;
1475
        }
1476

    
1477
        /**
1478
         * Inserta si se muestra el Grid del Layout.
1479
         *
1480
         * @param b
1481
         *            True si se muestra el Grid del Layout.
1482
         */
1483
        public void setIsDrawGrid(boolean b) {
1484
                isDrawCuadricula = b;
1485
        }
1486

    
1487
        /**
1488
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1489
         */
1490
        public void extentChanged(ExtentEvent e) {
1491
        }
1492

    
1493
        /**
1494
         * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
1495
         */
1496
        public void windowClosed() {
1497
                // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1498
        }
1499

    
1500
        /**
1501
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1502
         */
1503
        public void backColorChanged(ColorEvent e) {
1504
                // refresh();
1505
        }
1506

    
1507
        /**
1508
         * Devuelve un array con los FFrames seleccionados.
1509
         *
1510
         * @return Array con los FFrames seleccionados.
1511
         */
1512
        public IFFrame[] getFFrameSelected() {
1513
                ArrayList selecList = new ArrayList();
1514
                IFFrame[] fframes=getFFrames();
1515
                for (int i = fframes.length - 1; i >= 0; i--) {
1516
                        IFFrame fframe = fframes[i];
1517

    
1518
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1519
                                selecList.add(fframe);
1520
                        }
1521
                }
1522

    
1523
                return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1524
        }
1525

    
1526
        /**
1527
         * Opens a dialog where to pick a PDF-file to save the current Layout
1528
         * suggesting a name for the file given by the first argument
1529
         *
1530
         * @param suggestedName
1531
         */
1532
        public void layoutToPDF(String suggestedName) {
1533
                FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices
1534
                                .getText(this, "pdf"));
1535

    
1536
                JFileChooser jfc = new JFileChooser();
1537
                if (suggestedName != null)
1538
                        jfc.setSelectedFile(new File(suggestedName));
1539
                jfc.addChoosableFileFilter(pdfFilter);
1540
                jfc.setFileFilter(pdfFilter);
1541

    
1542
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1543
                        File f = jfc.getSelectedFile();
1544
                        File faux = null;
1545

    
1546
                        if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
1547
                                faux = f;
1548
                        } else {
1549
                                faux = new File(f.getPath() + ".pdf");
1550
                        }
1551

    
1552
                        layoutDraw.toPDF(faux);
1553
                }
1554
        }
1555
        /**
1556
         * Opens a dialog where to pick a PS-file to save the current Layout
1557
         * suggesting a name for the file given by the first argument
1558
         *
1559
         * @param suggestedName
1560
         */
1561
        public void layoutToPS(String suggestedName) {
1562
                FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices
1563
                                .getText(this, "ps"));
1564

    
1565
                JFileChooser jfc = new JFileChooser();
1566
                if (suggestedName != null)
1567
                        jfc.setSelectedFile(new File(suggestedName));
1568
                jfc.addChoosableFileFilter(pdfFilter);
1569
                jfc.setFileFilter(pdfFilter);
1570

    
1571
                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1572
                        File f = jfc.getSelectedFile();
1573
                        File faux = null;
1574

    
1575
                        if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
1576
                                faux = f;
1577
                        } else {
1578
                                faux = new File(f.getPath() + ".ps");
1579
                        }
1580

    
1581
                        layoutDraw.toPS(faux);
1582
                }
1583
        }
1584
        /**
1585
         * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1586
         * en este formato.
1587
         */
1588
        public void layoutToPDF() {
1589
                layoutToPDF(null);
1590
        }
1591
        /**
1592
         * Abre un di?logo para seleccionar un fichero ps donde guardar el Layout
1593
         * en este formato.
1594
         */
1595
        public void layoutToPS() {
1596
                layoutToPS(null);
1597
        }
1598
        /**
1599
         * @return Returns the bModeDebug.
1600
         */
1601
        public boolean isModeDebug() {
1602
                return bModeDebug;
1603
        }
1604

    
1605
        /**
1606
         * @param modeDebug
1607
         *            The bModeDebug to set.
1608
         */
1609
        public void setModeDebug(boolean modeDebug) {
1610
                bModeDebug = modeDebug;
1611
        }
1612

    
1613
        private ArrayList allFFrames(IFFrame[] fframes, ArrayList all) {
1614
                for (int i = 0; i < fframes.length; i++) {
1615
                        if (fframes[i] instanceof FFrameGroup) {
1616
                                return allFFrames(((FFrameGroup) fframes[i]).getFFrames(), all);
1617

    
1618
                        }
1619
                                all.add(fframes[i]);
1620
                }
1621
                return all;
1622
        }
1623

    
1624
        public IFFrame[] getAllFFrames() {
1625
                ArrayList all = new ArrayList();
1626
                return (IFFrame[]) allFFrames(getFFrames(), all)
1627
                                .toArray(new IFFrame[0]);
1628
        }
1629

    
1630
        public GeometryAdapter getGeometryAdapter() {
1631
                return geometryAdapter;
1632
        }
1633

    
1634
        public boolean isEditable() {
1635
                return isEditable;
1636
        }
1637

    
1638
        public void setEditable(boolean b) {
1639
                if (!b) {
1640
                        clearSelection();
1641
                        setTool(Layout.ZOOM_MAS);
1642
                        PluginServices.getMainFrame().setSelectedTool("ZOOM_IN");
1643
                }
1644
                isEditable = b;
1645

    
1646
        }
1647

    
1648
        public void initGeometryAdapter() {
1649
                if (getTool() == LINE) {
1650
                        geometryAdapter = new PolyLineAdapter();
1651
                } else if (getTool() == RECTANGLESIMPLE) {
1652
                        geometryAdapter = new RectangleAdapter();
1653
                } else if (getTool() == POLYLINE) {
1654
                        geometryAdapter = new PolyLineAdapter();
1655
                } else if (getTool() == POLYGON) {
1656
                        geometryAdapter = new PolygonAdapter();
1657
                } else if (getTool() == CIRCLE) {
1658
                        geometryAdapter = new CircleAdapter();
1659
                } else if (getTool() == POINT) {
1660
                        geometryAdapter = new PointAdapter();
1661
                }
1662
        }
1663

    
1664
        public void startEdit() {
1665
                IFFrame[] fframes=getFFrames();
1666
                for (int i = 0; i < fframes.length; i++) {
1667
                        IFFrame frame = fframes[i];
1668
                        if (frame instanceof IFFrameEditableVertex) {
1669
                                if (frame.getSelected() != IFFrame.NOSELECT) {
1670
                                        ((IFFrameEditableVertex) frame).startEditing();
1671
                                } else {
1672
                                        ((IFFrameEditableVertex) frame).stopEditing();
1673
                                }
1674
                        }
1675

    
1676
                }
1677
                refresh();
1678
        }
1679

    
1680
        public void stopEdit() {
1681
                boolean refresh = false;
1682
                IFFrame[] fframes=getFFrames();
1683
                for (int i = 0; i < fframes.length; i++) {
1684
                        IFFrame frame = fframes[i];
1685
                        if (frame instanceof IFFrameEditableVertex) {
1686
                                if (((IFFrameEditableVertex) frame).isEditing()) {
1687
                                        ((IFFrameEditableVertex) fframes[i]).stopEditing();
1688
                                        refresh = true;
1689
                                }
1690
                        }
1691
                }
1692
                if (refresh)
1693
                        refresh();
1694
        }
1695

    
1696
        public void delFFrameSelected() {
1697
                efs.startComplexCommand();
1698
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1699
                        IFFrame fframe = efs.getFFrame(i);
1700

    
1701
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1702
                                efs.removeFFrame(i);
1703
                        }
1704
                }
1705
                efs.endComplexCommand(PluginServices.getText(this,"remove_elements"));
1706
                updateFFrames();
1707
        }
1708

    
1709
        public void clearSelection() {
1710
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1711
                        IFFrame fframe = efs.getFFrame(i);
1712
                        if (fframe.getSelected() != IFFrame.NOSELECT) {
1713
                                fframe.setSelected(false);
1714
                        }
1715
                }
1716
        }
1717
        public void delFFrame(int index) {
1718
                for (int i = 0; i < getEFS().getAllFFrames().length; i++) {
1719
                        if (getEFS().getFFrame(i).equals(getFFrame(index))) {
1720
                                getEFS().removeFFrame(i);
1721
                        }
1722
                }
1723
                updateFFrames();
1724
        }
1725

    
1726
        public void delFFrame(IFFrame frame) {
1727
                for (int i = 0; i < getEFS().getAllFFrames().length; i++) {
1728
                        if (getEFS().getFFrame(i).equals(frame)) {
1729
                                getEFS().removeFFrame(i);
1730
                        }
1731
                }
1732
                updateFFrames();
1733
        }
1734

    
1735
        public EditableFeatureSource getEFS() {
1736
                return efs;
1737
        }
1738

    
1739
        public void commandRepaint() {
1740
                this.updateFFrames();
1741
                this.refresh();
1742
        }
1743

    
1744
        public void commandRefresh() {
1745
                commandRepaint();
1746

    
1747
        }
1748

    
1749
        /**
1750
         * Introduce la posibilidad de establecer que los cambios que se hacen a
1751
         * partir de ese momento hasta que se vuelva a poner a false, que todas las
1752
         * operaciones que realices son sobre los fframes que implementen
1753
         * IFFrameGroupSelectable.
1754
         *
1755
         * @param b
1756
         */
1757
        public void setEditGroup(boolean b) {
1758
                editGroup = b;
1759
        }
1760

    
1761
        /**
1762
         * Devuelve true si se est? en modo de edici?n de los fframes que
1763
         * implementen IFFrameGroupSelectable.
1764
         *
1765
         * @return
1766
         */
1767
        public boolean isEditGroup() {
1768
                return editGroup;
1769
        }
1770

    
1771
        public int getNumBehind() {
1772
                return --numBehind;
1773
        }
1774

    
1775
        public int getNumBefore() {
1776
                return ++numBefore;
1777
        }
1778

    
1779
        public void projectionChanged(ProjectionEvent e) {
1780
                // TODO Auto-generated method stub
1781

    
1782
        }
1783

    
1784
         public void endGraphic() {
1785
                if ((getTool() == Layout.LINE)
1786
                                || (getTool() == Layout.POLYLINE)
1787
                                || (getTool() == Layout.POLYGON)
1788
                                || (getTool() == Layout.CIRCLE)
1789
                                || (getTool() == Layout.RECTANGLESIMPLE)
1790
                                || (getTool() == Layout.POINT)) {
1791
                        getGeometryAdapter().end();
1792
                        PluginServices.getMainFrame().enableControls();
1793
                        FLayoutFunctions lf=new FLayoutFunctions(this);
1794
                        lf.addFFrame();
1795
                        initGeometryAdapter();
1796
                        refresh();
1797
                }
1798
        }
1799

    
1800
        public void delLastPoint() {
1801
                getGeometryAdapter().delLastPoint();
1802
        }
1803
}