Statistics
| Revision:

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

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

    
148

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

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

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

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

    
189
    public static final int EDIT=40;
190

    
191
    public static final Image iLayoutpan = new ImageIcon(AddLayer.class.getClassLoader()
192
                                                                       .getResource("images/LayoutHand.gif")).getImage();
193
    public static final Image ipan = new ImageIcon(AddLayer.class.getClassLoader()
194
                                                                 .getResource("images/Hand.gif")).getImage();
195
    public static final Image iLayoutzoomin = new ImageIcon(AddLayer.class.getClassLoader()
196
                                                                          .getResource("images/LayoutZoomInCursor.gif")).getImage();
197
    public static final Image izoomin = new ImageIcon(AddLayer.class.getClassLoader()
198
                                                                    .getResource("images/ZoomInCursor.gif")).getImage();
199
    public static final Image iLayoutzoomout = new ImageIcon(AddLayer.class.getClassLoader()
200
                                                                           .getResource("images/LayoutZoomOutCursor.gif")).getImage();
201
    public static final Image izoomout = new ImageIcon(AddLayer.class.getClassLoader()
202
                                                                     .getResource("images/ZoomOutCursor.gif")).getImage();
203
    public static final Image iinfo = new ImageIcon(AddLayer.class.getClassLoader()
204
                                                                  .getResource("images/InfoCursor.gif")).getImage();
205
    public static final Image icrux = new ImageIcon(AddLayer.class.getClassLoader()
206
                                                                  .getResource("images/CruxCursor.png")).getImage();
207
    public static final Image itag = new ImageIcon(AddLayer.class.getClassLoader()
208
                                                                 .getResource("images/tagCursor.gif")).getImage();
209
    public static final Image iPoint = new ImageIcon(AddLayer.class.getClassLoader()
210
                                                                   .getResource("images/PointCursor.png")).getImage();
211
    public static final Image iRect = new ImageIcon(AddLayer.class.getClassLoader()
212
                                                                  .getResource("images/RectCursor.png")).getImage();
213
    public static final Image iLine = new ImageIcon(AddLayer.class.getClassLoader()
214
                                                                  .getResource("images/LineCursor.png")).getImage();
215
    public static final Image iRectangle = new ImageIcon(AddLayer.class.getClassLoader()
216
                                                                       .getResource("images/RectangleCursor.png")).getImage();
217
    public static final Image iCircle = new ImageIcon(AddLayer.class.getClassLoader()
218
                                                                    .getResource("images/CircleCursor.png")).getImage();
219
    public static final Image iPoligon = new ImageIcon(AddLayer.class.getClassLoader()
220
                                                                     .getResource("images/PoligonCursor.png")).getImage();
221

    
222

    
223
    public static Hashtable nums = new Hashtable();
224
    private Point origin = new Point(50, 50);
225
    private Point rectOrigin = new Point(origin);
226
    private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
227
            rectOrigin.y, 400, 300);
228
    private Point m_FirstPoint = new Point(0, 0);
229
    private Point m_PointAnt = new Point(0, 0);
230
    private Point m_LastPoint = new Point(0, 0);
231
    private EventsHandler events;
232
    private int tool = ZOOM_MAS;
233
    private int status = DESACTUALIZADO;
234
    private BufferedImage img = null;
235
    private BufferedImage imgRuler = null;
236
    private AffineTransform m_MatrizTransf;
237
    private Rectangle2D rectVisible;
238
    private IFFrameDialog fframedialog = null;
239
    ///private ArrayList m_fframes = new ArrayList();
240
    private IFFrame[] fframes;
241
    private MapProperties m_propertiesLayout = null;
242
    private Attributes m_attributes = null;
243
    private PrintService[] m_cachePrintServices = null;
244
    private PrintService m_cachePrintService = null;
245
    private boolean m_bCancelDrawing = false;
246
    private boolean isCuadricula = false;
247
    private boolean initial = true;
248
    private ProjectMap map = null;
249
    private Rectangle reSel = null;
250
    private boolean isReSel = true;
251
    private boolean m_showRuler = true;
252
    private FLayoutDraw layoutDraw = null;
253
    private boolean isDrawCuadricula = true;
254
    private Doc doc = null;
255
    private PrintRequestAttributeSet att = null;
256
    private GeometryAdapter geometryAdapter=new PolyLineAdapter();
257
    private DefaultEditableFeatureSource efs;
258
    private boolean isEditable=true;
259
    private ViewInfo m_viewInfo = null;
260
    private int numBefore=0;
261
    private int numBehind=0;
262
    /**
263
     * Lo usamos cuando estamos haciendo una ficha y asignando tags
264
     * Se pone en modo debug cuando hacemos un VIEW_TAGS
265
     */
266
    private boolean bModeDebug = false;
267
        private boolean editGroup;
268

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

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

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

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

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

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

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

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

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

    
362
    /**
363
     * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
364
     *
365
     * @return Array con todos los fframes que contiene el Layout.
366
     */
367
    public IFFrame[] getFFrames() {
368
            return fframes;
369
    }
370
    public IFFrame getFFrame(int i){
371
            return fframes[i];
372
    }
373
    public void updateFFrames(){
374
            ArrayList frames=new ArrayList();
375
            IFFrame[] auxfframes=efs.getFFrames();
376
            for (int j=numBehind;j<=numBefore;j++){
377
            for (int i=0;i<auxfframes.length;i++){
378
            if (auxfframes[i].getLevel()==-1){
379
            //        frames.add(auxfframes[i]);
380
            }
381

    
382
                    if (auxfframes[i].getLevel()==j){
383
                            frames.add(auxfframes[i]);
384
                            continue;
385
                    }
386
            }
387
            }
388
            fframes=(IFFrame[])frames.toArray(new IFFrame[0]);
389
    }
390
    /**
391
     * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
392
     * entero.
393
     */
394
    public void fullRect() {
395
        rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
396
            getHeight() - (origin.x * 2));
397

    
398
        if (m_attributes.isLandSpace()) {
399
            rect = m_attributes.getRectangleLandscape(rect, getWidth(),
400
                    getHeight());
401
        } else {
402
            rect = m_attributes.getRectanglePortrait(rect, getWidth(),
403
                    getHeight());
404
        }
