Statistics
| Revision:

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

History | View | Annotate | Download (53.9 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.event.ActionEvent;
57
import java.awt.event.KeyEvent;
58
import java.awt.geom.AffineTransform;
59
import java.awt.geom.Rectangle2D;
60
import java.awt.image.BufferedImage;
61
import java.awt.print.PageFormat;
62
import java.awt.print.Printable;
63
import java.awt.print.PrinterException;
64
import java.awt.print.PrinterJob;
65
import java.beans.PropertyChangeEvent;
66
import java.beans.PropertyChangeListener;
67
import java.io.File;
68
import java.util.ArrayList;
69
import java.util.Hashtable;
70

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

    
92
import org.apache.log4j.Logger;
93

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

    
149

    
150
/**
151
 * Mapa.
152
 *
153
 * @author Vicente Caballero Navarro
154
 */
155
public class Layout extends JPanel implements SingletonView, ViewPortListener,
156
    ViewListener,CommandListener {
157
    private static Logger logger = Logger.getLogger(Layout.class.getName());
158
    public static final int ZOOM_MAS = 1;
159
    public static final int ZOOM_MENOS = 2;
160
    public static final int PAN = 3;
161
    public static final int DESACTUALIZADO = 4;
162
    public static final int ACTUALIZADO = 5;
163
    public static final int SELECT = 6;
164

    
165
    public static final int RECTANGLE = 10;
166
    public static final int RECTANGLEVIEW = 11;
167
    public static final int RECTANGLEPICTURE = 12;
168
    public static final int RECTANGLESCALEBAR = 13;
169
    public static final int RECTANGLELEGEND = 14;
170
    public static final int RECTANGLETEXT = 15;
171
    public static final int RECTANGLEGROUP = 16;
172
    public static final int RECTANGLESYMBOL = 17;
173
    public static final int RECTANGLENORTH = 18;
174
    public static final int RECTANGLEBOX=19;
175

    
176
    public static final int GRAPHICS = 20;
177
    public static final int POINT = 21;
178
    public static final int LINE = 22;
179
    public static final int POLYLINE = 23;
180
    public static final int RECTANGLESIMPLE = 24;
181
    public static final int CIRCLE = 25;
182
    public static final int POLYGON = 26;
183

    
184
    public static final int VIEW_ZOOMIN = 30;
185
    public static final int VIEW_ZOOMOUT = 31;
186
    public static final int VIEW_FULL = 32;
187
    public static final int VIEW_PAN = 33;
188
    public static final int SET_TAG = 34;
189

    
190
    public static final int EDIT=40;
191

    
192
    public static final Image iLayoutpan = new ImageIcon(AddLayer.class.getClassLoader()
193
                                                                       .getResource("images/LayoutHand.gif")).getImage();
194
    public static final Image ipan = new ImageIcon(AddLayer.class.getClassLoader()
195
                                                                 .getResource("images/Hand.gif")).getImage();
196
    public static final Image iLayoutzoomin = new ImageIcon(AddLayer.class.getClassLoader()
197
                                                                          .getResource("images/LayoutZoomInCursor.gif")).getImage();
198
    public static final Image izoomin = new ImageIcon(AddLayer.class.getClassLoader()
199
                                                                    .getResource("images/ZoomInCursor.gif")).getImage();
200
    public static final Image iLayoutzoomout = new ImageIcon(AddLayer.class.getClassLoader()
201
                                                                           .getResource("images/LayoutZoomOutCursor.gif")).getImage();
202
    public static final Image izoomout = new ImageIcon(AddLayer.class.getClassLoader()
203
                                                                     .getResource("images/ZoomOutCursor.gif")).getImage();
204
    public static final Image iinfo = new ImageIcon(AddLayer.class.getClassLoader()
205
                                                                  .getResource("images/InfoCursor.gif")).getImage();
206
    public static final Image icrux = new ImageIcon(AddLayer.class.getClassLoader()
207
                                                                  .getResource("images/CruxCursor.png")).getImage();
208
    public static final Image itag = new ImageIcon(AddLayer.class.getClassLoader()
209
                                                                 .getResource("images/tagCursor.gif")).getImage();
210
    public static final Image iPoint = new ImageIcon(AddLayer.class.getClassLoader()
211
                                                                   .getResource("images/PointCursor.png")).getImage();
212
    public static final Image iRect = new ImageIcon(AddLayer.class.getClassLoader()
213
                                                                  .getResource("images/RectCursor.png")).getImage();
214
    public static final Image iLine = new ImageIcon(AddLayer.class.getClassLoader()
215
                                                                  .getResource("images/LineCursor.png")).getImage();
216
    public static final Image iRectangle = new ImageIcon(AddLayer.class.getClassLoader()
217
                                                                       .getResource("images/RectangleCursor.png")).getImage();
218
    public static final Image iCircle = new ImageIcon(AddLayer.class.getClassLoader()
219
                                                                    .getResource("images/CircleCursor.png")).getImage();
220
    public static final Image iPoligon = new ImageIcon(AddLayer.class.getClassLoader()
221
                                                                     .getResource("images/PoligonCursor.png")).getImage();
222
    public static Hashtable nums = new Hashtable();
223
    private Point origin = new Point(50, 50);
224
    private Point rectOrigin = new Point(origin);
225
    private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
226
            rectOrigin.y, 400, 300);
227
    private Point m_FirstPoint = new Point(0, 0);
228
    private Point m_PointAnt = new Point(0, 0);
229
    private Point m_LastPoint = new Point(0, 0);
230
    private EventsHandler events;
231
    private int tool = ZOOM_MAS;
232
    private int status = DESACTUALIZADO;
233
    private BufferedImage img = null;
234
    private BufferedImage imgRuler = null;
235
    private AffineTransform m_MatrizTransf;
236
    private Rectangle2D rectVisible;
237
    private IFFrameDialog fframedialog = null;
238
    ///private ArrayList m_fframes = new ArrayList();
239
    private IFFrame[] fframes;
240
    private MapProperties m_propertiesLayout = null;
241
    private Attributes m_attributes = null;
242
    private PrintService[] m_cachePrintServices = null;
243
    private PrintService m_cachePrintService = null;
244
    private boolean m_bCancelDrawing = false;
245
    private boolean isCuadricula = false;
246
    private boolean initial = true;
247
    private ProjectMap map = null;
248
    private Rectangle reSel = null;
249
    private boolean isReSel = true;
250
    private boolean m_showRuler = true;
251
    private FLayoutDraw layoutDraw = null;
252
    private boolean isDrawCuadricula = true;
253
    private Doc doc = null;
254
    private PrintRequestAttributeSet att = null;
255
    private GeometryAdapter geometryAdapter=new PolyLineAdapter();
256
    private DefaultEditableFeatureSource efs;
257
    private boolean isEditable=true;
258
    private ViewInfo m_viewinfo = new ViewInfo(ViewInfo.ICONIFIABLE |
259
            ViewInfo.MAXIMIZABLE | ViewInfo.RESIZABLE);
260

    
261
    /**
262
     * Lo usamos cuando estamos haciendo una ficha y asignando tags
263
     * Se pone en modo debug cuando hacemos un VIEW_TAGS
264
     */
265
    private boolean bModeDebug = false;
266

    
267
    /**
268
     * Creates a new Layout object.
269
     */
270
    public Layout() {
271
            efs=new DefaultEditableFeatureSource();
272
            updateFFrames();
273
        this.setLayout(null);
274
        events = new EventsHandler(this);
275
        layoutDraw = new FLayoutDraw(this);
276
        addComponentListener(events);
277
        addMouseMotionListener(events);
278
        addMouseListener(events);
279
        addKeyListener(events);
280
        m_MatrizTransf = new AffineTransform();
281
        m_MatrizTransf.setToIdentity();
282
        this.initComponents();
283
    }
284

    
285
    /**
286
     * Rellena el ProjectMap del Layout.
287
     *
288
     * @param m ProjectMap.
289
     */
290
    public void setProjectMap(ProjectMap m) {
291
        map = m;
292
        this.setName(m.getName());
293
        map.addPropertyChangeListener(new PropertyChangeListener() {
294
                public void propertyChange(PropertyChangeEvent evt) {
295
                    if (evt.getPropertyName().equals("name")) {
296
                        PluginServices.getMDIManager().getViewInfo(Layout.this)
297
                                      .setTitle(PluginServices.getText(this,
298
                                "Mapa") + " : " + (String) evt.getNewValue());
299
                    }
300
                }
301
            });
302
    }
303

    
304
    /**
305
     * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
306
     *
307
     * @return Rect?ngulo de selecci?n.
308
     */
309
    public Rectangle getReSel() {
310
        return reSel;
311
    }
312

    
313
    /**
314
     * Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar
315
     * la sellecci?n.
316
     *
317
     * @return true si se realiza la selecci?n por rect?ngulo.
318
     */
319
    public boolean isReSel() {
320
        return isReSel;
321
    }
322

    
323
    /**
324
     * Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
325
     * selecci?n.
326
     *
327
     * @param b boolean.
328
     */
329
    public void setIsReSel(boolean b) {
330
        isReSel = b;
331
    }
332

    
333
    /**
334
     * Devuelve true si el dibujado ha sido cancelado.
335
     *
336
     * @return true si el dibujado ha sido cancelado.
337
     */
338
    public synchronized boolean isDrawingCancelled() {
339
        return m_bCancelDrawing;
340
    }
341

    
342
    /**
343
     * Pone el dibuja a cancelado o no seg?n se quiera.
344
     *
345
     * @param b true si se quiere cancelar el dibujado.
346
     */
347
    public synchronized void setCancelDrawing(boolean b) {
348
        m_bCancelDrawing = b;
349

    
350
        for (int i = 0; i < getFFrames().length; i++) {
351
            IFFrame fframe = (IFFrame) getFFrame(i);
352

    
353
            if (fframe instanceof IFFrameUseFMap &&
354
                    (((IFFrameUseFMap) fframe).getFMap() != null)) {
355
                ////TODO((FFrameView) getFFrames().get(i)).getFMap().setCancelDrawing(b);
356
            }
357
        }
358
    }
359

    
360
    /**
361
     * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
362
     *
363
     * @return Array con todos los fframes que contiene el Layout.
364
     */
365
    public IFFrame[] getFFrames() {
366
            return fframes;
367
    }
368
    public IFFrame getFFrame(int i){
369
            return fframes[i];
370
    }
371
    public void updateFFrames(){
372
            fframes=efs.getFFrames();
373
    }
374
    /**
375
     * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
376
     * entero.
377
     */
378
    public void fullRect() {
379
        rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
380
            getHeight() - (origin.x * 2));
381

    
382
        if (m_attributes.isLandSpace()) {
383
            rect = m_attributes.getRectangleLandscape(rect, getWidth(),
384
                    getHeight());
385
        } else {
386
            rect = m_attributes.getRectanglePortrait(rect, getWidth(),
387
                    getHeight());
388
        }
389
        /*IFFrame[] fframes=getFFrames();
390
        for (int i=0;i<fframes.length;i++){
391
                fframes[i].initialize();
392
        }*/
393
        status = DESACTUALIZADO;
394
        repaint();
395
    }
