Statistics
| Revision:

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

History | View | Annotate | Download (37.2 KB)

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

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

    
53
import com.iver.cit.gvsig.Abrir;
54
import com.iver.cit.gvsig.fmap.ColorEvent;
55
import com.iver.cit.gvsig.fmap.DriverException;
56
import com.iver.cit.gvsig.fmap.ExtentEvent;
57
import com.iver.cit.gvsig.fmap.ViewPortListener;
58
import com.iver.cit.gvsig.fmap.edition.EditionException;
59
import com.iver.cit.gvsig.fmap.layers.FBitSet;
60
import com.iver.cit.gvsig.gui.cad.CADToolAdapter;
61
import com.iver.cit.gvsig.gui.cad.CadGrid;
62
import com.iver.cit.gvsig.gui.cad.CadTool;
63
import com.iver.cit.gvsig.gui.cad.tools.ArcCadTool;
64
import com.iver.cit.gvsig.gui.cad.tools.CircleCadTool;
65
import com.iver.cit.gvsig.gui.cad.tools.EllipseCadTool;
66
import com.iver.cit.gvsig.gui.cad.tools.LineCadTool;
67
import com.iver.cit.gvsig.gui.cad.tools.PointCadTool;
68
import com.iver.cit.gvsig.gui.cad.tools.PolyLineCadTool;
69
import com.iver.cit.gvsig.gui.cad.tools.PolygonCadTool;
70
import com.iver.cit.gvsig.gui.cad.tools.RectangleCadTool;
71
import com.iver.cit.gvsig.gui.layout.dialogs.FConfigLayoutDialog;
72
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
73
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
74
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
75
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
76
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
77
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
78
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
79
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
80
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGraphicsDialog;
81
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameLegendDialog;
82
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFramePictureDialog;
83
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameScaleBarDialog;
84
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameTextDialog;
85
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameViewDialog;
86
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog;
87
import com.iver.cit.gvsig.gui.project.MapProperties;
88
import com.iver.cit.gvsig.project.Project;
89
import com.iver.cit.gvsig.project.ProjectMap;
90

    
91
import com.iver.utiles.XMLEntity;
92

    
93
import org.apache.log4j.Logger;
94

    
95
import java.awt.Color;
96
import java.awt.Cursor;
97
import java.awt.Graphics;
98
import java.awt.Graphics2D;
99
import java.awt.Image;
100
import java.awt.Point;
101
import java.awt.Rectangle;
102
import java.awt.Toolkit;
103
import java.awt.event.ActionEvent;
104
import java.awt.event.KeyEvent;
105
import java.awt.geom.AffineTransform;
106
import java.awt.geom.Point2D;
107
import java.awt.geom.Rectangle2D;
108
import java.awt.image.BufferedImage;
109
import java.awt.image.MemoryImageSource;
110
import java.awt.print.PageFormat;
111
import java.awt.print.Printable;
112
import java.awt.print.PrinterException;
113
import java.awt.print.PrinterJob;
114

    
115
import java.util.ArrayList;
116
import java.util.BitSet;
117
import java.util.HashMap;
118
import java.util.Hashtable;
119
import java.util.Stack;
120

    
121
import javax.print.Doc;
122
import javax.print.DocFlavor;
123
import javax.print.DocPrintJob;
124
import javax.print.PrintException;
125
import javax.print.PrintService;
126
import javax.print.PrintServiceLookup;
127
import javax.print.ServiceUI;
128
import javax.print.SimpleDoc;
129
import javax.print.attribute.PrintRequestAttributeSet;
130
import javax.print.event.PrintJobAdapter;
131
import javax.print.event.PrintJobEvent;
132
import javax.print.event.PrintJobListener;
133

    
134
import javax.swing.AbstractAction;
135
import javax.swing.Action;
136
import javax.swing.ImageIcon;
137
import javax.swing.JPanel;
138
import javax.swing.KeyStroke;
139

    
140

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

    
235
        // private String m_name = null;
236
        private boolean m_showRuler = true;
237
        private FLayoutDraw layoutPaint = null;
238
        private boolean isDrawCuadricula = true;
239
        private Doc doc = null;
240
        private PrintRequestAttributeSet att = null;
241
        private boolean cadtool = false;
242
        private HashMap namesCadTools = new HashMap();
243
        private LayoutCADToolAdapter cadToolAdapter;
244
        private HashMap namesMapTools = new HashMap();
245
        private Stack toolStack = new Stack();
246

    
247
        /**
248
         * Creates a new Layout object.
249
         */
250
        public Layout() {
251
                this.setLayout(null);
252
                cadToolAdapter=new LayoutCADToolAdapter(this);
253
                FFrameGraphics fg=new FFrameGraphics(cadToolAdapter);
254
                addFFrame(fg,true);
255
                events = new EventsHandler(this);
256
                layoutPaint = new FLayoutDraw(this);
257
                getCadToolAdapter().setEditableFeatureSource(new LayoutEditableFeature(this),new FBitSet());
258
                try {
259
                        getCadToolAdapter().getEditableFeatureSource().startEdition();
260
                } catch (EditionException e) {
261
                        e.printStackTrace();
262
                }
263
                addComponentListener(events);
264
                addMouseMotionListener(events);
265
                addMouseListener(events);
266
                m_MatrizTransf = new AffineTransform();
267
                m_MatrizTransf.setToIdentity();
268
                this.initComponents();
269
                
270

    
271
        }
