Statistics
| Revision:

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

History | View | Annotate | Download (26.2 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.JFileChooser;
73
import javax.swing.JOptionPane;
74
import javax.swing.JPanel;
75
import javax.swing.filechooser.FileFilter;
76

    
77
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
78
import com.iver.andami.PluginServices;
79
import com.iver.andami.messages.NotificationManager;
80
import com.iver.andami.ui.mdiManager.IWindowListener;
81
import com.iver.andami.ui.mdiManager.SingletonWindow;
82
import com.iver.andami.ui.mdiManager.WindowInfo;
83
import com.iver.cit.gvsig.fmap.ColorEvent;
84
import com.iver.cit.gvsig.fmap.ExtentEvent;
85
import com.iver.cit.gvsig.fmap.ProjectionEvent;
86
import com.iver.cit.gvsig.fmap.ViewPortListener;
87
import com.iver.cit.gvsig.fmap.edition.commands.CommandListener;
88
import com.iver.cit.gvsig.fmap.layers.XMLException;
89
import com.iver.cit.gvsig.project.Project;
90
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
91
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
92
import com.iver.cit.gvsig.project.documents.layout.Attributes;
93
import com.iver.cit.gvsig.project.documents.layout.LayoutContext;
94
import com.iver.cit.gvsig.project.documents.layout.LayoutControl;
95
import com.iver.cit.gvsig.project.documents.layout.ProjectMap;
96
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrame;
97
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
98
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
99
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
100
import com.iver.cit.gvsig.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
101
import com.iver.utiles.GenericFileFilter;
102
import com.iver.utiles.XMLEntity;
103

    
104
/**
105
 * Graphic representation of the elements to print.
106
 *
107
 * @author Vicente Caballero Navarro
108
 */
109
public class Layout extends JPanel implements SingletonWindow, ViewPortListener,
110
        IWindowListener, CommandListener {
111

    
112

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

    
132
    /**
133
     * Creates a new Layout object.
134
     */
135
    public Layout() {
136
            layoutContext=new LayoutContext();
137
        layoutControl=new LayoutControl(this);
138
        layoutContext.updateFFrames();
139
        this.initComponents();
140
    }
141

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

    
163

    
164

    
165

    
166

    
167

    
168
    /**
169
         * Method to print the Layout without modify the Affinetransform.
170
         *
171
         * @param g2 Geaphics2D
172
         */
173
    public void drawLayoutPrint(Graphics2D g2) {
174
        layoutControl.setCancelDrawing(false);
175

    
176
        setCursor(Cursor.getDefaultCursor());
177

    
178
        double scale = 0;
179
        scale = layoutControl.getRect().height / layoutContext.getAtributes().m_sizePaper.getAlto() * 1;
180
        AffineTransform escalado = new AffineTransform();
181
        AffineTransform translacion = new AffineTransform();
182
        translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY());
183
        escalado.setToScale(scale, scale);
184
        layoutControl.getAT().setToIdentity();
185
        layoutControl.getAT().concatenate(translacion);
186
        layoutControl.getAT().concatenate(escalado);
187
        layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect());
188
        layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect());
189
        IFFrame[] fframes=layoutContext.getFFrames();
190
        for (int i = 0; i < fframes.length; i++) {
191
            try {
192
                    fframes[i].setPrintingProperties(this.att);
193
                    fframes[i].print(g2, layoutControl.getAT(),null);
194
                    fframes[i].setPrintingProperties(null);
195
                } catch (ReadDriverException e) {
196
                NotificationManager.addError(e.getMessage(), e);
197
            }
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.getAtributes().setDistanceUnitX(layoutControl.getRect());
214
            layoutContext.getAtributes().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.getAtributes().getPageFormat();
227
        pf1 = job.pageDialog(pf1);
228
        layoutContext.getAtributes().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() {
239
            layoutContext.getAtributes().obtainRect(layoutControl.getRect());
240
    }
241

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

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

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

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

    
274
            try {
275
                job.setPrintable((Printable) PluginServices
276
                        .getExtension(com.iver.cit.gvsig.Print.class));
277
                job.print();
278
            } catch (PrinterException e) {
279
                e.printStackTrace();
280
            }
281
        } else {
282
            // Actualizar attributes
283
            att = layoutContext.getAtributes().toPrintAttributes();
284

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

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

    
302
            PrintService defaultService = null;
303

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

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

    
312
                return;
313
            }
