001/* ****************************************************************************/
002/*                              Splash                                        */
003/*                          - Tom B. Gutwin -                                 */
004/*  En Extended Frame to act as a splash pane that comes up before the app    */
005/* ************************************************************************** */
006/*  This program requires JVM 1.2 or JVM 1.1  SWING NOT REQUIRED              */
007/*  If building with the OS/2 JDK - at least 1.1.4 with the 1.1.4 fixes       */
008/* ****************************************************************************/
009
010/*
011$Copyright $
012
013$Header: v:/cvsroot/open/projects/WebARTS/ca/bc/webarts/widgets/Splash.java,v 1.4 2002/04/04 23:02:50 anonymous Exp $
014
015$Log: Splash.java,v $
016Revision 1.4  2002/04/04 23:02:50  anonymous
017Commented out some debug statements. Added some extra exception handling.
018
019Revision 1.3  2001/10/28 06:48:28  tgutwin
020
021Added some Constructors that take an image (so this class doesn't have to go looking for the file.
022
023Revision 1.2  2001/09/02 03:24:30  tgutwin
024
025Initial Rev of my custom DropDown Boxes.
026
027Revision 1.1.1.1  2001/03/03 23:36:06  tgutwin
028Imported Sources
029
030
031*/
032
033package ca.bc.webarts.widgets;
034
035import java.awt.*;
036import java.awt.event.*;
037import java.io.File;
038import java.lang.*;
039import java.awt.Dimension;
040import ca.bc.webarts.widgets.ImageCanvas;
041
042
043/**
044 * Splash is a Application Opening splash screen.
045 * It provides an expandable API for its use as a generic Splash, allowing
046 * the user to specify the graphic to use as well as the message to put up.
047 */
048public class Splash extends Frame implements Runnable{
049  Toolkit toolkit = Toolkit.getDefaultToolkit();
050  Window  window;
051  Image   image = null;
052  static String         imgName = "."+File.separator+
053                            "images"+File.separator+"dont_pan.gif";
054  static int            mSec = 3000;
055  static final int DEFAULT_SLEEP_TIME = 2000;
056  static Panel  messageArea;
057  boolean splashFinished = false;
058
059  static public void main(String[] args)
060  {
061    System.out.println("Splashing "+imgName);
062    if (args.length > 0)
063      imgName = args[0];
064    if (args.length > 1)
065      mSec = (Integer.valueOf(args[1])).intValue();
066    Frame frame = new Splash(imgName, mSec);
067    System.exit(0);
068  }
069
070  public Splash()
071  {
072    mSec = DEFAULT_SLEEP_TIME;
073    (new Thread(this)).start();
074  }
075
076  public Splash(String imageName)
077  {
078    mSec = DEFAULT_SLEEP_TIME;
079    imgName = imageName;
080    (new Thread(this)).start();
081  }
082
083  public Splash(Image img)
084  {
085    mSec = DEFAULT_SLEEP_TIME;
086    image = img;
087    imgName = "defaultImageName";
088    (new Thread(this)).start();
089  }
090
091  public Splash(String imageName,int time)
092  {
093    System.out.println("Splashing "+imgName);
094    imgName = imageName;
095    mSec=time;
096    (new Thread(this)).start();
097  }
098
099  public Splash(Image img,int time)
100  {
101    image = img;
102    imgName = "defaultImageName";
103    if (img==null)
104    {
105      System.out.println("Splash Image is NULL");
106    }
107    mSec=time;
108    (new Thread(this)).start();
109  }
110
111  public Splash(String imageName, int time, Panel messagePanel)
112  {
113    imgName = imageName;
114    mSec=time;
115    messageArea = messagePanel;
116    (new Thread(this)).start();
117  }
118
119  public Splash(Image img,int time, Panel messagePanel)
120  {
121    image = img;
122    mSec=time;
123    messageArea = messagePanel;
124    (new Thread(this)).start();
125  }
126
127  public Splash(String imageName, Panel messagePanel)
128  {
129    imgName = imageName;
130    mSec=DEFAULT_SLEEP_TIME;
131    messageArea = messagePanel;
132    (new Thread(this)).start();
133  }
134
135  public void finishSplash()
136  {
137    splashFinished = true;
138  }
139
140  public void   indicateUpdate()
141  {
142    /* do something to the splash screen to show that there
143      has been some progress*/
144  }
145
146  public void run()
147  {
148    Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
149    /*if (image == null)
150      System.out.println("Splashing "+imgName);
151    else
152        System.out.println("Splashing a passed-in image.");
153*/
154    ImageCanvas canvas = null;
155
156    window  = new Window(this);
157    if (image == null)
158      image   = toolkit.getImage(imgName); // "images/DONT_PAN.GIF");
159    try
160    {
161      canvas  = new ImageCanvas(image);
162    }
163    catch (java.lang.NullPointerException nullPtr)
164    {
165        nullPtr.printStackTrace();
166      //canvas  = new ImageCanvas(new Image());
167    }
168    window.setLayout (new BorderLayout() );
169
170    if (canvas != null )
171      window.add("Center", canvas);
172
173    if (messageArea !=null )
174      window.add("South",messageArea );
175
176    Dimension   scrnSize  = toolkit.getScreenSize();
177    int         imgWidth  = image.getWidth(this),
178                imgHeight = image.getHeight(this),
179                panelHeight = messageArea.getPreferredSize().height * 3 + 3;
180
181    window.setLocation(scrnSize.width/2  - (imgWidth/2),
182                       scrnSize.height/2 - ((imgHeight+panelHeight)/2));
183    window.setSize(imgWidth,imgHeight+panelHeight);
184    window.pack();
185    window.show();
186    window.toFront();
187    window.setVisible(true);
188    this.repaint();
189    //System.out.println("Splashing "+imgName);
190    while(!splashFinished)
191    {
192      try
193      {
194        Thread.currentThread().sleep(mSec);
195        finishSplash();
196      }
197      catch(Exception e) { e.printStackTrace(); }
198    }
199
200    window.dispose();
201  }
202}
203
204