Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / gui / DefaultLayoutPanel.java @ 365

History | View | Annotate | Download (23.4 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.gui;
23

    
24
import java.awt.BorderLayout;
25
import java.awt.Component;
26
import java.awt.Graphics2D;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.geom.AffineTransform;
30
import java.awt.geom.Rectangle2D;
31
import java.awt.print.PageFormat;
32
import java.awt.print.Printable;
33
import java.awt.print.PrinterException;
34
import java.awt.print.PrinterJob;
35
import java.beans.PropertyChangeEvent;
36
import java.beans.PropertyChangeListener;
37
import java.io.File;
38

    
39
import javax.print.Doc;
40
import javax.print.DocFlavor;
41
import javax.print.DocPrintJob;
42
import javax.print.PrintException;
43
import javax.print.PrintService;
44
import javax.print.PrintServiceLookup;
45
import javax.print.ServiceUI;
46
import javax.print.SimpleDoc;
47
import javax.print.attribute.PrintRequestAttributeSet;
48
import javax.print.event.PrintJobAdapter;
49
import javax.print.event.PrintJobEvent;
50
import javax.print.event.PrintJobListener;
51
import javax.swing.JOptionPane;
52
import javax.swing.JPanel;
53
import javax.swing.JSplitPane;
54
import javax.swing.filechooser.FileFilter;
55

    
56
import org.gvsig.andami.PluginServices;
57
import org.gvsig.andami.PluginsLocator;
58
import org.gvsig.andami.messages.NotificationManager;
59
import org.gvsig.andami.ui.mdiManager.IWindowListener;
60
import org.gvsig.andami.ui.mdiManager.WindowInfo;
61
import org.gvsig.app.ApplicationLocator;
62
import org.gvsig.app.gui.preferencespage.PreferenceKeys;
63
import org.gvsig.app.project.documents.Document;
64
import org.gvsig.app.project.documents.gui.WindowLayout;
65
import org.gvsig.app.project.documents.layout.DefaultLayoutControl;
66
import org.gvsig.app.project.documents.layout.DefaultLayoutDocument;
67
import org.gvsig.app.project.documents.layout.LayoutContext;
68
import org.gvsig.app.project.documents.layout.LayoutControl;
69
import org.gvsig.app.project.documents.layout.LayoutDocument;
70
import org.gvsig.app.project.documents.layout.LayoutManager;
71
import org.gvsig.app.project.documents.layout.TocModelChangedNotification;
72
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
73
import org.gvsig.app.project.documents.layout.fframes.IFFrameUseFMap;
74
import org.gvsig.app.project.documents.layout.fframes.LayoutPanelListener;
75
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
76
import org.gvsig.app.project.documents.layout.gui.dialogs.FConfigLayoutDialog;
77
import org.gvsig.app.project.documents.layout.toc.TocModelObserver;
78
import org.gvsig.app.project.documents.view.toc.gui.TOC;
79
import org.gvsig.fmap.mapcontext.MapContext;
80
import org.gvsig.fmap.mapcontext.events.ColorEvent;
81
import org.gvsig.gui.beans.swing.JFileChooser;
82
import org.gvsig.tools.ToolsLocator;
83
import org.gvsig.tools.dynobject.DynStruct;
84
import org.gvsig.tools.observer.Observable;
85
import org.gvsig.tools.persistence.PersistenceManager;
86
import org.gvsig.tools.persistence.PersistentState;
87
import org.gvsig.tools.persistence.exception.PersistenceException;
88
import org.gvsig.utils.GenericFileFilter;
89
import org.gvsig.utils.XMLEntity;
90

    
91
/**
92
 * Graphic representation of the elements to print.
93
 * 
94
 * @author Vicente Caballero Navarro
95
 */
96
public class DefaultLayoutPanel extends LayoutPanel {
97

    
98
    private static final long serialVersionUID = 916830228032567624L;
99

    
100
    private static final int DEFAULT_HEIGHT = 450;
101

    
102
    private static final int DEFAULT_WIDTH = 700;
103

    
104
    public static final String PERSISTENCE_DEFINITION_NAME = "LayoutPanel";
105
    private static final String LAYOUTCONTEXT_OBJECT = "LayoutContext";
106
    private static final String LAYOUTDOCUMENT_OBJECT = "LayoutDocument";
107

    
108
    public static final String PDF_AND_PS_FILECHOOSER =
109
        "PDF_AND_PS_FILECHOOSER";
110

    
111
    public static File defaultPDFFolderPath;
112

    
113
    private MapProperties m_propertiesLayout = null;
114
    private PrintService[] m_cachePrintServices = null;
115
    private PrintService m_cachePrintService = null;
116
    private LayoutDocument layoutDocument = null;
117
    private Doc doc = null;
118
    private PrintRequestAttributeSet att = null;
119
    private WindowInfo m_viewInfo = null;
120
    /**
121
     * We use it when we are doing a layout and assigning tags.
122
     * It is put in debug when we do a VIEW_TAGS
123
     */
124
    private boolean bShowIconTag = false;
125
    private LayoutControl layoutControl = null;
126
    private LayoutContext layoutContext = null;
127
    private LayoutManager layoutManager = null;
128
        private JPanel leftPanel;
129
        private TOC toc = null;
130

    
131
        private JSplitPane splitPane;
132
        private int lastPanePos = 150;
133

    
134
        private Boolean b_isTocEnabled = null;
135

    
136
    /**
137
     * Creates a new Layout object.
138
     */
139
    public DefaultLayoutPanel() {
140
        DefaultLayoutControl defaultLayoutControl = new DefaultLayoutControl();
141
        this.layoutControl = defaultLayoutControl;
142
        defaultLayoutControl.initialize(this);       
143
        this.initComponents();
144
    }
145

    
146
    public void setDocument(Document document) {
147
        layoutDocument = (LayoutDocument) document;
148
        setLayoutContext(layoutDocument.getLayoutContext());
149
        this.setName(document.getName());
150
        layoutDocument.addPropertyChangeListener(new PropertyChangeListener() {
151

    
152
            public void propertyChange(PropertyChangeEvent evt) {
153
                if (evt.getPropertyName().equals("name")) {
154
                    PluginServices
155
                        .getMDIManager()
156
                        .getWindowInfo(DefaultLayoutPanel.this)
157
                        .setTitle(
158
                            PluginServices.getText(this, "Mapa") + " : "
159
                                + (String) evt.getNewValue());
160
                }
161
            }
162
        });
163
        
164
        setToc();
165
    }
166
  
167
    /**
168
     * It initializes the components.
169
     */
170
    private void initComponents() {
171
            this.setLayout(new BorderLayout());
172
            if (isTocEnabled()) {
173
                    leftPanel = new JPanel(new BorderLayout());
174
                    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
175
                                    leftPanel, layoutControl.getComponent());
176
                    splitPane.setResizeWeight(0.2);
177
                    splitPane.setOneTouchExpandable(true);
178
                    splitPane.setContinuousLayout(true);
179
                    setToc();
180
                    add(splitPane, BorderLayout.CENTER);
181
            }
182
            else {
183
                    add(layoutControl.getComponent(), BorderLayout.CENTER);
184
            }
185
        layoutControl.getComponent().setDoubleBuffered(true);
186
    }
187
    
188
    private boolean isTocEnabled() {
189
            if (b_isTocEnabled==null) {
190
                    XMLEntity entity = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
191
                    if (entity.contains(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME)) {
192
                            b_isTocEnabled = entity.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_LAYOUT_TOC_KEY_NAME);
193
                    }
194
                    else {
195
                            b_isTocEnabled = PreferenceKeys.FACTORY_DEFAULT_SHOW_LAYOUT_TOC;
196
                    }
197
            }
198
            return b_isTocEnabled;
199
    }