405
        /*IFFrame[] fframes=getFFrames();
406
        for (int i=0;i<fframes.length;i++){
407
                fframes[i].initialize();
408
        }*/
409
        status = DESACTUALIZADO;
410
        repaint();
411
    }
412

    
413
    /**
414
     * M?todo para imprimir el Layout sin modificar la matriz de
415
     * transformaci?n.
416
     *
417
     * @param g2
418
     */
419
    public void drawLayoutPrint(Graphics2D g2) {
420
        setCancelDrawing(false);
421

    
422
        setCursor(Cursor.getDefaultCursor());
423

    
424
        double scale = 0;
425

    
426
        ///if (rect.width > rect.height) {
427
        ///    scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
428
        ///} else {
429
        scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
430

    
431
        ///}
432
        AffineTransform escalado = new AffineTransform();
433
        AffineTransform translacion = new AffineTransform();
434
        translacion.setToTranslation(rect.getMinX(), rect.getMinY());
435
        escalado.setToScale(scale, scale);
436
        m_MatrizTransf.setToIdentity();
437
        m_MatrizTransf.concatenate(translacion);
438
        m_MatrizTransf.concatenate(escalado);
439
        m_attributes.setDistanceUnitX(rect);
440
        m_attributes.setDistanceUnitY(rect);
441

    
442
        for (int i = 0; i < getFFrames().length; i++) {
443
            try {
444
                ((IFFrame) getFFrame(i)).print(g2, getAT());
445
            } catch (DriverException e) {
446
                NotificationManager.addError(e.getMessage(), e);
447
            }
448
        }
449

    
450
        //TODO Esto es para ver el rect?ngulo que representa el folio en la impresi?n.
451
        g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
452
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
453
    }
454

    
455
    /**
456
     * Clip sobre el rect?ngulo visible.
457
     *
458
     * @param g2d Graphics sobre el que hacer el clip.
459
     */
460
    private void clipVisibleRect(Graphics2D g2d) {
461
        rectVisible = this.getVisibleRect();
462
        g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
463
            (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
464
    }
465

    
466
    /**
467
     * Inicializa los componentes.
468
     */
469
    private void initComponents() {
470
        m_attributes = new Attributes();
471
        m_attributes.setDistanceUnitX(rect);
472
        m_attributes.setDistanceUnitY(rect);
473
        actionDelFFrame();
474
        setDoubleBuffered(true);
475
    }
476

    
477
    /**
478
     * Crea un ActionEvent para controlar las teclas que se pulsen cuando este
479
     * el Layout Focusable a true.
480
     */
481
    private void actionDelFFrame() {
482
        Action doNothing = new AbstractAction() {
483
                public void actionPerformed(ActionEvent e) {
484
                   delFFrameSelected();
485
                   refresh();
486
                }
487
            };
488

    
489
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
490
            "doNothing");
491
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
492
            "doNothing");
493
        this.getActionMap().put("doNothing", doNothing);
494
    }
495

    
496
    /**
497
     * paintComponent del Layout.
498
     *
499
     * @param g Graphics del Layout.
500
     */