396

    
397
    /**
398
     * M?todo para imprimir el Layout sin modificar la matriz de
399
     * transformaci?n.
400
     *
401
     * @param g2
402
     */
403
    public void drawLayoutPrint(Graphics2D g2) {
404
        setCancelDrawing(false);
405

    
406
        setCursor(Cursor.getDefaultCursor());
407

    
408
        double scale = 0;
409

    
410
        ///if (rect.width > rect.height) {
411
        ///    scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
412
        ///} else {
413
        scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
414

    
415
        ///}
416
        AffineTransform escalado = new AffineTransform();
417
        AffineTransform translacion = new AffineTransform();
418
        translacion.setToTranslation(rect.getMinX(), rect.getMinY());
419
        escalado.setToScale(scale, scale);
420
        m_MatrizTransf.setToIdentity();
421
        m_MatrizTransf.concatenate(translacion);
422
        m_MatrizTransf.concatenate(escalado);
423
        m_attributes.setDistanceUnitX(rect);
424
        m_attributes.setDistanceUnitY(rect);
425

    
426
        for (int i = 0; i < getFFrames().length; i++) {
427
            try {
428
                ((IFFrame) getFFrame(i)).print(g2, getAT());
429
            } catch (DriverException e) {
430
                NotificationManager.addError(e.getMessage(), e);
431
            }
432
        }
433

    
434
        //TODO Esto es para ver el rect?ngulo que representa el folio en la impresi?n.
435
        g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
436
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
437
    }
438

    
439
    /**
440
     * Clip sobre el rect?ngulo visible.
441
     *
442
     * @param g2d Graphics sobre el que hacer el clip.
443
     */