272

    
273
        /**
274
         * Rellena el ProjectMap del Layout.
275
         *
276
         * @param m ProjectMap.
277
         */
278
        public void setProjectMap(ProjectMap m) {
279
                map = m;
280
        }
281

    
282
        /**
283
         * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
284
         *
285
         * @return Rect?ngulo de selecci?n.
286
         */
287
        public Rectangle getReSel() {
288
                return reSel;
289
        }
290

    
291
        /**
292
         * Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar
293
         * la sellecci?n.
294
         *
295
         * @return true si se realiza la selecci?n por rect?ngulo.
296
         */
297
        public boolean isReSel() {
298
                return isReSel;
299
        }
300

    
301
        /**
302
         * Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
303
         * selecci?n.
304
         *
305
         * @param b boolean.
306
         */
307
        public void setIsReSel(boolean b) {
308
                isReSel = b;
309
        }
310

    
311
        /**
312
         * Devuelve true si el dibujado ha sido cancelado.
313
         *
314
         * @return true si el dibujado ha sido cancelado.
315
         */
316
        public synchronized boolean isDrawingCancelled() {
317
                return m_bCancelDrawing;
318
        }
319

    
320
        /**
321
         * Pone el dibuja a cancelado o no seg?n se quiera.
322
         *
323
         * @param b true si se quiere cancelar el dibujado.
324
         */
325
        public synchronized void setCancelDrawing(boolean b) {
326
                m_bCancelDrawing = b;
327

    
328
                for (int i = 0; i < getFFrames().size(); i++) {
329
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
330

    
331
                        if (fframe instanceof FFrameView &&
332
                                        (((FFrameView) fframe).getFMap() != null)) {
333
                                ////TODO((FFrameView) getFFrames().get(i)).getFMap().setCancelDrawing(b);
334
                        }
335
                }
336
        }
337

    
338
        /**
339
         * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
340
         *
341
         * @return Array con todos los fframes que contiene el Layout.
342
         */
343
        public ArrayList getFFrames() {
344
                return m_fframes;
345
        }
346

    
347
        /**
348
         * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
349
         * entero.
350
         */
351
        public void fullRect() {
352
                rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
353
                        getHeight() - (origin.x * 2));
354

    
355
                if (m_attributes.isLandSpace()) {
356
                        rect = m_attributes.getRectangleLandscape(rect, getWidth(),
357
                                        getHeight());
358
                } else {
359
                        rect = m_attributes.getRectanglePortrait(rect, getWidth(),
360
                                        getHeight());
361
                }
362

    
363
                status = DESACTUALIZADO;
364
                repaint();
365
        }
366

    
367
        /**
368
         * M?todo para imprimir el Layout sin modificar la matriz de
369
         * transformaci?n.
370
         *
371
         * @param g2
372
         */
373
        public void drawLayoutPrint(Graphics2D g2) {
374
                setCancelDrawing(false);
375

    
376
                setCursor(Cursor.getDefaultCursor());
377

    
378
                double scale = 0;
379

    
380
                ///if (rect.width > rect.height) {
381
                ///    scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
382
                ///} else {
383
                scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
384

    
385
                ///}
386
                AffineTransform escalado = new AffineTransform();
387
                AffineTransform translacion = new AffineTransform();
388
                translacion.setToTranslation(rect.getMinX(), rect.getMinY());
389
                escalado.setToScale(scale, scale);
390
                m_MatrizTransf.setToIdentity();
391
                m_MatrizTransf.concatenate(translacion);
392
                m_MatrizTransf.concatenate(escalado);
393
                m_attributes.setDistanceUnitX(rect);
394
                m_attributes.setDistanceUnitY(rect);
395

    
396
                for (int i = 0; i < getFFrames().size(); i++) {
397
                        try {
398
                                ((IFFrame) getFFrames().get(i)).print(g2, getAT());
399
                        } catch (DriverException e) {
400
                                NotificationManager.addError(e.getMessage(), e);
401
                        }
402
                }
403

    
404
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
405
        }
406

    
407
        /**
408
         * Clip sobre el rect?ngulo visible.
409
         *
410
         * @param g2d Graphics sobre el que hacer el clip.
411
         */