501
    protected void paintComponent(Graphics g) {
502
        super.paintComponent(g);
503

    
504
        clipVisibleRect((Graphics2D) g);
505

    
506
        Rectangle rClip = g.getClipBounds();
507

    
508
        if (rClip == null) {
509
            System.err.println("clip = null");
510
        }
511

    
512
        switch (status) {
513
            case ZOOM_MAS:
514
                logger.debug("zoom mas");
515
                layoutDraw.drawRectangle((Graphics2D) g);
516

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

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

    
526
                Rectangle r = new Rectangle();
527

    
528
                r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
529
                g.drawRect(r.x, r.y, r.width, r.height);
530

    
531
                break;
532

    
533
            case RECTANGLE:
534
                logger.debug("rectangle");
535
                layoutDraw.drawRectangle((Graphics2D) g);
536

    
537
                g.drawImage(img, 0, 0, this);
538

    
539
                g.setClip(rClip);
540
                //layoutDraw.drawGrid((Graphics2D) g);
541
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
542
                g.drawImage(imgRuler,0,0,this);
543
                g.setColor(Color.black);
544
                g.setXORMode(Color.white);
545

    
546
                Rectangle re = new Rectangle();
547
                re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
548

    
549
                if (isCuadricula()) {
550
                    FLayoutUtilities.setRectGrid(re,
551
                        m_attributes.getUnitInPixelsX(),
552
                        m_attributes.getUnitInPixelsY(), m_MatrizTransf);
553
                }
554

    
555
                g.drawRect(re.x, re.y, re.width, re.height);
556

    
557
                break;
558

    
559
            case PAN:
560
                logger.debug("pan");
561

    
562
                //g.setXORMode(Color.black);
563
                rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
564
                rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
565

    
566
                //g.clearRect(0, 0, getWidth(), getHeight());
567
                layoutDraw.drawRectangle((Graphics2D) g);
568

    
569
                if (img != null) {
570
                    g.drawImage(img, (getLastPoint().x - getPointAnt().x),
571
                        (getLastPoint().y - getPointAnt().y), this);
572
                }
573

    
574
                g.setClip(rClip);
575
                layoutDraw.drawGrid((Graphics2D) g);
576
                layoutDraw.drawRuler((Graphics2D) g, Color.black);
577
                //g.drawImage(imgRuler,0,0,this);
578
                break;
579

    
580
            case VIEW_PAN:
581

    
582
                // logger.debug("View pan");
583
                layoutDraw.drawRectangle((Graphics2D) g);
584

    
585
                for (int i = 0; i < getFFrames().length; i++) {
586
                    if (getFFrame(i) instanceof IFFrameUseFMap) {
587
                        IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
588

    
589
                        if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) {
590
                            Rectangle2D.Double rec = ((IFFrame)fframe).getBoundingBox(getAT());
591

    
592
                            if (img != null) {
593
                                //g.drawImage(img, 0, 0, this);
594
                                rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
595

    
596
                                //((Graphics2D)g).clearRect((int)rec.x,(int)rec.y,(int)rec.width,(int)rec.height);
597
                            }
598

    
599
                            if (fframe.getBufferedImage() != null) {
600
                                layoutDraw.drawHandlers((Graphics2D) g,
601
                                    Color.black);
602
                                g.clipRect((int) rec.x, (int) rec.y,
603
                                    (int) rec.width, (int) rec.height);
604

    
605
                                //g.setColor(Color.gray);
606
                                //g.fillRect(0,0,getWidth(),getHeight());
607
                                layoutDraw.drawRectangle((Graphics2D) g);
608
                                layoutDraw.drawRuler((Graphics2D) g, Color.black);
609
                                Rectangle2D.Double r1=((IFFrame)fframe).getBoundingBox(getAT());
610
                                g.drawImage(fframe.getBufferedImage(),(int)
611
                                    r1.getX()+m_LastPoint.x - m_PointAnt.x,
612
                                    (int)r1.getY()+m_LastPoint.y - m_PointAnt.y, this);
613

    
614
                               fframe.refresh();
615
                            }
616
                        }
617
                    }
618
                }
619

    
620
                g.setClip(rClip);
621
                //layoutDraw.drawGrid((Graphics2D) g);
622
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
623
                g.drawImage(imgRuler,0,0,this);
624

    
625
                break;
626

    
627
            case SELECT:
628
                logger.debug("select");
629
                layoutDraw.drawRectangle((Graphics2D) g);
630

    
631
                g.drawImage(img, 0, 0, this);
632

    
633
                if (isReSel) {
634
                    reSel = new Rectangle();
635
                    reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
636
                    g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
637
                }
638
                IFFrame[] frames=getFFrameSelected();
639
                for (int i = 0; i < frames.length; i++) {
640
                    //IFFrame fframe = (IFFrame) getFFrames().get(i);
641

    
642
                    //if (fframe.getSelected() != IFFrame.NOSELECT) {
643
                        g.setColor(Color.black);
644
                        frames[i].drawHandlers((Graphics2D) g);
645

    
646
                        int difx = (m_LastPoint.x - m_FirstPoint.x);
647
                        int dify = (m_LastPoint.y - m_FirstPoint.y);
648
                       // System.out.println(m_FirstPoint);
649
                       // System.out.println(m_LastPoint);
650
                        if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
651
                            Rectangle2D rectangle = frames[i].getMovieRect(difx,
652
                                    dify);
653
                            if (rectangle==null)
654
                                    return;
655
                            ((Graphics2D) g).rotate(Math.toRadians(
656
                                    frames[i].getRotation()),
657
                                rectangle.getX() + (rectangle.getWidth() / 2),
658
                                rectangle.getY() + (rectangle.getHeight() / 2));
659

    
660
                            if (rectangle != null) {
661
                                if (isCuadricula) {
662
                                    FLayoutUtilities.setRectGrid(rectangle,
663
                                        m_attributes.getUnitInPixelsX(),
664
                                        m_attributes.getUnitInPixelsY(),
665
                                        m_MatrizTransf);
666
                                }
667

    
668
                                g.drawRect((int) rectangle.getMinX(),
669
                                    (int) rectangle.getMinY(),
670
                                    (int) rectangle.getWidth(),
671
                                    (int) rectangle.getHeight());
672
                            }
673

    
674
                            ((Graphics2D) g).rotate(Math.toRadians(
675
                                    -frames[i].getRotation()),
676
                                rectangle.getX() + (rectangle.getWidth() / 2),
677
                                rectangle.getY() + (rectangle.getHeight() / 2));
678

    
679
                        }
680
                    //}
681
                }
682

    
683
                g.setClip(rClip);
684
                //layoutDraw.drawGrid((Graphics2D) g);
685
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
686
                g.drawImage(imgRuler,0,0,this);
687

    
688
                break;
689
             case GRAPHICS:
690
                    logger.debug("graphics");
691
                layoutDraw.drawRectangle((Graphics2D) g);
692
                g.drawImage(img, 0, 0, this);
693
                g.setClip(rClip);
694
                //layoutDraw.drawGrid((Graphics2D) g);
695
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
696
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
697

    
698
                if (getTool()==EDIT){
699
                        IFFrame[] fframeSelect=getFFrameSelected();
700
                        for(int i=0;i<fframeSelect.length;i++){
701
                                if (fframeSelect[i] instanceof IFFrameEditableVertex){
702
                                        ((IFFrameEditableVertex)fframeSelect[i]).paint((Graphics2D)g,getAT());
703
                                }
704
                        }
705
                }else{
706
                        geometryAdapter.paint((Graphics2D)g,getAT(),true);
707
                }
708
                g.drawImage(imgRuler,0,0,this);
709
                break;
710

    
711
            case DESACTUALIZADO:
712
                logger.debug("desactualizado");
713
                img = new BufferedImage(getWidth(), getHeight(),
714
                        BufferedImage.TYPE_INT_ARGB);
715
                imgRuler = new BufferedImage(getWidth(), getHeight(),
716
                        BufferedImage.TYPE_INT_ARGB);
717
                Graphics gimag = img.getGraphics();
718
                Graphics gimgRuler = imgRuler.getGraphics();
719

    
720
                clipVisibleRect((Graphics2D) gimag);
721

    
722
                if (initial) {
723
                    fullRect();
724
                    initial = false;
725
                }
726

    
727
                try {
728
                    layoutDraw.drawLayout((Graphics2D) gimag, img);
729
                } catch (DriverException e) {
730
                    e.printStackTrace();
731
                }
732

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

    
736
                g.drawImage(img, 0, 0, this);
737
                g.setClip(rClip);
738

    
739
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
740
                layoutDraw.drawGrid((Graphics2D) gimgRuler);
741
                layoutDraw.drawRuler((Graphics2D) gimgRuler, Color.black);
742
                g.drawImage(imgRuler,0,0,this);
743

    
744
                break;
745

    
746
            case ACTUALIZADO:
747
                    logger.debug("actualizado");
748
                layoutDraw.drawRectangle((Graphics2D) g);
749

    
750
                g.drawImage(img, 0, 0, this);
751

    
752
                g.setClip(rClip);
753
                //layoutDraw.drawGrid((Graphics2D) g);
754

    
755
                layoutDraw.drawHandlers((Graphics2D) g, Color.black);
756
                //layoutDraw.drawRuler((Graphics2D) g, Color.black);
757
                g.drawImage(imgRuler,0,0,this);
758
        }
759
    }
