/*
 *
 * Copyright (C) 05 janv. 2003  Jean-Yves Beaujean 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,  59
 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.

 * 
 */

package jxtray.gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.JWindow;
import javax.swing.JProgressBar;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

import jxtray.ui.JxtProgressBarUI;


import jxtray.Jxtray;

public class SplashScreen extends JWindow implements Runnable, ActionListener
{
  private JProgressBar pBar = new JProgressBar();

  private Thread thread;
  private boolean finished = false;
  private String text = new String();


  public SplashScreen(JFrame frame)
  {
	    try
    	{
      		jbInit();
      		pack();
    	}
    	catch(Exception ex)
    	{
      		ex.printStackTrace();
    	}
       	thread = new Thread(this);
       	thread.start();
  }

  void jbInit() throws Exception
  {
    pBar.setStringPainted(true);
    pBar.setOpaque(true);
    pBar.setString("");
    pBar.setUI(new JxtProgressBarUI());
    pBar.setFont(Jxtray.getFont());

    this.getContentPane().setLayout(new BorderLayout() );
	this.getContentPane().add(new JLabel((new ImageIcon(getClass().getResource("/images/splashscreen.gif")))), BorderLayout.CENTER);
	this.getContentPane().add(pBar, BorderLayout.SOUTH);

  }

  public void actionPerformed(ActionEvent e)
  {
       this.setVisible(false);
  }

  public void setText( String text )
  {
        this.text = text;
  }
  public void setValue( int val ) 
  {
  	pBar.setValue(val); 
  }

  public void run()
  {
        try
        {
            while ( !finished )
            {
				pBar.setString(text);
                Thread.sleep(500);
                
            }
        }
        catch ( InterruptedException e )
        {
        }
        this.setVisible(false);
  }

  public boolean isFinished() { return finished; }
  public void stop()       { finished = true; }

}