Statistics
| Revision:

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

History | View | Annotate | Download (35.8 KB)

1
/*
2
 * Created on 20-feb-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
package com.iver.cit.gvsig.gui.layout;
8

    
9
import java.awt.Color;
10
import java.awt.Cursor;
11
import java.awt.Graphics;
12
import java.awt.Graphics2D;
13
import java.awt.Image;
14
import java.awt.Point;
15
import java.awt.Rectangle;
16
import java.awt.Toolkit;
17
import java.awt.event.ActionEvent;
18
import java.awt.event.KeyEvent;
19
import java.awt.geom.AffineTransform;
20
import java.awt.geom.Rectangle2D;
21
import java.awt.image.BufferedImage;
22
import java.awt.print.PageFormat;
23
import java.awt.print.Printable;
24
import java.awt.print.PrinterException;
25
import java.awt.print.PrinterJob;
26
import java.util.ArrayList;
27

    
28
import javax.print.Doc;
29
import javax.print.DocFlavor;
30
import javax.print.DocPrintJob;
31
import javax.print.PrintException;
32
import javax.print.PrintService;
33
import javax.print.PrintServiceLookup;
34
import javax.print.ServiceUI;
35
import javax.print.SimpleDoc;
36
import javax.print.attribute.PrintRequestAttributeSet;
37
import javax.print.event.PrintJobAdapter;
38
import javax.print.event.PrintJobEvent;
39
import javax.print.event.PrintJobListener;
40
import javax.swing.AbstractAction;
41
import javax.swing.Action;
42
import javax.swing.ImageIcon;
43
import javax.swing.JPanel;
44
import javax.swing.KeyStroke;
45

    
46
import org.apache.log4j.Logger;
47

    
48
import com.iver.cit.gvsig.Abrir;
49
import com.iver.cit.gvsig.gui.layout.dialogs.FConfigLayoutDialog;
50
import com.iver.cit.gvsig.gui.layout.fframes.FFrame;
51
import com.iver.cit.gvsig.gui.layout.fframes.FFrameGraphics;
52
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
53
import com.iver.cit.gvsig.gui.layout.fframes.FFramePicture;
54
import com.iver.cit.gvsig.gui.layout.fframes.FFrameScaleBar;
55
import com.iver.cit.gvsig.gui.layout.fframes.FFrameText;
56
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
57
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame;
58
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameGraphicsDialog;
59
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameLegendDialog;
60
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFramePictureDialog;
61
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameScaleBarDialog;
62
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameTextDialog;
63
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.FFrameViewDialog;
64
import com.iver.cit.gvsig.gui.layout.fframes.dialogs.IFFrameDialog;
65
import com.iver.cit.gvsig.project.MapProperties;
66
import com.iver.cit.gvsig.project.Project;
67
import com.iver.cit.gvsig.project.ProjectMap;
68
import com.iver.cit.gvsig.project.castor.Map;
69
import com.iver.mdiApp.App;
70
import com.iver.mdiApp.Utilities;
71
import com.iver.mdiApp.ui.MDIManager.SingletonView;
72
import com.iver.mdiApp.ui.MDIManager.ViewInfo;
73
import com.iver.utiles.XMLEntity;
74

    
75

    
76
/**
77
 * Mapa.
78
 *
79
 * @author Vicente Caballero Navarro
80
 */
