Statistics
| Revision:

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

History | View | Annotate | Download (25.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.iver.andami.PluginServices;
78
import com.iver.andami.messages.NotificationManager;
79
import com.iver.andami.ui.mdiManager.IWindowListener;
80
import com.iver.andami.ui.mdiManager.SingletonWindow;
81
import com.iver.andami.ui.mdiManager.WindowInfo;
82
import com.iver.cit.gvsig.fmap.ColorEvent;
83
import com.iver.cit.gvsig.fmap.DriverException;
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
 * Mapa.
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
     * Lo usamos cuando estamos haciendo una ficha y asignando tags Se pone en
126
     * modo debug cuando hacemos un 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
     * Rellena el ProjectMap del Layout.
144
     *
145
     * @param m
146
     *            ProjectMap.
147
     */
148
    public void setProjectMap(ProjectMap m) {
149
        map = m;
150
        this.setName(m.getName());
151
        map.addPropertyChangeListener(new PropertyChangeListener() {
152
            public void propertyChange(PropertyChangeEvent evt) {
153
                if (evt.getPropertyName().equals("name")) {
154
                    PluginServices.getMDIManager().getWindowInfo(Layout.this)
155
                            .setTitle(
156
                                    PluginServices.getText(this, "Mapa")
157
                                            + " : "
158
                                            + (String) evt.getNewValue());
159
                }
160
            }
161
        });
162
    }
163

    
164

    
165

    
166

    
167

    
168

    
169
    /**
170
     * M?todo para imprimir el Layout sin modificar la matriz de transformaci?n.
171
     *
172
     * @param g2
173
     */
174
    public void drawLayoutPrint(Graphics2D g2) {
175
        layoutControl.setCancelDrawing(false);
176

    
177
        setCursor(Cursor.getDefaultCursor());
178

    
179
        double scale = 0;
180
        scale = layoutControl.getRect().height / layoutContext.getAtributes().m_sizePaper.getAlto() * 1;
181
        AffineTransform escalado = new AffineTransform();
182
        AffineTransform translacion = new AffineTransform();
183
        translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY());
184
        escalado.setToScale(scale, scale);
185
        layoutControl.getAT().setToIdentity();
186
        layoutControl.getAT().concatenate(translacion);
187
        layoutControl.getAT().concatenate(escalado);
188
        layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect());
189
        layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect());
190
        IFFrame[] fframes=layoutContext.getFFrames();
191
        for (int i = 0; i < fframes.length; i++) {
192
            try {
193
                fframes[i].print(g2, layoutControl.getAT());
194
            } catch (DriverException e) {
195
                NotificationManager.addError(e.getMessage(), e);
196
            }
197
        }
198

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

    
205

    
206

    
207
    /**
208
     * Inicializa los componentes.
209
     */
210
    private void initComponents() {
211
             this.setLayout(new GridLayout(1,1));
212

    
213
         add(layoutControl);
214
            //m_attributes = new Attributes();
215
            layoutContext.getAtributes().setDistanceUnitX(layoutControl.getRect());
216
            layoutContext.getAtributes().setDistanceUnitY(layoutControl.getRect());
217
        //actionDelFFrame();
218
        setDoubleBuffered(true);
219
    }
220

    
221
    /**
222
     * Abre el di?logo de propiedades del folio, pasando como par?metro el
223
     * PrinterJob.
224
     *
225
     * @param job
226
     */
