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 @ 326

History | View | Annotate | Download (23.2 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.print.PageFormat;
31
import java.awt.print.Printable;
32
import java.awt.print.PrinterException;
33
import java.awt.print.PrinterJob;
34
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
36
import java.io.File;
37

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

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

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

    
97
    private static final long serialVersionUID = 916830228032567624L;
98

    
99
    private static final int DEFAULT_HEIGHT = 450;
100

    
101
    private static final int DEFAULT_WIDTH = 700;
102

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

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

    
110
    public static File defaultPDFFolderPath;
111

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

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

    
133
        private Boolean b_isTocEnabled = null;
134

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

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

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

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

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

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

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

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

    
274
    public boolean showFProperties() {
275
        if (layoutDocument == null) {
276
            layoutDocument = new DefaultLayoutDocument();
277
            layoutDocument.setName(getName());
278
        }
279

    
280
        m_propertiesLayout = new MapProperties(layoutDocument);
281
        PluginServices.getMDIManager().addWindow(m_propertiesLayout);
282
        return m_propertiesLayout.isAccepted();
283
    }
284

    
285
    public void showPrintDialog(PrinterJob job) {
286
        if (job != null) {
287
            job.printDialog();
288

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

    
300
            // ------------------ The Printing things --------------------- //
301
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
302

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

    
317
            PrintService defaultService = null;
318

    
319
            if (m_cachePrintService == null) {
320
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
321
            }
322

    
323
            if ((defaultService == null) && (m_cachePrintService == null)) {
324
                JOptionPane.showMessageDialog((Component) PluginServices
325
                    .getMainFrame(), PluginServices.getText(this,
326
                    "ninguna_impresora_configurada"));
327

    
328
                return;
329
            }
330

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

    
341
            if (m_cachePrintService != null) {
342
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
343
                PrintJobListener pjlistener = new PrintJobAdapter() {
344

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

    
351
                jobNuevo.addPrintJobListener(pjlistener);
352

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

    
361
                Object printData = PluginServices.getExtension(org.gvsig.app.extension.Print.class);
362
                
363
                doc = new SimpleDoc(printData, flavor, null);
364

    
365
                try {
366
                    jobNuevo.print(doc, att);
367

    
368
                } catch (PrintException pe) {
369
                    NotificationManager.addError(pe);
370
                }
371
            }
372
        }
373
    }
374

    
375
    public IFFrameDialog createFFrameDialog(IFFrame fframe) {
376
        return layoutManager.createFFrameDialog(fframe, this);
377
    }
378

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

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

    
402
    public LayoutContext getLayoutContext() {
403
        return layoutContext;
404
    }
405

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

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

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

    
469
    /**
470
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
471
     */
472
    public Object getWindowModel() {
473
        return layoutDocument;
474
    }
475

    
476
    public Document getDocument() {
477
        return layoutDocument;
478
    }
479

    
480
    /**
481
     * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
482
     */
483
    public void windowClosed() {
484
            IFFrame[] frames = layoutContext.getFFrames();
485
            for (int i=0; i<frames.length; i++) {
486
                    if (frames[i] instanceof LayoutPanelListener) {
487
                            ((LayoutPanelListener)frames[i]).windowClosed();
488
                    }
489
            }
490
    }
491

    
492
    /**
493
     * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
494
     */
495
    public void backColorChanged(ColorEvent e) {
496
        // refresh();
497
    }
498

    
499
    public void layoutToPDF(String suggestedName) {
500
        FileFilter pdfFilter =
501
            new GenericFileFilter("pdf", PluginServices.getText(this, "pdf"));
502

    
503
        JFileChooser jfc =
504
            new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
505
        if (suggestedName != null) {
506
            jfc.setSelectedFile(new File(suggestedName));
507
        }
508
        jfc.addChoosableFileFilter(pdfFilter);
509
        jfc.setFileFilter(pdfFilter);
510

    
511
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
512
            File f = jfc.getSelectedFile();
513
            File faux = null;
514

    
515
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
516
                faux = f;
517
            } else {
518
                faux = new File(f.getPath() + ".pdf");
519
            }
520

    
521
            layoutControl.getLayoutDraw().toPDF(faux);
522
        }
523
    }
