Dépôt officiel du code source de l'ERP OpenConcerto
Rev 132 | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
*
* The contents of this file are subject to the terms of the GNU General Public License Version 3
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each file.
*/
package org.openconcerto.ui;
import org.openconcerto.ui.component.HTMLTextField;
import org.openconcerto.ui.component.ITextArea;
import org.openconcerto.utils.SystemInfo;
import org.openconcerto.utils.SystemInfo.Info;
import org.openconcerto.utils.i18n.TM;
import java.util.Locale;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.HyperlinkEvent;
import javax.swing.text.JTextComponent;
/**
* A panel displaying various system informations (eg vm version, user name, network address).
*
* @author Sylvain CUAZ
*/
public class SystemInfoPanel extends JPanel {
private final FormLayouter l;
public SystemInfoPanel() {
this(Locale.getDefault());
}
public SystemInfoPanel(final Locale locale) {
this.l = new FormLayouter(this, 1);
this.refresh(locale);
}
public final void refresh(final Locale locale) {
this.l.clear();
final Map<Info, String> infos = SystemInfo.get(true, locale);
final JEditorPane p = new HTMLTextField(infos.get(Info.JAVA)) {
private final String getClassName(HyperlinkEvent e) {
// the link is not an URL
final String uri = e.getDescription();
if (uri.startsWith(SystemInfo.CLASS_PROTOCOL + ':'))
return uri.substring(SystemInfo.CLASS_PROTOCOL.length() + 1);
else
return null;
}
@Override
protected String getToolTip(HyperlinkEvent e) {
final String className = getClassName(e);
if (className != null)
return className;
return super.getToolTip(e);
}
@Override
protected void linkActivated(HyperlinkEvent e, JComponent src) {
final String className = getClassName(e);
if (className != null) {
String msg = className;
try {
final Class<?> cl = Class.forName(className);
msg += " (exists\nand its superclass is " + cl.getSuperclass() + ")";
} catch (ClassNotFoundException e1) {
// OK
msg += " (couldn't be loaded)";
}
final JTextComponent txtComp = new ITextArea(msg, 3, 50);
txtComp.setEditable(false);
txtComp.setBorder(BorderFactory.createEmptyBorder());
txtComp.setOpaque(false);
JOptionPane.showMessageDialog(src, txtComp, "Class name", JOptionPane.INFORMATION_MESSAGE);
} else {
super.linkActivated(e, src);
}
}
};
this.l.add("Java", p);
// * Windows XP 5.1 (x86)
this.l.add(TM.tr(locale, "os"), new JLabel("<html>" + infos.get(Info.OS) + "</html>"));
// * Sylvain ; C:\Documents and Settings\Sylvain ; D:\workspace\CTech
this.l.add(TM.tr(locale, "user"), new HTMLTextField(infos.get(Info.USER)));
// * eth0 192.168.28.52/24, état: inactif, nom complet: ""
this.l.add(TM.tr(locale, "network"), new HTMLTextField(infos.get(Info.NETWORK)));
// TODO reverse vnc
this.l.getComponent().revalidate();
}
}