444
    private void clipVisibleRect(Graphics2D g2d) {
445
        rectVisible = this.getVisibleRect();
446
        g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
447
            (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
448
    }
449

    
450
    /**
451
     * Inicializa los componentes.
452
     */
453
    private void initComponents() {
454
        m_attributes = new Attributes();
455
        m_attributes.setDistanceUnitX(rect);
456
        m_attributes.setDistanceUnitY(rect);
457
        actionDelFFrame();
458
        setDoubleBuffered(true);
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
                   delFFrameSelected();
469
                   refresh();
470
                }
471
            };
472

    
473
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
474
            "doNothing");
475
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
476
            "doNothing");
477
        this.getActionMap().put("doNothing", doNothing);
478
    }
479

    
480
    /**
481
     * paintComponent del Layout.
482
     *
483
     * @param g Graphics del Layout.
484
     */
485
    protected void paintComponent(Graphics g) {
486
        super.paintComponent(g);
487

    
488
        clipVisibleRect((Graphics2D) g);
489

    
490
        Rectangle rClip = g.getClipBounds();
491

    
492
        if (rClip == null) {
493
            System.err.println("clip = null");
494
        }
495

    
496
        switch (status) {
497
            case ZOOM_MAS:
498
                logger.debug("zoom mas");
499
                layoutDraw.drawRectangle((Graphics2D) g);
500

    
501
                g.drawImage(img, 0, 0, this);
502

    
503
                g.setClip(rClip);
504
                //layoutDraw.drawGrid((Graphics2D) g);
505
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
506
                g.drawImage(imgRuler,0,0,this);
507
                g.setColor(Color.black);
508
                g.setXORMode(Color.white);
509

    
510
                Rectangle r = new Rectangle();
511

    
512
                r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
513
                g.drawRect(r.x, r.y, r.width, r.height);
514

    
515
                break;
516

    
517
            case RECTANGLE:
518
                logger.debug("rectangle");
519
                layoutDraw.drawRectangle((Graphics2D) g);
520

    
521
                g.drawImage(img, 0, 0, this);
522

    
523
                g.setClip(rClip);
524
                //layoutDraw.drawGrid((Graphics2D) g);
525
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
526
                g.drawImage(imgRuler,0,0,this);
527
                g.setColor(Color.black);
528
                g.setXORMode(Color.white);
529

    
530
                Rectangle re = new Rectangle();
531
                re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
532

    
533
                if (isCuadricula()) {
534
                    FLayoutUtilities.setRectGrid(re,
535
                        m_attributes.getUnitInPixelsX(),
536
                        m_attributes.getUnitInPixelsY(), m_MatrizTransf);
537
                }
538

    
539
                g.drawRect(re.x, re.y, re.width, re.height);
540

    
541
                break;
542

    
543
            case PAN:
544
                logger.debug("pan");
545

    
546
                //g.setXORMode(Color.black);
547
                rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
548
                rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
549

    
550
                //g.clearRect(0, 0, getWidth(), getHeight());
551
                layoutDraw.drawRectangle((Graphics2D) g);
552

    
553
                if (img != null) {
554
                    g.drawImage(img, (getLastPoint().x - getPointAnt().x),
555
                        (getLastPoint().y - getPointAnt().y), this);
556
                }
557

    
558
                g.setClip(rClip);
559
                layoutDraw.drawGrid((Graphics2D) g);
560
                layoutDraw.drawRuler((Graphics2D) g, Color.black);
561
                //g.drawImage(imgRuler,0,0,this);
562
                break;
563

    
564
            case VIEW_PAN:
565

    
566
                // logger.debug("View pan");
567
                layoutDraw.drawRectangle((Graphics2D) g);
568

    
569
                for (int i = 0; i < getFFrames().length; i++) {
570
                    if (getFFrame(i) instanceof IFFrameUseFMap) {
571
                        IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
572

    
573
                        if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) {
574
                            Rectangle2D.Double rec = ((IFFrame)fframe).getBoundingBox(getAT());
575

    
576
                            if (img != null) {
577
                                //g.drawImage(img, 0, 0, this);
578
                                rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
579

    
580
                                //((Graphics2D)g).clearRect((int)rec.x,(int)rec.y,(int)rec.width,(int)rec.height);
581
                            }
582

    
583
                            if (fframe.getBufferedImage() != null) {
584
                                layoutDraw.drawHandlers((Graphics2D) g,
585
                                    Color.black);
586
                                g.clipRect((int) rec.x, (int) rec.y,
587
                                    (int) rec.width, (int) rec.height);
588

    
589
                                //g.setColor(Color.gray);
590
                                //g.fillRect(0,0,getWidth(),getHeight());
591
                                layoutDraw.drawRectangle((Graphics2D) g);
592
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
593
                                Rectangle2D.Double r1=((IFFrame)fframe).getBoundingBox(getAT());
594
                                g.drawImage(fframe.getBufferedImage(),(int)
595
                                    r1.getX()+m_LastPoint.x - m_PointAnt.x,
596
                                    (int)r1.getY()+m_LastPoint.y - m_PointAnt.y, this);
597

    
598
                               fframe.refresh();
599
                            }
600
                        }
601
                    }
602
                }
603

    
604
                g.setClip(rClip);
605
                //layoutDraw.drawGrid((Graphics2D) g);
606
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
607
                g.drawImage(imgRuler,0,0,this);
608

    
609
                break;
610

    
611
            case SELECT:
612
                logger.debug("select");
613
                layoutDraw.drawRectangle((Graphics2D) g);
614

    
615
                g.drawImage(img, 0, 0, this);
616

    
617
                if (isReSel) {
618
                    reSel = new Rectangle();
619
                    reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
620
                    g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
621
                }
622
                IFFrame[] frames=getFFrameSelected();
623
                for (int i = 0; i < frames.length; i++) {
624
                    //IFFrame fframe = (IFFrame) getFFrames().get(i);
625

    
626
                    //if (fframe.getSelected() != IFFrame.NOSELECT) {
627
                        g.setColor(Color.black);
628
                        frames[i].drawHandlers((Graphics2D) g);
629

    
630
                        int difx = (m_LastPoint.x - m_FirstPoint.x);
631
                        int dify = (m_LastPoint.y - m_FirstPoint.y);
632
                       // System.out.println(m_FirstPoint);
633
                       // System.out.println(m_LastPoint);
634
                        if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
635
                            Rectangle2D rectangle = frames[i].getMovieRect(difx,
636
                                    dify);
637
                            ((Graphics2D) g).rotate(Math.toRadians(
638
                                    frames[i].getRotation()),
639
                                rectangle.getX() + (rectangle.getWidth() / 2),
640
                                rectangle.getY() + (rectangle.getHeight() / 2));
641

    
642
                            if (rectangle != null) {
643
                                if (isCuadricula) {
644
                                    FLayoutUtilities.setRectGrid(rectangle,
645
                                        m_attributes.getUnitInPixelsX(),
646
                                        m_attributes.getUnitInPixelsY(),
647
                                        m_MatrizTransf);
648
                                }
649

    
650
                                g.drawRect((int) rectangle.getMinX(),
651
                                    (int) rectangle.getMinY(),
652
                                    (int) rectangle.getWidth(),
653
                                    (int) rectangle.getHeight());
654
                            }
655

    
656
                            ((Graphics2D) g).rotate(Math.toRadians(
657
                                    -frames[i].getRotation()),
658
                                rectangle.getX() + (rectangle.getWidth() / 2),
659
                                rectangle.getY() + (rectangle.getHeight() / 2));
660
                        }
661
                    //}
662
                }