81
public class Layout extends JPanel implements SingletonView {
82
    private static Logger logger = Logger.getLogger(Layout.class.getName());
83

    
84
    /** DOCUMENT ME! */
85
    public static int numView = 0;
86

    
87
    /** DOCUMENT ME! */
88
    public static int numText = 0;
89

    
90
    /** DOCUMENT ME! */
91
    public static int numScaleBar = 0;
92

    
93
    /** DOCUMENT ME! */
94
    public static int numPicture = 0;
95

    
96
    /** DOCUMENT ME! */
97
    public static int numLegend = 0;
98

    
99
    /** DOCUMENT ME! */
100
    public static final int ZOOM_MAS = 1;
101

    
102
    /** DOCUMENT ME! */
103
    public static final int ZOOM_MENOS = 2;
104

    
105
    /** DOCUMENT ME! */
106
    public static final int PAN = 3;
107

    
108
    /** DOCUMENT ME! */
109
    public static final int DESACTUALIZADO = 4;
110

    
111
    /** DOCUMENT ME! */
112
    public static final int RECTANGLEVIEW = 5;
113

    
114
    /** DOCUMENT ME! */
115
    public static final int RECTANGLEPICTURE = 6;
116

    
117
    /** DOCUMENT ME! */
118
    public static final int RECTANGLESCALEBAR = 7;
119

    
120
    /** DOCUMENT ME! */
121
    public static final int RECTANGLELEGEND = 8;
122

    
123
    /** DOCUMENT ME! */
124
    public static final int RECTANGLETEXT = 9;
125

    
126
    /** DOCUMENT ME! */
127
    public static final int RECTANGLE = 10;
128

    
129
    /** DOCUMENT ME! */
130
    public static final int ACTUALIZADO = 11;
131

    
132
    /** DOCUMENT ME! */
133
    public static final int SELECT = 12;
134

    
135
    /** DOCUMENT ME! */
136
    public static final int POINT = 13;
137

    
138
    /** DOCUMENT ME! */
139
    public static final int LINE = 14;
140

    
141
    /** DOCUMENT ME! */
142
    public static final int POLYLINE = 15;
143

    
144
    /** DOCUMENT ME! */
145
    public static final int RECTANGLESIMPLE = 16;
146

    
147
    /** DOCUMENT ME! */
148
    public static final int CIRCLE = 17;
149

    
150
    /** DOCUMENT ME! */
151
    public static final int POLYGON = 18;
152

    
153
    /** DOCUMENT ME! */
154
    public static final int GRAPHICS = 19;
155

    
156
    /** DOCUMENT ME! */
157
    public static final int RECTANGLESYMBOL = 20;
158

    
159
    /** DOCUMENT ME! */
160
    public static final int RECTANGLEGROUP = 21;
161

    
162
    /** DOCUMENT ME! */
163
    public static final int VIEW_ZOOMIN = 22;
164

    
165
    /** DOCUMENT ME! */
166
    public static final int VIEW_ZOOMOUT = 23;
167

    
168
    /** DOCUMENT ME! */
169
    public static final int VIEW_FULL = 24;
170

    
171
    /** DOCUMENT ME! */
172
    public static final int VIEW_PAN = 25;
173

    
174
    /** DOCUMENT ME! */
175
    public static final Image iLayoutpan = new ImageIcon(Abrir.class.getClassLoader()
176
                                                                    .getResource("images/LayoutHand.gif")).getImage();
177

    
178
    /** DOCUMENT ME! */
179
    public static final Image ipan = new ImageIcon(Abrir.class.getClassLoader()
180
                                                              .getResource("images/Hand.gif")).getImage();
181

    
182
    /** DOCUMENT ME! */
183
    public static final Image iLayoutzoomin = new ImageIcon(Abrir.class.getClassLoader()
184
                                                                       .getResource("images/LayoutZoomInCursor.gif")).getImage();
185

    
186
    /** DOCUMENT ME! */
187
    public static final Image izoomin = new ImageIcon(Abrir.class.getClassLoader()
188
                                                                 .getResource("images/ZoomInCursor.gif")).getImage();
189

    
190
    /** DOCUMENT ME! */
191
    public static final Image iLayoutzoomout = new ImageIcon(Abrir.class.getClassLoader()
192
                                                                        .getResource("images/LayoutZoomOutCursor.gif")).getImage();
193

    
194
    /** DOCUMENT ME! */
195
    public static final Image izoomout = new ImageIcon(Abrir.class.getClassLoader()
196
                                                                  .getResource("images/ZoomOutCursor.gif")).getImage();
197

    
198
    /** DOCUMENT ME! */
199
    public static final Image iinfo = new ImageIcon(Abrir.class.getClassLoader()
200
                                                               .getResource("images/InfoCursor.gif")).getImage();
201

    
202
    /** DOCUMENT ME! */
203
    public static final Image icrux = new ImageIcon(Abrir.class.getClassLoader()
204
                                                               .getResource("images/CruxCursor.png")).getImage();
205
    private Point origin = new Point(50, 50);
206
    private Point rectOrigin = new Point(origin);
207
    private Rectangle2D.Double rect = new Rectangle2D.Double(rectOrigin.x,
208
            rectOrigin.y, 400, 300);
209
    private Point m_FirstPoint = new Point(0, 0);
210
    private Point m_PointAnt = new Point(0, 0);
211
    private Point m_LastPoint = new Point(0, 0);
212
    private EventsHandler events;
213
    private int tool = ZOOM_MAS;
214
    private int status = DESACTUALIZADO;
215
    private BufferedImage img = null;
216
    private AffineTransform m_MatrizTransf;
217
    private Rectangle2D rectVisible;
218
    private IFFrameDialog fframedialog = null;
219
    private ArrayList m_fframes = new ArrayList();
220
    private FConfigLayoutDialog m_configLayout = null;
221
    private MapProperties m_propertiesLayout = null;
222
    private Attributes m_attributes = null;
223
    private PrintService[] m_cachePrintServices = null;
224
    private PrintRequestAttributeSet m_cachePrintRequestAtributeSet = null;
225
    private PrintService m_cachePrintService = null;
226
    private boolean m_bCancelDrawing = false;
227
    private boolean isCuadricula = false;
228
    private boolean initial = true;
229
    private ProjectMap map = null;
230
    private Rectangle reSel = null;
231
    private boolean isReSel = true;
232
    private String m_name = null;
233
    private boolean m_showRuler = true;
234
    private FLayoutDraw layoutPaint = null;
235
    private ViewInfo m_viewinfo=null;
236
    private boolean isDrawCuadricula=true;
237
    /**
238
     * Creates a new Layout object.
239
     */
240
    public Layout() {
241
        this.setLayout(null);
242
        events = new EventsHandler(this);
243
        layoutPaint = new FLayoutDraw(this);
244
        addComponentListener(events);
245
        addMouseMotionListener(events);
246
        addMouseListener(events);
247
        m_MatrizTransf = new AffineTransform();
248
        m_MatrizTransf.setToIdentity();
249
        this.initComponents();
250
    }
251

    
252
    /**
253
     * Rellena el ProjectMap del Layout.
254
     *
255
     * @param m ProjectMap.
256
     */
257
    public void setProjectMap(ProjectMap m) {
258
        map = m;
259
    }
260

    
261
    /**
262
     * Devuelve el rect?ngulo de selecci?n por rect?ngulo.
263
     *
264
     * @return Rect?ngulo de selecci?n.
265
     */
266
    public Rectangle getReSel() {
267
        return reSel;
268
    }
269

    
270
    /**
271
     * Devuelve true si se debe dibujar el rect?ngulo de selecci?n y realizar
272
     * la sellecci?n.
273
     *
274
     * @return true si se realiza la selecci?n por rect?ngulo.
275
     */
276
    public boolean isReSel() {
277
        return isReSel;
278
    }
279

    
280
    /**
281
     * Rellena con true si se debe de dibujar y seleccionar por rect?ngulo de
282
     * selecci?n.
283
     *
284
     * @param b boolean.
285
     */
286
    public void setIsReSel(boolean b) {
287
        isReSel = b;
288
    }
289

    
290
    /**
291
     * Devuelve true si el dibujado ha sido cancelado.
292
     *
293
     * @return true si el dibujado ha sido cancelado.
294
     */
295
    public synchronized boolean isDrawingCancelled() {
296
        return m_bCancelDrawing;
297
    }
298

    
299
    /**
300
     * Pone el dibuja a cancelado o no seg?n se quiera.
301
     *
302
     * @param b true si se quiere cancelar el dibujado.
303
     */
304
    public synchronized void setCancelDrawing(boolean b) {
305
        m_bCancelDrawing = b;
306

    
307
        for (int i = 0; i < getFFrames().size(); i++) {
308
            IFFrame fframe = (IFFrame) getFFrames().get(i);
309

    
310
            if (fframe instanceof FFrameView &&
311
                    (((FFrameView) fframe).getFMap() != null)) {
312
                ((FFrameView) getFFrames().get(i)).getFMap().setCancelDrawing(b);
313
            }
314
        }
315
    }
316

    
317
    /**
318
     * Obtiene el ArrayList con todos los FFrames que se han a?adido al Layout.
319
     *
320
     * @return Array con todos los fframes que contiene el Layout.
321
     */
322
    public ArrayList getFFrames() {
323
        return m_fframes;
324
    }
325

    
326
    /**
327
     * DOCUMENT ME!
328
     *
329
     * @param frames DOCUMENT ME!
330
     */
331
    private void setFFrames(ArrayList frames) {
332
        m_fframes = frames;
333
    }
334

    
335
    /**
336
     * Obtiene el rect que se ajusta al tama?o de la ventana, para ver el folio
337
     * entero.
338
     */
339
    public void fullRect() {
340
        rect.setRect(origin.x, origin.y, getWidth() - (origin.x * 2),
341
            getHeight() - (origin.x * 2));
342

    
343
        if (m_attributes.isLandSpace()) {
344
            rect = m_attributes.getRectangleLandscape(rect, getWidth(),
345
                    getHeight());
346
        } else {
347
            rect = m_attributes.getRectanglePortrait(rect, getWidth(),
348
                    getHeight());
349
        }
350

    
351
        status = DESACTUALIZADO;
352
        repaint();
353
    }
354

    
355
    /**
356
     * M?todo para imprimir el Layout sin modificar la matriz de
357
     * transformaci?n.
358
     *
359
     * @param g2
360
     */
361
    public void drawLayoutPrint(Graphics2D g2) {
362
        setCancelDrawing(false);
363
        
364
        setCursor(Cursor.getDefaultCursor());
365

    
366
        double scale = 0;
367

    
368
        ///if (rect.width > rect.height) {
369
        ///    scale = rect.width / m_attributes.m_sizePaper.getAlto() * 1;
370
        ///} else {
371
        scale = rect.height / m_attributes.m_sizePaper.getAlto() * 1;
372

    
373
        ///}
374
        AffineTransform escalado = new AffineTransform();
375
        AffineTransform translacion = new AffineTransform();
376
        translacion.setToTranslation(rect.getMinX(), rect.getMinY());
377
        escalado.setToScale(scale, scale);
378
        m_MatrizTransf.setToIdentity();
379
        m_MatrizTransf.concatenate(translacion);
380
        m_MatrizTransf.concatenate(escalado);
381
        m_attributes.setDistanceUnitX(rect);
382
        m_attributes.setDistanceUnitY(rect);
383

    
384
        for (int i = 0; i < getFFrames().size(); i++) {
385
            ((IFFrame) getFFrames().get(i)).draw(g2, m_MatrizTransf, null, null);
386
        }
387
        
388
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
389
    }
390

    
391
    /**
392
     * Clip sobre el rect?ngulo visible.
393
     *
394
     * @param g2d Graphics sobre el que hacer el clip.
395
     */
396
    private void clipVisibleRect(Graphics2D g2d) {
397
        rectVisible = this.getVisibleRect();
398
        g2d.clipRect((int) rectVisible.getMinX(), (int) rectVisible.getMinY(),
399
            (int) rectVisible.getWidth(), (int) rectVisible.getHeight());
400
    }
401

    
402
    /**
403
     * Inicializa los componentes.
404
     */
405
    private void initComponents() {
406
        m_attributes = new Attributes();
407
        m_attributes.setDistanceUnitX(rect);
408
        m_attributes.setDistanceUnitY(rect);
409
        actionDelFFrame();
410
    }
411

    
412
    /**
413
     * Crea un ActionEvent para controlar las teclas que se pulsen cuando este
414
     * el Layout Focusable a true.
415
     */
416
    private void actionDelFFrame() {
417
        Action doNothing = new AbstractAction() {
418
                public void actionPerformed(ActionEvent e) {
419
                    for (int i = getFFrames().size() - 1; i >= 0; i--) {
420
                        IFFrame fframe = (IFFrame) getFFrames().get(i);
421

    
422
                        if (fframe.getSelected() != FFrame.NOSELECT) {
423
                            getFFrames().remove(i);
424
                        }
425
                    }
426

    
427
                    refresh();
428
                }
429
            };
430

    
431
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0),
432
            "doNothing");
