Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / gui / Layout.java @ 28304

History | View | Annotate | Download (25.6 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.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.fmap.dal.exception.ReadException;
77
import org.gvsig.fmap.mapcontext.events.ColorEvent;
78
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
79
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
80
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
81
import org.gvsig.gui.beans.swing.JFileChooser;
82
import org.gvsig.tools.observer.Observable;
83
import org.gvsig.tools.observer.Observer;
84

    
85
import com.iver.andami.PluginServices;
86
import com.iver.andami.messages.NotificationManager;
87
import com.iver.andami.ui.mdiManager.IWindowListener;
88
import com.iver.andami.ui.mdiManager.SingletonWindow;
89
import com.iver.andami.ui.mdiManager.WindowInfo;
90
import com.iver.cit.gvsig.project.Project;
91
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
92
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
93
import com.iver.cit.gvsig.project.documents.layout.Attributes;
94
import com.iver.cit.gvsig.project.documents.layout.LayoutContext;
95
import com.iver.cit.gvsig.project.documents.layout.LayoutControl;
96
import com.iver.cit.gvsig.project.documents.layout.ProjectMap;
97
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrame;
98
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameGroup;
99
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
100
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
101
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
102
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
103
import com.iver.utiles.GenericFileFilter;
104
import com.iver.utiles.XMLEntity;
105
import com.iver.utiles.XMLException;
106

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

    
116
        public static File defaultPDFFolderPath;
117

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

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

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

    
168

    
169

    
170

    
171

    
172

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

    
181
        setCursor(Cursor.getDefaultCursor());
182

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

    
205
        // TODO Esto es para ver el rect?ngulo que representa el folio en la
206
        // impresi?n.
207
        // g2.drawRect(0, 0, (int) rect.getWidth(), (int) rect.getHeight());
208
    }
209

    
210

    
211

    
212
    /**
213
         * It initializes the components.
214
         */
215
    private void initComponents() {
216
            this.setLayout(new GridLayout(1,1));
217
        add(layoutControl);
218
            layoutContext.getAttributes().setDistanceUnitX(layoutControl.getRect());
219
            layoutContext.getAttributes().setDistanceUnitY(layoutControl.getRect());
220
        setDoubleBuffered(true);
221
    }
222

    
223
    /**
224
         * Open the dialog of Layout properties.
225
         *
226
         * @param job PrinterJob
227
         */
228
    public void showPagePropertiesWindow(PrinterJob job) {
229
        PageFormat pf1;
230

    
231
        pf1 = layoutContext.getAttributes().getPageFormat();
232
        pf1 = job.pageDialog(pf1);
233
        layoutContext.getAttributes().setPageFormat(pf1);
234
        layoutControl.refresh();
235
    }
236

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

    
248
    /**
249
         * It shows the dialog of configuration of the Layout.
250
         */
251
    public void showFConfig() {
252
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
253
        PluginServices.getMDIManager().addWindow(m_configLayout);
254
    }
255

    
256
    /**
257
         * It shows the dialog of Layout?s properties.
258
         */
259
    public boolean showFProperties() {
260
        if (map == null) {
261
            map = new ProjectMap();
262
            map.setModel(this);
263
            map.setName(getName());
264
        }
265

    
266
        m_propertiesLayout = new MapProperties(map);
267
        PluginServices.getMDIManager().addWindow(m_propertiesLayout);
268
        return m_propertiesLayout.isAccepted();
269
    }
270

    
271
    /**
272
         * It shows the dialog of printing of the Layout.
273
         *
274
         * @param job PrinterJob
275
         */
