/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.component;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import org.apache.log4j.Logger;
/**
* Dialog that shows about info, the license, and the splashscreen image. It
* uses the properties from the app.properties file.
*
* @author Markus Kraetzig
*/
public class TopFrameAboutBox extends JDialog {
private static final Logger log = Logger.getLogger(TopFrameAboutBox.class);
private final String display;
private final String version;
private final String image;
private final String licenseFile;
private JLabel label = null;
private JTabbedPane tabPane = null;
private MultiLineLabel infoArea = null;
/**
* Creates an instance of this dialog that can be used as an about box.
*
* @param owner
* @param title
*/
public TopFrameAboutBox(Frame owner, String title, String version,
String display, String image, String licenseFile) {
super(owner, title, true);
this.version = version;
this.display = display;
this.image = image;
this.licenseFile = licenseFile;
initialize();
}
private JLabel getLabel() {
if (label == null) {
label = new JLabel("");
label.setBackground(Color.white);
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setVerticalAlignment(SwingConstants.TOP);
URL url = getClass().getResource(image);
if (url != null)
label.setIcon(new ImageIcon(url));
}
return label;
}
/**
* Gets the label with author and version info. Can be overriden by
* subclasses to change formatting.
*
* @return MultiLineLabel with formatted author and version
* info
*/
protected MultiLineLabel getInfoArea() {
if (infoArea == null) {
infoArea = new MultiLineLabel();
infoArea.setText("version: " + version);
infoArea.setHorizontalAlignment(SwingConstants.CENTER);
infoArea.setVerticalAlignment(SwingConstants.TOP);
infoArea.setMinimumSize(new Dimension(45, 30));
infoArea.setBackground(Color.white);
}
return infoArea;
}
private void addAuthorInfoArea() {
// Info area
JTextArea textArea = new JTextArea();
textArea.setEditable(false);
JScrollPane scroller = new JScrollPane(textArea);
textArea.setMargin(new Insets(5, 5, 5, 5));
textArea.setText(display);
scroller.setName("Info");
tabPane.add(scroller);
}
private void addLicenseArea() {
// Info area
final JTextPane textPane = new JTextPane();
textPane.setEditable(false);
JScrollPane scroller = new JScrollPane(textPane);
textPane.setMargin(new Insets(5, 5, 5, 5));
try {
textPane.setPage(new File(licenseFile).toURI().toURL());
} catch (IOException e) {
log.error("Setting license failed", e);
}
textPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
try {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
textPane.setPage(e.getURL());
} catch (Throwable ex) {
log.error("text pane updated failed", ex);
}
}
});
scroller.setName("License");
tabPane.add(scroller);
}
private void initialize() {
setSize(385, 360);
setLocationRelativeTo(getParent());
JPanel contentPane = new JPanel(new BorderLayout());
tabPane = new JTabbedPane();
JPanel displayPane = new JPanel();
displayPane.setLayout(new java.awt.GridBagLayout());
displayPane.setBackground(Color.white);
java.awt.GridBagConstraints constraintsJLabel1 = new java.awt.GridBagConstraints();
constraintsJLabel1.gridx = 0;
constraintsJLabel1.gridy = 0;
constraintsJLabel1.gridwidth = 1;
constraintsJLabel1.fill = java.awt.GridBagConstraints.BOTH;
displayPane.add(getLabel(), constraintsJLabel1);
java.awt.GridBagConstraints constraintsInfoArea = new java.awt.GridBagConstraints();
constraintsInfoArea.gridx = 0;
constraintsInfoArea.gridy = 1;
constraintsInfoArea.weightx = 1.0;
constraintsInfoArea.weighty = 1.0;
constraintsInfoArea.fill = java.awt.GridBagConstraints.BOTH;
constraintsInfoArea.insets = new java.awt.Insets(10, 20, 5, 5);
displayPane.add(getInfoArea(), constraintsInfoArea);
displayPane.setName("Version");
tabPane.add(displayPane);
// bring first tab to front
addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
tabPane.setSelectedIndex(0);
}
});
addAuthorInfoArea();
addLicenseArea();
contentPane.add(tabPane, BorderLayout.CENTER);
contentPane.setBackground(Color.white);
setContentPane(contentPane);
}
}
Ads help maintain this website.