227
    public void showPagePropertiesWindow(PrinterJob job) {
228
        PageFormat pf1;
229

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

    
236
    /**
237
     * Obtiene el rect?ngulo que representa el folio con las caracter?sticas que
238
     * contiene attributes y diferenciando si es para visualizar en pantalla o
239
     * para imprimir.
240
     *
241
     * @param isPrint
242
     *            si es para imprimir.
243
     */
244
    public void obtainRect(boolean isPrint) {
245
            layoutContext.getAtributes().obtainRect(isPrint, layoutControl.getRect(), getWidth(), getHeight());
246
    }
247

    
248
    /**
249
     * Muestra el di?logo de configuraci?n del Layout.
250
     */
251
    public void showFConfig() {
252
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
253
        PluginServices.getMDIManager().addWindow(m_configLayout);
254
    }
255

    
256
    /**
257
     * Mestra el di?logo de propiedades del Layout.
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
     * Muestra el di?logo de imprimir pasandole el printerJob como par?metro.
273
     *
274
     * @param job
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.getAtributes().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
                    pe.printStackTrace();
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
     * Se crean aqu? los dialogos cada vez que se necesitan.
371
     *
372
     * @param fframe
373
     *            Rectangle que representa el lugar que ocupara el elemento
374
     *            a?adido.
375
     *
376
     * @return true si se debe de a?adir el fframe.
377
     */
378
    public IFFrame openFFrameDialog(IFFrame fframe) {
379
        fframedialog=fframe.getPropertyDialog();
380
        if (fframedialog != null) {
381
            fframedialog.setRectangle(fframe.getBoundingBox(layoutControl.getAT()));
382
            PluginServices.getMDIManager().addWindow(fframedialog);
383
        }
384

    
385
        return fframedialog.getFFrame();
386
    }
387

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

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

    
410
    /**
411
     * Devuelve un Objeto XMLEntity con la informaci?n los atributos necesarios
412
     * para poder despu?s volver a crear el objeto original.
413
     *
414
     * @return XMLEntity.
415
     *
416
     * @throws XMLException
417
     */
418
    public XMLEntity getXMLEntity() {
419
        XMLEntity xml = new XMLEntity();
420
        xml.putProperty("className", this.getClass().getName());
421
        xml.setName("layout");
422
        xml.putProperty("isCuadricula", layoutContext.isAdjustingToGrid());
423
//        xml.putProperty("m_name", this.getName());
424
        xml.putProperty("isEditable", layoutContext.isEditable());
425
        xml.putProperty("numBehind", layoutContext.numBehind);
426
        xml.putProperty("numBefore", layoutContext.numBefore);
427
        xml.addChild(layoutContext.getAtributes().getXMLEntity());
428
        IFFrame[] fframes=layoutContext.getFFrames();
429
        for (int i = 0; i < fframes.length; i++) {
430
            try {
431
                XMLEntity xmlAux = fframes[i].getXMLEntity();
432
                xml.addChild(xmlAux);
433
            } catch (SaveException e) {
434
                e.showError();
435
            }
436
        }
437
        return xml;
438
    }
439
    public LayoutContext getLayoutContext() {
440
            return layoutContext;
441
    }
442
    public LayoutControl getLayoutControl() {
443
            return layoutControl;
444
    }
445
    /**
446
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
447
     *
448
     * @param xml
449
     *            XMLEntity
450
     * @param p
451
     *            Proyecto.
452
     *
453
     * @return Objeto de esta clase.
454
     * @throws OpenException
455
     */
456
    public static Layout createLayout(XMLEntity xml, Project p)
457
            throws OpenException {
458
        Layout layout = new Layout();
459
        try {
460
            layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
461
            //layout.setName(xml.getStringProperty("m_name"));
462
            layout.getLayoutContext().setAtributes(Attributes.createAtributes(xml.getChild(0)));
463
            if (xml.contains("isEditable")) {
464
                layout.layoutContext.setEditable(xml.getBooleanProperty("isEditable"));
465
            }
466
            if (xml.contains("numBehind")) {
467
                layout.layoutContext.numBehind = xml.getIntProperty("numBehind");
468
                layout.layoutContext.numBefore = xml.getIntProperty("numBefore");
469
            }
470
            //layout.layoutContext.getEFS().startComplexCommand();
471
//            for (int i = 1; i < xml.getChildrenCount(); i++) {
472
//                try {
473
//                    layout.layoutContext.addFFrame(FFrame.createFFrame(xml.getChild(i), p,
474
//                            layout), true, false);
475
//                } catch (OpenException e) {
476
//                    e.showError();
477
//                }
478
//            }
479

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

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

    
505
    /**
506
     * Crea un Objeto de esta clase a partir de la informaci?n del XMLEntity.
507
     *
508
     * @param xml
509
     *            XMLEntity
510
     * @param p
511
     *            Proyecto.
512
     *
513
     * @return Objeto de esta clase.
514
     */
515
    public static Layout createLayout03(XMLEntity xml, Project p) {
516
        Layout layout = new Layout();
517
        layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
518
        layout.setName(xml.getStringProperty("m_name"));
519
        layout.getLayoutContext().setAtributes(Attributes.createAtributes03(xml.getChild(0)));
520

    
521
        for (int i = 1; i < xml.getChildrenCount(); i++) {
522
            if (xml.getChild(i).getStringProperty("className").equals(
523
                    "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
524
                layout.layoutContext.addFFrame(FFrame.createFromXML03(xml.getChild(i),p, layout), true, false);
525
            }
526
        }
527

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

    
535
        return layout;
536
    }
537

    
538
    /**
539
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
540
     */
541
    public void windowActivated() {
542
        //fullRect();
543
        layoutControl.refresh();
544
        PluginServices.getMainFrame().getStatusBar().setMessage("units",
545
                PluginServices.getText(this, layoutContext.getAtributes().getNameUnit()));
546
    }
547

    
548
    /**
549
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
550
     */
551
    public Object getWindowModel() {
552
        return map;
553
    }
554
    public ProjectMap getModel() {
555
            return map;
556
    }
557
    /**
558
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
559
     */
560
    public void extentChanged(ExtentEvent e) {
561
    }
562

    
563
    /**
564
     * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
565
     */
566
    public void windowClosed() {
567
        // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
568
    }
569

    
570
    /**
571
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
572
     */
573
    public void backColorChanged(ColorEvent e) {
574
        // refresh();
575
    }
576

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

    
587
        JFileChooser jfc = new JFileChooser();
588
        if (suggestedName != null)
589
            jfc.setSelectedFile(new File(suggestedName));
590
        jfc.addChoosableFileFilter(pdfFilter);
591
        jfc.setFileFilter(pdfFilter);
592

    
593
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
594
            File f = jfc.getSelectedFile();
595
            File faux = null;
596

    
597
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
598
                faux = f;
599
            } else {
600
                faux = new File(f.getPath() + ".pdf");
601
            }
602

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

    
616
        JFileChooser jfc = new JFileChooser();
617
        if (suggestedName != null)
618
            jfc.setSelectedFile(new File(suggestedName));
619
        jfc.addChoosableFileFilter(pdfFilter);
620
        jfc.setFileFilter(pdfFilter);
621

    
622
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
623
            File f = jfc.getSelectedFile();
624
            File faux = null;
625

    
626
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
627
                faux = f;
628
            } else {
629
                faux = new File(f.getPath() + ".ps");
630
            }
631

    
632
            layoutControl.getLayoutDraw().toPS(faux);
633
        }
634
    }
