blob: f360402aee86706a30aaeb12d6b22228e9fc1c2b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
package net.sourceforge.jnlp;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Toolkit;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JDialog;
import net.sourceforge.jnlp.cache.ResourceTracker;
import net.sourceforge.jnlp.runtime.JNLPRuntime;
public class JNLPSplashScreen extends JDialog {
String applicationTitle;
String applicationVendor;
ResourceTracker resourceTracker;
URL splashImageUrl;
Image splashImage;
public JNLPSplashScreen(ResourceTracker resourceTracker,
String applicationTitle, String applicationVendor) {
// If the JNLP file does not contain any icon images, the splash image
// will consist of the application's title and vendor, as taken from the
// JNLP file.
this.resourceTracker = resourceTracker;
this.applicationTitle = applicationTitle;
this.applicationVendor = applicationVendor;
}
public void setSplashImageURL(URL url) {
splashImageUrl = url;
splashImage = null;
try {
splashImage = ImageIO.read(resourceTracker
.getCacheFile(splashImageUrl));
if (splashImage == null) {
if (JNLPRuntime.isDebug()) {
System.err.println("Error loading splash image: " + url);
}
return;
}
} catch (IOException e) {
if (JNLPRuntime.isDebug()) {
System.err.println("Error loading splash image: " + url);
}
splashImage = null;
return;
} catch (IllegalArgumentException argumentException) {
if (JNLPRuntime.isDebug()) {
System.err.println("Error loading splash image: " + url);
}
splashImage = null;
return;
}
correctSize();
}
public boolean isSplashScreenValid() {
return (splashImage != null);
}
private void correctSize() {
Insets insets = getInsets();
int minimumWidth = splashImage.getWidth(null) + insets.left
+ insets.right;
int minimumHeight = splashImage.getHeight(null) + insets.top
+ insets.bottom;
setMinimumSize(new Dimension(minimumWidth, minimumHeight));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((screenSize.width - minimumWidth) / 2,
(screenSize.height - minimumHeight) / 2);
}
@Override
public void paint(Graphics g) {
if (splashImage == null) {
return;
}
correctSize();
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(splashImage, getInsets().left, getInsets().top, null);
}
}
|