KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > uk > ac > roe > antigen > dialogs > SplashScreen


1 /*
2  * Created on 30-May-2005
3  *
4  * @todo To change the template for this generated file go to
5  * Window - Preferences - Java - Code Style - Code Templates
6  */

7 package uk.ac.roe.antigen.dialogs;
8
9 import java.awt.Color JavaDoc;
10 import java.awt.Font JavaDoc;
11 import java.awt.event.ActionEvent JavaDoc;
12 import java.awt.event.ActionListener JavaDoc;
13 import java.awt.event.WindowAdapter JavaDoc;
14 import java.awt.event.WindowEvent JavaDoc;
15 import java.util.logging.Level JavaDoc;
16 import java.util.logging.Logger JavaDoc;
17
18 import javax.swing.ImageIcon JavaDoc;
19 import javax.swing.JFrame JavaDoc;
20 import javax.swing.JLabel JavaDoc;
21 import javax.swing.JPanel JavaDoc;
22 import javax.swing.Timer JavaDoc;
23
24 import uk.ac.roe.antigen.utils.Config;
25
26 /**
27  * A very quick and dirty splashscreen class
28  * @author Jon Tayler johndavidtaylor@users.sourceforge.net
29  *
30  */

31 public class SplashScreen extends JFrame JavaDoc {
32     /**
33      * Logger for this class
34      */

35     private static final Logger JavaDoc logger = Logger.getLogger(SplashScreen.class.getName());
36
37     public SplashScreen() {
38         initGUI();
39     }
40
41     
42     /**
43      *
44      */

45     private void initGUI() {
46         setUndecorated(true);
47         
48         JPanel JavaDoc main = new JPanel JavaDoc();
49         JLabel JavaDoc graphic = new JLabel JavaDoc();
50         graphic.setOpaque(false);
51         main.setOpaque(true);
52         String JavaDoc logoPath = Config.getProperty("antigen.splash.logo");
53         String JavaDoc logoText = Config.getProperty("antigen.splash.text","Antigen");
54         graphic.setText(logoText);
55         
56         String JavaDoc colour = Config.getProperty("antigen.splash.colour","000000");
57         logger.fine("Setting foreground colour to "+colour);
58         graphic.setForeground(new Color JavaDoc(Integer.parseInt(colour,16)));
59         String JavaDoc backgroundColour = Config.getProperty("antigen.splash.background","fffff");
60         logger.fine("Setting background colour to "+backgroundColour);
61         main.setBackground(new Color JavaDoc(Integer.parseInt(backgroundColour,16)));
62         graphic.setFont(new Font JavaDoc(Config.getProperty("antigen.splash.font","Eurostile"),
63                 Integer.parseInt(Config.getProperty("antigen.splash.style","1")),
64                 Integer.parseInt(Config.getProperty("antigen.splash.size","36"))));
65      
66         
67         if (logoPath !=null) {
68             graphic.setIcon(new ImageIcon JavaDoc(getClass().getClassLoader()
69                     .getResource(logoPath)));
70         }
71
72         getContentPane().add(main);
73         main.add(graphic);
74         pack();
75         new FrameCenterer(this).center();
76         //Keep the SplashScreen on top.
77
addWindowListener(new WindowAdapter JavaDoc () {
78             public void windowDeactivated(WindowEvent JavaDoc e) {
79                     toFront();
80             }
81         });
82     }
83     
84
85     
86     /**
87      * Show the splash screen for a set number of millis
88      * @param millis time it's up
89      */

90     public void show(int millis) {
91         final Timer JavaDoc timer = new Timer JavaDoc(millis, new ActionListener JavaDoc() {
92
93             public void actionPerformed(ActionEvent JavaDoc arg0) {
94                 logger.fine("Closing Splashscreen");
95                 dispose();
96             }
97             
98         });
99         super.show();
100         timer.setRepeats(false);
101         timer.start();
102     }
103     
104     public void show() {
105         String JavaDoc delayString = Config.getProperty("antigen.splash.delay");
106         if (delayString==null) {
107             //Display forever
108
super.show();
109         } else {
110             show(Integer.parseInt(delayString));
111         }
112     }
113
114     public static void main(String JavaDoc[] args) throws InterruptedException JavaDoc {
115         Config.setProperty("antigen.splash.logo","local-img/world.jpg");
116         final SplashScreen test = new SplashScreen();
117    /* Timer timer = new Timer(1000, new ActionListener() {
118
119             public void actionPerformed(ActionEvent arg0) {
120                 test.dispose();
121             }
122             
123         });*/

124         test.show(2000);
125         //timer.start();
126

127     }
128 }
129
Popular Tags