OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Rev 149 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.common.ui;
15
 
16
import java.awt.Dimension;
17
import java.awt.GraphicsEnvironment;
18
import java.io.File;
19
 
20
import javax.swing.JFrame;
80 ilm 21
import javax.swing.SwingUtilities;
18 ilm 22
 
23
import org.jopendocument.model.OpenDocument;
24
import org.jopendocument.panel.ODSViewerPanel;
25
import org.jopendocument.print.DefaultXMLDocumentPrinter;
26
 
27
public class PreviewFrame extends JFrame {
28
 
80 ilm 29
    private PreviewFrame(OpenDocument doc, String title) {
30
        super(title);
18 ilm 31
        this.setContentPane(new ODSViewerPanel(doc, new DefaultXMLDocumentPrinter()));
83 ilm 32
        init();
33
    }
34
 
35
    public PreviewFrame(String title, String url, String odspXml) {
36
        this.setContentPane(new ODSViewerPanel(url, odspXml, new DefaultXMLDocumentPrinter(), true));
37
        this.setTitle(title);
38
        init();
39
    }
40
 
41
    private void init() {
42
        final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
18 ilm 43
        this.setMaximizedBounds(ge.getMaximumWindowBounds());
83 ilm 44
        final Dimension maxD = ge.getMaximumWindowBounds().getSize();
18 ilm 45
        this.setMaximumSize(maxD);
46
        this.pack();
47
        Dimension d = this.getSize();
48
        if (d.width > maxD.width) {
49
            d.setSize(maxD.width, d.height);
50
        }
51
        if (d.height > maxD.height) {
52
            d.setSize(d.width, maxD.height);
53
        }
54
        this.setSize(d);
55
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
56
 
57
        this.setLocationRelativeTo(null);
58
    }
59
 
80 ilm 60
    public static void show(File file) {
61
        final OpenDocument doc = new OpenDocument(file);
62
        final String title = file.getName();
63
        if (SwingUtilities.isEventDispatchThread()) {
64
            new PreviewFrame(doc, title).setVisible(true);
65
        } else {
66
            SwingUtilities.invokeLater(new Runnable() {
67
                @Override
68
                public void run() {
69
                    new PreviewFrame(doc, title).setVisible(true);
70
                }
71
            });
72
        }
83 ilm 73
 
18 ilm 74
    }
75
}