412
        private void clipVisibleRect(Graphics2D g2d) {
413
                rectVisible = this.getVisibleRect();
414
                g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
415
                        (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
416
        }
417

    
418
        /**
419
         * Inicializa los componentes.
420
         */
421
        private void initComponents() {
422
                m_attributes = new Attributes();
423
                m_attributes.setCADToolAdapter(this.getCadToolAdapter());
424
                m_attributes.setDistanceUnitX(rect);
425
                m_attributes.setDistanceUnitY(rect);
426
                actionDelFFrame();
427

    
428
                //Herramienta de CAD de a?adir punto
429
                PointCadTool pointCADTool = new PointCadTool();
430
                addCadTool("point", pointCADTool);
431

    
432
                //Herramienta de CAD de a?adir l?nea
433
                LineCadTool lineCADTool = new LineCadTool();
434
                addCadTool("line", lineCADTool);
435

    
436
                //Herramienta de CAD de a?adir c?rculo
437
                CircleCadTool circleCADTool=new CircleCadTool();
438
                addCadTool("circle",circleCADTool);
439

    
440
                //Herramienta de CAD de a?adir c?rculo
441
                EllipseCadTool ellipseCADTool=new EllipseCadTool();
442
                addCadTool("ellipse", ellipseCADTool);
443

    
444
                //Herramienta de CAD de a?adir c?rculo
445
                ArcCadTool arcCADTool=new ArcCadTool();
446
                addCadTool("arc",arcCADTool);
447

    
448
                //Herramienta de CAD de a?adir polyl?nea
449
                PolyLineCadTool polylineCADTool = new PolyLineCadTool();
450
                addCadTool("polyline", polylineCADTool);
451

    
452
                //Herramienta de CAD de a?adir rect?ngulo.
453
                RectangleCadTool rectangleCADTool = new RectangleCadTool();
454
                addCadTool("rectangle", rectangleCADTool);
455

    
456
                //Herramienta de CAD de a?adir pol?gono.
457
                PolygonCadTool polygonCADTool = new PolygonCadTool();
458
                addCadTool("polygon", polygonCADTool);
459
        }
460

    
461
        /**
462
         * Crea un ActionEvent para controlar las teclas que se pulsen cuando este
463
         * el Layout Focusable a true.
464
         */
465
        private void actionDelFFrame() {
466
                Action doNothing = new AbstractAction() {
467
                                public void actionPerformed(ActionEvent e) {
468
                                        for (int i = getFFrames().size() - 1; i >= 0; i--) {
469
                                                IFFrame fframe = (IFFrame) getFFrames().get(i);
470

    
471
                                                if (fframe.getSelected() != FFrame.NOSELECT) {
472
                                                        getFFrames().remove(i);
473
                                                }
474
                                        }
475

    
476
                                        refresh();
477
                                }
478
                        };
479

    
480
                this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
481
                        "doNothing");
482
                this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
483
                        "doNothing");
484
                this.getActionMap().put("doNothing", doNothing);
485
        }
486

    
487
        /**
488
         * paintComponent del Layout.
489
         *
490
         * @param g Graphics del Layout.
491
         */
