/*
	A basic extension of the java.awt.Dialog class
 */

import java.awt.*;

public class ErrorDialog extends Dialog
{
   Label label1;
   
	public ErrorDialog(Frame parent, String message, boolean modal)
	{
		super(parent, modal);

		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		setLayout(null);
		setVisible(false);
		setSize(getInsets().left + getInsets().right + 250,getInsets().top + getInsets().bottom + 100);
		setFont(new Font("Dialog", Font.PLAIN, 12));
		setBackground(new Color(12632256));
		okButton = new java.awt.Button();
		okButton.setActionCommand("button");
		okButton.setLabel("OK");
		okButton.setBounds(getInsets().left + 100,getInsets().top + 65,50,20);
		okButton.setBackground(new Color(12632256));
		add(okButton);
		label1 = new Label("");
		label1.setBounds(10, 20, 200, 20);
		add(label1);
		label1.setText(message);
		setTitle("Error:");
		//}}

		//{{REGISTER_LISTENERS
		SymWindow aSymWindow = new SymWindow();
		this.addWindowListener(aSymWindow);
		SymAction lSymAction = new SymAction();
		okButton.addActionListener(lSymAction);
		//}}
	}
	
	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 getInsets
		setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
		Component components[] = getComponents();
		for (int i = 0; i < components.length; i++)
		{
			Point p = components[i].getLocation();
			p.translate(getInsets().left, getInsets().top);
			components[i].setLocation(p);
		}
		fComponentsAdjusted = true;
	}

    // Used for addNotify check.
	boolean fComponentsAdjusted = false;


	public ErrorDialog(Frame parent, String message, String title, boolean modal)
	{
		this(parent, message, modal);
		setTitle(title);
	}

	public synchronized void show()
	{
		Rectangle bounds = getParent().bounds();
		Rectangle abounds = bounds();

		move(bounds.x + (bounds.width - abounds.width)/ 2,
			 bounds.y + (bounds.height - abounds.height)/2);

		super.show();
	}

	//{{DECLARE_CONTROLS
	java.awt.Button okButton;
	//}}

	class SymWindow extends java.awt.event.WindowAdapter
	{
		public void windowClosing(java.awt.event.WindowEvent event)
		{
			Object object = event.getSource();
			if (object == ErrorDialog.this)
				Dialog1_WindowClosing(event);
		}
	}
	
	void Dialog1_WindowClosing(java.awt.event.WindowEvent event)
	{
		hide();
	}

	class SymAction implements java.awt.event.ActionListener
	{
		public void actionPerformed(java.awt.event.ActionEvent event)
		{
			Object object = event.getSource();
			if (object == okButton)
				okButton_Action(event);
		}
	}

	void okButton_Action(java.awt.event.ActionEvent event)
	{
	   hide();
	}
	
	void setMessage(String message)
	{
	   label1.setText(message);
	}
}