200
    
201
    protected void createToc() {
202
                if (toc==null) {
203
                        toc = new TOC();
204
                }
205
                toc.setMapContext(getLayoutContext().getTocModel());
206
                leftPanel.removeAll();
207
                leftPanel.add(toc);
208
    }
209
    
210
    protected void setToc() {
211
            if (isTocEnabled()) {
212
                    if (getLayoutContext()!=null) {
213
                            if (getLayoutContext().getTocModel()!=null) {
214
                                    createToc();
215
                            }
216
                            else if (toc!=null) {
217
                                    DefaultLayoutPanel.this.leftPanel.remove(toc);
218
                            }
219

    
220
                            this.getLayoutContext().addTocObserver(new TocModelObserver() {
221

    
222
                                    public void tocUpdated(Object observable,
223
                                                    TocModelChangedNotification notification) {
224
                                            if (TocModelChangedNotification.Type.ITEM_UPDATED==notification.getType()) {
225
                                                    if (DefaultLayoutPanel.this.toc!=null){
226
                                                            DefaultLayoutPanel.this.toc.repaint();
227
                                                    }
228
                                            }
229
                                            else if (TocModelChangedNotification.Type.MODEL_CHANGED==notification.getType()) {
230
                                                    if (DefaultLayoutPanel.this.toc!=null){
231
                                                            DefaultLayoutPanel.this.toc.refresh();
232
                                                    }
233
                                            }
234
                                            else if (TocModelChangedNotification.Type.MODEL_SET==notification.getType()) {
235
                                                    MapContext mapContext = notification.getModel();
236
                                                    if (mapContext!=null) {
237
                                                            createToc();
238
                                                    }
239
                                                    else if (DefaultLayoutPanel.this.toc!=null){
240
                                                            DefaultLayoutPanel.this.leftPanel.remove(DefaultLayoutPanel.this.toc);
241
                                                            DefaultLayoutPanel.this.leftPanel.repaint();
242
                                                    }
243
                                            }
244
                                    }
245
                            });
246
                    }
247
            }
248
    }