492
        protected void paintComponent(Graphics g) {
493
                super.paintComponent(g);
494

    
495
                clipVisibleRect((Graphics2D) g);
496

    
497
                Rectangle rClip = g.getClipBounds();
498

    
499
                if (rClip == null) {
500
                        System.err.println("clip = null");
501
                }
502

    
503
                switch (status) {
504
                        case ZOOM_MAS:
505
                                logger.debug("zoom mas");
506
                                layoutPaint.drawRectangle((Graphics2D) g);
507

    
508
                                g.drawImage(img, 0, 0, this);
509

    
510
                                g.setClip(rClip);
511
                                cadToolAdapter.drawGrid(g);
512
                                layoutPaint.drawRuler((Graphics2D) g, Color.black);
513
                                g.setColor(Color.black);
514
                                g.setXORMode(Color.white);
515

    
516
                                Rectangle r = new Rectangle();
517

    
518
                                r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
519
                                g.drawRect(r.x, r.y, r.width, r.height);
520

    
521
                                break;
522

    
523
                        case RECTANGLE:
524
                                logger.debug("rectangle");
525
                                layoutPaint.drawRectangle((Graphics2D) g);
526

    
527
                                g.drawImage(img, 0, 0, this);
528

    
529
                                g.setClip(rClip);
530
                                cadToolAdapter.drawGrid(g);
531
                                layoutPaint.drawRuler((Graphics2D) g, Color.black);
532
                                g.setColor(Color.black);
533
                                g.setXORMode(Color.white);
534

    
535
                                Rectangle re = new Rectangle();
536
                                re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
537

    
538
                                if (isCuadricula()) {
539
                                        FLayoutUtilities.setRectGrid(re,
540
                                                m_attributes.getUnitInPixelsX(),
541
                                                m_attributes.getUnitInPixelsY(), m_MatrizTransf);
542
                                }
543

    
544
                                g.drawRect(re.x, re.y, re.width, re.height);
545
                        
546
                                break;
547

    
548
                        case PAN:
549

    
550
                                   logger.debug("pan");
551
                                   rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
552
                                   rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
553
                                   layoutPaint.drawRectangle((Graphics2D) g);
554
                                   if (img != null) {
555
                                           g.drawImage(img, (getLastPoint().x - getPointAnt().x),
556
                                                   (m_LastPoint.y - m_PointAnt.y), this);
557
                                   }
558
                                   g.setClip(rClip);
559
                                   layoutPaint.drawRuler((Graphics2D) g, Color.black);
560
        
561
                                break;
562

    
563
                        case VIEW_PAN:
564

    
565
                                layoutPaint.drawRectangle((Graphics2D) g);
566

    
567
                                for (int i = 0; i < getFFrames().size(); i++) {
568
                                        if (getFFrames().get(i) instanceof FFrameView) {
569
                                                FFrameView fframe = (FFrameView) getFFrames().get(i);
570

    
571
                                                if (fframe.getSelected() != FFrame.NOSELECT) {
572
                                                        Rectangle2D.Double rec = fframe.getBoundingBox(getAT());
573

    
574
                                                        if (img != null) {
575
                                                                rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
576
                                                        }
577

    
578
                                                        if (fframe.getBufferedImage() != null) {
579
                                                                layoutPaint.drawHandlers((Graphics2D) g,
580
                                                                        Color.black);
581
                                                                g.clipRect((int) rec.x, (int) rec.y,
582
                                                                        (int) rec.width, (int) rec.height);
583

    
584
                                                                layoutPaint.drawRectangle((Graphics2D) g);
585
                                                                layoutPaint.drawRuler((Graphics2D) g,
586
                                                                        Color.black);
587

    
588
                                                                g.drawImage(fframe.getBufferedImage(),
589
                                                                        m_LastPoint.x - m_PointAnt.x,
590
                                                                        m_LastPoint.y - m_PointAnt.y, this);
591
                                                        }
592
                                                }
593
                                        }
594
                                }
595

    
596
                                g.setClip(rClip);
597
                                cadToolAdapter.drawGrid(g);
598
                                layoutPaint.drawRuler((Graphics2D) g, Color.black);
599
                                break;
600

    
601
                        case SELECT:
602
                                logger.debug("select");
603
                                layoutPaint.drawRectangle((Graphics2D) g);
604

    
605
                                g.drawImage(img, 0, 0, this);
606

    
607
                                if (isReSel) {
608
                                        reSel = new Rectangle();
609
                                        reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
610
                                        g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
611
                                }
612

    
613
                                for (int i = 0; i < getFFrames().size(); i++) {
614
                                        IFFrame fframe = (IFFrame) getFFrames().get(i);
615

    
616
                                        if (fframe.getSelected() != FFrame.NOSELECT) {
617
                                                g.setColor(Color.black);
618
                                                fframe.drawHandlers((Graphics2D) g);
619

    
620
                                                int difx = (m_LastPoint.x - m_FirstPoint.x);
621
                                                int dify = (m_LastPoint.y - m_FirstPoint.y);
622

    
623
                                                if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
624
                                                        Rectangle2D rectangle = fframe.getMovieRect(difx,
625
                                                                        dify);
626

    
627
                                                        if (rectangle != null) {
628
                                                                if (isCuadricula) {
629
                                                                        FLayoutUtilities.setRectGrid(rectangle,
630
                                                                                m_attributes.getUnitInPixelsX(),
631
                                                                                m_attributes.getUnitInPixelsY(),
632
                                                                                m_MatrizTransf);
633
                                                                }
634

    
635
                                                                g.drawRect((int) rectangle.getMinX(),
636
                                                                        (int) rectangle.getMinY(),
637
                                                                        (int) rectangle.getWidth(),
638
                                                                        (int) rectangle.getHeight());
639
                                                        }
640
                                                }
641
                                        }
642
                                }
643

    
644
                                g.setClip(rClip);
645
                                cadToolAdapter.drawGrid(g);
646
                                layoutPaint.drawRuler((Graphics2D) g, Color.black);
647

    
648
                                break;
649

    
650
                        case GRAPHICS:
651
                                break;
652

    
653
                        case DESACTUALIZADO:
654
                                logger.debug("desactualizado");
655
                                img = new BufferedImage(getWidth(), getHeight(),
656
                                                BufferedImage.TYPE_INT_ARGB);
657

    
658
                                Graphics gimag = img.getGraphics();
659
                                clipVisibleRect((Graphics2D) gimag);
660

    
661
                                if (initial) {
662
                                        fullRect();
663
                                        initial = false;
664
                                }
665

    
666
                                try {
667
                                        layoutPaint.drawLayout((Graphics2D) gimag, img);
668
                                } catch (DriverException e) {
669
                                        e.printStackTrace();
670
                                }
671

    
672
                                g.setClip(rClip);
673
                                layoutPaint.drawRectangle((Graphics2D) g);
674

    
675
                                g.drawImage(img, 0, 0, this);
676
                                g.setClip(rClip);
677
                                cadToolAdapter.drawGrid(g);
678
                                
679
                                layoutPaint.drawHandlers((Graphics2D) g, Color.black);
680
                                layoutPaint.drawRuler((Graphics2D) g, Color.black);
681
                                if (getTool()==GRAPHICS){
682
                                        cadToolAdapter.drawCursor(g);
683
                                }
684
                                
685
                                break;
686

    
687
                        case ACTUALIZADO:
688
                                layoutPaint.drawRectangle((Graphics2D) g);
689

    
690
                                g.drawImage(img, 0, 0, this);
691

    
692
                                g.setClip(rClip);
693
                                layoutPaint.drawHandlers((Graphics2D) g, Color.black);
694
                                layoutPaint.drawRuler((Graphics2D) g, Color.black);
695
                                cadToolAdapter.drawGrid(g);
696
                                if (getTool()==GRAPHICS){
697
                                        cadToolAdapter.drawCursor(g);
698
                                }
699
                                cadToolAdapter.paintComponent(g);
700
                
701
                }
702
        }
703

    
704
        /**
705
         * A?ade un fframe al Arraylist m_fframes.
706
         *
707
         * @param frame fframe a a?adir.
708
         * @param clearSelection para que se quede seleccionado ?nicamente  el que
709
         *                   a?adimos y false si lo que se pretende es que no se
710
         *                   deseleccionen lo que ya est?n seleccionados.
711
         */
