package saccubus;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import psi.lib.swing.PopupRightClick;

/**
 * <p>
 * ^Cg: ΂
 * </p>
 *
 * <p>
 * : jRjR̓Rgŕۑ
 * </p>
 *
 * <p>
 * 쌠: Copyright (c) 2007 PSI
 * </p>
 *
 * <p>
 * Ж:
 * </p>
 *
 * @author 
 * @version 1.0
 */
public class MainFrame_AboutBox extends JDialog implements ActionListener {
	/**
	 *
	 */
	private static final long serialVersionUID = -4256413309312729840L;

	String version = "ver1.22r(2008/04/27)";

	public static final String rev = "1.22r3e2";
	private static final String modDate = " (2011/07/11)";

	String productBack =
		"{vO\n" +
		"  u΂ 1.22r3v\n" +
		"  u΂NicoBrowserg1.4.4v\n" +
		"̂łB  orz " + rev + modDate + "\n"+
		"Lі{vÕIWi͈ȉ̒ʂłB\n\n"+
		"΂\n"+
		version + "\n\n"+
		"Copyright (C) 2008 Saccubus Developers Team\n"+
		"              2007-2008 PSI\n\n"+
		"jRjR̓Rgŕۑ";

	String product =
		"<html>{vO<br/>" +
		"  u΂ 1.22r3v<br/>" +
		"  u΂NicoBrowserg1.4.4v<br/>" +
		"̂łB  orz " + rev + modDate + "<br/>"+
		"Lі{vÕIWi͈ȉ̒ʂłB<br/><br/>"+
		"΂<br/>"+
		version + "<br/><br/>"+
		"Copyright (C) 2008 Saccubus Developers Team<br/>"+
		"              2007-2008 PSI<br/><br/>"+
		"jRjR̓Rgŕۑ</html>";
	/**
	 * HTMLGfB^[
	 */
	/*
	private void initPane(Container c) {
		JEditorPane editor = new JEditorPane();
		editor.setContentType("text/html");

		editor.setText("<b>Hello</b>, <i>Swing</i>");

		c.add(editor);
	}
*/
	String str =
		"<a href='http://www.ne.jp/asahi/hishidama/home/tech/java/swing/index.html'>Swing</a>" +
		"N̎";
	JEditorPane text = new JEditorPane("text/html", str);

	text.setEditable(false);	//ҏWs
	text.setOpaque(false);	//wi𓧉

	text.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);	//tHgL
	text.setFont(new JLabel().getFont());					//tHgw

	text.addHyperlinkListener(new HyperlinkHandler());	//NCxgXi[o^
	private class HyperlinkHandler implements HyperlinkListener {

		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			if (e.getEventType() == EventType.ACTIVATED) {	//NbNꂽ
				URL url = e.getURL();

				//ftHg̃uEU[găN\
				Desktop dp = Desktop.getDesktop();
				try {
					dp.browse(url.toURI());
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
		}

		@Override
		public void hyperlinkUpdate(HyperlinkEvent e) {
			// TODO ꂽ\bhEX^u
			
		}
	}
	JEditorPane editor = new JEditorPane(
			"text/html", "<html><a href=''>"+"</a>");
	editor.setOpaque(false);
	//editor.setBackground(getBackground());
	//editor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
	editor.setEditable(false); //REQUIRED
	editor.addHyperlinkListener(new HyperlinkListener() {
	  @Override public void hyperlinkUpdate(HyperlinkEvent e) {
	    if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED) {
	      java.awt.Toolkit.getDefaultToolkit().beep();
	    }
	  }
	});	JPanel panel1 = new JPanel();

	JPanel panel2 = new JPanel();

	JPanel insetsPanel1 = new JPanel();

	JPanel insetsPanel2 = new JPanel();

	JPanel insetsPanel3 = new JPanel();

	JButton button1 = new JButton();

	JLabel imageLabel = new JLabel();

	JTextArea product_field = new JTextArea(product);

	ImageIcon image1 = new ImageIcon();

	BorderLayout borderLayout1 = new BorderLayout();

	BorderLayout borderLayout2 = new BorderLayout();

	FlowLayout flowLayout1 = new FlowLayout();

	GridLayout gridLayout1 = new GridLayout();

	public MainFrame_AboutBox(Frame parent) {
		super(parent);
		try {
			setDefaultCloseOperation(DISPOSE_ON_CLOSE);
			jbInit();
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}

	public MainFrame_AboutBox() {
		this(null);
	}

	/**
	 * R|[lg̏B
	 *
	 * @throws java.lang.Exception
	 */
	private void jbInit() throws Exception {
		image1 = new ImageIcon(saccubus.MainFrame.class.getResource("icon.png"));
		imageLabel.setIcon(image1);
		setTitle("o[W");
		panel1.setLayout(borderLayout1);
		panel2.setLayout(borderLayout2);
		insetsPanel1.setLayout(flowLayout1);
		insetsPanel2.setLayout(flowLayout1);
		insetsPanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		gridLayout1.setRows(1);
		gridLayout1.setColumns(1);
		insetsPanel3.setLayout(gridLayout1);
		insetsPanel3.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		button1.setText("OK");
		button1.addActionListener(this);
		insetsPanel2.add(imageLabel, null);
		panel2.add(insetsPanel2, BorderLayout.WEST);
		getContentPane().add(panel1, null);
		product_field.setForeground(insetsPanel3.getForeground());
		product_field.setBackground(insetsPanel3.getBackground());
		product_field.addMouseListener(new PopupRightClick(product_field));
		product_field.setEditable(false);
		insetsPanel3.add(product_field, null);
		panel2.add(insetsPanel3, BorderLayout.CENTER);
		insetsPanel1.add(button1, null);
		panel1.add(insetsPanel1, BorderLayout.SOUTH);
		panel1.add(panel2, BorderLayout.NORTH);
		setResizable(true);
	}

	/**
	 * {^CxgŃ_CAO
	 *
	 * @param actionEvent
	 *            ActionEvent
	 */
	@Override
	public void actionPerformed(ActionEvent actionEvent) {
		if (actionEvent.getSource() == button1) {
			dispose();
		}
	}
}