663

    
664
                g.setClip(rClip);
665
                //layoutDraw.drawGrid((Graphics2D) g);
666
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
667
                g.drawImage(imgRuler,0,0,this);
668

    
669
                break;
670
             case GRAPHICS:
671
                    logger.debug("graphics");
672
                layoutDraw.drawRectangle((Graphics2D) g);
673
                g.drawImage(img, 0, 0, this);
674
                g.setClip(rClip);
675
                //layoutDraw.drawGrid((Graphics2D) g);
676
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
677
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
678

    
679
                if (getTool()==EDIT){
680
                        IFFrame[] fframeSelect=getFFrameSelected();
681
                        for(int i=0;i<fframeSelect.length;i++){
682
                                if (fframeSelect[i] instanceof IFFrameEditable){
683
                                        ((IFFrameEditable)fframeSelect[i]).paint((Graphics2D)g,getAT());
684
                                }
685
                        }
686
                }else{
687
                        geometryAdapter.paint((Graphics2D)g,getAT(),true);
688
                }
689
                g.drawImage(imgRuler,0,0,this);
690
                break;
691

    
692
            case DESACTUALIZADO:
693
                logger.debug("desactualizado");
694
                img = new BufferedImage(getWidth(), getHeight(),
695
                        BufferedImage.TYPE_INT_ARGB);
696
                imgRuler = new BufferedImage(getWidth(), getHeight(),
697
                        BufferedImage.TYPE_INT_ARGB);
698
                Graphics gimag = img.getGraphics();
699
                Graphics gimgRuler = imgRuler.getGraphics();
700

    
701
                clipVisibleRect((Graphics2D) gimag);
702

    
703
                if (initial) {
704
                    fullRect();
705
                    initial = false;
706
                }
707

    
708
                try {
709
                    layoutDraw.drawLayout((Graphics2D) gimag, img);
710
                } catch (DriverException e) {
711
                    e.printStackTrace();
712
                }
713

    
714
                g.setClip(rClip);
715
                layoutDraw.drawRectangle((Graphics2D) g);
716

    
717
                g.drawImage(img, 0, 0, this);
718
                g.setClip(rClip);
719

    
720
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
721
                layoutDraw.drawGrid((Graphics2D) gimgRuler);
722
                layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
723
                g.drawImage(imgRuler,0,0,this);
724

    
725
                break;
726

    
727
            case ACTUALIZADO:
728
                    logger.debug("actualizado");
729
                layoutDraw.drawRectangle((Graphics2D) g);
730

    
731
                g.drawImage(img, 0, 0, this);
732

    
733
                g.setClip(rClip);
734
                //layoutDraw.drawGrid((Graphics2D) g);
735

    
736
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
737
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
738
                g.drawImage(imgRuler,0,0,this);
739
        }
740
    }
741

    
742
    /**
743
     * A?ade un fframe al Arraylist m_fframes.
744
     *
745
     * @param frame fframe a a?adir.
746
     * @param clearSelection para que se quede seleccionado ?nicamente  el que
747
     *        a?adimos y false si lo que se pretende es que no se
748
     *        deseleccionen lo que ya est?n seleccionados.
749
     * @param select Booleano que indica si se tiene que quedar seleccionado el
750
     *        FFrame que se a?ade o no.
751
     */
752
    public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) {
753
        if (clearSelection) {
754
            for (int i = getFFrames().length - 1; i >= 0; i--) {
755
                IFFrame fframe1 = (IFFrame) getFFrame(i);
756
                fframe1.setSelected(false);
757
            }
758
        }
759

    
760
        /*if (frame instanceof FFrameView &&
761
           (((FFrameView) frame).getFMap() != null)) {
762
           ((FFrameView) frame).getFMap().getViewPort().addViewPortListener(this);
763
           }
764
         */
765
        if (nums.containsKey(frame.getClass())) {
766
            nums.put(frame.getClass(),
767
                new Integer(Integer.parseInt(nums.get(frame.getClass())
768
                                                 .toString()) + 1));
769
        } else {
770
            nums.put(frame.getClass(), new Integer(0));
771
        }
772

    
773
        frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
774
        efs.addFFrame(frame);
775
        ///getFFrames().add(frame);
776
        frame.setSelected(select);
777
        updateFFrames();
778
    }
779

    
780
    /**
781
     * Abre el di?logo de propiedades del folio, pasando como par?metro el
782
     * PrinterJob.
783
     *
784
     * @param job
785
     */
786
    public void showPagePropertiesWindow(PrinterJob job) {
787
        PageFormat pf1; //=new PageFormat();
788

    
789
        pf1 = m_attributes.getPageFormat();
790
        pf1 = job.pageDialog(pf1);
791
        m_attributes.setPageFormat(pf1);
792
        refresh();
793
    }
794

    
795
    /**
796
     * Refresca el Layout.
797
     */
798
    public void refresh() {
799
        //rect = m_attributes.obtainRect(false, rect, getWidth(), getHeight());
800
        setStatus(DESACTUALIZADO);
801
        repaint();
802
    }
803

    
804
    /**
805
     * Obtiene el rect?ngulo que representa el folio con las caracter?sticas
806
     * que contiene attributes y diferenciando si es para visualizar en
807
     * pantalla o para imprimir.
808
     *
809
     * @param isPrint si es para imprimir.
810
     */
811
    public void obtainRect(boolean isPrint) {
812
        m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
813
    }