712
        public void addFFrame(IFFrame frame, boolean clearSelection) {
713
                if (clearSelection) {
714
                        for (int i = getFFrames().size() - 1; i >= 0; i--) {
715
                                IFFrame fframe1 = (IFFrame) getFFrames().get(i);
716
                                fframe1.setSelected(false);
717
                        }
718
                }
719

    
720
                if (frame instanceof FFrameView &&
721
                                (((FFrameView) frame).getFMap() != null)) {
722
                        ((FFrameView) frame).getFMap().getViewPort().addViewPortListener(this);
723
                }
724

    
725
                if (nums.containsKey(frame.getClass())) {
726
                        nums.put(frame.getClass(),
727
                                new Integer(Integer.parseInt(nums.get(frame.getClass())
728
                                                                                                 .toString()) + 1));
729
                } else {
730
                        nums.put(frame.getClass(), new Integer(0));
731
                }
732

    
733
                frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
734
                getFFrames().add(frame);
735
                frame.setSelected(true);
736
        }
737

    
738
        /**
739
         * Abre el di?logo de propiedades del folio, pasando como par?metro el
740
         * PrinterJob.
741
         *
742
         * @param job
743
         */
744
        public void showPagePropertiesWindow(PrinterJob job) {
745
                PageFormat pf1; //=new PageFormat();
746

    
747
                pf1 = m_attributes.getPageFormat();
748
                pf1 = job.pageDialog(pf1);
749
                m_attributes.setPageFormat(pf1);
750
                refresh();
751
        }
752

    
753
        /**
754
         * Refresca el Layout.
755
         */
756
        public void refresh() {
757
                rect = m_attributes.obtainRect(false, rect, getWidth(), getHeight());
758
                status = DESACTUALIZADO;
759
                repaint();
760
        }
761

    
762
        /**
763
         * Obtiene el rect?ngulo que representa el folio con las caracter?sticas
764
         * que contiene attributes y diferenciando si es para visualizar en
765
         * pantalla o para imprimir.
766
         *
767
         * @param isPrint si es para imprimir.
768
         */
769
        public void obtainRect(boolean isPrint) {
770
                m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
771
        }
772

    
773
        /**
774
         * Muestra el di?logo de configuraci?n del Layout.
775
         */
776
        public void showFConfig() {
777
                FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
778
                PluginServices.getMDIManager().addView(m_configLayout);
779
        }
780

    
781
        /**
782
         * Mestra el di?logo de propiedades del Layout.
783
         */
784
        public void showFProperties() {
785
                if (map == null) {
786
                        map = new ProjectMap();
787
                        map.setModel(this);
788
                        map.setName(getName());
789
                }
790

    
791
                m_propertiesLayout = new MapProperties(map);
792
                PluginServices.getMDIManager().addView(m_propertiesLayout);
793
        }
794

    
795
        /**
796
         * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
797
         *
798
         * @param job
799
         */
800
        public void showPrintDialog(PrinterJob job) {
801
                if (job != null) {
802
                        job.printDialog();
803

    
804
                        try {
805
                                job.setPrintable((Printable) PluginServices.getExtension(
806
                                                com.iver.cit.gvsig.Print.class));
807
                                job.print();
808
                        } catch (PrinterException e) {
809
                                e.printStackTrace();
810
                        }
811
                } else {
812
                        boolean print = false;
813

    
814
                        //Actualizar attributes
815
                        att = m_attributes.toPrintAttributes();
816

    
817
                        //------------------ The Printing things --------------------- //
818
                        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
819

    
820
                        // returns the set of printers that support printing a specific document type (such as GIF)
821
                        // with a specific set of attributes (such as two sided).
822
                        // PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
823
                        // interestingly, the printer dialog's default behavior has changed with the new API: by default the dialog is not shown.
824
                        // So we must use the ServiceUI class to create a print dialog
825
                        // returns the default print service.
826
                        if (m_cachePrintServices == null) {
827
                                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
828
                                                null);
829
                        }
830

    
831
                        PrintService defaultService = null;
832

    
833
                        if (m_cachePrintService == null) {
834
                                defaultService = PrintServiceLookup.lookupDefaultPrintService();
835
                        }
836

    
837
                        if (m_cachePrintService == null) {
838
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
839
                                                m_cachePrintServices, defaultService, flavor, att);
840

    
841
                                // m_cachePrintRequestAtributeSet = new HashPrintRequestAttributeSet();
842
                                // m_cachePrintRequestAtributeSet.addAll(pras);
843
                        } else {
844
                                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
845
                                                m_cachePrintServices, m_cachePrintService, flavor, att);
846
                        }
847

    
848
                        if (m_cachePrintService != null) {
849
                                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
850
                                PrintJobListener pjlistener = new PrintJobAdapter() {
851
                                                public void printDataTransferCompleted(PrintJobEvent e) {
852
                                                        System.out.println("Fin de impresi?n");
853
                                                }
854
                                        };
855

    
856
                                jobNuevo.addPrintJobListener(pjlistener);
857

    
858
                                // DocAttributeSet das = new HashDocAttributeSet();
859
                                doc = new SimpleDoc((Printable) PluginServices.getExtension(
860
                                                        com.iver.cit.gvsig.Print.class), flavor, null);
861

    
862
                                try {
863
                                        jobNuevo.print(doc, att);
864

    
865
                                        // m_attributes.
866
                                } catch (PrintException pe) {
867
                                        pe.printStackTrace();
868
                                }
869
                        }
