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

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.font.FontRenderContext;
import java.awt.geom.Rectangle2D;

import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JWindow;

import jp.riken.brain.ni.samuraigraph.base.SGImagePanel;


public class SGSplashWindow extends JWindow
{

	/**
	 * 
	 */
	private Image mImage;


	/**
	 * 
	 */
	private Dimension mImageSize = new Dimension();


	/**
	 * 
	 * @param win
	 */
/*	public SGSplashWindow( Image img )
	{
		super();

		if( img==null )
		{
			throw new NullPointerException("img==null");
		}

		// set the media tracker
		MediaTracker mt = new MediaTracker(this);
		mt.addImage( img, 0 );
		try
		{
			mt.waitForAll();
		}
		catch (InterruptedException ex)
		{
		}

		// set attributes
		this.mImage = img;
		mImageSize.width = mImage.getWidth(this);
		mImageSize.height = mImage.getHeight(this);

		// set the bounds of this window
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		this.setBounds(
			( screen.width - mImageSize.width )/2,
			( screen.height - mImageSize.height )/2,
			mImageSize.width,
			mImageSize.height
		);

	}
*/


	/**
	 * 
	 * @param win
	 */
	public SGSplashWindow( Image img )
	{
		super();

		if( img==null )
		{
			throw new NullPointerException("");
		}

		// set the media tracker
		MediaTracker mt = new MediaTracker(this);
		mt.addImage( img, 0 );
		try
		{
			mt.waitForAll();
		}
		catch (InterruptedException ex)
		{

		}

		// set attributes
		this.mImage = img;
		mImageSize.width = mImage.getWidth(this);
		mImageSize.height = mImage.getHeight(this);

		// set the bounds of this window
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		this.setBounds(
			( screen.width - mImageSize.width )/2,
			( screen.height - mImageSize.height )/2,
			mImageSize.width,
			mImageSize.height
		);


/*
		SGImagePanel imgPanel = new SGImagePanel();
		imgPanel.setImage( img );


		// set text and potision of the version number label .
		final String vertext = "Version "
			+ SGDrawingServer.MAJOR_VERSION_NUMBER + "."
			+ SGDrawingServer.MINOR_VERSION_NUMBER + "."
			+ SGDrawingServer.MICRO_VERSION_NUMBER;
		JLabel vLabel = new JLabel();
		vLabel.setText(vertext);

		final Font font = vLabel.getFont();
		final Rectangle2D verrect = font.getStringBounds(
			vertext, new FontRenderContext(null, false, false));
		final int vh = (int)verrect.getHeight();
		final int vw = (int)verrect.getWidth();
		final int h = (verpos_b - verpos_t - vh) / 2 + verpos_t;
		final int w = verpos_r - vw;
		vLabel.setSize(vw, vh);
		vLabel.setBounds(w, h, vw, vh);

		// set the layer superposition
		JLayeredPane lPane = new JLayeredPane();
		lPane.setLayer(imgPanel,1);
		lPane.setLayer(vLabel,2);

		this.getContentPane().add( imgPanel );

		this.pack();
*/

//this.setVisible(true);
	}

	private static final int verpos_r = 375;  // right position of the version label
	private static final int verpos_t = 125;  // top position of the version label
	private static final int verpos_b = 155;  // bottom position of the version label


	/**
	 * 
	 */	
	public void paint( Graphics g )
	{
		super.paint(g);
		g.drawImage(
			mImage, 0, 0, 
			mImageSize.width, mImageSize.height,
			this
		);
	}


}