760

    
761
    /**
762
     * A?ade un fframe al Arraylist m_fframes.
763
     *
764
     * @param frame fframe a a?adir.
765
     * @param clearSelection para que se quede seleccionado ?nicamente  el que
766
     *        a?adimos y false si lo que se pretende es que no se
767
     *        deseleccionen lo que ya est?n seleccionados.
768
     * @param select Booleano que indica si se tiene que quedar seleccionado el
769
     *        FFrame que se a?ade o no.
770
     */
771
    public void addFFrame(IFFrame frame, boolean clearSelection, boolean select) {
772
        IFFrame[] fframes=getFFrames();
773
            if (clearSelection) {
774
            for (int i = fframes.length - 1; i >= 0; i--) {
775
                IFFrame fframe1 = fframes[i];
776
                fframe1.setSelected(false);
777
            }
778
        }
779

    
780
        if (nums.containsKey(frame.getClass())) {
781
            nums.put(frame.getClass(),
782
                new Integer(Integer.parseInt(nums.get(frame.getClass())
783
                                                 .toString()) + 1));
784
        } else {
785
            nums.put(frame.getClass(), new Integer(0));
786
        }
787

    
788
        frame.setNum(Integer.parseInt(nums.get(frame.getClass()).toString()));
789
        efs.addFFrame(frame);
790
        frame.setSelected(select);
791
        frame.setLevel(getNumBefore());
792
        updateFFrames();
793
    }
794

    
795
    /**
796
     * Abre el di?logo de propiedades del folio, pasando como par?metro el
797
     * PrinterJob.
798
     *
799
     * @param job
800
     */
801
    public void showPagePropertiesWindow(PrinterJob job) {
802
        PageFormat pf1; //=new PageFormat();
803

    
804
        pf1 = m_attributes.getPageFormat();
805
        pf1 = job.pageDialog(pf1);
806
        m_attributes.setPageFormat(pf1);
807
        refresh();
808
    }
809

    
810
    /**
811
     * Refresca el Layout.
812
     */
813
    public void refresh() {
814
        //rect = m_attributes.obtainRect(false, rect, getWidth(), getHeight());
815
        setStatus(DESACTUALIZADO);
816
        repaint();
817
    }
818

    
819
    /**
820
     * Obtiene el rect?ngulo que representa el folio con las caracter?sticas
821
     * que contiene attributes y diferenciando si es para visualizar en
822
     * pantalla o para imprimir.
823
     *
824
     * @param isPrint si es para imprimir.
825
     */
826
    public void obtainRect(boolean isPrint) {
827
        m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
828
    }
829

    
830
    /**
831
     * Muestra el di?logo de configuraci?n del Layout.
832
     */
833
    public void showFConfig() {
834
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
835
        PluginServices.getMDIManager().addView(m_configLayout);
836
    }
837

    
838
    /**
839
     * Mestra el di?logo de propiedades del Layout.
840
     */
841
    public void showFProperties() {
842
        if (map == null) {
843
            map = new ProjectMap();
844
            map.setModel(this);
845
            map.setName(getName());
846
        }
847

    
848
        m_propertiesLayout = new MapProperties(map);
849
        PluginServices.getMDIManager().addView(m_propertiesLayout);
850
    }
851

    
852
    /**
853
     * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
854
     *
855
     * @param job
856
     */
857
    public void showPrintDialog(PrinterJob job) {
858
        if (job != null) {
859
            job.printDialog();
860

    
861
            try {
862
                job.setPrintable((Printable) PluginServices.getExtension(
863
                        com.iver.cit.gvsig.Print.class));
864
                job.print();
865
            } catch (PrinterException e) {
866
                e.printStackTrace();
867
            }
868
        } else {
869
            //Actualizar attributes
870
            att = m_attributes.toPrintAttributes();
871

    
872
            //------------------ The Printing things --------------------- //
873
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
874

    
875
            // returns the set of printers that support printing a specific document type (such as GIF)
876
            // with a specific set of attributes (such as two sided).
877
            // PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
878
            // interestingly, the printer dialog's default behavior has changed with the new API: by default the dialog is not shown.
879
            // So we must use the ServiceUI class to create a print dialog
880
            // returns the default print service.
881
            if (m_cachePrintServices == null) {
882
                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor,
883
                        null);
884
            }
885

    
886
            PrintService defaultService = null;
887

    
888
            if (m_cachePrintService == null) {
889
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
890
            }
891

    
892
            if ((defaultService == null) && (m_cachePrintService == null)) {
893
                JOptionPane.showMessageDialog((Component) PluginServices.getMainFrame(),
894
                    "ninguna_impresora_configurada");
895

    
896
                return;
897
            }
898

    
899
            if (m_cachePrintService == null) {
900
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
901
                        m_cachePrintServices, defaultService, flavor, att);
902

    
903
                // m_cachePrintRequestAtributeSet = new HashPrintRequestAttributeSet();
904
                // m_cachePrintRequestAtributeSet.addAll(pras);
905
            } else {
906
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
907
                        m_cachePrintServices, m_cachePrintService, flavor, att);
908
            }
909

    
910
            if (m_cachePrintService != null) {
911
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
912
                PrintJobListener pjlistener = new PrintJobAdapter() {
913
                        public void printDataTransferCompleted(PrintJobEvent e) {
914
                            System.out.println("Fin de impresi?n");
915
                            fullRect();
916
                        }
917
                    };
918

    
919
                jobNuevo.addPrintJobListener(pjlistener);
920

    
921
                // DocAttributeSet das = new HashDocAttributeSet();
922
                doc = new SimpleDoc((Printable) PluginServices.getExtension(
923
                            com.iver.cit.gvsig.Print.class), flavor, null);
924

    
925
                try {
926
                    jobNuevo.print(doc, att);
927

    
928
                    // m_attributes.
929
                } catch (PrintException pe) {
930
                    pe.printStackTrace();
931
                }
932
            }
933
        }
934

    
935
        /* try {
936
           print = job.printDialog(att);
937
           } catch (Exception e) {
938
               logger.error("Abriendo el Di?logo de imprimir"); //System.out.println("Excepci?n "+e);
939
           }
940
           if (print) {
941
               job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
942
               try {
943
                   job.print(att);
944
               } catch (Exception ex) {
945
                   ex.printStackTrace();
946
               }
947
           } */