814

    
815
    /**
816
     * Muestra el di?logo de configuraci?n del Layout.
817
     */
818
    public void showFConfig() {
819
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
820
        PluginServices.getMDIManager().addView(m_configLayout);
821
    }
822

    
823
    /**
824
     * Mestra el di?logo de propiedades del Layout.
825
     */
826
    public void showFProperties() {
827
        if (map == null) {
828
            map = new ProjectMap();
829
            map.setModel(this);
830
            map.setName(getName());
831
        }
832

    
833
        m_propertiesLayout = new MapProperties(map);
834
        PluginServices.getMDIManager().addView(m_propertiesLayout);
835
    }
836

    
837
    /**
838
     * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
839
     *
840
     * @param job
841
     */
842
    public void showPrintDialog(PrinterJob job) {
843
        if (job != null) {
844
            job.printDialog();
845

    
846
            try {
847
                job.setPrintable((Printable) PluginServices.getExtension(
848
                        com.iver.cit.gvsig.Print.class));
849
                job.print();
850
            } catch (PrinterException e) {
851
                e.printStackTrace();
852
            }
853
        } else {
854
            //Actualizar attributes
855
            att = m_attributes.toPrintAttributes();
856

    
857
            //------------------ The Printing things --------------------- //
858
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
859

    
860
            // returns the set of printers that support printing a specific document type (such as GIF)
861
            // with a specific set of attributes (such as two sided).
862
            // PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
863
            // interestingly, the printer dialog's default behavior has changed with the new API: by default the dialog is not shown.
864
            // So we must use the ServiceUI class to create a print dialog
865
            // returns the default print service.
866
            if (m_cachePrintServices == null) {
867
                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
868
                        null);
869
            }
870

    
871
            PrintService defaultService = null;
872

    
873
            if (m_cachePrintService == null) {
874
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
875
            }
876

    
877
            if ((defaultService == null) && (m_cachePrintService == null)) {
878
                JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
879
                    "ninguna_impresora_configurada");
880

    
881
                return;
882
            }
883

    
884
            if (m_cachePrintService == null) {
885
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
886
                        m_cachePrintServices, defaultService, flavor, att);
887

    
888
                // m_cachePrintRequestAtributeSet = new HashPrintRequestAttributeSet();
889
                // m_cachePrintRequestAtributeSet.addAll(pras);
890
            } else {
891
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
892
                        m_cachePrintServices, m_cachePrintService, flavor, att);
893
            }
894

    
895
            if (m_cachePrintService != null) {
896
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
897
                PrintJobListener pjlistener = new PrintJobAdapter() {
898
                        public void printDataTransferCompleted(PrintJobEvent e) {
899
                            System.out.println("Fin de impresi?n");
900
                            fullRect();
901
                        }
902
                    };
903

    
904
                jobNuevo.addPrintJobListener(pjlistener);
905

    
906
                // DocAttributeSet das = new HashDocAttributeSet();
907
                doc = new SimpleDoc((Printable) PluginServices.getExtension(
908
                            com.iver.cit.gvsig.Print.class), flavor, null);
909

    
910
                try {
911
                    jobNuevo.print(doc, att);
912

    
913
                    // m_attributes.
914
                } catch (PrintException pe) {
915
                    pe.printStackTrace();
916
                }
917
            }
918
        }
919

    
920
        /* try {
921
           print = job.printDialog(att);
922
           } catch (Exception e) {
923
               logger.error("Abriendo el Di?logo de imprimir"); //System.out.println("Excepci?n "+e);
924
           }
925
           if (print) {
926
               job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
927
               try {
928
                   job.print(att);
929
               } catch (Exception ex) {
930
                   ex.printStackTrace();
931
               }
932
           } */
933
    }
934

    
935
    /**
936
     * Sustituye el puntero del rat?n por la imagen que se le pasa como
937
     * par?metro.
938
     *
939
     * @param image
940
     */
941
    public void setMapCursor(Image image) {
942
        Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
943
                new Point(16, 16), "");
944
        setCursor(cur);
945
    }
946

    
947
    /**
948
     * Cambia el puntero del raton al cusor que se le introduce como par?metro.
949
     *
950
     * @param cursor cursor a mostrar en el puntero del rat?n.
951
     */
952
    public void setMapCursor(Cursor cursor) {
953
        setCursor(cursor);
954
    }
955

    
956
    /**
957
     * Pone como seleccionada a la herramienta a partir de su n?mero.
958
     *
959
     * @param i
960
     */
961
    public void setTool(int i) {
962
        tool = i;
963

    
964
        if (getTool() == PAN) {
965
            setMapCursor(ipan);
966
        } else if (getTool() == ZOOM_MAS) {
967
            setMapCursor(izoomin);
968
        } else if (getTool() == ZOOM_MENOS) {
969
            setMapCursor(izoomout);
970
        } else if (getTool() == RECTANGLEVIEW) {
971
            setMapCursor(icrux);
972
        } else if (getTool() == RECTANGLEPICTURE) {
973
            setMapCursor(icrux);
974
        } else if (getTool() == RECTANGLESCALEBAR) {
975
            setMapCursor(icrux);
976
        } else if (getTool() == RECTANGLELEGEND) {
977
            setMapCursor(icrux);
978
        } else if (getTool() == RECTANGLETEXT) {
979
            setMapCursor(icrux);
980
        } else if (getTool() == RECTANGLENORTH) {
981
            setMapCursor(icrux);
982
        } else if (getTool() == RECTANGLEBOX) {
983
            setMapCursor(icrux);
984
        } else if (getTool() == SELECT) {
985
            setCursor(Cursor.getDefaultCursor());
986
        } else if (getTool() == SET_TAG) {
987
            setMapCursor(itag);
988
        } else if (getTool() == POINT) {
989
            setMapCursor(iPoint);
990
        } else if (getTool() == LINE) {
991
            setMapCursor(iRect);
992
        } else if (getTool() == RECTANGLESIMPLE) {
993
            setMapCursor(iRectangle);
994
        } else if (getTool() == POLYLINE) {
995
            setMapCursor(iLine);
996
        } else if (getTool() == POLYGON) {
997
            setMapCursor(iPoligon);
998
        } else if (getTool() == CIRCLE) {
999
            setMapCursor(iCircle);
1000
        }
1001
        if (getTool() == EDIT){
1002
                setMapCursor(icrux);
1003
                startEdit();
1004
        }else{
1005
                stopEdit();
1006
        }
1007
        initGeometryAdapter();
1008
    }
