/**
 * JavaLife - Conway's Life Simulation
 * @author Scott Hurring - scott at hurring dot com
 * @version alpha1
 * @license GPL
 * For most recent version, go to this url:
 * http://hurring.com/code/java/javalife/
 */

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

/**
 * About Dialog
 */
public class AboutDialog extends JDialog
{
	private JavaLife parent;
	
	public AboutDialog(JavaLife parent)
	{
		super(new Frame(), "About Java Life");
		this.parent = parent;
	}
	
	void display()
	{
		setBounds(100, 100, 300, 300);
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				performCloseAction();
			}
		});

		JPanel p = new JPanel();
		p.setLayout(new BorderLayout());

		// Header text
		JEditorPane headText = createHtmlEditorPane();
		headText.setText("<center><h2>Java Life v"+ parent.VERSION +"</h2></center>");
		headText.setEditable(false);
		
		// About text
		JEditorPane aboutText = createHtmlEditorPane();
		aboutText.setBorder(new EmptyBorder(10,10,10,10));
		aboutText.setText("Conway's Life Simulation<p>" +
				"Scott Hurring<br>" +
				"sh5 at njit dot edu<br>" +
				"scott at hurring dot com<br>" +
				"http://hurring.com/<p>" +
				"v1.0 released May, 2005<p>");
		aboutText.setEditable(false);

		// OK Button
		JPanel s = new JPanel();
		s.setLayout(new FlowLayout());
		JButton closeButton = new JButton("Close");
		closeButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				performCloseAction();
			}
		});
		s.add(closeButton);

		p.add(headText, BorderLayout.NORTH);
		p.add(aboutText, BorderLayout.CENTER);
		p.add(s, BorderLayout.SOUTH);

		this.pack();
		getContentPane().add(p);
		
		setVisible(true);
	}
	
	private JEditorPane createHtmlEditorPane()
	{
		return new JEditorPane("text/html", "");
	}
	
	private void performCloseAction()
	{
		setVisible(false);
	}

}

