Statistics
| Revision:

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

History | View | Annotate | Download (53.4 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

    
390
        status = DESACTUALIZADO;
391
        repaint();
392
    }
393

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

    
403
        setCursor(Cursor.getDefaultCursor());
404

    
405
        double scale = 0;
406

    
407
        ///if (rect.width > rect.height) {
408
        ///    scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
409
        ///} else {
410
        scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
411

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

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

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

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

    
447
    /**
448
     * Inicializa los componentes.
449
     */
450
    private void initComponents() {
451
        m_attributes = new Attributes();
452
        m_attributes.setDistanceUnitX(rect);
453
        m_attributes.setDistanceUnitY(rect);
454
        actionDelFFrame();
455
        setDoubleBuffered(true);
456
    }
457

    
458
    /**
459
     * Crea un ActionEvent para controlar las teclas que se pulsen cuando este
460
     * el Layout Focusable a true.
461
     */
462
    private void actionDelFFrame() {
463
        Action doNothing = new AbstractAction() {
464
                public void actionPerformed(ActionEvent e) {
465
                   delFFrameSelected();
466
                   refresh();
467
                }
468
            };
469

    
470
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
471
            "doNothing");
472
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
473
            "doNothing");
474
        this.getActionMap().put("doNothing", doNothing);
475
    }
476

    
477
    /**
478
     * paintComponent del Layout.
479
     *
480
     * @param g Graphics del Layout.
481
     */
482
    protected void paintComponent(Graphics g) {
483
        super.paintComponent(g);
484

    
485
        clipVisibleRect((Graphics2D) g);
486

    
487
        Rectangle rClip = g.getClipBounds();
488

    
489
        if (rClip == null) {
490
            System.err.println("clip = null");
491
        }
492

    
493
        switch (status) {
494
            case ZOOM_MAS:
495
                logger.debug("zoom mas");
496
                layoutDraw.drawRectangle((Graphics2D) g);
497

    
498
                g.drawImage(img, 0, 0, this);
499

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

    
507
                Rectangle r = new Rectangle();
508

    
509
                r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
510
                g.drawRect(r.x, r.y, r.width, r.height);
511

    
512
                break;
513

    
514
            case RECTANGLE:
515
                logger.debug("rectangle");
516
                layoutDraw.drawRectangle((Graphics2D) g);
517

    
518
                g.drawImage(img, 0, 0, this);
519

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

    
527
                Rectangle re = new Rectangle();
528
                re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
529

    
530
                if (isCuadricula()) {
531
                    FLayoutUtilities.setRectGrid(re,
532
                        m_attributes.getUnitInPixelsX(),
533
                        m_attributes.getUnitInPixelsY(), m_MatrizTransf);
534
                }
535

    
536
                g.drawRect(re.x, re.y, re.width, re.height);
537

    
538
                break;
539

    
540
            case PAN:
541
                logger.debug("pan");
542

    
543
                //g.setXORMode(Color.black);
544
                rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
545
                rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
546

    
547
                //g.clearRect(0, 0, getWidth(), getHeight());
548
                layoutDraw.drawRectangle((Graphics2D) g);
549

    
550
                if (img != null) {
551
                    g.drawImage(img, (getLastPoint().x - getPointAnt().x),
552
                        (getLastPoint().y - getPointAnt().y), this);
553
                }
554

    
555
                g.setClip(rClip);
556
                layoutDraw.drawGrid((Graphics2D) g);
557
                layoutDraw.drawRuler((Graphics2D) g, Color.black);
558
                //g.drawImage(imgRuler,0,0,this);
559
                break;
560

    
561
            case VIEW_PAN:
562

    
563
                // logger.debug("View pan");
564
                layoutDraw.drawRectangle((Graphics2D) g);
565

    
566
                for (int i = 0; i < getFFrames().length; i++) {
567
                    if (getFFrame(i) instanceof IFFrameUseFMap) {
568
                        IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
569

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

    
573
                            if (img != null) {
574
                                //g.drawImage(img, 0, 0, this);
575
                                rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
576

    
577
                                //((Graphics2D)g).clearRect((int)rec.x,(int)rec.y,(int)rec.width,(int)rec.height);
578
                            }
579

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

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

    
595
                               fframe.refresh();
596
                            }
597
                        }
598
                    }
599
                }
600

    
601
                g.setClip(rClip);
602
                //layoutDraw.drawGrid((Graphics2D) g);
603
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
604
                g.drawImage(imgRuler,0,0,this);