314

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

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

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

    
336
                jobNuevo.addPrintJobListener(pjlistener);
337

    
338
                // DocAttributeSet das = new HashDocAttributeSet();
339
                doc = new SimpleDoc(PluginServices
340
                        .getExtension(com.iver.cit.gvsig.Print.class), flavor,
341
                        null);
342

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

    
346
                    // m_attributes.
347
                } catch (PrintException pe) {
348
                    pe.printStackTrace();
349
                }
350
            }
351
        }
352

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

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

    
378
        return fframedialog.getFFrame();
379
    }
380

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

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

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

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

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

    
510
    /**
511
         * It creates an Object of this class from the information of the XMLEntity.
512
         *
513
         * @param xml
514
         *            XMLEntity
515
         * @param p
516
         *            Project.
517
         *
518
         * @return Object of this class.
519
         * @throws OpenException
520
         */
521
    public static Layout createLayout03(XMLEntity xml, Project p) {
522
        Layout layout = new Layout();
523
        layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
524
        layout.setName(xml.getStringProperty("m_name"));
525
        layout.getLayoutContext().setAtributes(Attributes.createAtributes03(xml.getChild(0)));
526

    
527
        for (int i = 1; i < xml.getChildrenCount(); i++) {
528
            if (xml.getChild(i).getStringProperty("className").equals(
529
                    "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
530
                layout.layoutContext.addFFrame(FFrame.createFromXML03(xml.getChild(i),p, layout), true, false);
531
            }
532
        }
533

    
534
        for (int i = 1; i < xml.getChildrenCount(); i++) {
535
            if (!xml.getChild(i).getStringProperty("className").equals(
536
                    "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
537
                layout.layoutContext.addFFrame(FFrame.createFromXML03(xml.getChild(i), p, layout), true, false);
538
            }
539
        }
540

    
541
        return layout;
542
    }
543

    
544
    /**
545
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
546
     */
547
    public void windowActivated() {
548
        //fullRect();
549
        layoutControl.refresh();
550
        PluginServices.getMainFrame().getStatusBar().setMessage("units",
551
                PluginServices.getText(this, layoutContext.getAtributes().getNameUnit()));
552
            // ensure requestFocus is enabled
553
        if(!layoutControl.isRequestFocusEnabled()) {
554
                layoutControl.setRequestFocusEnabled(true);
555
               }
556
        requestFocus();
557
        layoutControl.requestFocus();
558
    }
559

    
560
    /**
561
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
562
     */
563
    public Object getWindowModel() {
564
        return map;
565
    }
566
    /**
567
     * Returns ProjectMap, the model of Layout.
568
     * @return ProjectMap.
569
     */
570
    public ProjectMap getModel() {
571
            return map;
572
    }
573
    /**
574
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
575
     */
576
    public void extentChanged(ExtentEvent e) {
577
    }
578

    
579
    /**
580
     * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
581
     */
582
    public void windowClosed() {
583
        // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
584
    }
585

    
586
    /**
587
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
588
     */
589
    public void backColorChanged(ColorEvent e) {
590
        // refresh();
591
    }
592

    
593
    /**
594
     * Opens a dialog where to pick a PDF-file to save the current Layout
595
     * suggesting a name for the file given by the first argument
596
     *
597
     * @param suggestedName
598
     */
599
    public void layoutToPDF(String suggestedName) {
600
        FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices
601
                .getText(this, "pdf"));
602

    
603
        JFileChooser jfc = new JFileChooser();
604
        if (suggestedName != null)
605
            jfc.setSelectedFile(new File(suggestedName));
606
        jfc.addChoosableFileFilter(pdfFilter);
607
        jfc.setFileFilter(pdfFilter);
608

    
609
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
610
            File f = jfc.getSelectedFile();
611
            File faux = null;
612

    
613
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
614
                faux = f;
615
            } else {
616
                faux = new File(f.getPath() + ".pdf");
617
            }
618

    
619
            layoutControl.getLayoutDraw().toPDF(faux);
620
        }
621
    }
622
    /**
623
     * Opens a dialog where to pick a PS-file to save the current Layout
624
     * suggesting a name for the file given by the first argument
625
     *
626
     * @param suggestedName
627
     */
