View Javadoc

1   package org.catacomb.icon.splash;
2   
3   import org.catacomb.report.E;
4   
5   import java.awt.Dimension;
6   import java.awt.Frame;
7   import java.awt.Toolkit;
8   import java.awt.image.BufferedImage;
9   import java.io.InputStream;
10  
11  import javax.imageio.ImageIO;
12  
13  
14  public class Splash implements Runnable {
15  
16      String imgsrc;
17  
18      SplashWindow splashWindow;
19  
20  
21      public Splash(String s, String fnm) {
22          imgsrc = s.replaceAll("\\.", "/") + "/" + fnm;
23      }
24  
25  
26      public void show() {
27  
28          InputStream fis = ClassLoader.getSystemResourceAsStream(imgsrc);
29  
30          try {
31              BufferedImage bim = ImageIO.read(fis);
32  
33              // NB creating this frame takes up half the startup time!
34              Frame frame = new Frame();
35  
36              splashWindow = new SplashWindow(bim, frame);
37  
38  
39              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
40              Dimension windowSize = splashWindow.getPreferredSize();
41  
42  
43              splashWindow.setLocation(screenSize.width / 2 - (windowSize.width / 2), screenSize.height
44                                       / 2 - (windowSize.height / 2));
45  
46              splashWindow.packShow();
47  
48              Thread th = new Thread(this);
49              th.start();
50          } catch (Exception ex) {
51              E.error("cant read splash " + imgsrc + " " + ex);
52          }
53      }
54  
55  
56  
57      public void run() {
58          try {
59              Thread.sleep(4000);
60          } catch (Exception ex) {
61  
62          }
63  
64          splashWindow.setVisible(false);
65  
66      }
67  
68  
69      public void hide() {
70          splashWindow.setVisible(false);
71      }
72  
73  
74  }