605

    
606
                break;
607

    
608
            case SELECT:
609
                logger.debug("select");
610
                layoutDraw.drawRectangle((Graphics2D) g);
611

    
612
                g.drawImage(img, 0, 0, this);
613

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

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

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

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

    
647
                                g.drawRect((int) rectangle.getMinX(),
648
                                    (int) rectangle.getMinY(),
649
                                    (int) rectangle.getWidth(),
650
                                    (int) rectangle.getHeight());
651
                            }
652

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

    
661
                g.setClip(rClip);
662
                //layoutDraw.drawGrid((Graphics2D) g);
663
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
664
                g.drawImage(imgRuler,0,0,this);
665

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

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

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

    
698
                clipVisibleRect((Graphics2D) gimag);
699

    
700
                if (initial) {
701
                    fullRect();
702
                    initial = false;
703
                }
704

    
705
                try {
706
                    layoutDraw.drawLayout((Graphics2D) gimag, img);
707
                } catch (DriverException e) {
708
                    e.printStackTrace();
709
                }
710

    
711
                g.setClip(rClip);
712
                layoutDraw.drawRectangle((Graphics2D) g);
713

    
714
                g.drawImage(img, 0, 0, this);
715
                g.setClip(rClip);
716

    
717
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
718
                layoutDraw.drawGrid((Graphics2D) gimgRuler);
719
                layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
720
                g.drawImage(imgRuler,0,0,this);
721

    
722
                break;
723

    
724
            case ACTUALIZADO:
725
                    logger.debug("actualizado");
726
                layoutDraw.drawRectangle((Graphics2D) g);
727

    
728
                g.drawImage(img, 0, 0, this);
729

    
730
                g.setClip(rClip);
731
                //layoutDraw.drawGrid((Graphics2D) g);
732

    
733
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
734
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
735
                g.drawImage(imgRuler,0,0,this);
736
        }
737
    }
738

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

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

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

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

    
786
        pf1 = m_attributes.getPageFormat();
787
        pf1 = job.pageDialog(pf1);
788
        m_attributes.setPageFormat(pf1);
789
        refresh();
790
    }
791

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

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

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

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

    
830
        m_propertiesLayout = new MapProperties(map);
831
        PluginServices.getMDIManager().addView(m_propertiesLayout);
832
    }
833

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

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

    
854
            //------------------ The Printing things --------------------- //
855
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
856

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

    
868
            PrintService defaultService = null;
869

    
870
            if (m_cachePrintService == null) {
871
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
872
            }
873

    
874
            if ((defaultService == null) && (m_cachePrintService == null)) {
875
                JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
876
                    "ninguna_impresora_configurada");
877

    
878
                return;
879
            }
880

    
881
            if (m_cachePrintService == null) {
882
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
883
                        m_cachePrintServices, defaultService, flavor, att);
884

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

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

    
901
                jobNuevo.addPrintJobListener(pjlistener);
902

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

    
907
                try {
908
                    jobNuevo.print(doc, att);
909

    
910
                    // m_attributes.
911
                } catch (PrintException pe) {
912
                    pe.printStackTrace();
913
                }
914
            }
915
        }
916

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

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

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

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

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

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

    
1020
                break;
1021

    
1022
            case RECTANGLEPICTURE:
1023
                fframedialog = new FFramePictureDialog(this,
1024
                        (FFramePicture) fframe);
1025

    
1026
                break;
1027

    
1028
            case RECTANGLESCALEBAR:
1029
                fframedialog = new FFrameScaleBarDialog(this,
1030
                        (FFrameScaleBar) fframe);
1031

    
1032
                break;
1033

    
1034
            case RECTANGLELEGEND:
1035
                fframedialog = new FFrameLegendDialog(this,
1036
                        (FFrameLegend) fframe);
1037

    
1038
                break;
1039

    
1040
            case RECTANGLETEXT:
1041
                fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
1042

    
1043
                break;
1044

    
1045
            case GRAPHICS:
1046
                fframedialog = new FFrameGraphicsDialog(this,
1047
                        (FFrameGraphics) fframe);
1048

    
1049
                break;
1050

    
1051
            case RECTANGLEGROUP:
1052
                fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe);
1053

    
1054
                break;
1055
            case RECTANGLENORTH:
1056
                fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe);
1057

    
1058
                break;
1059
            case RECTANGLEBOX:
1060
                fframedialog = new FFrameBoxDialog(this, (FFrameBox) fframe);
1061

    
1062
                break;
