Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / layout / gui / Layout.java @ 29596

History | View | Annotate | Download (25.4 KB)

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

    
47
import java.awt.Component;
48
import java.awt.Cursor;
49
import java.awt.Graphics2D;
50
import java.awt.GridLayout;
51
import java.awt.geom.AffineTransform;
52
import java.awt.print.PageFormat;
53
import java.awt.print.Printable;
54
import java.awt.print.PrinterException;
55
import java.awt.print.PrinterJob;
56
import java.beans.PropertyChangeEvent;
57
import java.beans.PropertyChangeListener;
58
import java.io.File;
59

    
60
import javax.print.Doc;
61
import javax.print.DocFlavor;
62
import javax.print.DocPrintJob;
63
import javax.print.PrintException;
64
import javax.print.PrintService;
65
import javax.print.PrintServiceLookup;
66
import javax.print.ServiceUI;
67
import javax.print.SimpleDoc;
68
import javax.print.attribute.PrintRequestAttributeSet;
69
import javax.print.event.PrintJobAdapter;
70
import javax.print.event.PrintJobEvent;
71
import javax.print.event.PrintJobListener;
72
import javax.swing.JOptionPane;
73
import javax.swing.JPanel;
74
import javax.swing.filechooser.FileFilter;
75

    
76
import org.gvsig.andami.PluginServices;
77
import org.gvsig.andami.messages.NotificationManager;
78
import org.gvsig.andami.ui.mdiManager.IWindowListener;
79
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
80
import org.gvsig.andami.ui.mdiManager.WindowInfo;
81
import org.gvsig.app.project.Project;
82
import org.gvsig.app.project.documents.exceptions.OpenException;
83
import org.gvsig.app.project.documents.exceptions.SaveException;
84
import org.gvsig.app.project.documents.layout.Attributes;
85
import org.gvsig.app.project.documents.layout.LayoutContext;
86
import org.gvsig.app.project.documents.layout.LayoutControl;
87
import org.gvsig.app.project.documents.layout.ProjectMap;
88
import org.gvsig.app.project.documents.layout.fframes.FFrame;
89
import org.gvsig.app.project.documents.layout.fframes.FFrameGroup;
90
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
91
import org.gvsig.app.project.documents.layout.fframes.IFFrameViewDependence;
92
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
93
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
94
import org.gvsig.fmap.mapcontext.events.ColorEvent;
95
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
96
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
97
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
98
import org.gvsig.gui.beans.swing.JFileChooser;
99
import org.gvsig.tools.observer.Observable;
100
import org.gvsig.tools.observer.Observer;
101
import org.gvsig.utils.GenericFileFilter;
102
import org.gvsig.utils.XMLEntity;
103
import org.gvsig.utils.XMLException;
104

    
105

    
106
/**
107
 * Graphic representation of the elements to print.
108
 *
109
 * @author Vicente Caballero Navarro
110
 */