433
        this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0),
434
            "doNothing");
435
        this.getActionMap().put("doNothing", doNothing);
436
    }
437

    
438
    /**
439
     * paintComponent del Layout.
440
     *
441
     * @param g Graphics del Layout.
442
     */
443
    protected void paintComponent(Graphics g) {
444
        super.paintComponent(g);
445

    
446
        switch (status) {
447
            case ZOOM_MAS:
448
                logger.debug("zoom mas");
449
                layoutPaint.drawRectangle((Graphics2D) g);
450

    
451
                g.drawImage(img, 0, 0, this);
452
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
453
                g.setColor(Color.black);
454
                g.setXORMode(Color.white);
455

    
456
                Rectangle r = new Rectangle();
457

    
458
                r.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
459
                g.drawRect(r.x, r.y, r.width, r.height);
460

    
461
                break;
462

    
463
            case RECTANGLE:
464
                logger.debug("rectangle");
465
                layoutPaint.drawRectangle((Graphics2D) g);
466

    
467
                g.drawImage(img, 0, 0, this);
468
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
469
                g.setColor(Color.black);
470
                g.setXORMode(Color.white);
471

    
472
                Rectangle re = new Rectangle();
473
                re.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
474

    
475
                if (isCuadricula()) {
476
                    FLayoutUtilities.setRectGrid(re,
477
                        m_attributes.getUnitInPixelsX(),
478
                        m_attributes.getUnitInPixelsY(), m_MatrizTransf);
479
                }
480

    
481
                g.drawRect(re.x, re.y, re.width, re.height);
482

    
483
                break;
484

    
485
            case PAN:
486
                logger.debug("pan");
487

    
488
                //g.setXORMode(Color.black);
489
                rect.x = rectOrigin.x + (m_LastPoint.x - m_PointAnt.x);
490
                rect.y = rectOrigin.y + (m_LastPoint.y - m_PointAnt.y);
491

    
492
                //g.clearRect(0, 0, getWidth(), getHeight());
493
                layoutPaint.drawRectangle((Graphics2D) g);
494

    
495
                if (img != null) {
496
                    g.drawImage(img, (getLastPoint().x - getPointAnt().x),
497
                        (m_LastPoint.y - m_PointAnt.y), this);
498
                }
499

    
500
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
501

    
502
                break;
503

    
504
            case VIEW_PAN:
505

    
506
                // logger.debug("View pan");
507
                layoutPaint.drawRectangle((Graphics2D) g);
508
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
509

    
510
                for (int i = 0; i < getFFrames().size(); i++) {
511
                    if (getFFrames().get(i) instanceof FFrameView) {
512
                        FFrameView fframe = (FFrameView) getFFrames().get(i);
513

    
514
                        if (fframe.getSelected() != FFrame.NOSELECT) {
515
                            Rectangle2D.Double rec = fframe.getBoundingBox(getAT());
516

    
517
                            if (img != null) {
518
                                    
519
                                //g.drawImage(img, 0, 0, this);
520
                               
521
                                rec = (Rectangle2D.Double) rec.createIntersection(getVisibleRect());
522
                                //((Graphics2D)g).clearRect((int)rec.x,(int)rec.y,(int)rec.width,(int)rec.height);
523
                            }
524

    
525
                            if (fframe.getBufferedImage() != null) {
526
                                layoutPaint.drawHandlers((Graphics2D) g,
527
                                    Color.black);
528
                                g.clipRect((int) rec.x, (int) rec.y,
529
                                    (int) rec.width, (int) rec.height);
530

    
531
                                //g.setColor(Color.gray);
532
                                //g.fillRect(0,0,getWidth(),getHeight());
533
                                layoutPaint.drawRectangle((Graphics2D) g);
534
                                layoutPaint.drawRuler((Graphics2D) g,
535
                                    Color.black);
536

    
537
                                g.drawImage(fframe.getBufferedImage(),
538
                                    m_LastPoint.x - m_PointAnt.x,
539
                                    m_LastPoint.y - m_PointAnt.y, this);
540
                                System.out.println(
541
                                    "m_LastPoint.x - m_PointAnt.x" +
542
                                    (m_LastPoint.x - m_PointAnt.x));
543
                                System.out.println(
544
                                    "m_LastPoint.y - m_PointAnt.y" +
545
                                    (m_LastPoint.y - m_PointAnt.y));
546
                            }
547
                        }
548
                    }
549
                }
550

    
551
                //g.setXORMode(Color.black);
552
                break;
553

    
554
            case SELECT:
555
                logger.debug("select");
556
                layoutPaint.drawRectangle((Graphics2D) g);
557

    
558
                g.drawImage(img, 0, 0, this);
559

    
560
                if (isReSel) {
561
                    reSel = new Rectangle();
562
                    reSel.setFrameFromDiagonal(m_FirstPoint, m_LastPoint);
563
                    g.drawRect(reSel.x, reSel.y, reSel.width, reSel.height);
564
                }
565

    
566
                for (int i = 0; i < getFFrames().size(); i++) {
567
                    IFFrame fframe = (IFFrame) getFFrames().get(i);
568

    
569
                    if (fframe.getSelected() != FFrame.NOSELECT) {
570
                        g.setColor(Color.black);
571
                        fframe.drawHandlers((Graphics2D) g);
572

    
573
                        int difx = (m_LastPoint.x - m_FirstPoint.x);
574
                        int dify = (m_LastPoint.y - m_FirstPoint.y);
575

    
576
                        if ((Math.abs(difx) > 3) || (Math.abs(dify) > 3)) {
577
                            Rectangle2D rectangle = fframe.getMovieRect(difx,
578
                                    dify);
579

    
580
                            if (rectangle != null) {
581
                                if (isCuadricula) {
582
                                    FLayoutUtilities.setRectGrid(rectangle,
583
                                        m_attributes.getUnitInPixelsX(),
584
                                        m_attributes.getUnitInPixelsY(),
585
                                        m_MatrizTransf);
586
                                }
587

    
588
                                g.drawRect((int) rectangle.getMinX(),
589
                                    (int) rectangle.getMinY(),
590
                                    (int) rectangle.getWidth(),
591
                                    (int) rectangle.getHeight());
592
                            }
593
                        }
594
                    }
595
                }
596

    
597
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
598

    
599
                break;
600

    
601
            case GRAPHICS:
602
                layoutPaint.drawRectangle((Graphics2D) g);
603
                g.drawImage(img, 0, 0, this);
604
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
605

    
606
                break;
607

    
608
            case DESACTUALIZADO:
609
                logger.debug("desactualizado");
610
                img = new BufferedImage(getWidth(), getHeight(),
611
                        BufferedImage.TYPE_INT_ARGB);
612

    
613
                Graphics gimag = img.getGraphics();
614
                clipVisibleRect((Graphics2D) gimag);
615

    
616
                if (initial) {
617
                    fullRect();
618
                    initial = false;
619
                }
620

    
621
                layoutPaint.drawLayout((Graphics2D) gimag, img);
622
                layoutPaint.drawRectangle((Graphics2D) g);
623

    
624
                g.drawImage(img, 0, 0, this);
625
                layoutPaint.drawHandlers((Graphics2D) g, Color.black);
626
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
627

    
628
                break;
629

    
630
            case ACTUALIZADO:
631
                layoutPaint.drawRectangle((Graphics2D) g);
632

    
633
                g.drawImage(img, 0, 0, this);
634
                layoutPaint.drawHandlers((Graphics2D) g, Color.black);
635
                layoutPaint.drawRuler((Graphics2D) g, Color.black);
636
        }
637
    }