1063
            default:
1064
                return true;
1065
        }
1066

    
1067
        if (fframedialog != null) {
1068
            fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
1069
            PluginServices.getMDIManager().addView(fframedialog);
1070
        }
1071

    
1072
        return fframedialog.getIsAcepted();
1073
    }
1074

    
1075
    /**
1076
     * Devuelve el Rectangle2D que representa en pixels al folio.
1077
     *
1078
     * @return Rectangle2D.Double
1079
     */
1080
    public Rectangle2D.Double getRect() {
1081
        return rect;
1082
    }
1083

    
1084
    /**
1085
     * Obtiene un entero que representa la herramienta seleccionada.
1086
     *
1087
     * @return entero.
1088
     */
1089
    public int getTool() {
1090
        return tool;
1091
    }
1092

    
1093
    /**
1094
     * Devuelve la Matriz transformada que se esta plicando al Layout.
1095
     *
1096
     * @return AffineTransform
1097
     */
1098
    public AffineTransform getAT() {
1099
        return m_MatrizTransf;
1100
    }
1101

    
1102
    /**
1103
     * Devuelve los atributos del Mapa.
1104
     *
1105
     * @return Attributes.
1106
     */
1107
    public Attributes getAtributes() {
1108
        return m_attributes;
1109
    }
1110

    
1111
    /**
1112
     * Pone el estado que se quiera.
1113
     *
1114
     * @param s estado.
1115
     */
1116
    public void setStatus(int s) {
1117
        status = s;
1118
    }
1119

    
1120
    /**
1121
     * Devuelve el punto que representa la esquina noroeste del mapa.
1122
     *
1123
     * @return un punto.
1124
     */
1125
    public Point getRectOrigin() {
1126
        return rectOrigin;
1127
    }
1128

    
1129
    /**
1130
     * Devuelve el punto del primer click de rat?n.
1131
     *
1132
     * @return un punto.
1133
     */
1134
    public Point getFirstPoint() {
1135
        return m_FirstPoint;
1136
    }
1137

    
1138
    /**
1139
     * Devuelve el punto de click de rat?n anterior.
1140
     *
1141
     * @return un punto.
1142
     */
1143
    public Point getPointAnt() {
1144
        return m_PointAnt;
1145
    }
1146

    
1147
    /**
1148
     * Devuelve el punto donde se solt? el bot?n del rat?n.
1149
     *
1150
     * @return un punto.
1151
     */
1152
    public Point getLastPoint() {
1153
        return m_LastPoint;
1154
    }
1155

    
1156
    /**
1157
     * Rellena el primer punto de click de rat?n.
1158
     *
1159
     * @param p punto.
1160
     */
1161
    public void setFirstPoint(Point p) {
1162
        m_FirstPoint = p;
1163
    }
1164

    
1165
    /**
1166
     * Rellena el punto de click de rat?n anterior.
1167
     *
1168
     * @param p punto.
1169
     */
1170
    public void setPointAnt(Point p) {
1171
        m_PointAnt = p;
1172
    }
1173

    
1174
    /**
1175
     * Rellena el punto donde se solto el bot?n del rat?n.
1176
     *
1177
     * @param p punto.
1178
     */
1179
    public void setLastPoint(Point p) {
1180
        m_LastPoint = p;
1181
    }
1182

    
1183
    /**
1184
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1185
     */
1186
    public ViewInfo getViewInfo() {
1187
        m_viewinfo.setWidth(500);
1188
        m_viewinfo.setHeight(400);
1189

    
1190
        m_viewinfo.setTitle(PluginServices.getText(this, "Mapa") + " : " +
1191
            getName());
1192

    
1193
        return m_viewinfo;
1194
    }
1195

    
1196
    /**
1197
     * Inserta si se muestra o no la regla del Layout.
1198
     *
1199
     * @param b True si se muestra la regla.
1200
     */
1201
    public void setRuler(boolean b) {
1202
        m_showRuler = b;
1203
    }
1204

    
1205
    /**
1206
     * Devuelve si se muestra la regla del Layout.
1207
     *
1208
     * @return True si se muestra la regla.
1209
     */
1210
    public boolean getRuler() {
1211
        return m_showRuler;
1212
    }
1213

    
1214
    /**
1215
     * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1216
     * cuadr?cula, o no.
1217
     *
1218
     * @return true si se esta aplicando la cuadr?cula.
1219
     */
1220
    public boolean isCuadricula() {
1221
        return isCuadricula;
1222
    }