249

    
250
    /**
251
     * Open the dialog of Layout properties.
252
     * 
253
     * @param job
254
     *            PrinterJob
255
     */
256
    public void showPagePropertiesWindow(PrinterJob job) {
257
        PageFormat pf1;
258

    
259
        pf1 = layoutContext.getAttributes().getPageFormat();
260
        pf1 = job.pageDialog(pf1);
261
        layoutContext.getAttributes().setPageFormat(pf1);
262
        layoutControl.refresh();
263
    }
264

    
265
    public void obtainRect(boolean isPrint) {
266
            Rectangle2D r = layoutControl.getRect(); 
267
        layoutContext.getAttributes().obtainRect(isPrint,
268
            r, getWidth(), getHeight());
269
        layoutControl.setRect(r);
270
    }
271
    
272
    public void showFConfig() {
273
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
274
        PluginServices.getMDIManager().addCentredWindow(m_configLayout);
275
    }
276

    
277
    public boolean showFProperties() {
278
        if (layoutDocument == null) {
279
            layoutDocument = new DefaultLayoutDocument();
280
            layoutDocument.setName(getName());
281
        }
282

    
283
        m_propertiesLayout = new MapProperties(layoutDocument);
284
        PluginServices.getMDIManager().addWindow(m_propertiesLayout);
285
        return m_propertiesLayout.isAccepted();
286
    }