870
                }
871

    
872
                /* try {
873
                   print = job.printDialog(att);
874
                   } catch (Exception e) {
875
                       logger.error("Abriendo el Di?logo de imprimir"); //System.out.println("Excepci?n "+e);
876
                   }
877
                   if (print) {
878
                       job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
879
                       try {
880
                           job.print(att);
881
                       } catch (Exception ex) {
882
                           ex.printStackTrace();
883
                       }
884
                   } */
885
                fullRect();
886
        }
887

    
888
        /**
889
         * Sustituye el puntero del rat?n por la imagen que se le pasa como
890
         * par?metro.
891
         *
892
         * @param image
893
         */
894
        public void setMapCursor(Image image) {
895
                Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
896
                                new Point(16, 16), "");
897
                setCursor(cur);
898
        }
899

    
900
        /**
901
         * Cambia el puntero del raton al cusor que se le introduce como par?metro.
902
         *
903
         * @param cursor cursor a mostrar en el puntero del rat?n.
904
         */
905
        public void setMapCursor(Cursor cursor) {
906
                setCursor(cursor);
907
        }
908

    
909
        /**
910
         * Pone como seleccionada a la herramienta a partir de su n?mero.
911
         *
912
         * @param i
913
         */
914
        public void setTool(int i) {
915
                tool = i;
916

    
917
                if (getTool() == PAN) {
918
                        setMapCursor(ipan);
919
                } else if (getTool() == ZOOM_MAS) {
920
                        setMapCursor(izoomin);
921
                } else if (getTool() == ZOOM_MENOS) {
922
                        setMapCursor(izoomout);
923
                } else if (getTool() == RECTANGLEVIEW || 
924
                                getTool() == RECTANGLEPICTURE ||
925
                                getTool() == RECTANGLESCALEBAR || 
926
                                getTool() == RECTANGLELEGEND ||
927
                                getTool() == RECTANGLETEXT) {
928
                        setMapCursor(icrux);
929
                } else if (getTool() == SELECT) {
930
                        setCursor(Cursor.getDefaultCursor());
931
                } else if (getTool() == SET_TAG) {
932
                        setMapCursor(itag);
933
                }else if (getTool() == GRAPHICS) {
934
                        clearMouseImage();
935
                } 
936
        }
937
        private void clearMouseImage(){
938
                int[] pixels = new int[16 * 16];
939
                Image image = Toolkit.getDefaultToolkit().createImage(
940
                        new MemoryImageSource(16, 16, pixels, 0, 16));
941
                Cursor transparentCursor =
942
                        Toolkit.getDefaultToolkit().createCustomCursor
943
                            (image, new Point(0,0), "invisiblecursor");
944
                this.setCursor(transparentCursor);
945
        }
946
        /**
947
         * Se crean aqu? los dialogos cada vez que se necesitan.
948
         *
949
         * @param fframe Rectangle que representa el lugar que ocupara el elemento
950
         *                   a?adido.
951
         *
952
         * @return true si se debe de a?adir el fframe.
953
         */
954
        public boolean openFFrameDialog(IFFrame fframe) {
955
                switch (tool) {
956
                        case RECTANGLEVIEW:
957
                                fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
958

    
959
                                break;
960

    
961
                        case RECTANGLEPICTURE:
962
                                fframedialog = new FFramePictureDialog(this,
963
                                                (FFramePicture) fframe);
964

    
965
                                break;
966

    
967
                        case RECTANGLESCALEBAR:
968
                                fframedialog = new FFrameScaleBarDialog(this,
969
                                                (FFrameScaleBar) fframe);
970

    
971
                                break;
972

    
973
                        case RECTANGLELEGEND:
974
                                fframedialog = new FFrameLegendDialog(this,
975
                                                (FFrameLegend) fframe);
976

    
977
                                break;
978

    
979
                        case RECTANGLETEXT:
980
                                fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
981

    
982
                                break;
983

    
984
                        case GRAPHICS:
985
                                fframedialog = new FFrameGraphicsDialog(this,
986
                                                (FFrameGraphics) fframe);
987

    
988
                                break;
989

    
990
                        default:
991
                                return true;
992
                }
993

    
994
                if (fframedialog != null) {
995
                        fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
996
                        PluginServices.getMDIManager().addView(fframedialog);
997
                }
998

    
999
                return fframedialog.getIsAcepted();
1000
        }
1001

    
1002
        /**
1003
         * Devuelve el Rectangle2D que representa en pixels al folio.
1004
         *
1005
         * @return Rectangle2D.Double
1006
         */
1007
        public Rectangle2D.Double getRect() {
1008
                return rect;
1009
        }
1010

    
1011
        /**
1012
         * Obtiene un entero que representa la herramienta seleccionada.
1013
         *
1014
         * @return entero.
1015
         */
1016
        public int getTool() {
1017
                return tool;
1018
        }
1019

    
1020
        /**
1021
         * Devuelve la Matriz transformada que se esta plicando al Layout.
1022
         *
1023
         * @return AffineTransform
1024
         */
1025
        public AffineTransform getAT() {
1026
                return m_MatrizTransf;
1027
        }