1009

    
1010
    /**
1011
     * Se crean aqu? los dialogos cada vez que se necesitan.
1012
     *
1013
     * @param fframe Rectangle que representa el lugar que ocupara el elemento
1014
     *        a?adido.
1015
     *
1016
     * @return true si se debe de a?adir el fframe.
1017
     */
1018
    public boolean openFFrameDialog(IFFrame fframe) {
1019
        switch (tool) {
1020
            case RECTANGLEVIEW:
1021
                fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
1022

    
1023
                break;
1024

    
1025
            case RECTANGLEPICTURE:
1026
                fframedialog = new FFramePictureDialog(this,
1027
                        (FFramePicture) fframe);
1028

    
1029
                break;
1030

    
1031
            case RECTANGLESCALEBAR:
1032
                fframedialog = new FFrameScaleBarDialog(this,
1033
                        (FFrameScaleBar) fframe);
1034

    
1035
                break;
1036

    
1037
            case RECTANGLELEGEND:
1038
                fframedialog = new FFrameLegendDialog(this,
1039
                        (FFrameLegend) fframe);
1040

    
1041
                break;
1042

    
1043
            case RECTANGLETEXT:
1044
                fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
1045

    
1046
                break;
1047

    
1048
            case GRAPHICS:
1049
                fframedialog = new FFrameGraphicsDialog(this,
1050
                        (FFrameGraphics) fframe);
1051

    
1052
                break;
1053

    
1054
            case RECTANGLEGROUP:
1055
                fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe);
1056

    
1057
                break;
1058
            case RECTANGLENORTH:
1059
                fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe);
1060

    
1061
                break;
1062
            case RECTANGLEBOX:
1063
                fframedialog = new FFrameBoxDialog(this, (FFrameBox) fframe);
1064

    
1065
                break;
1066
            default:
1067
                return true;
1068
        }
1069

    
1070
        if (fframedialog != null) {
1071
            fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
1072
            PluginServices.getMDIManager().addView(fframedialog);
1073
        }
1074

    
1075
        return fframedialog.getIsAcepted();
1076
    }
1077

    
1078
    /**
1079
     * Devuelve el Rectangle2D que representa en pixels al folio.
1080
     *
1081
     * @return Rectangle2D.Double
1082
     */
1083
    public Rectangle2D.Double getRect() {
1084
        return rect;
1085
    }
1086
    public void setRect(Rectangle2D r){
1087
            rect.setRect(r);
1088
    }
1089
    /**
1090
     * Obtiene un entero que representa la herramienta seleccionada.
1091
     *
1092
     * @return entero.
1093
     */
1094
    public int getTool() {
1095
        return tool;
1096
    }
1097

    
1098
    /**
1099
     * Devuelve la Matriz transformada que se esta plicando al Layout.
1100
     *
1101
     * @return AffineTransform
1102
     */
1103
    public AffineTransform getAT() {
1104
        return m_MatrizTransf;
1105
    }
1106

    
1107
    /**
1108
     * Devuelve los atributos del Mapa.
1109
     *
1110
     * @return Attributes.
1111
     */
1112
    public Attributes getAtributes() {
1113
        return m_attributes;
1114
    }
1115

    
1116
    /**
1117
     * Pone el estado que se quiera.
1118
     *
1119
     * @param s estado.
1120
     */
1121
    public void setStatus(int s) {
1122
        status = s;
1123
    }
1124

    
1125
    /**
1126
     * Devuelve el punto que representa la esquina noroeste del mapa.
1127
     *
1128
     * @return un punto.
1129
     */
1130
    public Point getRectOrigin() {
1131
        return rectOrigin;
1132
    }
1133

    
1134
    /**
1135
     * Devuelve el punto del primer click de rat?n.
1136
     *
1137
     * @return un punto.
1138
     */
1139
    public Point getFirstPoint() {
1140
        return m_FirstPoint;
1141
    }
1142

    
1143
    /**
1144
     * Devuelve el punto de click de rat?n anterior.
1145
     *
1146
     * @return un punto.
1147
     */
1148
    public Point getPointAnt() {
1149
        return m_PointAnt;
1150
    }
1151

    
1152
    /**
1153
     * Devuelve el punto donde se solt? el bot?n del rat?n.
1154
     *
1155
     * @return un punto.
1156
     */
1157
    public Point getLastPoint() {
1158
        return m_LastPoint;
1159
    }
1160

    
1161
    /**
1162
     * Rellena el primer punto de click de rat?n.
1163
     *
1164
     * @param p punto.
1165
     */
1166
    public void setFirstPoint(Point p) {
1167
        m_FirstPoint = p;
1168
    }
1169

    
1170
    /**
1171
     * Rellena el punto de click de rat?n anterior.
1172
     *
1173
     * @param p punto.
1174
     */
1175
    public void setPointAnt(Point p) {
1176
        m_PointAnt = p;
1177
    }
1178

    
1179
    /**
1180
     * Rellena el punto donde se solto el bot?n del rat?n.
1181
     *
1182
     * @param p punto.
1183
     */
1184
    public void setLastPoint(Point p) {
1185
        m_LastPoint = p;
1186
    }
1187

    
1188
    /**
1189
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1190
     */
1191
    public ViewInfo getViewInfo() {
1192
        m_viewinfo.setWidth(500);
1193
        m_viewinfo.setHeight(400);
1194

    
1195
        m_viewinfo.setTitle(PluginServices.getText(this, "Mapa") + " : " +
1196
            getName());
1197

    
1198
        return m_viewinfo;
1199
    }
1200

    
1201
    /**
1202
     * Inserta si se muestra o no la regla del Layout.
1203
     *
1204
     * @param b True si se muestra la regla.
1205
     */
1206
    public void setRuler(boolean b) {
1207
        m_showRuler = b;
1208
    }
1209

    
1210
    /**
1211
     * Devuelve si se muestra la regla del Layout.
1212
     *
1213
     * @return True si se muestra la regla.
1214
     */
1215
    public boolean getRuler() {
1216
        return m_showRuler;
1217
    }
1218

    
1219
    /**
1220
     * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1221
     * cuadr?cula, o no.
1222
     *
1223
     * @return true si se esta aplicando la cuadr?cula.
1224
     */
1225
    public boolean isCuadricula() {
1226
        return isCuadricula;
1227
    }
1228

    
1229
    /**
1230
     * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1231
     *
1232
     * @param b true si se aplica la cuadr?cula.
1233
     */