287

    
288
    public void showPrintDialog(PrinterJob job) {
289
        if (job != null) {
290
            job.printDialog();
291

    
292
            try {
293
                job.setPrintable((Printable) PluginServices
294
                    .getExtension(org.gvsig.app.extension.Print.class));
295
                job.print();
296
            } catch (PrinterException e) {
297
                e.printStackTrace();
298
            }
299
        } else {
300
            // Actualizar attributes
301
            att = layoutContext.getAttributes().toPrintRequestAttributeSet();
302

    
303
            // ------------------ The Printing things --------------------- //
304
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
305

    
306
            // returns the set of printers that support printing a specific
307
            // document type (such as GIF)
308
            // with a specific set of attributes (such as two sided).
309
            // PrintRequestAttributeSet pras = new
310
            // HashPrintRequestAttributeSet();
311
            // interestingly, the printer dialog's default behavior has changed
312
            // with the new API: by default the dialog is not shown.
313
            // So we must use the ServiceUI class to create a print dialog
314
            // returns the default print service.
315
            if (m_cachePrintServices == null) {
316
                m_cachePrintServices =
317
                    PrintServiceLookup.lookupPrintServices(flavor, null);
318
            }
319

    
320
            PrintService defaultService = null;
321

    
322
            if (m_cachePrintService == null) {
323
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
324
            }
325

    
326
            if ((defaultService == null) && (m_cachePrintService == null)) {
327
                JOptionPane.showMessageDialog((Component) PluginServices
328
                    .getMainFrame(), PluginServices.getText(this,
329
                    "ninguna_impresora_configurada"));
330

    
331
                return;
332
            }
333

    
334
            if (m_cachePrintService == null) {
335
                m_cachePrintService =
336
                    ServiceUI.printDialog(null, 200, 200, m_cachePrintServices,
337
                        defaultService, flavor, att);
338
            } else {
339
                m_cachePrintService =
340
                    ServiceUI.printDialog(null, 200, 200, m_cachePrintServices,
341
                        m_cachePrintService, flavor, att);
342
            }
343

    
344
            if (m_cachePrintService != null) {
345
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
346
                PrintJobListener pjlistener = new PrintJobAdapter() {
347

    
348
                    public void printDataTransferCompleted(PrintJobEvent e) {
349
                        // System.out.println("Fin de impresi?n");
350
                        layoutControl.fullRect();
351
                    }
352
                };
353

    
354
                jobNuevo.addPrintJobListener(pjlistener);
355

    
356
                Printable pb = null;
357
                Class repClass = null;
358
                try {
359
                     repClass = Class.forName(flavor.getRepresentationClassName());
360
                } catch (Throwable e) {
361
                    throw new IllegalArgumentException("unknown representation class");
362
                }
363

    
364
                Object printData = PluginServices.getExtension(org.gvsig.app.extension.Print.class);
365
                
366
                doc = new SimpleDoc(printData, flavor, null);
367

    
368
                try {
369
                    jobNuevo.print(doc, att);
370

    
371
                } catch (PrintException pe) {
372
                    NotificationManager.addError(pe);
373
                }
374
            }
375
        }
376
    }
377

    
378
    public IFFrameDialog createFFrameDialog(IFFrame fframe) {
379
        return layoutManager.createFFrameDialog(fframe, this);
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 =
394
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.RESIZABLE
395
                    | WindowInfo.MAXIMIZABLE);
396
            m_viewInfo.setWidth(DEFAULT_WIDTH);
397
            m_viewInfo.setHeight(DEFAULT_HEIGHT);
398

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

    
405
    public LayoutContext getLayoutContext() {
406
        return layoutContext;
407
    }
408

    
409
    public LayoutControl getLayoutControl() {
410
        return layoutControl;
411
    }
412
    
413
    private boolean isInitConfigDialogEnabled() {
414
            XMLEntity entity = PluginsLocator.getManager().getPlugin(this).getPersistentXML();
415
            if (entity.contains(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME)) {
416
                    return entity.getBooleanProperty(PreferenceKeys.DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_KEY_NAME);
417
            }
418
            else {
419
                    return PreferenceKeys.FACTORY_DEFAULT_SHOW_INITIAL_CONFIG_DIALOG_FOR_LAYOUT;
420
            }
421
    }
422

    
423
    
424
    protected void onInitialConfigCanceled() {
425
            if (layoutDocument!=null) {
426
                    ApplicationLocator.getManager().getUIManager().closeWindow(this);
427
                    ApplicationLocator.getProjectManager().getCurrentProject().removeDocument(layoutDocument);
428
            }
429
    }
430
    
431
    /**
432
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
433
     */