1028

    
1029
        /**
1030
         * Devuelve los atributos del Mapa.
1031
         *
1032
         * @return Attributes.
1033
         */
1034
        public Attributes getAtributes() {
1035
                return m_attributes;
1036
        }
1037

    
1038
        /**
1039
         * Pone el estado que se quiera.
1040
         *
1041
         * @param s estado.
1042
         */
1043
        public void setStatus(int s) {
1044
                status = s;
1045
        }
1046

    
1047
        /**
1048
         * Devuelve el punto que representa la esquina noroeste del mapa.
1049
         *
1050
         * @return un punto.
1051
         */
1052
        public Point getRectOrigin() {
1053
                return rectOrigin;
1054
        }
1055

    
1056
        /**
1057
         * Devuelve el punto del primer click de rat?n.
1058
         *
1059
         * @return un punto.
1060
         */
1061
        public Point getFirstPoint() {
1062
                return m_FirstPoint;
1063
        }
1064

    
1065
        /**
1066
         * Devuelve el punto de click de rat?n anterior.
1067
         *
1068
         * @return un punto.
1069
         */
1070
        public Point getPointAnt() {
1071
                return m_PointAnt;
1072
        }
1073

    
1074
        /**
1075
         * Devuelve el punto donde se solt? el bot?n del rat?n.
1076
         *
1077
         * @return un punto.
1078
         */
1079
        public Point getLastPoint() {
1080
                return m_LastPoint;
1081
        }
1082

    
1083
        /**
1084
         * Rellena el primer punto de click de rat?n.
1085
         *
1086
         * @param p punto.
1087
         */
1088
        public void setFirstPoint(Point p) {
1089
                m_FirstPoint = p;
1090
        }
1091

    
1092
        /**
1093
         * Rellena el punto de click de rat?n anterior.
1094
         *
1095
         * @param p punto.
1096
         */
1097
        public void setPointAnt(Point p) {
1098
                m_PointAnt = p;
1099
        }
1100

    
1101
        /**
1102
         * Rellena el punto donde se solto el bot?n del rat?n.
1103
         *
1104
         * @param p punto.
1105
         */
1106
        public void setLastPoint(Point p) {
1107
                m_LastPoint = p;
1108
        }
1109

    
1110
        /**
1111
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1112
         */
1113
        public ViewInfo getViewInfo() {
1114
                ViewInfo m_viewinfo = new ViewInfo(ViewInfo.ICONIFIABLE |
1115
                                ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE);
1116

    
1117
                m_viewinfo.setWidth(500);
1118
                m_viewinfo.setHeight(400);
1119

    
1120
                m_viewinfo.setTitle(PluginServices.getText(this, "Mapa") + " : " +
1121
                        getName());
1122

    
1123
                return m_viewinfo;
1124
        }
1125

    
1126
        /**
1127
         * Inserta si se muestra o no la regla del Layout.
1128
         *
1129
         * @param b True si se muestra la regla.
1130
         */
1131
        public void setRuler(boolean b) {
1132
                m_showRuler = b;
1133
        }
1134

    
1135
        /**
1136
         * Devuelve si se muestra la regla del Layout.
1137
         *
1138
         * @return True si se muestra la regla.
1139
         */
1140
        public boolean getRuler() {
1141
                return m_showRuler;
1142
        }
1143

    
1144
        /**
1145
         * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1146
         * cuadr?cula, o no.
1147
         *
1148
         * @return true si se esta aplicando la cuadr?cula.
1149
         */
1150
        public boolean isCuadricula() {
1151
                return isCuadricula;
1152
        }
1153

    
1154
        /**
1155
         * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1156
         *
1157
         * @param b true si se aplica la cuadr?cula.
1158
         */
1159
        public void setIsCuadricula(boolean b) {
1160
                isCuadricula = b;
1161
                getCadToolAdapter().setAdjustGrid(b);
1162
        }
1163

    
1164
        /**
1165
         * Realiza una exteni?n completa de las capas que contiene la vista del
1166
         * FFrameView.
1167
         *
1168
         * @throws DriverException
1169
         */
1170
        public void viewFull() throws DriverException {
1171
                for (int i = 0; i < getFFrames().size(); i++) {
1172
                        if (getFFrames().get(i) instanceof FFrameView) {
1173
                                FFrameView fframe = (FFrameView) getFFrames().get(i);
1174

    
1175
                                if (fframe.getSelected() != FFrame.NOSELECT) {
1176
                                        fframe.getFMap().getViewPort().setExtent(fframe.getFMap()
1177
                                                                                                                                   .getFullExtent());
1178
                                }
1179
                        }
1180
                }
1181

    
1182
                setStatus(DESACTUALIZADO);
1183
                repaint();
1184
        }
1185

    
1186
        /**
1187
         * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1188
         * para poder despu?s volver a crear el objeto original.
1189
         *
1190
         * @return XMLEntity.
1191
         */
1192
        public XMLEntity getXMLEntity() {
1193
                XMLEntity xml = new XMLEntity();
1194
                xml.putProperty("className", this.getClass().getName());
1195
                xml.setName("layout");
1196
                xml.putProperty("isCuadricula", isCuadricula());
1197
                xml.putProperty("m_name", this.getName());
1198
                xml.addChild(getAtributes().getXMLEntity());
1199

    
1200
                for (int i = 0; i < getFFrames().size(); i++) {
1201
                        xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity());
1202
                }