638

    
639
    /**
640
     * A?ade un fframe al Arraylist m_fframes.
641
     *
642
     * @param frame fframe a a?adir.
643
     * @param clearSelection para que se quede seleccionado ?nicamente  el que
644
     *        a?adimos y false si lo que se pretende es que no se
645
     *        deseleccionen lo que ya est?n seleccionados.
646
     */
647
    public void addFFrame(IFFrame frame, boolean clearSelection) {
648
        if (clearSelection) {
649
            for (int i = getFFrames().size() - 1; i >= 0; i--) {
650
                IFFrame fframe1 = (IFFrame) getFFrames().get(i);
651
                fframe1.setSelected(false);
652
            }
653
        }
654

    
655
        if (frame instanceof FFrameView &&
656
                (((FFrameView) frame).getFMap() != null)) {
657
            ((FFrameView) frame).getFMap().addExtentListener(this);
658
        }
659

    
660
        frame.updateNum();
661
        getFFrames().add(frame);
662
        frame.setSelected(true);
663
    }
664

    
665
    /**
666
     * Abre el di?logo de propiedades del folio, pasando como par?metro el
667
     * PrinterJob.
668
     *
669
     * @param job
670
     */
671
    public void showPagePropertiesWindow(PrinterJob job) {
672
        PageFormat pf1; //=new PageFormat();
673

    
674
        pf1 = m_attributes.getPageFormat();
675
        pf1 = job.pageDialog(pf1);
676
        m_attributes.setPageFormat(pf1);
677
        refresh();
678
    }