434
    public void windowActivated() {
435
                if (getLayoutContext()!=null && !getLayoutContext().hasDocBeenOpened()) {
436
                        getLayoutContext().setHasDocBeenOpened(true);
437
            if (isInitConfigDialogEnabled()) {
438
                    FConfigLayoutDialog configDialog = new FConfigLayoutDialog(this, true);
439
                    ApplicationLocator.getManager().getUIManager().addCentredWindow(configDialog);
440
                    configDialog.addCancelButtonActionListener(new ActionListener() {
441

    
442
                                        public void actionPerformed(ActionEvent e) {
443
                                                DefaultLayoutPanel.this.onInitialConfigCanceled();
444
                                        }
445
                            
446
                    });
447
            }
448
            
449
            }
450
                if (layoutControl.getRect().getWidth()<=0) {
451
                        layoutControl.fullRect();
452
                }
453
                else {
454
                        layoutControl.refresh();
455
                }
456
        PluginServices
457
            .getMainFrame()
458
            .getStatusBar()
459
            .setMessage(
460
                "units",
461
                PluginServices.getText(this, layoutContext.getAttributes()
462
                    .getNameUnit()));
463
        // ensure requestFocus is enabled
464
        if (!layoutControl.getComponent().isRequestFocusEnabled()) {
465
            layoutControl.getComponent().setRequestFocusEnabled(true);
466
        }
467
        // notify fframes
468
            IFFrame[] frames = layoutContext.getFFrames();
469
            for (int i=0; i<frames.length; i++) {
470
                    if (frames[i] instanceof LayoutPanelListener) {
471
                            ((LayoutPanelListener)frames[i]).windowActivated();
472
                    }
473
            }
474
        requestFocus();
475
        layoutControl.getComponent().requestFocus();
476
    }
477

    
478
    /**
479
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
480
     */
481
    public Object getWindowModel() {
482
        return layoutDocument;
483
    }
484

    
485
    public Document getDocument() {
486
        return layoutDocument;
487
    }
488

    
489
    /**
490
     * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
491
     */
492
    public void windowClosed() {
493
            IFFrame[] frames = layoutContext.getFFrames();
494
            for (int i=0; i<frames.length; i++) {
495
                    if (frames[i] instanceof LayoutPanelListener) {
496
                            ((LayoutPanelListener)frames[i]).windowClosed();
497
                    }
498
            }
499
    }
500

    
501
    /**
502
     * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
503
     */
504
    public void backColorChanged(ColorEvent e) {
505
        // refresh();
506
    }
507

    
508
    public void layoutToPDF(String suggestedName) {
509
        FileFilter pdfFilter =
510
            new GenericFileFilter("pdf", PluginServices.getText(this, "pdf"));
511

    
512
        JFileChooser jfc =
513
            new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
514
        if (suggestedName != null) {
515
            jfc.setSelectedFile(new File(suggestedName));
516
        }
517
        jfc.addChoosableFileFilter(pdfFilter);
518
        jfc.setFileFilter(pdfFilter);
519

    
520
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
521
            File f = jfc.getSelectedFile();
522
            File faux = null;
523

    
524
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
525
                faux = f;
526
            } else {
527
                faux = new File(f.getPath() + ".pdf");
528
            }
529

    
530
            layoutControl.getLayoutDraw().toPDF(faux);
531
        }
532
    }
533

    
534
    public void layoutToPS(String suggestedName) {
535
        FileFilter pdfFilter =
536
            new GenericFileFilter("ps", PluginServices.getText(this, "ps"));
537

    
538
        JFileChooser jfc =
539
            new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
540
        if (suggestedName != null) {
541
            jfc.setSelectedFile(new File(suggestedName));
542
        }
543
        jfc.addChoosableFileFilter(pdfFilter);
544
        jfc.setFileFilter(pdfFilter);
545

    
546
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
547
            File f = jfc.getSelectedFile();
548
            File faux = null;
549

    
550
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
551
                faux = f;
552
            } else {
553
                faux = new File(f.getPath() + ".ps");
554
            }
555

    
556
            layoutControl.getLayoutDraw().toPS(faux);
557
        }
558
    }
559

    
560
    public void layoutToPDF() {
561
        layoutToPDF(null);
562
    }
563

    
564
    public void layoutToPS() {
565
        layoutToPS(null);
566
    }
