OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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