948
    }
949

    
950
    /**
951
     * Sustituye el puntero del rat?n por la imagen que se le pasa como
952
     * par?metro.
953
     *
954
     * @param image
955
     */
956
    public void setMapCursor(Image image) {
957
        Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
958
                new Point(16, 16), "");
959
        setCursor(cur);
960
    }
961

    
962
    /**
963
     * Cambia el puntero del raton al cusor que se le introduce como par?metro.
964
     *
965
     * @param cursor cursor a mostrar en el puntero del rat?n.
966
     */
967
    public void setMapCursor(Cursor cursor) {
968
        setCursor(cursor);
969
    }
970

    
971
    /**
972
     * Pone como seleccionada a la herramienta a partir de su n?mero.
973
     *
974
     * @param i
975
     */
976
    public void setTool(int i) {
977
        tool = i;
978

    
979
        if (getTool() == PAN) {
980
            setMapCursor(ipan);
981
        } else if (getTool() == ZOOM_MAS) {
982
            setMapCursor(izoomin);
983
        } else if (getTool() == ZOOM_MENOS) {
984
            setMapCursor(izoomout);
985
        } else if (getTool() == RECTANGLEVIEW) {
986
            setMapCursor(icrux);
987
        } else if (getTool() == RECTANGLEPICTURE) {
988
            setMapCursor(icrux);
989
        } else if (getTool() == RECTANGLESCALEBAR) {
990
            setMapCursor(icrux);
991
        } else if (getTool() == RECTANGLELEGEND) {
992
            setMapCursor(icrux);
993
        } else if (getTool() == RECTANGLETEXT) {
994
            setMapCursor(icrux);
995
        } else if (getTool() == RECTANGLENORTH) {
996
            setMapCursor(icrux);
997
        } else if (getTool() == RECTANGLEBOX) {
998
            setMapCursor(icrux);
999
        } else if (getTool() == SELECT) {
1000
            setCursor(Cursor.getDefaultCursor());
1001
        } else if (getTool() == SET_TAG) {
1002
            setMapCursor(itag);
1003
        } else if (getTool() == POINT) {
1004
            setMapCursor(iPoint);
1005
        } else if (getTool() == LINE) {
1006
            setMapCursor(iRect);
1007
        } else if (getTool() == RECTANGLESIMPLE) {
1008
            setMapCursor(iRectangle);
1009
        } else if (getTool() == POLYLINE) {
1010
            setMapCursor(iLine);
1011
        } else if (getTool() == POLYGON) {
1012
            setMapCursor(iPoligon);
1013
        } else if (getTool() == CIRCLE) {
1014
            setMapCursor(iCircle);
1015
        }
1016
        if (getTool() == EDIT){
1017
                setMapCursor(icrux);
1018
                startEdit();
1019
        }else{
1020
                stopEdit();
1021
        }
1022
        initGeometryAdapter();
1023
    }
1024

    
1025
    /**
1026
     * Se crean aqu? los dialogos cada vez que se necesitan.
1027
     *
1028
     * @param fframe Rectangle que representa el lugar que ocupara el elemento
1029
     *        a?adido.
1030
     *
1031
     * @return true si se debe de a?adir el fframe.
1032
     */
1033
    public boolean openFFrameDialog(IFFrame fframe) {
1034
        switch (tool) {
1035
            case RECTANGLEVIEW:
1036
                fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
1037

    
1038
                break;
1039

    
1040
            case RECTANGLEPICTURE:
1041
                fframedialog = new FFramePictureDialog(this,
1042
                        (FFramePicture) fframe);
1043

    
1044
                break;
1045

    
1046
            case RECTANGLESCALEBAR:
1047
                fframedialog = new FFrameScaleBarDialog(this,
1048
                        (FFrameScaleBar) fframe);
1049

    
1050
                break;
1051

    
1052
            case RECTANGLELEGEND:
1053
                fframedialog = new FFrameLegendDialog(this,
1054
                        (FFrameLegend) fframe);
1055

    
1056
                break;
1057

    
1058
            case RECTANGLETEXT:
1059
                fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
1060

    
1061
                break;
1062

    
1063
            case GRAPHICS:
1064
                fframedialog = new FFrameGraphicsDialog(this,
1065
                        (FFrameGraphics) fframe);
1066

    
1067
                break;
1068

    
1069
            case RECTANGLEGROUP:
1070
                fframedialog = new FFrameGroupDialog(this, (FFrameGroup) fframe);
1071

    
1072
                break;
1073
            case RECTANGLENORTH:
1074
                fframedialog = new FFrameNorthDialog(this, (FFrameNorth) fframe);
1075

    
1076
                break;
1077
            case RECTANGLEBOX:
1078
                fframedialog = new FFrameBoxDialog(this, (FFrameTable) fframe);
1079

    
1080
                break;
1081
            default:
1082
                return true;
1083
        }
1084

    
1085
        if (fframedialog != null) {
1086
            fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
1087
            PluginServices.getMDIManager().addView(fframedialog);
1088
        }
1089

    
1090
        return fframedialog.getIsAcepted();
1091
    }
1092

    
1093
    /**
1094
     * Devuelve el Rectangle2D que representa en pixels al folio.
1095
     *
1096
     * @return Rectangle2D.Double
1097
     */
1098
    public Rectangle2D.Double getRect() {
1099
        return rect;
1100
    }
1101
    public void setRect(Rectangle2D r){
1102
            rect.setRect(r);
1103
    }
1104
    /**
1105
     * Obtiene un entero que representa la herramienta seleccionada.
1106
     *
1107
     * @return entero.
1108
     */
1109
    public int getTool() {
1110
        return tool;
1111
    }
1112

    
1113
    /**
1114
     * Devuelve la Matriz transformada que se esta plicando al Layout.
1115
     *
1116
     * @return AffineTransform
1117
     */
1118
    public AffineTransform getAT() {
1119
        return m_MatrizTransf;
1120
    }
1121

    
1122
    /**
1123
     * Devuelve los atributos del Mapa.
1124
     *
1125
     * @return Attributes.
1126
     */
1127
    public Attributes getAtributes() {
1128
        return m_attributes;
1129
    }
1130

    
1131
    /**
1132
     * Pone el estado que se quiera.
1133
     *
1134
     * @param s estado.
1135
     */