111
public class Layout extends JPanel implements SingletonWindow, ViewPortListener,
112
        IWindowListener, Observer {
113
        public static final String PDF_AND_PS_FILECHOOSER = "PDF_AND_PS_FILECHOOSER";
114

    
115
        public static File defaultPDFFolderPath;
116

    
117
    private static Boolean defaultShowGrid = null;
118
    private static Boolean defaultAdjustToGrid = null;
119
    private static Boolean defaultShowRulers = null;
120
    private IFFrameDialog fframedialog = null;
121
    private MapProperties m_propertiesLayout = null;
122
    private PrintService[] m_cachePrintServices = null;
123
    private PrintService m_cachePrintService = null;
124
    private ProjectMap map = null;
125
    private Doc doc = null;
126
    private PrintRequestAttributeSet att = null;
127
    private WindowInfo m_viewInfo = null;
128
    /**
129
     * We use it when we are doing a layout and assigning tags.
130
     * It is put in debug when we do a VIEW_TAGS
131
     */
132
    private boolean bShowIconTag = false;
133
          private LayoutControl layoutControl;
134
        private LayoutContext layoutContext;
135

    
136
    /**
137
     * Creates a new Layout object.
138
     */
139
    public Layout() {
140
            layoutContext=new LayoutContext();
141
        layoutControl=new LayoutControl(this);
142
        layoutContext.updateFFrames();
143
        this.initComponents();
144
    }
145

    
146
    /**
147
         * Inserts the ProjectMap of this Layout.
148
         *
149
         * @param m ProjectMap.
150
         */
151
    public void setProjectMap(ProjectMap m) {
152
        map = m;
153
        this.setName(m.getName());
154
        map.addPropertyChangeListener(new PropertyChangeListener() {
155
            public void propertyChange(PropertyChangeEvent evt) {
156
                if (evt.getPropertyName().equals("name")) {
157
                    PluginServices.getMDIManager().getWindowInfo(Layout.this)
158
                            .setTitle(
159
                                    PluginServices.getText(this, "Mapa")
160
                                            + " : "
161
                                            + (String) evt.getNewValue());
162
                }
163
            }
164
        });
165
    }
166

    
167

    
168

    
169

    
170

    
171

    
172
    /**
173
         * Method to print the Layout without modify the Affinetransform.
174
         *
175
         * @param g2 Geaphics2D
176
         */
177
    public void drawLayoutPrint(Graphics2D g2) {
178
        layoutControl.setCancelDrawing(false);
179

    
180
        setCursor(Cursor.getDefaultCursor());
181

    
182
        double scale = 0;
183
        scale = layoutControl.getRect().height / layoutContext.getAttributes().m_sizePaper.getAlto() * 1;
184
        AffineTransform escalado = new AffineTransform();
185
        AffineTransform translacion = new AffineTransform();
186
        translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY());
187
        escalado.setToScale(scale, scale);
188
        layoutControl.getAT().setToIdentity();
189
        layoutControl.getAT().concatenate(translacion);
190
        layoutControl.getAT().concatenate(escalado);
191
        layoutContext.getAttributes().setDistanceUnitX(layoutControl.getRect());
192
        layoutContext.getAttributes().setDistanceUnitY(layoutControl.getRect());
193
        IFFrame[] fframes=layoutContext.getFFrames();
194
        for (int i = 0; i < fframes.length; i++) {
195
//                    fframes[i].setPrintingProperties(this.att);
196
                   fframes[i].print(g2, layoutControl.getAT(),null, layoutContext.getAttributes().toPrintAttributes());
197
//                    fframes[i].setPrintingProperties(null);
198
        }
199

    
200
        // TODO Esto es para ver el rect?ngulo que representa el folio en la
201
        // impresi?n.
202
        // g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
203
    }
204

    
205

    
206

    
207
    /**
208
         * It initializes the components.
209
         */
210
    private void initComponents() {
211
            this.setLayout(new GridLayout(1,1));
212
        add(layoutControl);
213
            layoutContext.getAttributes().setDistanceUnitX(layoutControl.getRect());
214
            layoutContext.getAttributes().setDistanceUnitY(layoutControl.getRect());
215
        setDoubleBuffered(true);
216
    }
217

    
218
    /**
219
         * Open the dialog of Layout properties.
220
         *
221
         * @param job PrinterJob
222
         */
223
    public void showPagePropertiesWindow(PrinterJob job) {
224
        PageFormat pf1;
225

    
226
        pf1 = layoutContext.getAttributes().getPageFormat();
227
        pf1 = job.pageDialog(pf1);
228
        layoutContext.getAttributes().setPageFormat(pf1);
229
        layoutControl.refresh();
230
    }
231

    
232
    /**
233
         * It obtains the rect?ngulo that represents the sheet with the characteristics
234
         * that contains attributes and differentiating if is to visualize in screen or
235
         * for print.
236
         *
237
         */
238
    public void obtainRect(boolean isPrint) {
239
            layoutContext.getAttributes().obtainRect(isPrint,layoutControl.getRect(), getWidth(), getHeight());
240
//            layoutContext.getAtributes().obtainRect(layoutControl.getRect());
241
    }
242

    
243
    /**
244
         * It shows the dialog of configuration of the Layout.
245
         */
246
    public void showFConfig() {
247
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
248
        PluginServices.getMDIManager().addWindow(m_configLayout);
249
    }
250

    
251
    /**
252
         * It shows the dialog of Layout?s properties.
253
         */
