OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Go to most recent revision | Details | 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;
21
 
22
import org.jopendocument.model.OpenDocument;
23
import org.jopendocument.panel.ODSViewerPanel;
24
import org.jopendocument.print.DefaultXMLDocumentPrinter;
25
 
26
public class PreviewFrame extends JFrame {
27
 
28
    private PreviewFrame(File file) {
29
        super();
30
        final OpenDocument doc = new OpenDocument(file);
31
        this.setContentPane(new ODSViewerPanel(doc, new DefaultXMLDocumentPrinter()));
32
        this.setTitle(file.getName());
33
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
34
        this.setMaximizedBounds(ge.getMaximumWindowBounds());
35
        Dimension maxD = ge.getMaximumWindowBounds().getSize();
36
        this.setMaximumSize(maxD);
37
        this.pack();
38
        Dimension d = this.getSize();
39
        if (d.width > maxD.width) {
40
            d.setSize(maxD.width, d.height);
41
        }
42
        if (d.height > maxD.height) {
43
            d.setSize(d.width, maxD.height);
44
        }
45
        this.setSize(d);
46
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
47
 
48
        this.setLocationRelativeTo(null);
49
    }
50
 
51
    public static void show(File f) {
52
        new PreviewFrame(f).setVisible(true);
53
    }
54
 
55
}