package net.oni2.aeinstaller.gui.about;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.ResourceBundle;

import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.KeyStroke;

import net.oni2.resourcebundle.UTF8ResourceBundleLoader;
import net.oni2.swingcomponents.HTMLLinkLabel;

import org.javabuilders.BuildResult;
import org.javabuilders.swing.SwingJavaBuilder;

/**
 * @author Christian Illy
 */
public class AboutDialog extends JDialog {
	private static final long serialVersionUID = 1632257865019785612L;

	private ResourceBundle bundle = UTF8ResourceBundleLoader.getBundle(getClass()
			.getName());
	@SuppressWarnings("unused")
	private BuildResult result = SwingJavaBuilder.build(this, bundle);

	private JLabel lblAppname;
	private HTMLLinkLabel txtLinks;
	private HTMLLinkLabel lblAE;

	/**
	 * Open the dialog
	 */
	public AboutDialog() {
		lblAppname.setText(SwingJavaBuilder.getConfig().getResource("appname")
				+ SwingJavaBuilder.getConfig().getResource("appversion"));

		txtLinks.setText(bundle.getString("Links"));
		lblAE.setText(bundle.getString("ae"));

		pack();

		AbstractAction closeAction = new AbstractAction() {

			private static final long serialVersionUID = 1L;

			public void actionPerformed(ActionEvent arg0) {
				dispose();
			}
		};
		KeyStroke ksCtrlW = KeyStroke
				.getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK);
		getRootPane()
				.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
				.put(ksCtrlW, "close");
		getRootPane().getActionMap().put("close", closeAction);

		setLocationRelativeTo(null);
	}

}