254
    public boolean showFProperties() {
255
        if (map == null) {
256
            map = new ProjectMap();
257
            map.setModel(this);
258
            map.setName(getName());
259
        }
260

    
261
        m_propertiesLayout = new MapProperties(map);
262
        PluginServices.getMDIManager().addWindow(m_propertiesLayout);
263
        return m_propertiesLayout.isAccepted();
264
    }
265

    
266
    /**
267
         * It shows the dialog of printing of the Layout.
268
         *
269
         * @param job PrinterJob
270
         */
271
    public void showPrintDialog(PrinterJob job) {
272
        if (job != null) {
273
            job.printDialog();
274

    
275
            try {
276
                job.setPrintable((Printable) PluginServices
277
                        .getExtension(org.gvsig.app.extension.Print.class));
278
                job.print();
279
            } catch (PrinterException e) {
280
                e.printStackTrace();
281
            }
282
        } else {
283
            // Actualizar attributes
284
                        att = layoutContext.getAttributes().toPrintRequestAttributeSet();
285

    
286
            // ------------------ The Printing things --------------------- //
287
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
288

    
289
            // returns the set of printers that support printing a specific
290
            // document type (such as GIF)
291
            // with a specific set of attributes (such as two sided).
292
            // PrintRequestAttributeSet pras = new
293
            // HashPrintRequestAttributeSet();
294
            // interestingly, the printer dialog's default behavior has changed
295
            // with the new API: by default the dialog is not shown.
296
            // So we must use the ServiceUI class to create a print dialog
297
            // returns the default print service.
298
            if (m_cachePrintServices == null) {
299
                m_cachePrintServices = PrintServiceLookup.lookupPrintServices(
300
                        flavor, null);
301
            }
302

    
303
            PrintService defaultService = null;
304

    
305
            if (m_cachePrintService == null) {
306
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
307
            }
308

    
309
            if ((defaultService == null) && (m_cachePrintService == null)) {
310
                JOptionPane.showMessageDialog((Component) PluginServices
311
                        .getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada"));
312

    
313
                return;
314
            }
315

    
316
            if (m_cachePrintService == null) {
317
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
318
                        m_cachePrintServices, defaultService, flavor, att);
319

    
320
                // m_cachePrintRequestAtributeSet = new
321
                // HashPrintRequestAttributeSet();
322
                // m_cachePrintRequestAtributeSet.addAll(pras);
323
            } else {
324
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
325
                        m_cachePrintServices, m_cachePrintService, flavor, att);
326
            }
327

    
328
            if (m_cachePrintService != null) {
329
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
330
                PrintJobListener pjlistener = new PrintJobAdapter() {
331
                    public void printDataTransferCompleted(PrintJobEvent e) {
332
//                        System.out.println("Fin de impresi?n");
333
                        layoutControl.fullRect();
334
                    }
335
                };
336

    
337
                jobNuevo.addPrintJobListener(pjlistener);
338

    
339
                // DocAttributeSet das = new HashDocAttributeSet();
340
                doc = new SimpleDoc(PluginServices
341
                        .getExtension(org.gvsig.app.extension.Print.class), flavor,
342
                        null);
343

    
344
                try {
345
                    jobNuevo.print(doc, att);
346

    
347
                    // m_attributes.
348
                } catch (PrintException pe) {
349
                    NotificationManager.addError(pe);
350
                }
351
            }
352
        }
353

    
354
        /*
355
         * try { print = job.printDialog(att); } catch (Exception e) {
356
         * logger.error("Abriendo el Di?logo de imprimir");
357
         * //System.out.println("Excepci?n "+e); } if (print) {
358
         * job.setPrintable((Printable)
359
         * App.instance.getPc().getExtension(com.iver.cit.gvsig.Print.class));
360
         * try { job.print(att); } catch (Exception ex) { ex.printStackTrace(); } }
361
         */
362
    }
363

    
364
    /**
365
         * The dialogs are created here each time that are needed.
366
         *
367
         * @param fframe
368
         *            Rectangle that represents the place that occupied the element added.
369
         *
370
         * @return IFFrame Returns the FFrame added or null if the fframe has not been added.
371
         */