1203

    
1204
                return xml;
1205
        }
1206

    
1207
        /**
1208
         * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1209
         *
1210
         * @param xml XMLEntity
1211
         * @param p Proyecto.
1212
         *
1213
         * @return Objeto de esta clase.
1214
         */
1215
        public static Layout createLayout(XMLEntity xml, Project p) {
1216
                Layout layout = new Layout();
1217
                layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1218
                layout.setName(xml.getStringProperty("m_name"));
1219
                layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1220
                layout.m_attributes.setCADToolAdapter(layout.getCadToolAdapter());
1221
                for (int i = 1; i < xml.getNumChild(); i++) {
1222
                        if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1223
                                layout.addFFrame(FFrame.createFFrame(xml.getChild(i), layout, p),
1224
                                        true);
1225
                        }
1226
                }
1227

    
1228
                for (int i = 1; i < xml.getNumChild(); i++) {
1229
                        if (!xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1230
                                layout.addFFrame(FFrame.createFFrame(xml.getChild(i), layout, p),
1231
                                        true);
1232
                        }
1233
                }
1234

    
1235
                return layout;
1236
        }
1237

    
1238
        /**
1239
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1240
         */
1241
        public void viewActivated() {
1242
                PluginServices.getMainFrame().getStatusBar().setMessage("1",
1243
                        getAtributes().getNameUnit());
1244

    
1245
                ///System.out.println("---------- 1 "+ getAtributes().getNameUnit());
1246
        }
1247

    
1248
        /**
1249
         * @see com.iver.cit.gvsig.fmap.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
1250
         */
1251
        public void extentChanged(Rectangle2D newExtent) {
1252
        }
1253

    
1254
        /**
1255
         * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1256
         */
1257
        public Object getViewModel() {
1258
                return map;
1259
        }
1260

    
1261
        /**
1262
         * Devuelve si se dibuja el Grid en el Layout o no.
1263
         *
1264
         * @return True si se dibuja el Grid en el Layout.
1265
         */
1266
        public boolean getIsDrawGrid() {
1267
                return isDrawCuadricula;
1268
        }
1269

    
1270
        /**
1271
         * Inserta si se muestra el Grid del Layout.
1272
         *
1273
         * @param b True si se muestra el Grid del Layout.
1274
         */
1275
        public void setIsDrawGrid(boolean b) {
1276
                isDrawCuadricula = b;
1277
                getCadToolAdapter().setGrid(b);
1278
        }
1279

    
1280
        /**
1281
         * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1282
         */
1283
        public void extentChanged(ExtentEvent e) {
1284
        }
1285

    
1286
        /**
1287
         * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
1288
         */
1289
        public void viewClosed() {
1290
                try {
1291
                        cadToolAdapter.getEditableFeatureSource().stopEdition();
1292
                        ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1293
                } catch (EditionException e) {
1294
                        e.printStackTrace();
1295
                }
1296
        }
1297

    
1298
        /**
1299
         * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1300
         */
1301
        public void backColorChanged(ColorEvent e) {
1302
        }
1303

    
1304
        /**
1305
         * DOCUMENT ME!
1306
         *
1307
         * @return DOCUMENT ME!
1308
         */
1309
        public IFFrame[] getFFrameSelected() {
1310
                ArrayList selecList = new ArrayList();
1311

    
1312
                for (int i = getFFrames().size() - 1; i >= 0; i--) {
1313
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
1314

    
1315
                        if (fframe.getSelected() != FFrame.NOSELECT) {
1316
                                selecList.add(fframe);
1317
                        }
1318
                }
1319

    
1320
                return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1321
        }
1322

    
1323
        /**
1324
         * DOCUMENT ME!
1325
         *
1326
         * @return DOCUMENT ME!
1327
         */
1328
        public CadTool getCadTool() {
1329
                return cadToolAdapter.getCadTool();
1330
        }
1331

    
1332
        /**
1333
         * DOCUMENT ME!
1334
         *
1335
         * @param name DOCUMENT ME!
1336
         * @param c DOCUMENT ME!
1337
         */
1338
        public void addCadTool(String name, CadTool c) {
1339
                namesCadTools.put(name, c);
1340
        }
1341

    
1342
        /**
1343
         * DOCUMENT ME!
1344
         *
1345
         * @param text DOCUMENT ME!
1346
         */
1347
        public void setCadTool(String text) {
1348
                CadTool ct = (CadTool) namesCadTools.get(text);
1349

    
1350
                if (ct == null) {
1351
                        throw new RuntimeException("No such cad tool");
1352
                }
1353

    
1354
                cadToolAdapter.setCadTool(ct);
1355
                cadtool = true;
1356
                setTool(GRAPHICS);
1357

    
1358
                //clearMouseImage();
1359
        }
1360

    
1361
        /**
1362
         * DOCUMENT ME!
1363
         *
1364
         * @return DOCUMENT ME!
1365
         */
1366
        public CADToolAdapter getCadToolAdapter() {
1367
                return (CADToolAdapter)cadToolAdapter;
1368
        }
1369
        public FFrameGraphics getFFrameGraphics(){
1370
                return (FFrameGraphics)getFFrames().get(0);
1371
        }
1372
}