package gve.calc;

import awt.Button;
import awt.GridPackLayout;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.Applet;
import java.awt.image.ImageObserver;
import java.io.*;

public class AboutWindow extends Frame implements WindowListener,ActionListener
{
	public AboutWindow(Applet app) {
		super("About SICECAS " + Main.versionString);
		setBackground(Color.lightGray);

		Panel rightPanel;

		setLayout(new FlowLayout());
		// NOTE: first pack()ing and show()ing the window
		// causes the window to resize automatically
		// when the image is loaded.
		try {
			URL url = getClass().getResource("geert.gif");
			if (url != null) {
				Image im = createImage(
					(java.awt.image.ImageProducer)url.getContent());
				add(new awt.ImagePanel(im,this));
			} else {
				// Netscape does not support getResource()
				// zie http://developer.netscape.com/support/faqs/index.html?content=champions/java.html
				// maar wel getResourceAsStream();
				InputStream stream = getClass().getResourceAsStream("geert.gif");
				if (stream != null) {
					ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
					int c;
					while ((c = stream.read()) >= 0)
						bytestream.write(c);
					Image im = getToolkit().createImage(bytestream.toByteArray());
					add(new awt.ImagePanel(im,this));
					stream.close();
				}
			}
		} catch (IOException exc) {}

		add(rightPanel = new Panel());
		rightPanel.setLayout(new GridPackLayout(0,1));
		rightPanel.add(new Label("SICECAS " + Main.versionString,
			Label.CENTER));
		rightPanel.add(new Label("a SImplistic Calculator & Computer Algebra System",Label.CENTER));
		rightPanel.add(new Label(""));
		rightPanel.add(new Label("Copyright (C) 1997, 1998, 1999, 2000, 2001, Geert Vernaeve.",
			Label.CENTER));
		rightPanel.add(new Label("SICECAS comes with ABSOLUTELY NO WARRANTY.",Label.CENTER));
		rightPanel.add(new Label("This is free software, and you are welcome to redistribute it",Label.CENTER));
		rightPanel.add(new Label("under certain conditions. For details, see the license.",Label.CENTER));
		rightPanel.add(new Label("E-mail: geert.vernaeve@rug.ac.be",
			Label.CENTER));
		Panel buttonPanel = new Panel();
		Button b;
		buttonPanel.add(b = new Button("OK"));
		b.addActionListener(this);
		buttonPanel.add(b = new Button("License"));
		b.addActionListener(this);
		rightPanel.add(buttonPanel);
		pack();
		setVisible(true);
		addWindowListener(this);
	}

	public void windowActivated(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {}
	public void windowClosing(WindowEvent e) { dispose(); }
	public void windowDeactivated(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowOpened(WindowEvent e) {}

	public void actionPerformed(ActionEvent evt) {
		if (evt.getActionCommand().equals("OK"))
			dispose();
		else if (evt.getActionCommand().equals("License"))
			new LicenseWindow();
	}
}