372
    public IFFrame openFFrameDialog(IFFrame fframe) {
373
        fframedialog=fframe.getPropertyDialog();
374
        if (fframedialog != null) {
375
            fframedialog.setRectangle(fframe.getBoundingBox(layoutControl.getAT()));
376
            PluginServices.getMDIManager().addWindow(fframedialog);
377
        }
378

    
379
        return fframedialog.getFFrame();
380
    }
381

    
382
    /**
383
     * This method is used to get <strong>an initial</strong> ViewInfo object
384
     * for this Map. It is not intended to retrieve the ViewInfo object in a
385
     * later time. <strong>Use PluginServices.getMDIManager().getViewInfo(view)
386
     * to retrieve the ViewInfo object at any time after the creation of the
387
     * object.
388
     *
389
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
390
     */
391
    public WindowInfo getWindowInfo() {
392
        if (m_viewInfo == null) {
393
            m_viewInfo = new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
394
                    | WindowInfo.MAXIMIZABLE);
395
            m_viewInfo.setWidth(500);
396
            m_viewInfo.setHeight(400);
397

    
398
            m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : "
399
                    + map.getName());
400
        }
401
        return m_viewInfo;
402
    }
403

    
404
    /**
405
         * It returns an Object XMLEntity with the information the necessary attributes
406
         * to be able later to create again the original object.
407
         *
408
         * @return XMLEntity.
409
         *
410
         * @throws XMLException
411
         */
412
    public XMLEntity getXMLEntity() {
413
        XMLEntity xml = new XMLEntity();
414
        xml.putProperty("className", this.getClass().getName());
415
        xml.setName("layout");
416
        xml.putProperty("isCuadricula", layoutContext.isAdjustingToGrid());
417
//        xml.putProperty("m_name", this.getName());
418
        xml.putProperty("isEditable", layoutContext.isEditable());
419
        xml.putProperty("numBehind", layoutContext.numBehind);
420
        xml.putProperty("numBefore", layoutContext.numBefore);
421
        xml.addChild(layoutContext.getAttributes().getXMLEntity());
422
        IFFrame[] fframes=layoutContext.getFFrames();
423
        for (int i = 0; i < fframes.length; i++) {
424
            try {
425
                XMLEntity xmlAux = fframes[i].getXMLEntity();
426
                xml.addChild(xmlAux);
427
            } catch (SaveException e) {
428
                e.showError();
429
            }
430
        }
431
        return xml;
432
    }
433
    /**
434
     * Returns the LayoutContext.
435
     * @return LayoutContext.
436
     */
437
    public LayoutContext getLayoutContext() {
438
            return layoutContext;
439
    }
440
    /**
441
     * Returns LayoutControl.
442
     * @return LayoutControl.
443
     */
444
    public LayoutControl getLayoutControl() {
445
            return layoutControl;
446
    }
447
    /**
448
         * It creates an Object of this class from the information of the XMLEntity.
449
         *
450
         * @param xml
451
         *            XMLEntity
452
         * @param p
453
         *            Project.
454
         *
455
         * @return Object of this class.
456
         * @throws OpenException
457
         */
458
    public static Layout createLayout(XMLEntity xml, Project p)