524

    
525
    public void layoutToPS(String suggestedName) {
526
        FileFilter pdfFilter =
527
            new GenericFileFilter("ps", PluginServices.getText(this, "ps"));
528

    
529
        JFileChooser jfc =
530
            new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
531
        if (suggestedName != null) {
532
            jfc.setSelectedFile(new File(suggestedName));
533
        }
534
        jfc.addChoosableFileFilter(pdfFilter);
535
        jfc.setFileFilter(pdfFilter);
536

    
537
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
538
            File f = jfc.getSelectedFile();
539
            File faux = null;
540

    
541
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
542
                faux = f;
543
            } else {
544
                faux = new File(f.getPath() + ".ps");
545
            }
546

    
547
            layoutControl.getLayoutDraw().toPS(faux);
548
        }
549
    }
550

    
551
    public void layoutToPDF() {
552
        layoutToPDF(null);
553
    }
554

    
555
    public void layoutToPS() {
556
        layoutToPS(null);
557
    }
558

    
559
    public boolean isShowIconTag() {
560
        return bShowIconTag;
561
    }
562

    
563
    public void setShowIconTag(boolean modeDebug) {
564
        bShowIconTag = modeDebug;
565
    }
566

    
567
    public void update(Observable observable, Object notification) {
568
            this.layoutContext.updateFFrames();
569
            this.layoutControl.refresh();
570
    }
571

    
572
    public Object getWindowProfile() {
573
        return WindowInfo.EDITOR_PROFILE;
574
    }
575

    
576
    public void saveToState(PersistentState state) throws PersistenceException {
577
        state.set(LAYOUTCONTEXT_OBJECT, layoutContext);
578
        state.set(LAYOUTDOCUMENT_OBJECT, layoutDocument);
579
    }
580

    
581
    public void loadFromState(PersistentState state)
582
        throws PersistenceException {
583
        this.layoutContext = (LayoutContext) state.get(LAYOUTCONTEXT_OBJECT);
584
        this.setDocument((LayoutDocument) state.get(LAYOUTDOCUMENT_OBJECT));
585
    }
586

    
587
    public static void registerPersistent() {
588
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
589
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
590
            DynStruct definition =
591
                manager.addDefinition(DefaultLayoutPanel.class,
592
                    PERSISTENCE_DEFINITION_NAME,
593
                    "Layout panel persistence definition", null, null);
594

    
595
            definition.addDynFieldObject(LAYOUTCONTEXT_OBJECT)
596
                .setClassOfValue(LayoutContext.class).setMandatory(true);
597
            definition.addDynFieldObject(LAYOUTDOCUMENT_OBJECT)
598
                .setClassOfValue(LayoutDocument.class).setMandatory(true);
599
        }
600
    }
601

    
602
    public WindowLayout getWindowLayout() {
603
        return null;
604
    }
605

    
606
    public void setWindowLayout(WindowLayout layout) {
607

    
608
    }
609

    
610
    private void setLayoutContext(LayoutContext theLayoutcontext) {
611
        this.layoutContext = theLayoutcontext;
612
        this.layoutControl.setLayoutContext(theLayoutcontext);
613
        layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect());
614
        layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect());
615
        layoutControl.setDefaultTool();
616
    }
617

    
618
    @Override
619
    public void setLayoutManager(LayoutManager layoutManager) {
620
        this.layoutManager = layoutManager;
621
    }
622
    
623
    
624
    /**
625
     * Method to print the Layout without modify the Affinetransform.
626
     *
627
     * @param g2 Geaphics2D
628
     */
629
    public void drawLayoutPrint(Graphics2D g2) {
630
        layoutControl.setCancelDrawing(false);
631

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

    
661
        public void showToc() {
662
                if (isTocEnabled()) {
663
                        splitPane.setDividerLocation(lastPanePos);
664
                }
665
        }
666

    
667
}