679

    
680
    /**
681
     * Refresca el Layout.
682
     */
683
    public void refresh() {
684
        rect = m_attributes.obtainRect(false, rect, getWidth(), getHeight());
685
        status = DESACTUALIZADO;
686
        repaint();
687
    }
688

    
689
    /**
690
     * Obtiene el rect?ngulo que representa el folio con las caracter?sticas
691
     * que contiene attributes y diferenciando si es para visualizar en
692
     * pantalla o para imprimir.
693
     *
694
     * @param isPrint si es para imprimir.
695
     */
696
    public void obtainRect(boolean isPrint) {
697
        m_attributes.obtainRect(isPrint, rect, getWidth(), getHeight());
698
    }
699

    
700
    /**
701
     * Muestra el di?logo de configuraci?n del Layout.
702
     */
703
    public void showFConfig() {
704
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
705
        App.instance.getMDIContext().addView(m_configLayout);
706
    }
707

    
708
    /**
709
     * Mestra el di?logo de propiedades del Layout.
710
     */
711
    public void showFProperties() {
712
        if (map == null) {
713
            map = new Map();
714
            map.setModel(this);
715
            map.setName(getName());
716
        }
717

    
718
        m_propertiesLayout = new MapProperties(map);
719
        App.instance.getMDIContext().addView(m_propertiesLayout);
720
    }
