/**
	AUTHOR & Copyright Holder: Anthony Hand (anthony@handaweb.com)

	COURSE: University of Michigan SI 544

	DATE: 11/3/98

	URL
		http://www.handaweb.com/anthony/coursework/

	SUMMARY:
 		This class creates window frames specificly designed to draw the user's
 		attention to an error in the applet. The user should close the window 
 		before proceeding.

   CREDITS:
		o This was originally created for Anthony's Samurai Age applet.

   INPUT (this class):
		o This class should be sent 3 strings:
		  1 instantiate a new ErrorWin (title), where "title" is the text you 
		    want for the frame title.
		  2 Call setErrorTA(errorType, userDoes) with these two strings:
		    - errorType is the type of error causing the window to pop up
		    - userDoes is what the user should do next -- be succinct & specific!

   BAD DATA CHECKING:
		o N/A

   OUTPUT:
		o Creates Error popup windows with customizable messages.

   CLASS HIERARCHY:
        Object
        |
        +---ReadBean
        |
        +---WriteBean
        |
        +---Component
            |
            +---Container
                |
                +---Panel
                |   |
                |   +---Applet
                |       |
                |       +---JBDemo
                |
                +---Window
                    |
                    +---Frame
                        |
                        +---BrowseWin
                        |
                        +---RespondWin
                        |
                        +---CheckWin
                        |
                        +---PostWin
                        |
                        +---ErrorWin
                        |
                        +---StyleBean

   ASSUMPTIONS
		o The error message should display on the first line of the text area.
		o The user will close the window before attempting to preceed with use of
		  the applet.

	NOTES
	    o The GUI was purposefully designed to be a little obnoxious with the
	      orange color with the hope that it'll not only draw the user's attention,
	      but also cause her to want to close it before proceeding.
	    o I used  code that came from the original ErrorPopup class I wrote for
	      the SamuraiAge game during Winter 98's Java class
*/


import java.awt.*;
import java.beans.*;
import java.awt.Toolkit.*;

public class ErrorWin extends java.awt.Frame
{
	//GUI objects
	java.awt.Button closeBtn;
	java.awt.TextArea errorTA;
	java.awt.Label errorWinLbl;
	StyleBean styleBean;

	public ErrorWin()
	{
		styleBean = new StyleBean ();
		setLayout(null);
		setVisible(false);
		setSize(482,302);
		setFont(styleBean.getRegularTAFont());
		setBackground(new Color(16762880)); //orange

		closeBtn = new java.awt.Button();
		closeBtn.setLabel("Close  Error  Window");
		closeBtn.setBounds(150,240,styleBean.getBtnWidth(),styleBean.getBtnHeight());
		closeBtn.setFont(styleBean.getBtnFont());
		closeBtn.setForeground(new Color(16777215));
		closeBtn.setBackground(new Color(-16764058));
		add(closeBtn);

		errorTA = new java.awt.TextArea();
		errorTA.setText("There's been an error! \n" +
		    "Close this window and try again."); //default text
		errorTA.setBounds(11,84,460,132);
		errorTA.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
		errorTA.setBackground(new Color(16777215));
		add(errorTA);

		errorWinLbl = new java.awt.Label("Error!",Label.CENTER);
		errorWinLbl.setBounds(156,12,168,48);
		errorWinLbl.setFont(new Font("Dialog", Font.BOLD, 24));
		errorWinLbl.setForeground(new Color(0));
		add(errorWinLbl);
		setTitle("Error!");
		this.pack();

		//listeners
		ErrorWinAdapter errorWinAdapter = new ErrorWinAdapter();
		this.addWindowListener(errorWinAdapter);
		ErrorWinActionListener errorActionListener = new ErrorWinActionListener();
		closeBtn.addActionListener(errorActionListener);
	}

	//single parameter ErrorPopup constructor
	public ErrorWin(String title)
	{
		this();
		setTitle(title);
	} //single parameter ErrorPopup constructor


    public void setErrorWinTitle (String newTitle)
    {
        setTitle (newTitle);
    } //setErrorWinTitle

    //errorType is the type of error causing the window to pop up
    //userDoes is what the user should do next -- be specific!
    public void setErrorTA (String errorType, String userDoes)
    {
        errorTA.setText (errorType + " \n" + userDoes);
    } //setErrorTA



    //*********************SYMANTEC METHODS**************************
    //    Methods from here to Listeners created by Symantec
    //*********************SYMANTEC METHODS**************************

	public synchronized void show()
	{
		move(50, 50);
		super.show();
	} //show
	public void addNotify()
	{
		// Record the size of the window prior to calling parents addNotify.
		Dimension d = getSize();

		super.addNotify();

		if (fComponentsAdjusted)
			return;

		// Adjust components according to the insets
		setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
		Component components[] = getComponents();
		for (int i = 0; i < components.length; i++)
			{
			Point p = components[i].getLocation();
			p.translate(insets().left, insets().top);
			components[i].setLocation(p);
		} //for
		fComponentsAdjusted = true;
	} //addnotify

	// Used for addNotify check.
	boolean fComponentsAdjusted = false;


    //*********************INNER CLASS*****************************
    //                  handles Window events 
    //*********************INNER CLASS*****************************
    class ErrorWinAdapter extends java.awt.event.WindowAdapter
    {
        public void windowClosing(java.awt.event.WindowEvent event)
        {
            Object object = event.getSource();
            if (object == ErrorWin.this)
                ErrorWin_WindowClosing(event);
        } //window closing
    } //ErrorPopupWinAdapter

	//this works with the above inner class
	void ErrorWin_WindowClosing(java.awt.event.WindowEvent event)
	{
		dispose();		 // dispose of the Frame.
	} //ErrorWin_WindowClosing


    //*********************INNER CLASS*****************************
    //              handles events for close button
    //*********************INNER CLASS*****************************
	class ErrorWinActionListener implements java.awt.event.ActionListener
	{
		public void actionPerformed(java.awt.event.ActionEvent event)
		{
			Object object = event.getSource();
			if (object == closeBtn)
				closeBtn_ActionPerformed(event);
		} //actionPerformed
	} //ErrorWinActionListener

	//this works with the above inner class
	void closeBtn_ActionPerformed(java.awt.event.ActionEvent event)
	{
		dispose();		 // dispose of the Frame.
	} //closeBtn_ActionPerformed

} //ErrorPopup