OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 83 | 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()));
32
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
33
        this.setMaximizedBounds(ge.getMaximumWindowBounds());
34
        Dimension maxD = ge.getMaximumWindowBounds().getSize();
35
        this.setMaximumSize(maxD);
36
        this.pack();
37
        Dimension d = this.getSize();
38
        if (d.width > maxD.width) {
39
            d.setSize(maxD.width, d.height);
40
        }
41
        if (d.height > maxD.height) {
42
            d.setSize(d.width, maxD.height);
43
        }
44
        this.setSize(d);
45
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
46
 
47
        this.setLocationRelativeTo(null);
48
    }
49
 
80 ilm 50
    public static void show(File file) {
51
        final OpenDocument doc = new OpenDocument(file);
52
        final String title = file.getName();
53
        if (SwingUtilities.isEventDispatchThread()) {
54
            new PreviewFrame(doc, title).setVisible(true);
55
        } else {
56
            SwingUtilities.invokeLater(new Runnable() {
57
                @Override
58
                public void run() {
59
                    new PreviewFrame(doc, title).setVisible(true);
60
                }
61
            });
62
        }
18 ilm 63
    }
64
 
65
}