721

    
722
    /**
723
     * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
724
     *
725
     * @param job
726
     */
727
    public void showPrintDialog(PrinterJob job) {
728
            if (job!=null){
729
                job.printDialog();
730
                        try {
731
                                job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
732
                                job.print();
733
                                } catch (PrinterException e) {
734
                                        e.printStackTrace();
735
                                }
736
           }else{
737
            boolean print = false;
738

    
739
        //Actualizar attributes
740
        
741
        PrintRequestAttributeSet att = m_attributes.toPrintAttributes();
742
        
743
        //------------------ The Printing things --------------------- //
744
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
745

    
746
        // returns the set of printers that support printing a specific document type (such as GIF)
747
        // with a specific set of attributes (such as two sided).
748
        // PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
749
        
750

    
751
        // interestingly, the printer dialog's default behavior has changed with the new API: by default the dialog is not shown.
752
        // So we must use the ServiceUI class to create a print dialog
753
        // returns the default print service.
754
        if (m_cachePrintServices == null)
755
                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(flavor, null);
756
        
757
        PrintService defaultService = null;
758
        if (m_cachePrintService == null)
759
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
760
                
761
        if (m_cachePrintService == null)
762
        {
763
                
764
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200, 
765
                        m_cachePrintServices, defaultService, flavor, att);
766
                
767
                // m_cachePrintRequestAtributeSet = new HashPrintRequestAttributeSet();
768
                // m_cachePrintRequestAtributeSet.addAll(pras);
769
        }
770
        else
771
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200, 
772
                            m_cachePrintServices, m_cachePrintService, flavor, att);
773
                
774
        if (m_cachePrintService != null)
775
        {
776
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
777
                PrintJobListener pjlistener = new PrintJobAdapter() {
778
                        public void printDataTransferCompleted(PrintJobEvent e) {
779
                            System.out.println("Fin de impresi?n");
780
                        }
781
                    };
782
                jobNuevo.addPrintJobListener(pjlistener);
783
        
784
                // DocAttributeSet das = new HashDocAttributeSet();
785
                Doc doc =new SimpleDoc((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class), flavor, null);
786
                
787
                try {
788
                        
789
                        jobNuevo.print(doc, att);
790

    
791
                    // m_attributes.
792
                } catch (PrintException pe) {
793
                    pe.printStackTrace();
794
                }
795
                }
796
        }        
797

    
798
        /* try {
799
            print = job.printDialog(att);
800
        } catch (Exception e) {
801
            logger.error("Abriendo el Di?logo de imprimir"); //System.out.println("Excepci?n "+e);
802
        }
803

804
        if (print) {
805
            job.setPrintable((Printable) App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
806
            try {
807
                job.print(att);
808
            } catch (Exception ex) {
809
                ex.printStackTrace();
810
            }
811
        } */
812

    
813
        fullRect(); 
814
    }
815

    
816
    /**
817
     * Sustituye el puntero del rat?n por la imagen que se le pasa como
818
     * par?metro.
819
     *
820
     * @param image
821
     */
822
    public void setMapCursor(Image image) {
823
        Cursor cur = Toolkit.getDefaultToolkit().createCustomCursor(image,
824
                new Point(16, 16), "");
825
        setCursor(cur);
826
    }
827

    
828
    /**
829
     * Cambia el puntero del raton al cusor que se le introduce como par?metro.
830
     *
831
     * @param cursor cursor a mostrar en el puntero del rat?n.
832
     */
833
    public void setMapCursor(Cursor cursor) {
834
        setCursor(cursor);
835
    }
836

    
837
    /**
838
     * Pone como seleccionada a la herramienta a partir de su n?mero.
839
     *
840
     * @param i
841
     */