628
    public void layoutToPS(String suggestedName) {
629
        FileFilter pdfFilter = new GenericFileFilter("ps", PluginServices
630
                .getText(this, "ps"));
631

    
632
        JFileChooser jfc = new JFileChooser();
633
        if (suggestedName != null)
634
            jfc.setSelectedFile(new File(suggestedName));
635
        jfc.addChoosableFileFilter(pdfFilter);
636
        jfc.setFileFilter(pdfFilter);
637

    
638
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
639
            File f = jfc.getSelectedFile();
640
            File faux = null;
641

    
642
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
643
                faux = f;
644
            } else {
645
                faux = new File(f.getPath() + ".ps");
646
            }
647

    
648
            layoutControl.getLayoutDraw().toPS(faux);
649
        }
650
    }
651
    /**
652
         * It opens a dialog to select pdf file where to save the Layout in this format.
653
         */
654
    public void layoutToPDF() {
655
        layoutToPDF(null);
656
    }
657
    /**
658
         * It opens a dialog to select ps file where to save the Layout in this format.
659
         */
660
    public void layoutToPS() {
661
        layoutToPS(null);
662
    }
663
    /**
664
         * @return Returns the bShowIconTag.
665
         */
666
    public boolean isShowIconTag() {
667
        return bShowIconTag;
668
    }
669

    
670
    /**
671
     * @param modeDebug
672
     *            The bModeDebug to set.
673
     */
674
    public void setShowIconTag(boolean modeDebug) {
675
        bShowIconTag = modeDebug;
676
    }
677

    
678
    /**
679
         * Repaint the Layout.
680
         */
681
    public void commandRepaint() {
682
        this.layoutContext.updateFFrames();
683
        this.layoutControl.refresh();
684
    }
685
    /**
686
         * Repaint the Layout.
687
         */
688
    public void commandRefresh() {
689
        commandRepaint();
690

    
691
    }
692
    /**
693
         * Event to change the projection.
694
         */
695
    public void projectionChanged(ProjectionEvent e) {
696
        // TODO Auto-generated method stub
697

    
698
    }
699
    /**
700
         * Returns if the grid sould be show.
701
         * @return True if the grid sould be show.
702
         */
703
    public static boolean getDefaultShowGrid() {
704
        if (defaultShowGrid == null) {
705
            XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
706
            if (xml.contains("DefaultShowLayoutGrid")) {
707
                defaultShowGrid = new Boolean(xml.getBooleanProperty("DefaultShowLayoutGrid"));
708
            }
709
            else {
710
                // factory default is true
711
                defaultShowGrid = new Boolean(true);
712
            }
713
        }
714
        return defaultShowGrid.booleanValue();
715
    }
716
    /**
717
         * Returns if the adjust to grid sould be actived.
718
         * @return True if the adjust to grid sould be actived.
719
         */
720
    public static boolean getDefaultAdjustToGrid() {
721
        if (defaultAdjustToGrid == null) {
722
            XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
723
            if (xml.contains("DefaultEnableLayoutGrid")) {
724
                defaultAdjustToGrid = new Boolean(xml.getBooleanProperty("DefaultEnableLayoutGrid"));
725
            }
726
            else {
727
                // factory default is false
728
                defaultAdjustToGrid = new Boolean(false);
729
            }
730
        }
731
        return defaultAdjustToGrid.booleanValue();
732
    }
733
    /**
734
         * Returns if the ruler sould be show.
735
         * @return True if the ruler sould be show.
736
         */
737
    public static boolean getDefaultShowRulers() {
738
        if (defaultShowRulers == null){
739
            XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
740
            if (xml.contains("DefaultShowLayoutRules")) {
741
                defaultShowRulers = new Boolean(xml.getBooleanProperty("DefaultShowLayoutRules"));
742
            }
743
            else {
744
                // factory default is true
745
                defaultShowRulers = new Boolean(true);
746
            }
747
        }
748
        return defaultShowRulers.booleanValue();
749
    }
750
    /**
751
         * Inserts if the grid sould be show.
752
         * @param showGrid
753
         */
754
    public static void setDefaultShowGrid(boolean showGrid) {
755
        defaultShowGrid = new Boolean(showGrid);
756
    }
757
    /**
758
         * Inserts if the adjust togrid sould be actived.
759
         * @param gridEnable
760
         */
761
    public static void setDefaultAdjustToGrid(boolean gridEnabled) {
762
        defaultAdjustToGrid = new Boolean(gridEnabled);
763
    }
764
    /**
765
         * Inserts if the ruler sould be show.
766
         * @param showRuler
767
         */
768
    public static void setDefaultShowRulers(boolean showRules) {
769
        defaultShowRulers  = new Boolean(showRules);
770
    }
771
}