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

History | View | Annotate | Download (22.8 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.GridBagConstraints;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.geom.AffineTransform;
31
import java.awt.geom.Rectangle2D;
32
import java.awt.print.PageFormat;
33
import java.awt.print.Printable;
34
import java.awt.print.PrinterException;
35
import java.awt.print.PrinterJob;
36
import java.beans.PropertyChangeEvent;
37
import java.beans.PropertyChangeListener;
38
import java.io.File;
39
import java.util.Collections;
40

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

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

    
97
/**
98
 * Layout document window 
99
 * 
100
 * 
101
 * @author Vicente Caballero Navarro
102
 */
103
public class DefaultLayoutPanel extends LayoutPanel {
104

    
105
    private static final long serialVersionUID = 916830228032567624L;
106

    
107
    private static final int DEFAULT_HEIGHT = 450;
108

    
109
    private static final int DEFAULT_WIDTH = 700;
110

    
111
    public static final String PERSISTENCE_DEFINITION_NAME = "LayoutPanel";
112
    private static final String LAYOUTCONTEXT_OBJECT = "LayoutContext";
113
    private static final String LAYOUTDOCUMENT_OBJECT = "LayoutDocument";
114

    
115
    public static final String PDF_AND_PS_FILECHOOSER =
116
        "PDF_AND_PS_FILECHOOSER";
117

    
118
    public static File defaultPDFFolderPath;
119

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

    
138
        private JSplitPane splitPane;
139
        private int lastPanePos = 150;
140

    
141
        private Boolean b_isTocEnabled = null;
142

    
143
    /**
144
     * Creates a new Layout object.
145
     */
146
    public DefaultLayoutPanel() {
147
        DefaultLayoutControl defaultLayoutControl = new DefaultLayoutControl();
148
        this.layoutControl = defaultLayoutControl;
149
        defaultLayoutControl.initialize(this);       
150
        this.initComponents();
151
    }
152

    
153
    public void setDocument(Document document) {
154
        layoutDocument = (LayoutDocument) document;
155
        setLayoutContext(layoutDocument.getLayoutContext());
156
        this.setName(document.getName());
157
        layoutDocument.addPropertyChangeListener(new PropertyChangeListener() {
158

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

    
227
                            this.getLayoutContext().addTocObserver(new TocModelObserver() {
228

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

    
257
    /**
258
     * Open the dialog of Layout properties.
259
     * 
260
     * @param job
261
     *            PrinterJob
262
     */
263
    public void showPagePropertiesWindow(PrinterJob job) {
264
        PageFormat pf1;
265

    
266
        pf1 = layoutContext.getAttributes().getPageFormat();
267
        pf1 = job.pageDialog(pf1);
268
        layoutContext.getAttributes().setPageFormat(pf1);
269
        layoutControl.refresh();
270
    }
271

    
272
    public void obtainRect(boolean isPrint) {
273
            Rectangle2D r = layoutControl.getRect(); 
274
        layoutContext.getAttributes().obtainRect(isPrint,
275
            r, getWidth(), getHeight());
276
        layoutControl.setRect(r);
277
    }
278
    
279
    public void showFConfig() {
280
        FConfigLayoutDialog m_configLayout = new FConfigLayoutDialog(this);
281
        I18nManager i18n = ToolsLocator.getI18nManager();
282
        ((WindowManager_v2)ToolsSwingLocator.getWindowManager()).showWindow(
283
                m_configLayout,
284
                i18n.getTranslation("Preparar_pagina"),
285
                WindowManager.MODE.WINDOW,
286
                Collections.singletonMap("align", GridBagConstraints.CENTER)
287
        );
288
    }
289

    
290
    public boolean showFProperties() {
291
        if (layoutDocument == null) {
292
            layoutDocument = new DefaultLayoutDocument();
293
            layoutDocument.setName(getName());
294
        }
295

    
296
        m_propertiesLayout = new MapProperties(layoutDocument);
297
        PluginServices.getMDIManager().addWindow(m_propertiesLayout);
298
        return m_propertiesLayout.isAccepted();
299
    }
300

    
301
    public void showPrintDialog(PrinterJob job) {
302
        if (job != null) {
303
            job.printDialog();
304

    
305
            try {
306
                job.setPrintable((Printable) PluginServices
307
                    .getExtension(org.gvsig.app.extension.Print.class));
308
                job.print();
309
            } catch (PrinterException e) {
310
                e.printStackTrace();
311
            }
312
        } else {
313
            // Actualizar attributes
314
            att = layoutContext.getAttributes().toPrintRequestAttributeSet();
315

    
316
            // ------------------ The Printing things --------------------- //
317
            DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
318

    
319
            // returns the set of printers that support printing a specific
320
            // document type (such as GIF)
321
            // with a specific set of attributes (such as two sided).
322
            // PrintRequestAttributeSet pras = new
323
            // HashPrintRequestAttributeSet();
324
            // interestingly, the printer dialog's default behavior has changed
325
            // with the new API: by default the dialog is not shown.
326
            // So we must use the ServiceUI class to create a print dialog
327
            // returns the default print service.
328
            if (m_cachePrintServices == null) {
329
                m_cachePrintServices =
330
                    PrintServiceLookup.lookupPrintServices(flavor, null);
331
            }
332

    
333
            PrintService defaultService = null;
334

    
335
            if (m_cachePrintService == null) {
336
                defaultService = PrintServiceLookup.lookupDefaultPrintService();
337
            }
338

    
339
//            if ((defaultService == null) && (m_cachePrintService == null)) {
340
//                JOptionPane.showMessageDialog((Component) PluginServices
341
//                    .getMainFrame(), PluginServices.getText(this,
342
//                    "ninguna_impresora_configurada"));
343
//
344
//                return;
345
//            }
346

    
347
            if (m_cachePrintService == null) {
348
                m_cachePrintService = 
349
                    ServiceUI.printDialog(null, 200, 200, m_cachePrintServices,
350
                        defaultService, flavor, att);
351
            } else {
352
                m_cachePrintService =
353
                    ServiceUI.printDialog(null, 200, 200, m_cachePrintServices,
354
                        m_cachePrintService, flavor, att);
355
            }
356

    
357
            if (m_cachePrintService != null) {
358
                DocPrintJob jobNuevo = m_cachePrintService.createPrintJob();
359
                PrintJobListener pjlistener = new PrintJobAdapter() {
360

    
361
                    public void printDataTransferCompleted(PrintJobEvent e) {
362
                        // System.out.println("Fin de impresi?n");
363
                        layoutControl.fullRect();
364
                    }
365
                };
366

    
367
                jobNuevo.addPrintJobListener(pjlistener);
368

    
369
                Printable pb = null;
370
                Class repClass = null;
371
                try {
372
                     repClass = Class.forName(flavor.getRepresentationClassName());
373
                } catch (Throwable e) {
374
                    throw new IllegalArgumentException("unknown representation class");
375
                }
376

    
377
                Object printData = PluginServices.getExtension(org.gvsig.app.extension.Print.class);
378
                
379
                doc = new SimpleDoc(printData, flavor, null);
380

    
381
                try {
382
                    jobNuevo.print(doc, att);
383

    
384
                } catch (PrintException pe) {
385
                    NotificationManager.addError(pe);
386
                }
387
            }
388
        }
389
    }
390

    
391
    public IFFrameDialog createFFrameDialog(IFFrame fframe) {
392
        return layoutManager.createFFrameDialog(fframe, this);
393
    }
394

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

    
412
            m_viewInfo.setTitle(PluginServices.getText(this, "Mapa") + " : "
413
                + layoutDocument.getName());
414
        }
415
        return m_viewInfo;
416
    }
417

    
418
    public LayoutContext getLayoutContext() {
419
        return layoutContext;
420
    }
421

    
422
    public LayoutControl getLayoutControl() {
423
        return layoutControl;
424
    }
425
    
426
    /**
427
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
428
     */
429
    public void windowActivated() {
430
                if (layoutControl.getRect().getWidth()<=0) {
431
                        layoutControl.fullRect();
432
                }
433
                else {
434
                        layoutControl.refresh();
435
                }
436
        PluginServices
437
            .getMainFrame()
438
            .getStatusBar()
439
            .setMessage(
440
                "units",
441
                PluginServices.getText(this, layoutContext.getAttributes()
442
                    .getNameUnit()));
443
        // ensure requestFocus is enabled
444
        if (!layoutControl.getComponent().isRequestFocusEnabled()) {
445
            layoutControl.getComponent().setRequestFocusEnabled(true);
446
        }
447
        // notify fframes
448
            IFFrame[] frames = layoutContext.getFFrames();
449
            for (int i=0; i<frames.length; i++) {
450
                    if (frames[i] instanceof LayoutPanelListener) {
451
                            ((LayoutPanelListener)frames[i]).windowActivated();
452
                    }
453
            }
454
        requestFocus();
455
        layoutControl.getComponent().requestFocus();
456
    }
457

    
458
    /**
459
     * @see com.iver.mdiApp.ui.MDIManager.SingletonWindow#getWindowModel()
460
     */
461
    public Object getWindowModel() {
462
        return layoutDocument;
463
    }
464

    
465
    public Document getDocument() {
466
        return layoutDocument;
467
    }
468

    
469
    /**
470
     * @see org.gvsig.andami.ui.mdiManager.IWindowListener#windowClosed()
471
     */
472
    public void windowClosed() {
473
            IFFrame[] frames = layoutContext.getFFrames();
474
            for (int i=0; i<frames.length; i++) {
475
                    if (frames[i] instanceof LayoutPanelListener) {
476
                            ((LayoutPanelListener)frames[i]).windowClosed();
477
                    }
478
            }
479
    }
480

    
481
    /**
482
     * @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent)
483
     */
484
    public void backColorChanged(ColorEvent e) {
485
        // refresh();
486
    }
487

    
488
    public void layoutToPDF(File file) {
489
        layoutControl.getLayoutDraw().toPDF(file);
490
    }
491
    
492
    public void layoutToPDF(String suggestedName) {
493
        FileFilter pdfFilter =
494
            new GenericFileFilter("pdf", PluginServices.getText(this, "pdf"));
495

    
496
        JFileChooser jfc =
497
            new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
498
        if (suggestedName != null) {
499
            jfc.setSelectedFile(new File(suggestedName));
500
        }
501
        jfc.addChoosableFileFilter(pdfFilter);
502
        jfc.setFileFilter(pdfFilter);
503

    
504
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
505
            File f = jfc.getSelectedFile();
506
            File faux = null;
507

    
508
            if (f.getName().endsWith(".pdf") || f.getName().endsWith(".PDF")) {
509
                faux = f;
510
            } else {
511
                faux = new File(f.getPath() + ".pdf");
512
            }
513
            this.layoutToPDF(faux);
514
        }
515
    }
516

    
517
    public void layoutToPS(String suggestedName) {
518
        FileFilter pdfFilter =
519
            new GenericFileFilter("ps", PluginServices.getText(this, "ps"));
520

    
521
        JFileChooser jfc =
522
            new JFileChooser(PDF_AND_PS_FILECHOOSER, defaultPDFFolderPath);
523
        if (suggestedName != null) {
524
            jfc.setSelectedFile(new File(suggestedName));
525
        }
526
        jfc.addChoosableFileFilter(pdfFilter);
527
        jfc.setFileFilter(pdfFilter);
528

    
529
        if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
530
            File f = jfc.getSelectedFile();
531
            File faux = null;
532

    
533
            if (f.getName().endsWith(".ps") || f.getName().endsWith(".PS")) {
534
                faux = f;
535
            } else {
536
                faux = new File(f.getPath() + ".ps");
537
            }
538

    
539
            layoutControl.getLayoutDraw().toPS(faux);
540
        }
541
    }
542

    
543
    public void layoutToPDF() {
544
        layoutToPDF((String)null);
545
    }
546

    
547
    public void layoutToPS() {
548
        layoutToPS(null);
549
    }
550

    
551
    public boolean isShowIconTag() {
552
        return bShowIconTag;
553
    }
554

    
555
    public void setShowIconTag(boolean modeDebug) {
556
        bShowIconTag = modeDebug;
557
    }
558

    
559
    public void update(Observable observable, Object notification) {
560
            this.layoutContext.updateFFrames();
561
            this.layoutControl.refresh();
562
    }
563

    
564
    public Object getWindowProfile() {
565
        return WindowInfo.EDITOR_PROFILE;
566
    }
567

    
568
    public void saveToState(PersistentState state) throws PersistenceException {
569
        state.set(LAYOUTCONTEXT_OBJECT, layoutContext);
570
        state.set(LAYOUTDOCUMENT_OBJECT, layoutDocument);
571
    }
572

    
573
    public void loadFromState(PersistentState state)
574
        throws PersistenceException {
575
        this.layoutContext = (LayoutContext) state.get(LAYOUTCONTEXT_OBJECT);
576
        this.setDocument((LayoutDocument) state.get(LAYOUTDOCUMENT_OBJECT));
577
    }
578

    
579
    public static void registerPersistent() {
580
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
581
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
582
            DynStruct definition =
583
                manager.addDefinition(DefaultLayoutPanel.class,
584
                    PERSISTENCE_DEFINITION_NAME,
585
                    "Layout panel persistence definition", null, null);
586

    
587
            definition.addDynFieldObject(LAYOUTCONTEXT_OBJECT)
588
                .setClassOfValue(LayoutContext.class).setMandatory(true);
589
            definition.addDynFieldObject(LAYOUTDOCUMENT_OBJECT)
590
                .setClassOfValue(LayoutDocument.class).setMandatory(true);
591
        }
592
    }
593

    
594
    public WindowLayout getWindowLayout() {
595
        return null;
596
    }
597

    
598
    public void setWindowLayout(WindowLayout layout) {
599

    
600
    }
601

    
602
    private void setLayoutContext(LayoutContext theLayoutcontext) {
603
        this.layoutContext = theLayoutcontext;
604
        this.layoutControl.setLayoutContext(theLayoutcontext);
605
        layoutContext.getAttributes().calculateGridGapX(layoutControl.getRect());
606
        layoutContext.getAttributes().calculateGridGapY(layoutControl.getRect());
607
        layoutControl.setDefaultTool();
608
    }
609

    
610
    @Override
611
    public void setLayoutManager(LayoutManager layoutManager) {
612
        this.layoutManager = layoutManager;
613
    }
614
    
615
    
616
    /**
617
     * Method to print the Layout without modify the Affinetransform.
618
     *
619
     * @param g2 Geaphics2D
620
     */
621
    public void drawLayoutPrint(Graphics2D g2) {
622
        layoutControl.setCancelDrawing(false);
623

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

    
653
        public void showToc() {
654
                if (isTocEnabled()) {
655
                        splitPane.setDividerLocation(lastPanePos);
656
                }
657
        }
658

    
659
}