842
    public void setTool(int i) {
843
        tool = i;
844

    
845
        if (getTool() == PAN) {
846
            setMapCursor(ipan);
847
        } else if (getTool() == ZOOM_MAS) {
848
            setMapCursor(izoomin);
849
        } else if (getTool() == ZOOM_MENOS) {
850
            setMapCursor(izoomout);
851
        } else if (getTool() == RECTANGLEVIEW) {
852
            setMapCursor(icrux);
853
        } else if (getTool() == RECTANGLEPICTURE) {
854
            setMapCursor(icrux);
855
        } else if (getTool() == RECTANGLESCALEBAR) {
856
            setMapCursor(icrux);
857
        } else if (getTool() == RECTANGLELEGEND) {
858
            setMapCursor(icrux);
859
        } else if (getTool() == RECTANGLETEXT) {
860
            setMapCursor(icrux);
861
        } else if (getTool() == SELECT) {
862
            setCursor(Cursor.getDefaultCursor());
863
        }
864
    }
865

    
866
    /**
867
     * Se crean aqu? los dialogos cada vez que se necesitan.
868
     *
869
     * @param fframe Rectangle que representa el lugar que ocupara el elemento
870
     *        a?adido.
871
     *
872
     * @return true si se debe de a?adir el fframe.
873
     */
874
    public boolean openFFrameDialog(IFFrame fframe) {
875
        switch (tool) {
876
            case RECTANGLEVIEW:
877
                fframedialog = new FFrameViewDialog(this, (FFrameView) fframe);
878

    
879
                break;
880

    
881
            case RECTANGLEPICTURE:
882
                fframedialog = new FFramePictureDialog(this,
883
                        (FFramePicture) fframe);
884

    
885
                break;
886

    
887
            case RECTANGLESCALEBAR:
888
                fframedialog = new FFrameScaleBarDialog(this,
889
                        (FFrameScaleBar) fframe);
890

    
891
                break;
892

    
893
            case RECTANGLELEGEND:
894
                fframedialog = new FFrameLegendDialog(this,
895
                        (FFrameLegend) fframe);
896

    
897
                break;
898

    
899
            case RECTANGLETEXT:
900
                fframedialog = new FFrameTextDialog(this, (FFrameText) fframe);
901

    
902
                break;
903

    
904
            case GRAPHICS:
905
                fframedialog = new FFrameGraphicsDialog(this,
906
                        (FFrameGraphics) fframe);
907

    
908
                break;
909

    
910
            default:
911
                return true;
912
        }
913

    
914
        if (fframedialog != null) {
915
            fframedialog.setRectangle(fframe.getBoundingBox(m_MatrizTransf));
916
            App.instance.getMDIContext().addView(fframedialog);
917
        }
918

    
919
        return fframedialog.getIsAcepted();
920
    }
921

    
922
    /**
923
     * Devuelve el Rectangle2D que representa en pixels al folio.
924
     *
925
     * @return Rectangle2D.Double
926
     */
927
    public Rectangle2D.Double getRect() {
928
        return rect;
929
    }
930

    
931
    /**
932
     * Obtiene un entero que representa la herramienta seleccionada.
933
     *
934
     * @return entero.
935
     */
936
    public int getTool() {
937
        return tool;
938
    }
939

    
940
    /**
941
     * Devuelve la Matriz transformada que se esta plicando al Layout.
942
     *
943
     * @return AffineTransform
944
     */
945
    public AffineTransform getAT() {
946
        return m_MatrizTransf;
947
    }
948

    
949
    /**
950
     * Devuelve los atributos del Mapa.
951
     *
952
     * @return Attributes.
953
     */
954
    public Attributes getAtributes() {
955
        return m_attributes;
956
    }
957

    
958
    /**
959
     * Pone el estado que se quiera.
960
     *
961
     * @param s estado.
962
     */
963
    public void setStatus(int s) {
964
        status = s;
965
    }
966

    
967
    /**
968
     * Devuelve el punto que representa la esquina noroeste del mapa.
969
     *
970
     * @return un punto.
971
     */
972
    public Point getRectOrigin() {
973
        return rectOrigin;
974
    }
975

    
976
    /**
977
     * Devuelve el punto del primer click de rat?n.
978
     *
979
     * @return un punto.
980
     */
981
    public Point getFirstPoint() {
982
        return m_FirstPoint;
983
    }
984

    
985
    /**
986
     * Devuelve el punto de click de rat?n anterior.
987
     *
988
     * @return un punto.
989
     */
990
    public Point getPointAnt() {
991
        return m_PointAnt;
992
    }
993

    
994
    /**
995
     * Devuelve el punto donde se solt? el bot?n del rat?n.
996
     *
997
     * @return un punto.
998
     */
999
    public Point getLastPoint() {
1000
        return m_LastPoint;
1001
    }
1002

    
1003
    /**
1004
     * Rellena el primer punto de click de rat?n.
1005
     *
1006
     * @param p punto.
1007
     */
1008
    public void setFirstPoint(Point p) {
1009
        m_FirstPoint = p;
1010
    }
1011

    
1012
    /**
1013
     * Rellena el punto de click de rat?n anterior.
1014
     *
1015
     * @param p punto.
1016
     */
1017
    public void setPointAnt(Point p) {
1018
        m_PointAnt = p;
1019
    }
1020

    
1021
    /**
1022
     * Rellena el punto donde se solto el bot?n del rat?n.
1023
     *
1024
     * @param p punto.
1025
     */
