OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 177 | 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
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 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.action;
15
 
142 ilm 16
import org.openconcerto.erp.config.Benchmark;
156 ilm 17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
41 ilm 18
import org.openconcerto.sql.ui.InfoPanel;
156 ilm 19
import org.openconcerto.ui.DefaultGridBagConstraints;
142 ilm 20
import org.openconcerto.ui.JLabelBold;
21
import org.openconcerto.ui.ReloadPanel;
18 ilm 22
 
142 ilm 23
import java.awt.BorderLayout;
156 ilm 24
import java.awt.Component;
18 ilm 25
import java.awt.Dimension;
142 ilm 26
import java.awt.FlowLayout;
156 ilm 27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
18 ilm 29
import java.awt.event.ActionEvent;
142 ilm 30
import java.awt.event.ActionListener;
156 ilm 31
import java.io.File;
18 ilm 32
 
33
import javax.swing.AbstractAction;
34
import javax.swing.Action;
142 ilm 35
import javax.swing.JButton;
18 ilm 36
import javax.swing.JFrame;
142 ilm 37
import javax.swing.JLabel;
38
import javax.swing.JPanel;
18 ilm 39
import javax.swing.JScrollPane;
142 ilm 40
import javax.swing.SwingUtilities;
41
import javax.swing.SwingWorker;
18 ilm 42
 
43
public final class AboutAction extends AbstractAction {
44
 
177 ilm 45
    private final ComptaPropsConfiguration conf;
18 ilm 46
 
177 ilm 47
    public AboutAction(final ComptaPropsConfiguration conf) {
18 ilm 48
        super("Informations");
177 ilm 49
        this.conf = conf;
18 ilm 50
    }
51
 
52
    @Override
53
    public void actionPerformed(final ActionEvent event) {
54
        final JFrame frame = new JFrame((String) this.getValue(Action.NAME));
142 ilm 55
        JPanel p = new JPanel();
56
        p.setLayout(new BorderLayout());
57
 
177 ilm 58
        final JScrollPane contentPane = new JScrollPane(new InfoPanel(this.conf.getLocale()));
156 ilm 59
        p.add(createComptaInfoPanel(), BorderLayout.NORTH);
142 ilm 60
        p.add(contentPane, BorderLayout.CENTER);
61
        p.add(createBenchMarkPanel(), BorderLayout.SOUTH);
62
        frame.setContentPane(p);
18 ilm 63
        frame.pack();
64
 
65
        final Dimension size = frame.getSize();
66
 
67
        final Dimension maxSize = new Dimension(size.width, 700);
68
        if (size.height > maxSize.height) {
69
            frame.setMinimumSize(maxSize);
70
            frame.setPreferredSize(maxSize);
71
            frame.setSize(maxSize);
72
        } else {
73
            frame.setMinimumSize(size);
74
            frame.setPreferredSize(size);
75
            frame.setSize(size);
76
        }
77
        final Dimension maximumSize = maxSize;
78
        frame.setMaximumSize(maximumSize);
79
 
80
        frame.setLocationRelativeTo(null);
81
 
82
        frame.setVisible(true);
83
    }
142 ilm 84
 
156 ilm 85
    private Component createComptaInfoPanel() {
86
        final JPanel p = new JPanel();
87
        p.setLayout(new GridBagLayout());
88
        GridBagConstraints c = new DefaultGridBagConstraints();
89
        final File confFile = ComptaPropsConfiguration.getConfFile(ComptaPropsConfiguration.productInfo);
90
        String path = "";
91
        if (confFile != null) {
92
            path = confFile.getAbsolutePath();
93
        }
94
        c.fill = GridBagConstraints.NONE;
95
        c.weightx = 0;
96
        c.anchor = GridBagConstraints.EAST;
97
        p.add(new JLabelBold("Fichier de configuration : "), c);
98
        c.gridx++;
99
        c.weightx = 1;
100
        c.anchor = GridBagConstraints.WEST;
101
        p.add(new JLabel(path), c);
102
        c.gridy++;
103
        c.gridx = 0;
177 ilm 104
        final String serverIp = this.conf.getServerIp();
156 ilm 105
        if (serverIp.startsWith("file:")) {
177 ilm 106
            final String dbPath = serverIp.substring(5);
156 ilm 107
            c.weightx = 0;
108
            c.anchor = GridBagConstraints.EAST;
109
            p.add(new JLabelBold("Fichier de base de données : "), c);
110
            c.gridx++;
111
            c.weightx = 1;
112
            c.anchor = GridBagConstraints.WEST;
113
            p.add(new JLabel(dbPath), c);
114
        }
115
        c.gridy++;
182 ilm 116
        c.gridx = 0;
117
        c.weightx = 0;
118
        c.anchor = GridBagConstraints.EAST;
119
        p.add(new JLabelBold("Dossiers des modules : "), c);
120
        c.gridx++;
121
        c.weightx = 1;
122
        c.anchor = GridBagConstraints.WEST;
123
        p.add(new JLabel(this.conf.getModuleManager().getFolders().toString()), c);
156 ilm 124
 
125
        return p;
126
    }
127
 
142 ilm 128
    private JPanel createBenchMarkPanel() {
129
        final JPanel p = new JPanel();
130
        p.setLayout(new FlowLayout(FlowLayout.LEFT));
131
        final JLabel lt = new JLabelBold("Test de performance : ");
132
        p.add(lt);
133
        final JLabel l = new JLabel("CLiquez sur démarrer pour lancer le test");
134
        p.add(l);
135
        final JButton b = new JButton("Démarrer");
136
        p.add(b);
137
        final ReloadPanel r = new ReloadPanel();
138
        p.add(r);
139
        b.addActionListener(new ActionListener() {
140
 
141
            @Override
142
            public void actionPerformed(ActionEvent e) {
143
                l.setText("Test en cours");
144
                b.setEnabled(false);
145
                r.setMode(ReloadPanel.MODE_ROTATE);
146
                SwingWorker<String, String> s = new SwingWorker<String, String>() {
147
 
148
                    @Override
149
                    protected String doInBackground() throws Exception {
150
                        Benchmark bench = new Benchmark();
151
                        String s = "";
152
                        s += "Base de données : " + bench.testDB();
153
                        final String s1 = s;
154
                        SwingUtilities.invokeLater(new Runnable() {
155
 
156
                            @Override
157
                            public void run() {
158
                                l.setText(s1);
159
 
160
                            }
161
                        });
162
                        s += " - Processeur : " + bench.testCPU();
163
                        final String s2 = s;
164
                        SwingUtilities.invokeLater(new Runnable() {
165
 
166
                            @Override
167
                            public void run() {
168
                                l.setText(s2);
169
 
170
                            }
171
                        });
172
                        s += " - Disque dur : " + bench.testWriteHD();
173
                        return s;
174
                    }
175
 
176
                    protected void done() {
177
                        b.setEnabled(true);
178
                        try {
179
                            String result = get();
180
                            l.setText(result);
181
                            r.setMode(ReloadPanel.MODE_EMPTY);
182
                        } catch (Exception e) {
183
                            r.setMode(ReloadPanel.MODE_BLINK);
184
                            e.printStackTrace();
185
                        }
186
                    };
187
                };
188
                s.execute();
189
 
190
            }
191
        });
192
        return p;
193
    }
18 ilm 194
}