1136
    public void setStatus(int s) {
1137
        status = s;
1138
    }
1139

    
1140
    /**
1141
     * Devuelve el punto que representa la esquina noroeste del mapa.
1142
     *
1143
     * @return un punto.
1144
     */
1145
    public Point getRectOrigin() {
1146
        return rectOrigin;
1147
    }
1148

    
1149
    /**
1150
     * Devuelve el punto del primer click de rat?n.
1151
     *
1152
     * @return un punto.
1153
     */
1154
    public Point getFirstPoint() {
1155
        return m_FirstPoint;
1156
    }
1157

    
1158
    /**
1159
     * Devuelve el punto de click de rat?n anterior.
1160
     *
1161
     * @return un punto.
1162
     */
1163
    public Point getPointAnt() {
1164
        return m_PointAnt;
1165
    }
1166

    
1167
    /**
1168
     * Devuelve el punto donde se solt? el bot?n del rat?n.
1169
     *
1170
     * @return un punto.
1171
     */
1172
    public Point getLastPoint() {
1173
        return m_LastPoint;
1174
    }
1175

    
1176
    /**
1177
     * Rellena el primer punto de click de rat?n.
1178
     *
1179
     * @param p punto.
1180
     */
1181
    public void setFirstPoint(Point p) {
1182
        m_FirstPoint = p;
1183
    }
1184

    
1185
    /**
1186
     * Rellena el punto de click de rat?n anterior.
1187
     *
1188
     * @param p punto.
1189
     */
1190
    public void setPointAnt(Point p) {
1191
        m_PointAnt = p;
1192
    }
1193

    
1194
    /**
1195
     * Rellena el punto donde se solto el bot?n del rat?n.
1196
     *
1197
     * @param p punto.
1198
     */
1199
    public void setLastPoint(Point p) {
1200
        m_LastPoint = p;
1201
    }
1202

    
1203
    /**
1204
     * This method is used to get <strong>an initial</strong> ViewInfo object
1205
     * for this Map. It is not intended to retrieve the ViewInfo object in a
1206
     * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
1207
     * to retrieve the ViewInfo object at any time after the creation of the
1208
     * object.
1209
     *
1210
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1211
     */
1212
    public ViewInfo getViewInfo() {
1213
            if (m_viewInfo == null) {
1214
                    m_viewInfo = new ViewInfo(ViewInfo.ICONIFIABLE | ViewInfo.RESIZABLE |
1215
                ViewInfo.MAXIMIZABLE);
1216
                    m_viewInfo.setWidth(500);
1217
                    m_viewInfo.setHeight(400);
1218

    
1219
                    m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : " +
1220
                                    getName());
1221
            }
1222
            return m_viewInfo;
1223
    }
1224

    
1225
    /**
1226
     * Inserta si se muestra o no la regla del Layout.
1227
     *
1228
     * @param b True si se muestra la regla.
1229
     */
1230
    public void setRuler(boolean b) {
1231
        m_showRuler = b;
1232
    }
1233

    
1234
    /**
1235
     * Devuelve si se muestra la regla del Layout.
1236
     *
1237
     * @return True si se muestra la regla.
1238
     */
1239
    public boolean getRuler() {
1240
        return m_showRuler;
1241
    }
1242

    
1243
    /**
1244
     * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1245
     * cuadr?cula, o no.
1246
     *
1247
     * @return true si se esta aplicando la cuadr?cula.
1248
     */
1249
    public boolean isCuadricula() {
1250
        return isCuadricula;
1251
    }
1252

    
1253
    /**
1254
     * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1255
     *
1256
     * @param b true si se aplica la cuadr?cula.
1257
     */
1258
    public void setIsCuadricula(boolean b) {
1259
        isCuadricula = b;
1260
    }
1261

    
1262
    /**
1263
     * Realiza una exteni?n completa de las capas que contiene la vista del
1264
     * FFrameView.
1265
     *
1266
     * @throws DriverException
1267
     */
1268
    public void viewFull() throws DriverException {
1269
            IFFrame[] fframes=getFFrameSelected();
1270
            for (int i = 0; i < fframes.length; i++) {
1271
            if (fframes[i] instanceof IFFrameUseFMap) {
1272
                IFFrameUseFMap fframe = (IFFrameUseFMap)fframes[i];
1273

    
1274
                if (fframe.getFMap() != null) {
1275
                    fframe.fullExtent();//getFMap().getViewPort().setExtent(fframe.getFMap()
1276
                                        //                           .getFullExtent());
1277
                }
1278
                fframe.refresh();
1279
            }
1280
        }
1281
//        for (int i = 0; i < getFFrames().length; i++) {
1282
//            if (getFFrame(i) instanceof IFFrameUseFMap) {
1283
//                IFFrameUseFMap fframe = (IFFrameUseFMap) getFFrame(i);
1284
//
1285
//                if ((((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) &&
1286
//                        (fframe.getFMap() != null)) {
1287
//                    fframe.getFMap().getViewPort().setExtent(fframe.getFMap()
1288
//                                                                   .getFullExtent());
1289
//                }
1290
//                fframe.refresh();
1291
//            }
1292
//        }
1293

    
1294
        setStatus(DESACTUALIZADO);
1295
        repaint();
1296
    }
1297

    
1298
    /**
1299
     * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1300
     * para poder despu?s volver a crear el objeto original.
1301
     *
1302
     * @return XMLEntity.
1303
     *
1304
     * @throws XMLException
1305
     */
