OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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