/[debian]/jabref/trunk/src/java/net/sf/jabref/SplashScreen.java~
ViewVC logotype

Contents of /jabref/trunk/src/java/net/sf/jabref/SplashScreen.java~

Parent Directory Parent Directory | Revision Log Revision Log


Revision 265 - (show annotations)
Sat May 20 15:07:28 2006 UTC (15 years, 2 months ago) by gregoa
File size: 3284 byte(s)
* New upstream release
1 package net.sf.jabref;
2
3 //import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.net.URL;
7
8 /**
9 * <p>Title: </p>
10 * <p>Description: </p>
11 * <p>Copyright: Copyright (c) 2003</p>
12 * <p>Company: </p>
13 * @author not attributable
14 * @version 1.0
15 */
16
17 public class SplashScreen extends Window {
18 private Image splashImage;
19 private boolean paintCalled = false;
20
21 public SplashScreen(Frame owner) {
22 super(owner);
23 URL imageURL = SplashScreen.class.getResource("/images/jabref-2.0-splash.png");
24 splashImage = Toolkit.getDefaultToolkit().createImage(imageURL);
25
26 // Load the image
27 MediaTracker mt = new MediaTracker(this);
28 mt.addImage(splashImage,0);
29 try {
30 mt.waitForID(0);
31 } catch(InterruptedException ie) {}
32
33
34 // Center the window on the screen.
35 int imgWidth = splashImage.getWidth(this);
36 int imgHeight = splashImage.getHeight(this);
37
38 setSize(imgWidth, imgHeight);
39 Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
40 setLocation(
41 (screenDim.width - imgWidth) / 2,
42 (screenDim.height - imgHeight) / 2
43 );
44
45 }
46
47
48 /**
49 * Updates the display area of the window.
50 */
51 public void update(Graphics g) {
52 // Note: Since the paint method is going to draw an
53 // image that covers the complete area of the component we
54 // do not fill the component with its background color
55 // here. This avoids flickering.
56
57 g.setColor(getForeground());
58 paint(g);
59 }
60 /**
61 * Paints the image on the window.
62 */
63
64 public void paint(Graphics g) {
65 g.drawImage(splashImage, 0, 0, this);
66
67 // Notify method splash that the window
68 // has been painted.
69 if (! paintCalled) {
70 paintCalled = true;
71 synchronized (this) { notifyAll(); }
72 }
73 }
74
75 /**
76 * Constructs and displays a SplashWindow.<p>
77 * This method is useful for startup splashs.
78 * Dispose the returned frame to get rid of the splash window.<p>
79 *
80 * @param splashImage The image to be displayed.
81 * @return Returns the frame that owns the SplashWindow.
82 */
83
84 public static Frame splash() {
85 Frame f = new Frame();
86 SplashScreen w = new SplashScreen(f);
87
88 // Show the window.
89 w.setVisible(true);
90 w.toFront();
91
92 // Note: To make sure the user gets a chance to see the
93 // splash window we wait until its paint method has been
94 // called at least once by the AWT event dispatcher thread.
95
96 // sebwills adds: However, just in case the paint method never gets called
97 // (e.g. if the splashscreen is completely obscured by an 'always on top'
98 // window of some other application), we time-out after 5 seconds.
99 if (! EventQueue.isDispatchThread()) {
100 synchronized (w) {
101 if (! w.paintCalled) {
102 try {
103 w.wait(5000);
104 } catch (InterruptedException e) {}
105 }
106 }
107 }
108 return f;
109 }
110 }

  ViewVC Help
Powered by ViewVC 1.1.26