1306
    public XMLEntity getXMLEntity() {
1307
            //getEFS().compact();
1308
        XMLEntity xml = new XMLEntity();
1309
        xml.putProperty("className", this.getClass().getName());
1310
        xml.setName("layout");
1311
        xml.putProperty("isCuadricula", isCuadricula());
1312
        xml.putProperty("m_name", this.getName());
1313
        xml.putProperty("isEditable",isEditable);
1314
        xml.putProperty("numBehind",numBehind);
1315
        xml.putProperty("numBefore",numBefore);
1316
        xml.addChild(getAtributes().getXMLEntity());
1317

    
1318
        for (int i = 0; i < getFFrames().length; i++) {
1319
                try{
1320
                        XMLEntity xmlAux=((IFFrame) getFFrame(i)).getXMLEntity();
1321
                        //xmlAux.putProperty("level",i);
1322
                        xml.addChild(xmlAux);
1323
                }catch (SaveException e) {
1324
                            e.showError();
1325
                    }
1326
        }
1327
        return xml;
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
     * @throws OpenException
1337
     */
1338
    public static Layout createLayout(XMLEntity xml,Project p) throws OpenException {
1339
        Layout layout = new Layout();
1340
        try{
1341
        layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1342
        layout.setName(xml.getStringProperty("m_name"));
1343
        layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1344
         if (xml.contains("isEditable")){
1345
                layout.setEditable(xml.getBooleanProperty("isEditable"));
1346
        }
1347
         if (xml.contains("numBehind")){
1348
                 layout.numBehind=xml.getIntProperty("numBehind");
1349
                 layout.numBefore=xml.getIntProperty("numBefore");
1350
         }
1351
        layout.getEFS().startComplexCommand();
1352
        for (int i = 1; i < xml.getNumChild(); i++) {
1353
                    try {
1354
                                        layout.addFFrame(FFrame.createFFrame(xml.getChild(i),p,layout),
1355
                                            true, false);
1356
                                } catch (OpenException e) {
1357
                                        e.showError();
1358
                                }
1359
        }
1360
        layout.getEFS().endComplexCommand();
1361
        IFFrame[] fframes=layout.getAllFFrames();
1362
        for (int i=0;i<fframes.length;i++){
1363
                if (fframes[i] instanceof IFFrameLayoutDependence){
1364
                        ((IFFrameLayoutDependence)fframes[i]).setLayout(layout);
1365
                }
1366
                if (fframes[i] instanceof IFFrameViewDependence){
1367
                        ((IFFrameViewDependence)fframes[i]).initDependence(fframes);
1368
                }
1369
        }
1370
        }catch(Exception e){
1371
                        throw new OpenException(e,layout.getClass().getName());
1372
                }
1373
       return layout;
1374
    }
1375

    
1376
    /**
1377
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1378
     *
1379
     * @param xml XMLEntity
1380
     * @param p Proyecto.
1381
     *
1382
     * @return Objeto de esta clase.
1383
     */
1384
    public static Layout createLayout03(XMLEntity xml, Project p) {
1385
        Layout layout = new Layout();
1386
        layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1387
        layout.setName(xml.getStringProperty("m_name"));
1388
        layout.m_attributes = Attributes.createAtributes03(xml.getChild(0));
1389

    
1390
        for (int i = 1; i < xml.getNumChild(); i++) {
1391
            if (xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1392
                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1393
                        p), true, false);
1394
            }
1395
        }
1396

    
1397
        for (int i = 1; i < xml.getNumChild(); i++) {
1398
            if (!xml.getChild(i).getStringProperty("className").equals("com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
1399
                layout.addFFrame(FFrame.createFFrame03(xml.getChild(i), layout,
1400
                        p), true, false);
1401
            }
1402
        }
1403

    
1404
        return layout;
1405
    }
1406

    
1407
    /**
1408
     * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1409
     */
1410
    public void viewActivated() {
1411
            //Rectangle2D r=(Rectangle2D)getRect().clone();
1412
            fullRect();
1413
            /*IFFrame[] fframes=getFFrames();
1414
        for (int i=0;i<fframes.length;i++){
1415
                fframes[i].initialize();
1416
        }
1417
        setRect(r);
1418
        */
1419
        repaint();
1420
        PluginServices.getMainFrame().getStatusBar().setMessage("1",
1421
            getAtributes().getNameUnit());
1422

    
1423
        ///System.out.println("---------- 1 "+ getAtributes().getNameUnit());
1424
    }
1425

    
1426
    /**
1427
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1428
     */
1429
    public Object getViewModel() {
1430
        return map;
1431
    }
1432

    
1433
    /**
1434
     * Devuelve si se dibuja el Grid en el Layout o no.
1435
     *
1436
     * @return True si se dibuja el Grid en el Layout.
1437
     */
1438
    public boolean getIsDrawGrid() {
1439
        return isDrawCuadricula;
1440
    }
1441

    
1442
    /**
1443
     * Inserta si se muestra el Grid del Layout.
1444
     *
1445
     * @param b True si se muestra el Grid del Layout.
1446
     */
1447
    public void setIsDrawGrid(boolean b) {
1448
        isDrawCuadricula = b;
1449
    }
1450

    
1451
    /**
1452
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
1453
     */
1454
    public void extentChanged(ExtentEvent e) {
1455
    }
1456

    
1457
    /**
1458
     * @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
1459
     */
1460
    public void viewClosed() {
1461
        ///PluginServices.getMainFrame().getStatusBar().setMessage("1","");
1462
    }
1463

    
1464
    /**
1465
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
1466
     */
1467
    public void backColorChanged(ColorEvent e) {
1468
        //        refresh();
1469
    }
1470

    
1471
    /**
1472
     * Devuelve un array con los FFrames seleccionados.
1473
     *
1474
     * @return Array con los FFrames seleccionados.
1475
     */
1476
    public IFFrame[] getFFrameSelected() {
1477
        ArrayList selecList = new ArrayList();
1478

    
1479
        for (int i = getFFrames().length - 1; i >= 0; i--) {
1480
            IFFrame fframe = (IFFrame) getFFrame(i);
1481

    
1482
            if (fframe.getSelected() != IFFrame.NOSELECT) {
1483
                selecList.add(fframe);
1484
            }
1485
        }
1486

    
1487
        return (IFFrame[]) selecList.toArray(new IFFrame[0]);
1488
    }
1489

    
1490
    /**
1491
     * Opens a dialog where to pick a PDF-file to save the current Layout
1492
     * suggesting a name for the file given by the first argument
1493
     *
1494
     * @param suggestedName DOCUMENT ME!
1495
     */
1496
    public void layoutToPDF(String suggestedName) {
1497
        FileFilter pdfFilter = new GenericFileFilter("pdf",
1498
                PluginServices.getText(this, "pdf"));
1499

    
1500
        JFileChooser jfc = new JFileChooser();
1501
        if (suggestedName!=null)
1502
        jfc.setSelectedFile(new File(suggestedName));
1503
        jfc.addChoosableFileFilter(pdfFilter);
1504
        jfc.setFileFilter(pdfFilter);
1505

    
1506
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
1507
            File f = jfc.getSelectedFile();
1508
            File faux = null;
1509

    
1510
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
1511
                faux = f;
1512
            } else {
1513
                faux = new File(f.getPath() + ".pdf");
1514
            }