459
            throws OpenException {
460
        Layout layout = new Layout();
461
        try {
462
            layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
463
            //layout.setName(xml.getStringProperty("m_name"));
464
            layout.getLayoutContext().setAtributes(Attributes.createAtributes(xml.getChild(0)));
465
            if (xml.contains("isEditable")) {
466
                layout.layoutContext.setEditable(xml.getBooleanProperty("isEditable"));
467
            }
468
            if (xml.contains("numBehind")) {
469
                layout.layoutContext.numBehind = xml.getIntProperty("numBehind");
470
                layout.layoutContext.numBefore = xml.getIntProperty("numBefore");
471
            }
472
            //layout.layoutContext.getEFS().startComplexCommand();
473
//            for (int i = 1; i < xml.getChildrenCount(); i++) {
474
//                try {
475
//                    layout.layoutContext.addFFrame(FFrame.createFFrame(xml.getChild(i), p,
476
//                            layout), true, false);
477
//                } catch (OpenException e) {
478
//                    e.showError();
479
//                }
480
//            }
481

    
482
            for (int i = 1; i < xml.getChildrenCount(); i++) {
483
                                try {
484
                                        IFFrame frame = FFrame.createFromXML(xml
485
                                                        .getChild(i),p, layout);
486
                                        layout.layoutContext.addFFrame(frame,true,frame.getSelected()==IFFrame.RECT);
487
                                } catch (OpenException e) {
488
                                        e.showError();
489
                                }
490
                        }
491

    
492
            //layout.layoutContext.getEFS().endComplexCommand(PluginServices.getText(layout,"Inicializando"));
493
            IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
494
            for (int i = 0; i < fframes.length; i++) {
495
                fframes[i].setLayout(layout);
496
                if (fframes[i] instanceof IFFrameViewDependence) {
497
                    try {
498
                        ((IFFrameViewDependence) fframes[i])
499
                            .initDependence(fframes);
500
                    }catch (Exception e) {
501
                                                System.out.println("Fallo FFrameGroup");
502
                                        }
503
                    }
504
            }
505
            IFFrame[] fs = layout.getLayoutContext().getFFrames();
506
                        for (int i = 0; i < fs.length; i++) {
507
                                if (fs[i] instanceof FFrameGroup) {
508
                                        ((IFFrameViewDependence) fs[i]).initDependence(fframes);
509
                                }
510
                        }
511
        } catch (Exception e) {
512
            throw new OpenException(e, layout.getClass().getName());
513
        }
514
        return layout;
515
    }
516

    
517
    /**
518
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
519
     */
520
    public void windowActivated() {
521
        //fullRect();
522
        layoutControl.refresh();
523
        PluginServices.getMainFrame().getStatusBar().setMessage("units",
524
                PluginServices.getText(this, layoutContext.getAttributes().getNameUnit()));
525
            // ensure requestFocus is enabled
526
        if(!layoutControl.isRequestFocusEnabled()) {
527
                layoutControl.setRequestFocusEnabled(true);
528
               }
529
        requestFocus();
530
        layoutControl.requestFocus();
531
    }
532

    
533
    /**
534
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
535
     */
536
    public Object getWindowModel() {
537
        return map;
538
    }
539
    /**
540
     * Returns ProjectMap, the model of Layout.
541
     * @return ProjectMap.
542
     */
543
    public ProjectMap getModel() {
544
            return map;
545
    }
546
    /**
547
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(org.gvsig.fmap.mapcontext.events.ExtentEvent)
548
     */
549
    public void extentChanged(ExtentEvent e) {
550
    }
551

    
552
    /**
553
     * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
554
     */
555
    public void windowClosed() {
556
        // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
557
    }
558

    
559
    /**
560
     * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
561
     */
562
    public void backColorChanged(ColorEvent e) {
563
        // refresh();
564
    }
565

    
566
    /**
567
     * Opens a dialog where to pick a PDF-file to save the current Layout
568
     * suggesting a name for the file given by the first argument
569
     *
570
     * @param suggestedName
571
     */
572
    public void layoutToPDF(String suggestedName) {
573
        FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices
574
                .getText(this, "pdf"));
575

    
576
        JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
577
        if (suggestedName != null) {
578
                        jfc.setSelectedFile(new File(suggestedName));
579
                }
580
        jfc.addChoosableFileFilter(pdfFilter);
581
        jfc.setFileFilter(pdfFilter);
582

    
583
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
584
            File f = jfc.getSelectedFile();
585
            File faux = null;
586

    
587
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
588
                faux = f;
589
            } else {
590
                faux = new File(f.getPath() + ".pdf");
591
            }
592

    
593
            layoutControl.getLayoutDraw().toPDF(faux);
594
        }
595
    }
596
    /**
597
     * Opens a dialog where to pick a PS-file to save the current Layout
598
     * suggesting a name for the file given by the first argument
599
     *
600
     * @param suggestedName
601
     */
602
    public void layoutToPS(String suggestedName) {
603
        FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices
604
                .getText(this, "ps"));
605

    
606
        JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
607
        if (suggestedName != null) {
608
                        jfc.setSelectedFile(new File(suggestedName));
609
                }
610
        jfc.addChoosableFileFilter(pdfFilter);
611
        jfc.setFileFilter(pdfFilter);
612

    
613
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
614
            File f = jfc.getSelectedFile();
615
            File faux = null;
616

    
617
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
618
                faux = f;