276
    public void showPrintDialog(PrinterJob job) {
277
        if (job != null) {
278
            job.printDialog();
279

    
280
            try {
281
                job.setPrintable((Printable) PluginServices
282
                        .getExtension(com.iver.cit.gvsig.Print.class));
283
                job.print();
284
            } catch (PrinterException e) {
285
                e.printStackTrace();
286
            }
287
        } else {
288
            // Actualizar attributes
289
            att = layoutContext.getAttributes().toPrintAttributes();
290

    
291
            // ------------------ The Printing things --------------------- //
292
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
293

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

    
308
            PrintService defaultService = null;
309

    
310
            if (m_cachePrintService == null) {
311
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
312
            }
313

    
314
            if ((defaultService == null) && (m_cachePrintService == null)) {
315
                JOptionPane.showMessageDialog((Component) PluginServices
316
                        .getMainFrame(),PluginServices.getText(this,"ninguna_impresora_configurada"));
317

    
318
                return;
319
            }
320

    
321
            if (m_cachePrintService == null) {
322
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
323
                        m_cachePrintServices, defaultService, flavor, att);
324

    
325
                // m_cachePrintRequestAtributeSet = new
326
                // HashPrintRequestAttributeSet();
327
                // m_cachePrintRequestAtributeSet.addAll(pras);
328
            } else {
329
                m_cachePrintService = ServiceUI.printDialog(null, 200, 200,
330
                        m_cachePrintServices, m_cachePrintService, flavor, att);
331
            }
332

    
333
            if (m_cachePrintService != null) {
334
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
335
                PrintJobListener pjlistener = new PrintJobAdapter() {
336
                    public void printDataTransferCompleted(PrintJobEvent e) {
337
//                        System.out.println("Fin de impresi?n");
338
                        layoutControl.fullRect();
339
                    }
340
                };
341

    
342
                jobNuevo.addPrintJobListener(pjlistener);
343

    
344
                // DocAttributeSet das = new HashDocAttributeSet();
345
                doc = new SimpleDoc(PluginServices
346
                        .getExtension(com.iver.cit.gvsig.Print.class), flavor,
347
                        null);
348

    
349
                try {
350
                    jobNuevo.print(doc, att);
351

    
352
                    // m_attributes.
353
                } catch (PrintException pe) {
354
                    NotificationManager.addError(pe);
355
                }
356
            }
357
        }
358

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

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

    
384
        return fframedialog.getFFrame();
385
    }
386

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

    
403
            m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : "
404
                    + map.getName());
405
        }
406
        return m_viewInfo;
407
    }
408

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

    
487
            for (int i = 1; i < xml.getChildrenCount(); i++) {
488
                                try {
489
                                        IFFrame frame = FFrame.createFromXML(xml
490
                                                        .getChild(i),p, layout);
491
                                        layout.layoutContext.addFFrame(frame,true,frame.getSelected()==IFFrame.RECT);
492
                                } catch (OpenException e) {
493
                                        e.showError();
494
                                }
495
                        }
496

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

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

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

    
557
    /**
558
     * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
559
     */
560
    public void windowClosed() {
561
        // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
562
    }
563

    
564
    /**
565
     * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
566
     */
567
    public void backColorChanged(ColorEvent e) {
568
        // refresh();
569
    }
570

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

    
581
        JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
582
        if (suggestedName != null) {
583
                        jfc.setSelectedFile(new File(suggestedName));
584
                }
585
        jfc.addChoosableFileFilter(pdfFilter);
586
        jfc.setFileFilter(pdfFilter);
587

    
588
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
589
            File f = jfc.getSelectedFile();
590
            File faux = null;
591

    
592
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
593
                faux = f;
594
            } else {
595
                faux = new File(f.getPath() + ".pdf");
596
            }
597

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

    
611
        JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
612
        if (suggestedName != null) {
613
                        jfc.setSelectedFile(new File(suggestedName));
614
                }
615
        jfc.addChoosableFileFilter(pdfFilter);
616
        jfc.setFileFilter(pdfFilter);
617

    
618
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
619
            File f = jfc.getSelectedFile();
620
            File faux = null;
621

    
622
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
623
                faux = f;
624
            } else {
625
                faux = new File(f.getPath() + ".ps");
626
            }
627

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

    
650
    /**
651
     * @param modeDebug
652
     *            The bModeDebug to set.
653
     */
654
    public void setShowIconTag(boolean modeDebug) {
655
        bShowIconTag = modeDebug;
656
    }
657

    
658
    /**
659
         * Event to change the projection.
660
         */
661
    public void projectionChanged(ProjectionEvent e) {
662
        // TODO Auto-generated method stub
663

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

    
738
        public void update(Observable observable, Object notification) {
739
                this.layoutContext.updateFFrames();
740
        this.layoutControl.refresh();
741
        }
742

    
743
        public Object getWindowProfile() {
744
                return WindowInfo.EDITOR_PROFILE;
745
        }
746
}