567

    
568
    public boolean isShowIconTag() {
569
        return bShowIconTag;
570
    }
571

    
572
    public void setShowIconTag(boolean modeDebug) {
573
        bShowIconTag = modeDebug;
574
    }
575

    
576
    public void update(Observable observable, Object notification) {
577
            this.layoutContext.updateFFrames();
578
            this.layoutControl.refresh();
579
    }
580

    
581
    public Object getWindowProfile() {
582
        return WindowInfo.EDITOR_PROFILE;
583
    }
584

    
585
    public void saveToState(PersistentState state) throws PersistenceException {
586
        state.set(LAYOUTCONTEXT_OBJECT, layoutContext);
587
        state.set(LAYOUTDOCUMENT_OBJECT, layoutDocument);
588
    }
589

    
590
    public void loadFromState(PersistentState state)
591
        throws PersistenceException {
592
        this.layoutContext = (LayoutContext) state.get(LAYOUTCONTEXT_OBJECT);
593
        this.setDocument((LayoutDocument) state.get(LAYOUTDOCUMENT_OBJECT));
594
    }
595

    
596
    public static void registerPersistent() {
597
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
598
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
599
            DynStruct definition =
600
                manager.addDefinition(DefaultLayoutPanel.class,
601
                    PERSISTENCE_DEFINITION_NAME,
602
                    "Layout panel persistence definition", null, null);
603

    
604
            definition.addDynFieldObject(LAYOUTCONTEXT_OBJECT)
605
                .setClassOfValue(LayoutContext.class).setMandatory(true);
606
            definition.addDynFieldObject(LAYOUTDOCUMENT_OBJECT)
607
                .setClassOfValue(LayoutDocument.class).setMandatory(true);
608
        }
609
    }
610

    
611
    public WindowLayout getWindowLayout() {
612
        return null;
613
    }
614

    
615
    public void setWindowLayout(WindowLayout layout) {
616

    
617
    }
618

    
619
    private void setLayoutContext(LayoutContext theLayoutcontext) {
620
        this.layoutContext = theLayoutcontext;
621
        this.layoutControl.setLayoutContext(theLayoutcontext);
622
        layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect());
623
        layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect());
624
        layoutControl.setDefaultTool();
625
    }
626

    
627
    @Override
628
    public void setLayoutManager(LayoutManager layoutManager) {
629
        this.layoutManager = layoutManager;
630
    }
631
    
632
    
633
    /**
634
     * Method to print the Layout without modify the Affinetransform.
635
     *
636
     * @param g2 Geaphics2D
637
     */
638
    public void drawLayoutPrint(Graphics2D g2) {
639
        layoutControl.setCancelDrawing(false);
640

    
641
        double scale = 0;
642
        scale = layoutControl.getRect().height / layoutContext.getAttributes().m_sizePaper.getHeight() * 1;
643
        AffineTransform escalado = new AffineTransform();
644
        AffineTransform translacion = new AffineTransform();
645
        translacion.setToTranslation(layoutControl.getRect().getMinX(), layoutControl.getRect().getMinY());
646
        escalado.setToScale(scale, scale);
647
        layoutControl.getAT().setToIdentity();
648
        layoutControl.getAT().concatenate(translacion);
649
        layoutControl.getAT().concatenate(escalado);
650
        layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect());
651
        layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect());
652
        IFFrame[] fframes=layoutContext.getFFrames();
653
        
654
        for (int i = 0; i < fframes.length; i++) {
655
            fframes[i].print(
656
                g2,
657
                layoutControl.getAT(),
658
                null,
659
                layoutContext.getAttributes().toPrintAttributes());
660
        }
661
    }
662
        
663
        public void hideToc() {
664
                if (isTocEnabled()) {
665
                        lastPanePos = splitPane.getDividerLocation();
666
                        splitPane.setDividerLocation(0);
667
                }
668
        }
669

    
670
        public void showToc() {
671
                if (isTocEnabled()) {
672
                        splitPane.setDividerLocation(lastPanePos);
673
                }
674
        }
675

    
676
}