635
    /**
636
     * Abre un di?logo para seleccionar un fichero pdf donde guardar el Layout
637
     * en este formato.
638
     */
639
    public void layoutToPDF() {
640
        layoutToPDF(null);
641
    }
642
    /**
643
     * Abre un di?logo para seleccionar un fichero ps donde guardar el Layout
644
     * en este formato.
645
     */
646
    public void layoutToPS() {
647
        layoutToPS(null);
648
    }
649
    /**
650
     * @return Returns the bModeDebug.
651
     */
652
    public boolean isShowIconTag() {
653
        return bShowIconTag;
654
    }
655

    
656
    /**
657
     * @param modeDebug
658
     *            The bModeDebug to set.
659
     */
660
    public void setShowIconTag(boolean modeDebug) {
661
        bShowIconTag = modeDebug;
662
    }
663

    
664

    
665
    public void commandRepaint() {
666
        this.layoutContext.updateFFrames();
667
        this.layoutControl.refresh();
668
    }
669

    
670
    public void commandRefresh() {
671
        commandRepaint();
672

    
673
    }
674

    
675
    public void projectionChanged(ProjectionEvent e) {
676
        // TODO Auto-generated method stub
677

    
678
    }
679
    public static boolean getDefaultShowGrid() {
680
        if (defaultShowGrid == null) {
681
            XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
682
            if (xml.contains("DefaultShowLayoutGrid")) {
683
                defaultShowGrid = new Boolean(xml.getBooleanProperty("DefaultShowLayoutGrid"));
684
            }
685
            else {
686
                // factory default is true
687
                defaultShowGrid = new Boolean(true);
688
            }
689
        }
690
        return defaultShowGrid.booleanValue();
691
    }
692

    
693
    public static boolean getDefaultAdjustToGrid() {
694
        if (defaultAdjustToGrid == null) {
695
            XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
696
            if (xml.contains("DefaultEnableLayoutGrid")) {
697
                defaultAdjustToGrid = new Boolean(xml.getBooleanProperty("DefaultEnableLayoutGrid"));
698
            }
699
            else {
700
                // factory default is false
701
                defaultAdjustToGrid = new Boolean(false);
702
            }
703
        }
704
        return defaultAdjustToGrid.booleanValue();
705
    }
706

    
707
    public static boolean getDefaultShowRulers() {
708
        if (defaultShowRulers == null){
709
            XMLEntity xml = PluginServices.getPluginServices("com.iver.cit.gvsig").getPersistentXML();
710
            if (xml.contains("DefaultShowLayoutRules")) {
711
                defaultShowRulers = new Boolean(xml.getBooleanProperty("DefaultShowLayoutRules"));
712
            }
713
            else {
714
                // factory default is true
715
                defaultShowRulers = new Boolean(true);
716
            }
717
        }
718
        return defaultShowRulers.booleanValue();
719
    }
720

    
721
    public static void setDefaultShowGrid(boolean showGrid) {
722
        defaultShowGrid = new Boolean(showGrid);
723
    }
724

    
725
    public static void setDefaultAdjustToGrid(boolean gridEnabled) {
726
        defaultAdjustToGrid = new Boolean(gridEnabled);
727
    }
728

    
729
    public static void setDefaultShowRulers(boolean showRules) {
730
        defaultShowRulers  = new Boolean(showRules);
731
    }
732
}