/*
 * Created on 2004/10/28
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package jp.riken.brain.ni.samuraigraph.base;

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.colorchooser.*;


/**
 * @author kuromaru
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public abstract class SGDialog extends JDialog
	implements ActionListener, WindowListener, ComponentListener, SGIConstants
{


	/**
	 * 
	 */
	public static final String OK_BUTTON_TEXT = "OK";


	/**
	 * 
	 */
	public static final String CANCEL_BUTTON_TEXT = "Cancel";


	/**
	 * 
	 */
	protected ArrayList mActionListenerList = new ArrayList();


	/**
	 * 
	 */
	public SGDialog()
	{
		super();
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Dialog owner )
	{
		super( owner );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Dialog owner, boolean modal )
	{
		super( owner, modal );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Dialog owner, String title )
	{
		super( owner, title );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Dialog owner, String title, boolean modal )
	{
		super( owner, title, modal );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Dialog owner, String title, boolean modal, GraphicsConfiguration gc )
	{
		super( owner, title, modal, gc );
		this.initialize();
	}



	/**
	 * 
	 */
	public SGDialog( Frame owner )
	{
		super( owner );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Frame owner, boolean modal )
	{
		super( owner, modal );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Frame owner, String title )
	{
		super( owner, title );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Frame owner, String title, boolean modal )
	{
		super( owner, title, modal );
		this.initialize();
	}


	/**
	 * 
	 */
	public SGDialog( Frame owner, String title, boolean modal, GraphicsConfiguration gc )
	{
		super( owner, title, modal, gc );
		this.initialize();
	}



	/**
	 * 
	 * @return
	 */
	private boolean initialize()
	{
		// set unresizable
		this.setResizable(false);

		//
		this.addComponentListener(this);

		//
		this.addWindowListener(this);


		return true;

	}



	/**
	 * コンポーネントが可視になると呼び出されます。 
	 */
	public void componentShown(final ComponentEvent e)
	{
	}


	/**
	 * コンポーネントが不可視になると呼び出されます。 
	 */
	public void componentHidden(final ComponentEvent e)
	{
	}


	/**
	 * コンポーネントの位置が変わると呼び出されます。 
	 */
	public void componentMoved(final ComponentEvent e)
	{
		Object owner = this.getOwner();
		if( owner instanceof Window )
		{
			Window wnd = (Window)owner;
			wnd.repaint();
		}
	}


	/**
	 * コンポーネントのサイズが変わると呼び出されます。 
	 */
	public void componentResized(final ComponentEvent e)
	{
	}



	/**
	 * 
	 */
	public void windowActivated(final WindowEvent e)
	{
	}


	/**
	 * 
	 */
	public void windowDeactivated(final WindowEvent e)
	{
	}


	/**
	 * 
	 */
	public void windowIconified(final WindowEvent e)
	{
	}


	/**
	 * 
	 */
	public void windowDeiconified(final WindowEvent e)
	{
	}


	/**
	 * 
	 */
	public void windowOpened(final WindowEvent e)
	{
	}


	/**
	 * 
	 */
	public void windowClosed(final WindowEvent e)
	{
	}


	/**
	 * 
	 */
	public void windowClosing(final WindowEvent e)
	{
	}



	/**
	 * 
	 */
	protected ActionEvent getActionEvent( final String command )
	{
		return new ActionEvent( this, 0, command );
	}


	/**
	 * 
	 */
	public void addActionListener( final ActionListener listener )
	{
		for( int ii=0; ii<mActionListenerList.size(); ii++ )
		{
			final ActionListener el = (ActionListener)mActionListenerList.get(ii);
			if( el.equals(listener) )
			{
				return;
			}
		}
		mActionListenerList.add(listener);
	}


	/**
	 * 
	 */
	public void removeActionListener( ActionListener listener )
	{
		for( int ii=mActionListenerList.size()-1; ii>=0; ii-- )
		{
			final ActionListener el = (ActionListener)mActionListenerList.get(ii);
			if( el.equals(listener) )
			{
				mActionListenerList.remove(listener);
			}
		}
	}


	/**
	 * 
	 */
	protected void notifyToListener( final String command )
	{
		for( int ii=0; ii<mActionListenerList.size(); ii++ )
		{
			final ActionListener el = (ActionListener)mActionListenerList.get(ii);
			el.actionPerformed( this.getActionEvent( command ) );
		}
	}



	/**
	 * 
	 * @param wnd
	 * @return
	 */
	public void setCenter( final Window owner )
	{
		SGUtility.setCenter( this, owner );
	}


}