1234
    public void setIsCuadricula(boolean b) {
1235
        isCuadricula = b;
1236
    }
1237

    
1238
    /**
1239
     * Realiza una exteni?n completa de las capas que contiene la vista del
1240
     * FFrameView.
1241
     *
1242
     * @throws DriverException
1243
     */
1244
    public void viewFull() throws DriverException {
1245
        for (int i = 0; i < getFFrames().length; i++) {
1246
            if (getFFrame(i) instanceof IFFrameUseFMap) {
1247
                IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
1248

    
1249
                if ((((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) &&
1250
                        (fframe.getFMap() != null)) {
1251
                    fframe.getFMap().getViewPort().setExtent(fframe.getFMap()
1252
                                                                   .getFullExtent());
1253
                }
1254
                fframe.refresh();
1255
            }
1256
        }
1257

    
1258
        setStatus(DESACTUALIZADO);
1259
        repaint();
1260
    }
1261

    
1262
    /**
1263
     * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1264
     * para poder despu?s volver a crear el objeto original.
1265
     *
1266
     * @return XMLEntity.
1267
     *
1268
     * @throws XMLException
1269
     */
1270
    public XMLEntity getXMLEntity() {
1271
            //getEFS().compact();
1272
        XMLEntity xml = new XMLEntity();
1273
        xml.putProperty("className", this.getClass().getName());
1274
        xml.setName("layout");
1275
        xml.putProperty("isCuadricula", isCuadricula());
1276
        xml.putProperty("m_name", this.getName());
1277
        xml.putProperty("isEditable",isEditable);
1278
        xml.addChild(getAtributes().getXMLEntity());
1279

    
1280
        for (int i = 0; i < getFFrames().length; i++) {
1281
                try{
1282
                        XMLEntity xmlAux=((IFFrame) getFFrame(i)).getXMLEntity();
1283
                        xmlAux.putProperty("level",i);
1284
                        xml.addChild(xmlAux);
1285
                }catch (SaveException e) {
1286
                            e.showError();
1287
                    }
1288
        }
1289
        return xml;
1290
    }
1291
    /**
1292
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1293
     *
1294
     * @param xml XMLEntity
1295
     * @param p Proyecto.
1296
     *
1297
     * @return Objeto de esta clase.
1298
     * @throws OpenException
1299
     */
1300
    public static Layout createLayout(XMLEntity xml,Project p) throws OpenException {
1301
        Layout layout = new Layout();
1302
        try{
1303
        layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1304
        layout.setName(xml.getStringProperty("m_name"));
1305
        layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1306
         if (xml.contains("isEditable")){
1307
                layout.setEditable(xml.getBooleanProperty("isEditable"));
1308
        }
1309
        layout.getEFS().startComplexCommand();
1310
        for (int i = 1; i < xml.getNumChild(); i++) {
1311
                    try {
1312
                                        layout.addFFrame(FFrame.createFFrame(xml.getChild(i),p),
1313
                                            true, false);
1314
                                } catch (OpenException e) {
1315
                                        e.showError();
1316
                                }
1317
        }
1318
        layout.getEFS().endComplexCommand();
1319
        IFFrame[] fframes=layout.getAllFFrames();
1320
        for (int i=0;i<fframes.length;i++){
1321
                if (fframes[i] instanceof IFFrameLayoutDependence){
1322
                        ((IFFrameLayoutDependence)fframes[i]).setLayout(layout);
1323
                }
1324
                if (fframes[i] instanceof IFFrameViewDependence){
1325
                        ((IFFrameViewDependence)fframes[i]).initDependence(fframes);
1326
                }
1327
        }
1328
        }catch(Exception e){
1329
                        throw new OpenException(e,layout.getClass().getName());
1330
                }
1331
       return layout;
1332
    }
1333

    
1334
    /**
1335
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1336
     *
1337
     * @param xml XMLEntity
1338
     * @param p Proyecto.
1339
     *
1340
     * @return Objeto de esta clase.
1341
     */
1342
    public static Layout createLayout03(XMLEntity xml, Project p) {
1343
        Layout layout = new Layout();
1344
        layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1345
        layout.setName(xml.getStringProperty("m_name"));
1346
        layout.m_attributes = Attributes.createAtributes03(xml.getChild(0));
1347

    
1348
        for (int i = 1; i < xml.getNumChild(); i++) {
1349
            if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1350
                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1351
                        p), true, false);
1352
            }
1353
        }
1354

    
1355
        for (int i = 1; i < xml.getNumChild(); i++) {
1356
            if (!xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1357
                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1358
                        p), true, false);
1359
            }
1360
        }
1361

    
1362
        return layout;
1363
    }
1364

    
1365
    /**
1366
     * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1367
     */
1368
    public void viewActivated() {
1369
            //Rectangle2D r=(Rectangle2D)getRect().clone();
1370
            fullRect();
1371
            /*IFFrame[] fframes=getFFrames();
1372
        for (int i=0;i<fframes.length;i++){
1373
                fframes[i].initialize();
1374
        }
1375
        setRect(r);
1376
        */
1377
        repaint();
1378
        PluginServices.getMainFrame().getStatusBar().setMessage("1",
1379
            getAtributes().getNameUnit());
1380

    
1381
        ///System.out.println("---------- 1 "+ getAtributes().getNameUnit());
1382
    }
1383

    
1384
    /**
1385
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1386
     */
1387
    public Object getViewModel() {
1388
        return map;
1389
    }
1390

    
1391
    /**
1392
     * Devuelve si se dibuja el Grid en el Layout o no.
1393
     *
1394
     * @return True si se dibuja el Grid en el Layout.
1395
     */
1396
    public boolean getIsDrawGrid() {
1397
        return isDrawCuadricula;
1398
    }
1399

    
1400
    /**
1401
     * Inserta si se muestra el Grid del Layout.
1402
     *
1403
     * @param b True si se muestra el Grid del Layout.
1404
     */
1405
    public void setIsDrawGrid(boolean b) {
1406
        isDrawCuadricula = b;
1407
    }
1408

    
1409
    /**
1410
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1411
     */
1412
    public void extentChanged(ExtentEvent e) {
1413
    }
1414

    
1415
    /**
1416
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
1417
     */
1418
    public void viewClosed() {
1419
        ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1420
    }
1421

    
1422
    /**
1423
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1424
     */
1425
    public void backColorChanged(ColorEvent e) {
1426
        //        refresh();
1427
    }
1428

    
1429
    /**
1430
     * Devuelve un array con los FFrames seleccionados.
1431
     *
1432
     * @return Array con los FFrames seleccionados.
1433
     */
