17 |
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.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.ui.component.HTMLTextField;
|
73 |
ilm |
17 |
import org.openconcerto.ui.component.ITextArea;
|
83 |
ilm |
18 |
import org.openconcerto.utils.SystemInfo;
|
|
|
19 |
import org.openconcerto.utils.SystemInfo.Info;
|
73 |
ilm |
20 |
import org.openconcerto.utils.i18n.TM;
|
17 |
ilm |
21 |
|
177 |
ilm |
22 |
import java.util.Locale;
|
83 |
ilm |
23 |
import java.util.Map;
|
17 |
ilm |
24 |
|
80 |
ilm |
25 |
import javax.swing.BorderFactory;
|
73 |
ilm |
26 |
import javax.swing.JComponent;
|
17 |
ilm |
27 |
import javax.swing.JEditorPane;
|
|
|
28 |
import javax.swing.JLabel;
|
73 |
ilm |
29 |
import javax.swing.JOptionPane;
|
17 |
ilm |
30 |
import javax.swing.JPanel;
|
73 |
ilm |
31 |
import javax.swing.event.HyperlinkEvent;
|
|
|
32 |
import javax.swing.text.JTextComponent;
|
17 |
ilm |
33 |
|
|
|
34 |
/**
|
|
|
35 |
* A panel displaying various system informations (eg vm version, user name, network address).
|
|
|
36 |
*
|
|
|
37 |
* @author Sylvain CUAZ
|
|
|
38 |
*/
|
|
|
39 |
public class SystemInfoPanel extends JPanel {
|
|
|
40 |
|
132 |
ilm |
41 |
private final FormLayouter l;
|
|
|
42 |
|
83 |
ilm |
43 |
public SystemInfoPanel() {
|
177 |
ilm |
44 |
this(Locale.getDefault());
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public SystemInfoPanel(final Locale locale) {
|
132 |
ilm |
48 |
this.l = new FormLayouter(this, 1);
|
177 |
ilm |
49 |
this.refresh(locale);
|
132 |
ilm |
50 |
}
|
|
|
51 |
|
177 |
ilm |
52 |
public final void refresh(final Locale locale) {
|
132 |
ilm |
53 |
this.l.clear();
|
177 |
ilm |
54 |
final Map<Info, String> infos = SystemInfo.get(true, locale);
|
73 |
ilm |
55 |
|
83 |
ilm |
56 |
final JEditorPane p = new HTMLTextField(infos.get(Info.JAVA)) {
|
17 |
ilm |
57 |
|
73 |
ilm |
58 |
private final String getClassName(HyperlinkEvent e) {
|
|
|
59 |
// the link is not an URL
|
|
|
60 |
final String uri = e.getDescription();
|
83 |
ilm |
61 |
if (uri.startsWith(SystemInfo.CLASS_PROTOCOL + ':'))
|
|
|
62 |
return uri.substring(SystemInfo.CLASS_PROTOCOL.length() + 1);
|
73 |
ilm |
63 |
else
|
|
|
64 |
return null;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
@Override
|
|
|
68 |
protected String getToolTip(HyperlinkEvent e) {
|
|
|
69 |
final String className = getClassName(e);
|
|
|
70 |
if (className != null)
|
|
|
71 |
return className;
|
|
|
72 |
return super.getToolTip(e);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
@Override
|
|
|
76 |
protected void linkActivated(HyperlinkEvent e, JComponent src) {
|
|
|
77 |
final String className = getClassName(e);
|
|
|
78 |
if (className != null) {
|
|
|
79 |
String msg = className;
|
|
|
80 |
try {
|
|
|
81 |
final Class<?> cl = Class.forName(className);
|
|
|
82 |
msg += " (exists\nand its superclass is " + cl.getSuperclass() + ")";
|
|
|
83 |
} catch (ClassNotFoundException e1) {
|
|
|
84 |
// OK
|
|
|
85 |
msg += " (couldn't be loaded)";
|
|
|
86 |
}
|
|
|
87 |
final JTextComponent txtComp = new ITextArea(msg, 3, 50);
|
83 |
ilm |
88 |
txtComp.setEditable(false);
|
80 |
ilm |
89 |
txtComp.setBorder(BorderFactory.createEmptyBorder());
|
73 |
ilm |
90 |
txtComp.setOpaque(false);
|
|
|
91 |
|
|
|
92 |
JOptionPane.showMessageDialog(src, txtComp, "Class name", JOptionPane.INFORMATION_MESSAGE);
|
|
|
93 |
} else {
|
|
|
94 |
super.linkActivated(e, src);
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
};
|
|
|
98 |
|
132 |
ilm |
99 |
this.l.add("Java", p);
|
17 |
ilm |
100 |
|
|
|
101 |
// * Windows XP 5.1 (x86)
|
177 |
ilm |
102 |
this.l.add(TM.tr(locale, "os"), new JLabel("<html>" + infos.get(Info.OS) + "</html>"));
|
17 |
ilm |
103 |
|
|
|
104 |
// * Sylvain ; C:\Documents and Settings\Sylvain ; D:\workspace\CTech
|
177 |
ilm |
105 |
this.l.add(TM.tr(locale, "user"), new HTMLTextField(infos.get(Info.USER)));
|
17 |
ilm |
106 |
|
|
|
107 |
// * eth0 192.168.28.52/24, état: inactif, nom complet: ""
|
177 |
ilm |
108 |
this.l.add(TM.tr(locale, "network"), new HTMLTextField(infos.get(Info.NETWORK)));
|
17 |
ilm |
109 |
|
|
|
110 |
// TODO reverse vnc
|
177 |
ilm |
111 |
|
|
|
112 |
this.l.getComponent().revalidate();
|
17 |
ilm |
113 |
}
|
|
|
114 |
}
|