1515

    
1516
            layoutDraw.toPDF(faux);
1517
        }
1518
    }
1519

    
1520
    /**
1521
     * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
1522
     * en este formato.
1523
     */
1524
    public void layoutToPDF() {
1525
            layoutToPDF(null);
1526
    }
1527

    
1528
    /**
1529
     * @return Returns the bModeDebug.
1530
     */
1531
    public boolean isModeDebug() {
1532
        return bModeDebug;
1533
    }
1534

    
1535
    /**
1536
     * @param modeDebug The bModeDebug to set.
1537
     */
1538
    public void setModeDebug(boolean modeDebug) {
1539
        bModeDebug = modeDebug;
1540
    }
1541

    
1542
    private ArrayList allFFrames(IFFrame[] fframes, ArrayList all){
1543
            for (int i=0;i<fframes.length;i++){
1544
                    if (fframes[i] instanceof FFrameGroup){
1545
                            return allFFrames(((FFrameGroup)fframes[i]).getFFrames(),all);
1546

    
1547
                    }else{
1548
                            all.add(fframes[i]);
1549
                    }
1550
            }
1551
            return all;
1552
    }
1553
        public IFFrame[] getAllFFrames() {
1554
                ArrayList all=new ArrayList();
1555
                return (IFFrame[])allFFrames(getFFrames(),all).toArray(new IFFrame[0]);
1556
        }
1557

    
1558
        public GeometryAdapter getGeometryAdapter() {
1559
                return geometryAdapter;
1560
        }
1561
        public boolean isEditable(){
1562
                return isEditable;
1563
        }
1564
        public void setEditable(boolean b) {
1565
                isEditable=b;
1566
        }
1567
        public void initGeometryAdapter() {
1568
                if (getTool() == LINE) {
1569
                        geometryAdapter=new PolyLineAdapter();
1570
        } else if (getTool() == RECTANGLESIMPLE) {
1571
                geometryAdapter=new RectangleAdapter();
1572
        } else if (getTool() == POLYLINE) {
1573
            geometryAdapter=new PolyLineAdapter();
1574
        } else if (getTool() == POLYGON) {
1575
            geometryAdapter=new PolygonAdapter();
1576
        } else if (getTool() == CIRCLE) {
1577
                geometryAdapter=new CircleAdapter();
1578
        } else if (getTool() == POINT) {
1579
                geometryAdapter=new PointAdapter();
1580
        }
1581
        }
1582
        public void startEdit() {
1583
                for(int i=0;i<getFFrames().length;i++){
1584
                        IFFrame frame=(IFFrame)getFFrame(i);
1585
                        if (frame instanceof IFFrameEditableVertex){
1586
                                if (frame.getSelected()!=IFFrame.NOSELECT){
1587
                                        ((IFFrameEditableVertex)frame).startEditing();
1588
                                }else{
1589
                                        ((IFFrameEditableVertex)frame).stopEditing();
1590
                                }
1591
                        }
1592

    
1593
                }
1594
                refresh();
1595
        }
1596
        public void stopEdit(){
1597
                boolean refresh=false;
1598
                for(int i=0;i<getFFrames().length;i++){
1599
                        IFFrame frame=(IFFrame)getFFrame(i);
1600
                        if (frame instanceof IFFrameEditableVertex){
1601
                                if (((IFFrameEditableVertex)frame).isEditing()){
1602
                                        ((IFFrameEditableVertex)getFFrame(i)).stopEditing();
1603
                                        refresh=true;
1604
                                }
1605
                        }
1606
                }
1607
                if (refresh) refresh();
1608
        }
1609
        public void delFFrameSelected(){
1610
                efs.startComplexCommand();
1611
                for (int i = efs.getAllFFrames().length - 1; i >= 0; i--) {
1612
             IFFrame fframe = (IFFrame) efs.getFFrame(i);
1613

    
1614
             if (fframe.getSelected() != IFFrame.NOSELECT) {
1615
                     efs.removeFFrame(i);
1616
                    // getFFrames().remove(i);
1617
             }
1618
         }
1619
                efs.endComplexCommand();
1620
                updateFFrames();
1621
        }
1622
        public void delFFrame(int index){
1623
                for(int i=0;i<getEFS().getAllFFrames().length;i++){
1624
                        if (getEFS().getFFrame(i).equals(getFFrame(index))){
1625
                                getEFS().removeFFrame(i);
1626
                        }
1627
                }
1628
                updateFFrames();
1629
        }
1630
        public void delFFrame(IFFrame frame){
1631
                for(int i=0;i<getEFS().getAllFFrames().length;i++){
1632
                        if (getEFS().getFFrame(i).equals(frame)){
1633
                                getEFS().removeFFrame(i);
1634
                        }
1635
                }
1636
                updateFFrames();
1637
        }
1638
        public EditableFeatureSource getEFS(){
1639
                return efs;
1640
        }
1641

    
1642
        public void commandRepaint() {
1643
                this.updateFFrames();
1644
                this.refresh();
1645
        }
1646

    
1647
        public void commandRefresh() {
1648
                commandRepaint();
1649

    
1650
        }
1651
/**
1652
 * Introduce la posibilidad de establecer que los cambios que se hacen
1653
 * a partir de ese momento hasta que se vuelva aponer a false, que todas
1654
 * las operaciones que se realices son sobre los fframes que implementen
1655
 * IFFrameGroupSelectable.
1656
 *
1657
 * @param b
1658
 */
1659
        public void setEditGroup(boolean b) {
1660
                editGroup=b;
1661
        }
1662
        /**
1663
         * Devuelve true si se est? en modo de edici?n de los fframes que
1664
         * implementen IFFrameGroupSelectable.
1665
         *
1666
         * @return
1667
         */
1668
        public boolean isEditGroup(){
1669
                return editGroup;
1670
        }
1671

    
1672
        public int getNumBehind() {
1673
                return --numBehind;
1674
        }
1675

    
1676
        public int getNumBefore() {
1677
                return ++numBefore;
1678
        }
1679
}