1026
    public void setLastPoint(Point p) {
1027
        m_LastPoint = p;
1028
    }
1029

    
1030
    /**
1031
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
1032
     */
1033
    public ViewInfo getViewInfo() {
1034
       if (m_viewinfo==null){
1035
               m_viewinfo=new ViewInfo();
1036
            m_viewinfo.setFeatures(ViewInfo.ICONIFIABLE | ViewInfo.MAXIMIZABLE |
1037
            ViewInfo.RESIZABLE);
1038
        
1039
        m_viewinfo.setWidth(500);
1040
        m_viewinfo.setHeight(400);
1041
       }
1042
       m_viewinfo.setTitle(Utilities.getMessage(this, "Mapa") + " : " + getName());
1043
        return m_viewinfo;
1044
    }
1045

    
1046
    /**
1047
     * DOCUMENT ME!
1048
     *
1049
     * @param b DOCUMENT ME!
1050
     */
1051
    public void setRuler(boolean b) {
1052
        m_showRuler = b;
1053
    }
1054

    
1055
    /**
1056
     * DOCUMENT ME!
1057
     *
1058
     * @return DOCUMENT ME!
1059
     */
1060
    public boolean getRuler() {
1061
        return m_showRuler;
1062
    }
1063

    
1064
    /**
1065
     * Devuelve si se esta aplicando en los fframes que se a?den al Layout la
1066
     * cuadr?cula, o no.
1067
     *
1068
     * @return true si se esta aplicando la cuadr?cula.
1069
     */
1070
    public boolean isCuadricula() {
1071
        return isCuadricula;
1072
    }
1073

    
1074
    /**
1075
     * Se actualiza el estado de la cuadr?cula, si se aplica o no.
1076
     *
1077
     * @param b true si se aplica la cuadr?cula.
1078
     */
1079
    public void setIsCuadricula(boolean b) {
1080
        isCuadricula = b;
1081
    }
1082

    
1083
    /**
1084
     * DOCUMENT ME!
1085
     */
1086
    public void viewFull() {
1087
        for (int i = 0; i < getFFrames().size(); i++) {
1088
            if (getFFrames().get(i) instanceof FFrameView) {
1089
                FFrameView fframe = (FFrameView) getFFrames().get(i);
1090

    
1091
                if (fframe.getSelected() != FFrame.NOSELECT) {
1092
                    fframe.getFMap().setExtent(fframe.getFMap().getFullExtent());
1093
                }
1094
            }
1095
        }
1096

    
1097
        setStatus(DESACTUALIZADO);
1098
        repaint();
1099
    }
1100

    
1101
    /**
1102
     * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
1103
     * para poder despu?s volver a crear el objeto original.
1104
     *
1105
     * @return XMLEntity.
1106
     */
1107
    public XMLEntity getXMLEntity() {
1108
        XMLEntity xml = new XMLEntity();
1109
        xml.setName("layout");
1110
        xml.putProperty("isCuadricula", isCuadricula());
1111
        xml.putProperty("m_name", m_name);
1112
        xml.addChild(getAtributes().getXMLEntity());
1113

    
1114
        for (int i = 0; i < getFFrames().size(); i++) {
1115
            xml.addChild(((IFFrame) getFFrames().get(i)).getXMLEntity());
1116
        }
1117

    
1118
        return xml;
1119
    }
1120

    
1121
    /**
1122
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
1123
     *
1124
     * @param xml XMLEntity
1125
     * @param p DOCUMENT ME!
1126
     *
1127
     * @return Objeto de esta clase.
1128
     */
1129
    public static Layout createLayout(XMLEntity xml, Project p) {
1130
        Layout layout = new Layout();
1131
        layout.isCuadricula = xml.getBooleanProperty("isCuadricula");
1132
        layout.m_name = xml.getStringProperty("m_name");
1133
        layout.m_attributes = Attributes.createAtributes(xml.getChild(0));
1134

    
1135
        for (int i = 1; i < xml.getNumChild(); i++) {
1136
            layout.addFFrame(FFrame.createFFrame(xml.getChild(i), p), true);
1137
        }
1138

    
1139
        return layout;
1140
    }
1141

    
1142
    /**
1143
     * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
1144
     */
1145
    public void viewActivated() {
1146
        App.instance.getMDIContext().setMessage("5", "");
1147
        status = DESACTUALIZADO;
1148
        repaint();
1149

    
1150
        //refresh();
1151
    }
1152

    
1153
    /**
1154
     * @see com.iver.cit.gvsig.fmap.IMapExtentListener#extentChanged(java.awt.geom.Rectangle2D)
1155
     */
1156
    public void extentChanged(Rectangle2D newExtent) {
1157
        //refresh();
1158
    }
1159

    
1160
    /**
1161
     * @see com.iver.mdiApp.ui.MDIManager.SingletonView#getViewModel()
1162
     */
1163
    public Object getViewModel() {
1164
        return this;
1165
    }
1166
    public boolean getIsDrawGrid(){
1167
            return isDrawCuadricula;
1168
    }
1169
    public void setIsDrawGrid(boolean b){
1170
            isDrawCuadricula=b;
1171
    }
1172
}