/**
 * Scott's XML Editor - Swing and JDOM XML Editor
 * @author Scott Hurring - scott at hurring dot com
 * @version beta1
 * @license GPL
 * For most recent version, go to this url:
 * http://hurring.com/code/java/xmleditor/
 */

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
{
	public AboutDialog() {
		super(new Frame(), "About");
	}
	
	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>About Scott's XML Editor</h2></center>");
		headText.setEditable(false);
		
		// About text
		JEditorPane aboutText = createHtmlEditorPane();
		aboutText.setBorder(new EmptyBorder(10,10,10,10));
		aboutText.setText("Swing XML Editor using JDom<p>" +
				"Scott Hurring<br>" +
				"scott at hurring dot com<br>" +
				"http://hurring.com/<p>" +
				"v1.0 beta 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);

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

}

