package j3deditor.bin.components;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JDialog;


/**
 * Base class for popup dialogues.
 * 
 * @author Risto Seene
 */
public class PopupDialog extends JDialog{
	
	/**
	 * Creates an instance of <code>PopupDialog</code>.
	 */
	public PopupDialog(){}
	
	/**
	 * Creates an instance of <code>PopupDialog</code>
	 * with the given title and size.
	 * 
	 * @param title
	 * 	the String to display in the dialog's title bar 
	 * @param x
	 * 	width of this dialog
	 * @param y
	 * 	height of this dialog
	 */
	public PopupDialog(String title, int x, int y){
		this.initDialog(title, x, y);
	}
	
	/**
	 * Creates an instance of <code>PopupDialog</code>
	 * with the given icon, title and size.
	 * 
	 * @param icon
	 * 	the image to dispaly in the dialog's icon area
	 * @param title
	 * 	the String to display in the dialog's title bar
	 * @param x
	 * 	width of this dialog
	 * @param y
	 * 	height of this dialog
	 */
	public PopupDialog(Image icon, String title, int x, int y){
		this.initDialog(icon, title, x, y);
	}
	
	/**
	 * Creates an instance of <code>PopupDialog</code>
	 * with the given title, size and component in it
	 * and makes it visible.
	 * 
	 * @param title
	 * 	the String to display in the dialog's title bar
	 * @param x
	 * 	width of this dialog
	 * @param y
	 * 	height of this dialog
	 * @param component
	 * 	component which will be shown in this dialog
	 */
	public PopupDialog(String title, int x, int y, Component component){
		this.initDialog(title, x, y);
		this.add(component);
		this.setVisible(true);
	}
	
	/**
	 * Creates an instance of <code>PopupDialog</code>
	 * with the given icon, title, size and component in it
	 * and makes it visible.
	 * 
	 * @param icon
	 * 	the image to dispaly in the dialog's icon area
	 * @param title
	 *	the String to display in the dialog's title bar
	 * @param x
	 * 	width of this dialog
	 * @param y
	 * 	height of this dialog
	 * @param component
	 * 	component which will be shown in this dialog
	 */
	public PopupDialog(Image icon, String title, int x, int y, Component component){
		this.initDialog(icon, title, x, y);
		this.add(component);
		this.setVisible(true);
	}
	
	/**
	 * Initializes this dialog properly.
	 * Makes this dialog modal and non-resizable.
	 * 
	 * @param title
	 * 	the String to display in the dialog's title bar
	 * @param x
	 * 	width of this dialog
	 * @param y
	 * 	height of this dialog
	 */
	protected void initDialog(String title, int x, int y){
		this.setModal(true);

		this.setTitle(title);
		this.setSize(x, y);
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation((int)((dim.getWidth() - getWidth()) / 2), (int)((dim.getHeight() - getHeight()) / 2));
		this.setResizable(false);
	}
	
	/**
	 * Initializes this dialog properly.
	 * Makes this dialog modal and non-resizable.
	 * 
	 * @param icon
	 * 	the image to dispaly in the dialog's icon area
	 * @param title
	 * 	the String to display in the dialog's title bar
	 * @param x
	 * 	width of this dialog
	 * @param y
	 * 	height of this dialog
	 */
	protected void initDialog(Image icon, String title, int x, int y){
		this.setModal(true);

		this.setIconImage(icon);
		this.setTitle(title);
		this.setSize(x, y);
		Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation((int)((dim.getWidth() - getWidth()) / 2), (int)((dim.getHeight() - getHeight()) / 2));
		this.setResizable(false);
	}
	
}
