OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 174 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 174 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
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
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
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.
9
 * language governing permissions and limitations under the License.
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.common.ui;
14
 package org.openconcerto.erp.core.common.ui;
15
 
15
 
16
import org.openconcerto.erp.generationDoc.A4;
16
import org.openconcerto.erp.generationDoc.A4;
17
import org.openconcerto.erp.generationDoc.AbstractSheetXml;
-
 
18
import org.openconcerto.erp.generationDoc.DefaultNXDocumentPrinter;
17
import org.openconcerto.erp.generationDoc.DefaultNXDocumentPrinter;
19
import org.openconcerto.erp.generationDoc.ODTPrinterNX;
18
import org.openconcerto.utils.Action;
20
import org.openconcerto.utils.ExceptionHandler;
19
import org.openconcerto.utils.ExceptionHandler;
21
 
20
 
22
import java.awt.Dimension;
21
import java.awt.Dimension;
23
import java.awt.GraphicsEnvironment;
22
import java.awt.GraphicsEnvironment;
24
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
24
import java.awt.event.ActionListener;
26
import java.awt.print.Paper;
25
import java.awt.print.Paper;
27
import java.awt.print.PrinterException;
-
 
28
import java.awt.print.PrinterJob;
26
import java.awt.print.PrinterJob;
29
import java.io.File;
27
import java.io.File;
30
import java.util.Arrays;
28
import java.util.Collections;
31
import java.util.List;
29
import java.util.List;
32
 
30
 
33
import javax.print.PrintService;
-
 
34
import javax.print.attribute.Attribute;
31
import javax.print.attribute.Attribute;
35
import javax.print.attribute.HashPrintRequestAttributeSet;
32
import javax.print.attribute.HashPrintRequestAttributeSet;
36
import javax.print.attribute.Size2DSyntax;
33
import javax.print.attribute.Size2DSyntax;
37
import javax.print.attribute.standard.Copies;
34
import javax.print.attribute.standard.Copies;
38
import javax.print.attribute.standard.MediaPrintableArea;
35
import javax.print.attribute.standard.MediaPrintableArea;
39
import javax.print.attribute.standard.MediaSizeName;
36
import javax.print.attribute.standard.MediaSizeName;
40
import javax.swing.JButton;
37
import javax.swing.JButton;
41
import javax.swing.JComponent;
-
 
42
import javax.swing.JFrame;
38
import javax.swing.JFrame;
43
import javax.swing.JOptionPane;
-
 
44
import javax.swing.SwingUtilities;
39
import javax.swing.SwingUtilities;
45
 
40
 
46
import org.jopendocument.model.OpenDocument;
41
import org.jopendocument.model.OpenDocument;
47
import org.jopendocument.panel.ODSViewerPanel;
42
import org.jopendocument.panel.ODSViewerPanel;
48
import org.jopendocument.print.DefaultXMLDocumentPrinter;
43
import org.jopendocument.print.DefaultXMLDocumentPrinter;
49
import org.jopendocument.print.ODTPrinterXML;
-
 
50
 
44
 
51
public class PreviewFrame extends JFrame {
45
public class PreviewFrame extends JFrame {
52
 
46
 
53
    private PreviewFrame(OpenDocument doc, String title) {
47
    private PreviewFrame(OpenDocument doc, String title) {
54
        super(title);
48
        super(title);
55
        final ODSViewerPanel viewerPanel = new ODSViewerPanel(doc, createDocumentPrinter());
49
        final ODSViewerPanel viewerPanel = new ODSViewerPanel(doc, createDocumentPrinter());
-
 
50
        viewerPanel.showSaveAsButton(false);
56
        this.setContentPane(viewerPanel);
51
        this.setContentPane(viewerPanel);
57
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
52
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
58
    }
53
    }
59
 
54
 
60
    public PreviewFrame(String title, String url, String odspXml) {
55
    public PreviewFrame(String title, String url, String odspXml) {
61
        final ODSViewerPanel contentPane = new ODSViewerPanel(url, odspXml, createDocumentPrinter(), true);
56
        final ODSViewerPanel contentPane = new ODSViewerPanel(url, odspXml, createDocumentPrinter(), true);
62
 
-
 
-
 
57
        contentPane.showSaveAsButton(false);
63
        this.setContentPane(contentPane);
58
        this.setContentPane(contentPane);
64
        this.setTitle(title);
59
        this.setTitle(title);
65
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
60
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
66
    }
61
    }
67
 
62
 
68
    public void addTool(String n, Runnable r) {
63
    public void addTool(Action a) {
69
        JButton b = new JButton(n);
64
        JButton b = new JButton(a.getName());
70
        ((ODSViewerPanel) this.getContentPane()).addTool(b);
65
        ((ODSViewerPanel) this.getContentPane()).addTool(b);
71
        b.addActionListener(new ActionListener() {
66
        b.addActionListener(new ActionListener() {
72
 
67
 
73
            @Override
68
            @Override
74
            public void actionPerformed(ActionEvent e) {
69
            public void actionPerformed(ActionEvent e) {
75
                r.run();
70
                a.run(PreviewFrame.this);
76
            }
71
            }
77
        });
72
        });
78
    }
73
    }
79
 
74
 
80
    public DefaultXMLDocumentPrinter createDocumentPrinter() {
75
    public DefaultXMLDocumentPrinter createDocumentPrinter() {
Line 147... Line 142...
147
        }
142
        }
148
        this.setLocationRelativeTo(null);
143
        this.setLocationRelativeTo(null);
149
    }
144
    }
150
 
145
 
151
    public static void show(File file) {
146
    public static void show(File file) {
152
        show(file, null, null);
147
        show(file, Collections.emptyList());
153
    }
148
    }
154
 
149
 
155
    public static void show(File file, String actionName, Runnable r) {
150
    public static void show(File file, List<Action> actions) {
156
        final OpenDocument doc = new OpenDocument(file);
151
        final OpenDocument doc = new OpenDocument(file);
157
        final String title = file.getName();
152
        final String title = file.getName();
158
        if (SwingUtilities.isEventDispatchThread()) {
153
        if (SwingUtilities.isEventDispatchThread()) {
159
            PreviewFrame previewFrame = new PreviewFrame(doc, title);
154
            PreviewFrame previewFrame = new PreviewFrame(doc, title);
160
            if (r != null) {
155
            for (Action a : actions) {
161
                previewFrame.addTool(actionName, r);
156
                previewFrame.addTool(a);
162
            }
157
            }
163
            previewFrame.pack();
158
            previewFrame.pack();
164
            previewFrame.setVisible(true);
159
            previewFrame.setVisible(true);
165
        } else {
160
        } else {
166
            SwingUtilities.invokeLater(new Runnable() {
161
            SwingUtilities.invokeLater(new Runnable() {
167
                @Override
162
                @Override
168
                public void run() {
163
                public void run() {
169
                    PreviewFrame previewFrame = new PreviewFrame(doc, title);
164
                    PreviewFrame previewFrame = new PreviewFrame(doc, title);
170
                    if (r != null) {
165
                    for (Action a : actions) {
171
                        previewFrame.addTool(actionName, r);
166
                        previewFrame.addTool(a);
172
                    }
167
                    }
173
                    previewFrame.pack();
168
                    previewFrame.pack();
174
                    previewFrame.setVisible(true);
169
                    previewFrame.setVisible(true);
175
                }
170
                }
176
            });
171
            });