1223

    
1224
    /**
1225
     * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1226
     *
1227
     * @param b true si se aplica la cuadr?cula.
1228
     */
1229
    public void setIsCuadricula(boolean b) {
1230
        isCuadricula = b;
1231
    }
1232

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

    
1244
                if ((((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) &&
1245
                        (fframe.getFMap() != null)) {
1246
                    fframe.getFMap().getViewPort().setExtent(fframe.getFMap()
1247
                                                                   .getFullExtent());
1248
                }
1249
                fframe.refresh();
1250
            }
1251
        }
1252

    
1253
        setStatus(DESACTUALIZADO);
1254
        repaint();
1255
    }
1256

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

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

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

    
1343
        for (int i = 1; i < xml.getNumChild(); i++) {
1344
            if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1345
                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1346
                        p), true, false);
1347
            }
1348
        }
1349

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

    
1357
        return layout;
1358
    }
1359

    
1360
    /**
1361
     * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1362
     */
1363
    public void viewActivated() {
1364
        repaint();
1365
        PluginServices.getMainFrame().getStatusBar().setMessage("1",
1366
            getAtributes().getNameUnit());
1367

    
1368
        ///System.out.println("---------- 1 "+ getAtributes().getNameUnit());
1369
    }
1370

    
1371
    /**
1372
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1373
     */
1374
    public Object getViewModel() {
1375
        return map;
1376
    }
1377

    
1378
    /**
1379
     * Devuelve si se dibuja el Grid en el Layout o no.
1380
     *
1381
     * @return True si se dibuja el Grid en el Layout.
1382
     */
1383
    public boolean getIsDrawGrid() {
1384
        return isDrawCuadricula;
1385
    }
1386

    
1387
    /**
1388
     * Inserta si se muestra el Grid del Layout.
1389
     *
1390
     * @param b True si se muestra el Grid del Layout.
1391
     */
1392
    public void setIsDrawGrid(boolean b) {
1393
        isDrawCuadricula = b;
1394
    }
1395

    
1396
    /**
1397
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1398
     */
1399
    public void extentChanged(ExtentEvent e) {
1400
    }
1401

    
1402
    /**
1403
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
1404
     */
1405
    public void viewClosed() {
1406
        ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1407
    }
1408

    
1409
    /**
1410
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1411
     */
1412
    public void backColorChanged(ColorEvent e) {
1413
        //        refresh();
1414
    }
1415

    
1416
    /**
1417
     * Devuelve un array con los FFrames seleccionados.
1418
     *
1419
     * @return Array con los FFrames seleccionados.
1420
     */
1421
    public IFFrame[] getFFrameSelected() {
1422
        ArrayList selecList = new ArrayList();
1423

    
1424
        for (int i = getFFrames().length - 1; i >= 0; i--) {
1425
            IFFrame fframe = (IFFrame) getFFrame(i);
1426

    
1427
            if (fframe.getSelected() != IFFrame.NOSELECT) {
1428
                selecList.add(fframe);
1429
            }
1430
        }
1431

    
1432
        return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1433
    }
1434

    
1435
    /**
1436
     * Opens a dialog where to pick a PDF-file to save the current Layout
1437
     * suggesting a name for the file given by the first argument
1438
     *
1439
     * @param suggestedName DOCUMENT ME!
1440
     */
1441
    public void layoutToPDF(String suggestedName) {
1442
        FileFilter pdfFilter = new GenericFileFilter("pdf",
1443
                PluginServices.getText(this, "pdf"));
1444

    
1445
        JFileChooser jfc = new JFileChooser();
1446
        if (suggestedName!=null)
1447
        jfc.setSelectedFile(new File(suggestedName));
1448
        jfc.addChoosableFileFilter(pdfFilter);
1449
        jfc.setFileFilter(pdfFilter);
1450

    
1451
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1452
            File f = jfc.getSelectedFile();
1453
            File faux = null;
1454

    
1455
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
1456
                faux = f;
1457
            } else {
1458
                faux = new File(f.getPath() + ".pdf");
1459
            }
1460

    
1461
            layoutDraw.toPDF(faux);
1462
        }
1463
    }
1464

    
1465
    /**
1466
     * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1467
     * en este formato.
1468
     */
1469
    public void layoutToPDF() {
1470
            layoutToPDF(null);
1471
    }
1472

    
1473
    /**
1474
     * @return Returns the bModeDebug.
1475
     */
1476
    public boolean isModeDebug() {
1477
        return bModeDebug;
1478
    }
