Statistics
| Revision:

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

History | View | Annotate | Download (26.8 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.gui.beans.swing.JFileChooser;
77

    
78
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
79
import com.iver.andami.PluginServices;
80
import com.iver.andami.messages.NotificationManager;
81
import com.iver.andami.ui.mdiManager.IWindowListener;
82
import com.iver.andami.ui.mdiManager.SingletonWindow;
83
import com.iver.andami.ui.mdiManager.WindowInfo;
84
import com.iver.cit.gvsig.fmap.ColorEvent;
85
import com.iver.cit.gvsig.fmap.ExtentEvent;
86
import com.iver.cit.gvsig.fmap.ProjectionEvent;
87
import com.iver.cit.gvsig.fmap.ViewPortListener;
88
import com.iver.cit.gvsig.fmap.edition.commands.CommandListener;
89
import com.iver.cit.gvsig.fmap.layers.XMLException;
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

    
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, CommandListener {
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.getAtributes().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.getAtributes().setDistanceUnitX(layoutControl.getRect());
192
        layoutContext.getAtributes().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.getAtributes().getAttributes());
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.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(boolean isPrint) {
239
            layoutContext.getAtributes().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(com.iver.cit.gvsig.Print.class));
278
                job.print();
279
            } catch (PrinterException e) {
280
                e.printStackTrace();
281
            }
282
        } else {
283
            // Actualizar attributes
284
            att = layoutContext.getAtributes().toPrintAttributes();
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(com.iver.cit.gvsig.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.getAtributes().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
         * It creates an Object of this class from the information of the XMLEntity.
519
         *
520
         * @param xml
521
         *            XMLEntity
522
         * @param p
523
         *            Project.
524
         *
525
         * @return Object of this class.
526
         * @throws OpenException
527
         */
528
    public static Layout createLayout03(XMLEntity xml, Project p) {
529
        Layout layout = new Layout();
530
        layout.layoutContext.setAdjustToGrid(xml.getBooleanProperty("isCuadricula"));
531
        layout.setName(xml.getStringProperty("m_name"));
532
        layout.getLayoutContext().setAtributes(Attributes.createAtributes03(xml.getChild(0)));
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
        for (int i = 1; i < xml.getChildrenCount(); i++) {
542
            if (!xml.getChild(i).getStringProperty("className").equals(
543
                    "com.iver.cit.gvsig.gui.layout.fframe.FFrameView")) {
544
                layout.layoutContext.addFFrame(FFrame.createFromXML03(xml.getChild(i), p, layout), true, false);
545
            }
546
        }
547

    
548
        return layout;
549
    }
550

    
551
    /**
552
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
553
     */
554
    public void windowActivated() {
555
        //fullRect();
556
        layoutControl.refresh();
557
        PluginServices.getMainFrame().getStatusBar().setMessage("units",
558
                PluginServices.getText(this, layoutContext.getAtributes().getNameUnit()));
559
            // ensure requestFocus is enabled
560
        if(!layoutControl.isRequestFocusEnabled()) {
561
                layoutControl.setRequestFocusEnabled(true);
562
               }
563
        requestFocus();
564
        layoutControl.requestFocus();
565
    }
566

    
567
    /**
568
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
569
     */
570
    public Object getWindowModel() {
571
        return map;
572
    }
573
    /**
574
     * Returns ProjectMap, the model of Layout.
575
     * @return ProjectMap.
576
     */
577
    public ProjectMap getModel() {
578
            return map;
579
    }
580
    /**
581
     * @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
582
     */
583
    public void extentChanged(ExtentEvent e) {
584
    }
585

    
586
    /**
587
     * @see com.iver.andami.ui.mdiManager.IWindowListener#windowClosed()
588
     */
589
    public void windowClosed() {
590
        // /PluginServices.getMainFrame().getStatusBar().setMessage("1","");
591
    }
592

    
593
    /**
594
     * @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
595
     */
596
    public void backColorChanged(ColorEvent e) {
597
        // refresh();
598
    }
599

    
600
    /**
601
     * Opens a dialog where to pick a PDF-file to save the current Layout
602
     * suggesting a name for the file given by the first argument
603
     *
604
     * @param suggestedName
605
     */
606
    public void layoutToPDF(String suggestedName) {
607
        FileFilter pdfFilter = new GenericFileFilter("pdf", PluginServices
608
                .getText(this, "pdf"));
609

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

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

    
620
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
621
                faux = f;
622
            } else {
623
                faux = new File(f.getPath() + ".pdf");
624
            }
625

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

    
639
        JFileChooser jfc = new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
640
        if (suggestedName != null)
641
            jfc.setSelectedFile(new File(suggestedName));
642
        jfc.addChoosableFileFilter(pdfFilter);
643
        jfc.setFileFilter(pdfFilter);
644

    
645
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
646
            File f = jfc.getSelectedFile();
647
            File faux = null;
648

    
649
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
650
                faux = f;
651
            } else {
652
                faux = new File(f.getPath() + ".ps");
653
            }
654

    
655
            layoutControl.getLayoutDraw().toPS(faux);
656
        }
657
    }
658
    /**
659
         * It opens a dialog to select pdf file where to save the Layout in this format.
660
         */
661
    public void layoutToPDF() {
662
        layoutToPDF(null);
663
    }
664
    /**
665
         * It opens a dialog to select ps file where to save the Layout in this format.
666
         */
667
    public void layoutToPS() {
668
        layoutToPS(null);
669
    }
670
    /**
671
         * @return Returns the bShowIconTag.
672
         */
673
    public boolean isShowIconTag() {
674
        return bShowIconTag;
675
    }
676

    
677
    /**
678
     * @param modeDebug
679
     *            The bModeDebug to set.
680
     */
681
    public void setShowIconTag(boolean modeDebug) {
682
        bShowIconTag = modeDebug;
683
    }
684

    
685
    /**
686
         * Repaint the Layout.
687
         */
688
    public void commandRepaint() {
689
        this.layoutContext.updateFFrames();
690
        this.layoutControl.refresh();
691
    }
692
    /**
693
         * Repaint the Layout.
694
         */
695
    public void commandRefresh() {
696
        commandRepaint();
697

    
698
    }
699
    /**
700
         * Event to change the projection.
701
         */
702
    public void projectionChanged(ProjectionEvent e) {
703
        // TODO Auto-generated method stub
704

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

    
779
        public Object getWindowProfile() {
780
                return WindowInfo.EDITOR_PROFILE;
781
        }
782
}