package ckelling.baukasten;

/**
    A basic extension of the java.awt.Frame class
 */

import java.awt.*;

public class ErrorMessage extends Frame {

	public ErrorMessage(String message) {

		//{{INIT_CONTROLS
		GridBagLayout gridBagLayout;
		gridBagLayout = new GridBagLayout();
		setLayout(gridBagLayout);
		addNotify();
		resize(insets().left + insets().right + 211,insets().top + insets().bottom + 154);
		setFont(new Font("Helvetica", Font.PLAIN, 12));
		setBackground(new Color(12632256));
		buttonOK = new java.awt.Button("OK");
		buttonOK.reshape(insets().left + 90,insets().top + 99,31,23);
		GridBagConstraints gbc;
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.gridy = 2;
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(0,30,10,30);
		gridBagLayout.setConstraints(buttonOK, gbc);
		add(buttonOK);
		titleLabel = new java.awt.Label("Es ist ein Fehler aufgetreten:");
		titleLabel.reshape(insets().left + 10,insets().top + 32,171,23);
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.gridy = 0;
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.fill = GridBagConstraints.NONE;
		gbc.insets = new Insets(10,10,0,10);
		gridBagLayout.setConstraints(titleLabel, gbc);
		add(titleLabel);
		setTitle("FEHLER");
		//}}

		messageLabel = new RTFTextArea(Rechner.SMALLFONT);
		messageLabel.reshape(insets().left + 10,insets().top + 43,191,68);
		messageLabel.setBackground(new Color(12632256));
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.gridy = 1;
		gbc.weightx = 1.0;
		gbc.weighty = 1.0;
		gbc.fill = GridBagConstraints.BOTH;
		gbc.insets = new Insets(10,10,10,10);
		gridBagLayout.setConstraints(messageLabel, gbc);
		add(messageLabel);
		messageLabel.setText(message);

		pack();

		Rectangle bounds = bounds();
		int x = (640 - bounds.width) / 2;
		int y = (480 - bounds.height) / 2;
		x = (x + Rechner.numberOfErrorMessagesShowing*25) % 640;
		y = (y + Rechner.numberOfErrorMessagesShowing*25) % 480;
		move(x, y);

		Rechner.numberOfErrorMessagesShowing++;

		repaint();

		//{{INIT_MENUS
		//}}
	}

	/**
	 * @param title Der Titel des frame (Standard: "FEHLER")
	 * @param subTitle Die Überschrift im frame (Standard: "Es ist ein Fehler aufgetreten:")
	 * @param message Die anzuzeigende Meldung
	 */
	public ErrorMessage(String title, String subTitle, String message) {
	    this(message);
	    titleLabel.setText(subTitle);
	    setTitle(title);
	}

	public boolean handleEvent(Event event) {
    	if ( (event.id == Event.WINDOW_DESTROY) ||
    	     (event.id == Event.ACTION_EVENT && event.target == buttonOK) )
    	{
    		Rechner.numberOfErrorMessagesShowing--;
    		hide();
    		dispose();
    	}

		return super.handleEvent(event);
	}

	//{{DECLARE_CONTROLS
	java.awt.Button buttonOK;
	java.awt.Label titleLabel;
	//}}
	RTFTextArea messageLabel;

	//{{DECLARE_MENUS
	//}}
}