1479

    
1480
    /**
1481
     * @param modeDebug The bModeDebug to set.
1482
     */
1483
    public void setModeDebug(boolean modeDebug) {
1484
        bModeDebug = modeDebug;
1485
    }
1486

    
1487
    private ArrayList allFFrames(IFFrame[] fframes, ArrayList all){
1488
            for (int i=0;i<fframes.length;i++){
1489
                    if (fframes[i] instanceof FFrameGroup){
1490
                            return allFFrames(((FFrameGroup)fframes[i]).getFFrames(),all);
1491

    
1492
                    }else{
1493
                            all.add(fframes[i]);
1494
                    }
1495
            }
1496
            return all;
1497
    }
1498
        public IFFrame[] getAllFFrames() {
1499
                ArrayList all=new ArrayList();
1500
                return (IFFrame[])allFFrames(getFFrames(),all).toArray(new IFFrame[0]);
1501
        }
1502

    
1503
        public GeometryAdapter getGeometryAdapter() {
1504
                return geometryAdapter;
1505
        }
1506
        public boolean isEditable(){
1507
                return isEditable;
1508
        }
1509
        public void setEditable(boolean b) {
1510
                isEditable=b;
1511
        }
1512
        public void initGeometryAdapter() {
1513
                if (getTool() == LINE) {
1514
                        geometryAdapter=new PolyLineAdapter();
1515
        } else if (getTool() == RECTANGLESIMPLE) {
1516
                geometryAdapter=new RectangleAdapter();
1517
        } else if (getTool() == POLYLINE) {
1518
            geometryAdapter=new PolyLineAdapter();
1519
        } else if (getTool() == POLYGON) {
1520
            geometryAdapter=new PolygonAdapter();
1521
        } else if (getTool() == CIRCLE) {
1522
                geometryAdapter=new CircleAdapter();
1523
        } else if (getTool() == POINT) {
1524
                geometryAdapter=new PointAdapter();
1525
        }
1526
        }
1527
        public void startEdit() {
1528
                for(int i=0;i<getFFrames().length;i++){
1529
                        IFFrame frame=(IFFrame)getFFrame(i);
1530
                        if (frame instanceof IFFrameEditable){
1531
                                if (frame.getSelected()!=IFFrame.NOSELECT){
1532
                                        ((IFFrameEditable)frame).startEditing();
1533
                                }else{
1534
                                        ((IFFrameEditable)frame).stopEditing();
1535
                                }
1536
                        }
1537

    
1538
                }
1539
                refresh();
1540
        }
1541
        public void stopEdit(){
1542
                boolean refresh=false;
1543
                for(int i=0;i<getFFrames().length;i++){
1544
                        IFFrame frame=(IFFrame)getFFrame(i);
1545
                        if (frame instanceof IFFrameEditable){
1546
                                if (((IFFrameEditable)frame).isEditing()){
1547
                                        ((IFFrameEditable)getFFrame(i)).stopEditing();
1548
                                        refresh=true;
1549
                                }
1550
                        }
1551
                }
1552
                if (refresh) refresh();
1553
        }
1554
        public void delFFrameSelected(){
1555
                efs.startComplexCommand();
1556
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1557
             IFFrame fframe = (IFFrame) efs.getFFrame(i);
1558

    
1559
             if (fframe.getSelected() != IFFrame.NOSELECT) {
1560
                     efs.removeFFrame(i);
1561
                    // getFFrames().remove(i);
1562
             }
1563
         }
1564
                efs.endComplexCommand();
1565
                updateFFrames();
1566
        }
1567
        public void delFFrame(int index){
1568
                for(int i=0;i<getEFS().getAllFFrames().length;i++){
1569
                        if (getEFS().getFFrame(i).equals(getFFrame(index))){
1570
                                getEFS().removeFFrame(i);
1571
                        }
1572
                }
1573
                updateFFrames();
1574
        }
1575
        public void delFFrame(IFFrame frame){
1576
                for(int i=0;i<getEFS().getAllFFrames().length;i++){
1577
                        if (getEFS().getFFrame(i).equals(frame)){
1578
                                getEFS().removeFFrame(i);
1579
                        }
1580
                }
1581
                updateFFrames();
1582
        }
1583
        public EditableFeatureSource getEFS(){
1584
                return efs;
1585
        }
1586

    
1587
        public void executeCommand(CommandEvent e) {
1588
                this.updateFFrames();
1589
                this.refresh();
1590
        }
1591
}