/*
 * @(#)HelpWin.java
 *
 * This file is part of webCDwriter - Network CD Writing.
 *
 * Copyright (C) 1999-2004 Jörg P. M. Haeger
 *
 * webCDwriter is free software. See CDcreator.java for details.
 */

import java.awt.Rectangle;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.*;
import javax.swing.event.*;

public class HelpWin extends JFrame {
	public HelpWin(URL url) {
		super(CDcreator.i18n("titleHelpWin"));
		Rectangle screenRect;
		try {
			getClass().getMethod("getGraphicsConfiguration", null);
			screenRect = getGraphicsConfiguration().getBounds();
		}
		catch (NoSuchMethodException e) {
			screenRect = new Rectangle(0, 0, 1024, 768);
		}
		int width = 640, height = 480;
		setBounds(
			screenRect.x + (screenRect.width - width) / 2,
			screenRect.y + (screenRect.height - height) / 2,
			width, height);
		setContentPane(new HtmlPane(url));
	}
}

class HtmlPane
	extends JScrollPane
	implements HyperlinkListener {
	JEditorPane html;

	public HtmlPane(URL url) {
		try {
			html = new JEditorPane(url);
			html.setEditable(false);
			html.addHyperlinkListener(this);

			JViewport vp = getViewport();
			vp.add(html);
		} catch (IOException e) {
			System.out.println("IOException: " + e);
		}
	}

	/**
	 *
	 */
	public void hyperlinkUpdate(HyperlinkEvent e) {
		if (e.getEventType()
			== HyperlinkEvent.EventType.ACTIVATED) {
			try {
				System.out.println(e.getURL());
				html.setPage(e.getURL());
			}
			catch (IOException e2) {
				System.out.println("IOException: " + e2);
			}
		}
	}
}