619
            } else {
620
                faux = new File(f.getPath() + ".ps");
621
            }
622

    
623
            layoutControl.getLayoutDraw().toPS(faux);
624
        }
625
    }
626
    /**
627
         * It opens a dialog to select pdf file where to save the Layout in this format.
628
         */
629
    public void layoutToPDF() {
630
        layoutToPDF(null);
631
    }
632
    /**
633
         * It opens a dialog to select ps file where to save the Layout in this format.
634
         */
635
    public void layoutToPS() {
636
        layoutToPS(null);
637
    }
638
    /**
639
         * @return Returns the bShowIconTag.
640
         */
641
    public boolean isShowIconTag() {
642
        return bShowIconTag;
643
    }
644

    
645
    /**
646
     * @param modeDebug
647
     *            The bModeDebug to set.
648
     */
649
    public void setShowIconTag(boolean modeDebug) {
650
        bShowIconTag = modeDebug;
651
    }
652

    
653
    /**
654
         * Event to change the projection.
655
         */
656
    public void projectionChanged(ProjectionEvent e) {
657
        // TODO Auto-generated method stub
658

    
659
    }
660
    /**
661
         * Returns if the grid sould be show.
662
         * @return True if the grid sould be show.
663
         */
664
    public static boolean getDefaultShowGrid() {
665
        if (defaultShowGrid == null) {
666
            XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app").getPersistentXML();
667
            if (xml.contains("DefaultShowLayoutGrid")) {
668
                defaultShowGrid = new Boolean(xml.getBooleanProperty("DefaultShowLayoutGrid"));
669
            }
670
            else {
671
                // factory default is true
672
                defaultShowGrid = new Boolean(true);
673
            }
674
        }
675
        return defaultShowGrid.booleanValue();
676
    }
677
    /**
678
         * Returns if the adjust to grid sould be actived.
679
         * @return True if the adjust to grid sould be actived.
680
         */
681
    public static boolean getDefaultAdjustToGrid() {
682
        if (defaultAdjustToGrid == null) {
683
            XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app").getPersistentXML();
684
            if (xml.contains("DefaultEnableLayoutGrid")) {
685
                defaultAdjustToGrid = new Boolean(xml.getBooleanProperty("DefaultEnableLayoutGrid"));
686
            }
687
            else {
688
                // factory default is false
689
                defaultAdjustToGrid = new Boolean(false);
690
            }
691
        }
692
        return defaultAdjustToGrid.booleanValue();
693
    }
694
    /**
695
         * Returns if the ruler sould be show.
696
         * @return True if the ruler sould be show.
697
         */
698
    public static boolean getDefaultShowRulers() {
699
        if (defaultShowRulers == null){
700
            XMLEntity xml = PluginServices.getPluginServices("org.gvsig.app").getPersistentXML();
701
            if (xml.contains("DefaultShowLayoutRules")) {
702
                defaultShowRulers = new Boolean(xml.getBooleanProperty("DefaultShowLayoutRules"));
703
            }
704
            else {
705
                // factory default is true
706
                defaultShowRulers = new Boolean(true);
707
            }
708
        }
709
        return defaultShowRulers.booleanValue();
710
    }
711
    /**
712
         * Inserts if the grid sould be show.
713
         * @param showGrid
714
         */
715
    public static void setDefaultShowGrid(boolean showGrid) {
716
        defaultShowGrid = new Boolean(showGrid);
717
    }
718
    /**
719
         * Inserts if the adjust togrid sould be actived.
720
         * @param gridEnable
721
         */
722
    public static void setDefaultAdjustToGrid(boolean gridEnabled) {
723
        defaultAdjustToGrid = new Boolean(gridEnabled);
724
    }
725
    /**
726
         * Inserts if the ruler sould be show.
727
         * @param showRuler
728
         */
729
    public static void setDefaultShowRulers(boolean showRules) {
730
        defaultShowRulers  = new Boolean(showRules);
731
    }
732

    
733
        public void update(Observable observable, Object notification) {
734
                this.layoutContext.updateFFrames();
735
        this.layoutControl.refresh();
736
        }
737

    
738
        public Object getWindowProfile() {
739
                return WindowInfo.EDITOR_PROFILE;
740
        }
741
}