1434
    public IFFrame[] getFFrameSelected() {
1435
        ArrayList selecList = new ArrayList();
1436

    
1437
        for (int i = getFFrames().length - 1; i >= 0; i--) {
1438
            IFFrame fframe = (IFFrame) getFFrame(i);
1439

    
1440
            if (fframe.getSelected() != IFFrame.NOSELECT) {
1441
                selecList.add(fframe);
1442
            }
1443
        }
1444

    
1445
        return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1446
    }
1447

    
1448
    /**
1449
     * Opens a dialog where to pick a PDF-file to save the current Layout
1450
     * suggesting a name for the file given by the first argument
1451
     *
1452
     * @param suggestedName DOCUMENT ME!
1453
     */
1454
    public void layoutToPDF(String suggestedName) {
1455
        FileFilter pdfFilter = new GenericFileFilter("pdf",
1456
                PluginServices.getText(this, "pdf"));
1457

    
1458
        JFileChooser jfc = new JFileChooser();
1459
        if (suggestedName!=null)
1460
        jfc.setSelectedFile(new File(suggestedName));
1461
        jfc.addChoosableFileFilter(pdfFilter);
1462
        jfc.setFileFilter(pdfFilter);
1463

    
1464
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1465
            File f = jfc.getSelectedFile();
1466
            File faux = null;
1467

    
1468
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
1469
                faux = f;
1470
            } else {
1471
                faux = new File(f.getPath() + ".pdf");
1472
            }
1473

    
1474
            layoutDraw.toPDF(faux);
1475
        }
1476
    }
1477

    
1478
    /**
1479
     * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1480
     * en este formato.
1481
     */
1482
    public void layoutToPDF() {
1483
            layoutToPDF(null);
1484
    }
1485

    
1486
    /**
1487
     * @return Returns the bModeDebug.
1488
     */
1489
    public boolean isModeDebug() {
1490
        return bModeDebug;
1491
    }
1492

    
1493
    /**
1494
     * @param modeDebug The bModeDebug to set.
1495
     */
1496
    public void setModeDebug(boolean modeDebug) {
1497
        bModeDebug = modeDebug;
1498
    }
1499

    
1500
    private ArrayList allFFrames(IFFrame[] fframes, ArrayList all){
1501
            for (int i=0;i<fframes.length;i++){
1502
                    if (fframes[i] instanceof FFrameGroup){
1503
                            return allFFrames(((FFrameGroup)fframes[i]).getFFrames(),all);
1504

    
1505
                    }else{
1506
                            all.add(fframes[i]);
1507
                    }
1508
            }
1509
            return all;
1510
    }
1511
        public IFFrame[] getAllFFrames() {
1512
                ArrayList all=new ArrayList();
1513
                return (IFFrame[])allFFrames(getFFrames(),all).toArray(new IFFrame[0]);
1514
        }
1515

    
1516
        public GeometryAdapter getGeometryAdapter() {
1517
                return geometryAdapter;
1518
        }
1519
        public boolean isEditable(){
1520
                return isEditable;
1521
        }
1522
        public void setEditable(boolean b) {
1523
                isEditable=b;
1524
        }
1525
        public void initGeometryAdapter() {
1526
                if (getTool() == LINE) {
1527
                        geometryAdapter=new PolyLineAdapter();
1528
        } else if (getTool() == RECTANGLESIMPLE) {
1529
                geometryAdapter=new RectangleAdapter();
1530
        } else if (getTool() == POLYLINE) {
1531
            geometryAdapter=new PolyLineAdapter();
1532
        } else if (getTool() == POLYGON) {
1533
            geometryAdapter=new PolygonAdapter();
1534
        } else if (getTool() == CIRCLE) {
1535
                geometryAdapter=new CircleAdapter();
1536
        } else if (getTool() == POINT) {
1537
                geometryAdapter=new PointAdapter();
1538
        }
1539
        }
1540
        public void startEdit() {
1541
                for(int i=0;i<getFFrames().length;i++){
1542
                        IFFrame frame=(IFFrame)getFFrame(i);
1543
                        if (frame instanceof IFFrameEditable){
1544
                                if (frame.getSelected()!=IFFrame.NOSELECT){
1545
                                        ((IFFrameEditable)frame).startEditing();
1546
                                }else{
1547
                                        ((IFFrameEditable)frame).stopEditing();
1548
                                }
1549
                        }
1550

    
1551
                }
1552
                refresh();
1553
        }
1554
        public void stopEdit(){
1555
                boolean refresh=false;
1556
                for(int i=0;i<getFFrames().length;i++){
1557
                        IFFrame frame=(IFFrame)getFFrame(i);
1558
                        if (frame instanceof IFFrameEditable){
1559
                                if (((IFFrameEditable)frame).isEditing()){
1560
                                        ((IFFrameEditable)getFFrame(i)).stopEditing();
1561
                                        refresh=true;
1562
                                }
1563
                        }
1564
                }
1565
                if (refresh) refresh();
1566
        }
1567
        public void delFFrameSelected(){
1568
                efs.startComplexCommand();
1569
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1570
             IFFrame fframe = (IFFrame) efs.getFFrame(i);
1571

    
1572
             if (fframe.getSelected() != IFFrame.NOSELECT) {
1573
                     efs.removeFFrame(i);
1574
                    // getFFrames().remove(i);
1575
             }
1576
         }
1577
                efs.endComplexCommand();
1578
                updateFFrames();
1579
        }
1580
        public void delFFrame(int index){
1581
                for(int i=0;i<getEFS().getAllFFrames().length;i++){
1582
                        if (getEFS().getFFrame(i).equals(getFFrame(index))){
1583
                                getEFS().removeFFrame(i);
1584
                        }
1585
                }
1586
                updateFFrames();
1587
        }
1588
        public void delFFrame(IFFrame frame){
1589
                for(int i=0;i<getEFS().getAllFFrames().length;i++){
1590
                        if (getEFS().getFFrame(i).equals(frame)){
1591
                                getEFS().removeFFrame(i);
1592
                        }
1593
                }
1594
                updateFFrames();
1595
        }
1596
        public EditableFeatureSource getEFS(){
1597
                return efs;
1598
        }
1599

    
1600
        public void commandRepaint() {
1601
                this.updateFFrames();
1602
                this.refresh();
1603
        }
1604

    
1605
        public void commandRefresh() {
1606
                commandRepaint();
1607

    
1608
        }
1609
}