/**
 *#########################################################################
 *
 * A component of the Greenstone Librarian Interface (GLI) application, 
 * part of the Greenstone digital library software suite from the New 
 * Zealand Digital Library Project at the University of Waikato, 
 * New Zealand.
 *
 * Author: John Thompson
 *         Greenstone Project, New Zealand Digital Library
 *         University of Waikato
 *         http://www.nzdl.org
 *
 * Copyright (C) 2004 New Zealand Digital Library, University of Waikato
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *########################################################################
 */
package org.greenstone.gatherer.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.greenstone.gatherer.Dictionary;
import org.greenstone.gatherer.Gatherer;
import org.greenstone.gatherer.util.JarTools;
import org.greenstone.gatherer.util.Utility;

/** Generates a pretty about dialog which not only thanks those for their contributions but also meets our legal requirements if we wish to ship the JVM with GLI.
 * @author John Thompson, Greenstone Project, New Zealand Digital Library, University of Waikato
 * @version 2.41 final
 */
// RICOH SOURCE CODE PUBLIC LICENSE - http://www.risource.org/RPL/RPL-1.0A.shtml
public class AboutDialog
    extends JDialog {
    /** The default size of the about dialog. */
    static final private Dimension SIZE = new Dimension(600, 325);
    /** The size of the GLI icon to display on dialog. */
    static final private int ICON_SIZE = 65;
    /** A reference to ourself so that our inner classes can dismiss us. */
    private AboutDialog self;
    /** The button used for dismissing the about dialog. */
    private JButton close_button;
    /** The constructor not only builds, but displays the about dialog. This method doesn't return until the dialog is dismissed.
     * @param parent the JFrame which owns this dialog for use in centering the dialog
     * @see org.greenstone.gatherer.Dictionary#get
     * @see org.greenstone.gatherer.Dictionary#setBoth
     * @see org.greenstone.gatherer.Dictionary#setText
     * @see org.greenstone.gatherer.gui.AboutDialog.CloseButtonListener
     * @see org.greenstone.gatherer.gui.GLIButton
     */
    public AboutDialog(JFrame parent) {
	super(parent, Dictionary.get("AboutDialog.Title"), true);
	this.self = this;
	setSize(SIZE);
		  
	JPanel content_pane = (JPanel) getContentPane();
	JPanel upper_pane = new JPanel();
	ImageIcon icon = JarTools.getImage("gatherer_medium.gif");
	ImageIcon scaled_icon = new ImageIcon(icon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT));
	JLabel icon_label = new JLabel(scaled_icon);
	JPanel title_pane = new JPanel();
	JLabel title_one_label = new JLabel(Dictionary.get("AboutDialog.Title_One"));
	JLabel title_two_label = new JLabel(Gatherer.PROGRAM_NAME + " " + Gatherer.PROGRAM_VERSION + " " + Dictionary.get("AboutDialog.Date"));
	JLabel title_three_label = new JLabel(Dictionary.get("AboutDialog.Title_Two"));
	JLabel copyright_label = new JLabel(Dictionary.get("AboutDialog.Copyright"));
	JLabel gpl_label = new JLabel(Dictionary.get("AboutDialog.Copyright_Two"));
	
	JTextArea text = new JTextArea();
	text.setLineWrap(true);
	text.setWrapStyleWord(true);

	JPanel button_pane = new JPanel();
	close_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
	
	// Connection
	close_button.addActionListener(new CloseButtonListener());

	// Layout
	icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));

	title_pane.setLayout(new GridLayout(5,1,0,2));
	title_pane.add(title_one_label);
	title_pane.add(title_two_label);
	title_pane.add(title_three_label);
	title_pane.add(copyright_label);
	title_pane.add(gpl_label);
		  
	upper_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
	upper_pane.setLayout(new BorderLayout());
	upper_pane.add(icon_label, BorderLayout.WEST);
	upper_pane.add(title_pane, BorderLayout.CENTER);

	button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
	button_pane.setLayout(new BorderLayout());
	button_pane.add(close_button, BorderLayout.EAST);

	content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
	content_pane.setLayout(new BorderLayout());
	content_pane.add(upper_pane, BorderLayout.NORTH);
	content_pane.add(new JScrollPane(text), BorderLayout.CENTER);
	content_pane.add(button_pane, BorderLayout.SOUTH);

	// Build text content
	text.append(Dictionary.get("AboutDialog.Java_Req"));
	text.append("\n");
	text.append(Dictionary.get("AboutDialog.Java_Req_One"));
	text.append("\n");
	text.append(Dictionary.get("AboutDialog.Java_Req_Two"));
	text.append("\n\n");
	text.append("*****" + Dictionary.get("AboutDialog.Acknowledgement") + "*****");
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item0"));
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item2"));
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item3"));
	text.append("\n\n");
	text.append("*****" + Dictionary.get("AboutDialog.Thanks") + "*****");
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item4"));
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item5"));
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item6"));
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item7"));
	text.append("\n\n");
	text.append(Dictionary.get("AboutDialog.Item8"));
	text.setCaretPosition(0);

	// Show
	Rectangle frame_bounds = parent.getBounds();
	setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
	setVisible(true);
    }
    /** Listens for actions upon the close button, and when detected closes the dialog. */
    private class CloseButtonListener
	implements ActionListener {
	/** Called whenever an action occurs on the close button, thus asking the dialog to close.
	 * @param event an ActionEvent containing information about the button press
	 */
	public void actionPerformed(ActionEvent event) {
	    self.setVisible(false);
	    self.dispose();
	}
    }
}
