/*
* UFO Saved Game Editor
* Copyright (C) 2010 Christopher Davoren
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.rubikscomplex.ufosge.gui;
import java.awt.Component;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import net.rubikscomplex.ufosge.resources.ResourceManager;
/**
*
* @author Chris Davoren
*/
public class AboutDialog extends JDialog implements ActionListener {
protected HyperlinkLabel linkLabel;
protected HyperlinkLabel licenseLinkLabel;
public AboutDialog(Window owner) {
super(owner, "About UFO Saved Game Editor");
setIconImage(ResourceManager.getDefaultFrameIcon().getImage());
setModal(true);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
ImageIcon iconImage = new ImageIcon();
try {
iconImage.setImage(ImageIO.read(ResourceManager.getImageResource("icon-128.png")));
}
catch(IOException e) {
JOptionPane.showMessageDialog(this, "Error loading icon image:\n\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
JLabel iconLabel = new JLabel(iconImage);
iconLabel.setAlignmentY(Component.TOP_ALIGNMENT);
JLabel titleLabel = new JLabel("UFO Saved Game Editor");
titleLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD).deriveFont((float)(titleLabel.getFont().getSize() + 6)));
JLabel versionLabel = new JLabel("Version " + ResourceManager.getProperty(ResourceManager.PROP_VERSION));
versionLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
JLabel authorLabel = new JLabel("Copyright \u00A9 2010 Chris Davoren");
authorLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
linkLabel = new HyperlinkLabel("http://www.rubikscomplex.net/ufosge/");
linkLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
linkLabel.setActionCommand("link");
linkLabel.addActionListener(this);
// JLabel licenseLabel = new JLabel("This software is released under the GNU General Public License v3.0.\\nFor more information see:");
// licenseLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
JTextArea licenseText = new JTextArea("This software is released under the GNU General Public License v3. For more information see:");
licenseText.setAlignmentX(Component.LEFT_ALIGNMENT);
licenseText.setOpaque(false);
licenseText.setFont(versionLabel.getFont());
licenseText.setEditable(false);
licenseText.setWrapStyleWord(true);
licenseText.setColumns(30);
licenseText.setLineWrap(true);
licenseLinkLabel = new HyperlinkLabel("http://www.gnu.org/licenses/gpl-3.0.html");
licenseLinkLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
licenseLinkLabel.setActionCommand("licenseLink");
licenseLinkLabel.addActionListener(this);
JPanel infoPanel = new JPanel();
infoPanel.setLayout(new BoxLayout(infoPanel, BoxLayout.Y_AXIS));
infoPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
infoPanel.setAlignmentY(Component.TOP_ALIGNMENT);
infoPanel.add(titleLabel);
infoPanel.add(authorLabel);
infoPanel.add(linkLabel);
infoPanel.add(Box.createVerticalStrut(20));
infoPanel.add(versionLabel);
infoPanel.add(Box.createVerticalStrut(20));
infoPanel.add(licenseText);
infoPanel.add(licenseLinkLabel);
JPanel upperPanel = new JPanel();
upperPanel.setLayout(new BoxLayout(upperPanel, BoxLayout.X_AXIS));
upperPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
upperPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
upperPanel.add(iconLabel);
upperPanel.add(infoPanel);
JButton okButton = new JButton("OK");
okButton.setMnemonic(KeyEvent.VK_O);
okButton.setAlignmentX(Component.CENTER_ALIGNMENT);
okButton.addActionListener(this);
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
contentPane.add(upperPanel);
contentPane.add(okButton);
contentPane.add(Box.createVerticalStrut(10));
getRootPane().setDefaultButton(okButton);
pack();
setResizable(false);
setLocationRelativeTo(owner);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("OK")) {
this.dispose();
}
else if (e.getActionCommand().equals("link") || e.getActionCommand().equals("licenseLink")) {
String url = ((HyperlinkLabel)e.getSource()).getText();
try {
Desktop.getDesktop().browse(new URI(url));
}
catch(IOException ioe) {
JOptionPane.showMessageDialog(this, "A default browser could not be opened:\n\n" + ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
catch(URISyntaxException se) {
JOptionPane.showMessageDialog(this, "Internal URI syntax exception:\n\n" + se.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
}