blob: d8e97d643bce145f142cc3335c1b83ea60420218 (
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
|
package simulator;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.io.InputStream;
/**
* Splash screen for the DS-Sim application
*
* @author Paul C. Buetow
*/
public class VSSplashScreen extends JWindow {
private static final int DISPLAY_TIME = 3000; // 3 seconds
/**
* Creates and shows the splash screen
*/
public VSSplashScreen() {
initSplashScreen();
}
/**
* Initialize the splash screen components
*/
private void initSplashScreen() {
try {
// Load the splash image from resources
InputStream imageStream = getClass().getResourceAsStream("/splash.png");
if (imageStream == null) {
// Fallback if image not found
showTextSplash();
return;
}
BufferedImage splashImage = ImageIO.read(imageStream);
// Reduce size by 60% (scale to 40% of original)
int scaledWidth = (int)(splashImage.getWidth() * 0.4);
int scaledHeight = (int)(splashImage.getHeight() * 0.4);
Image scaledImage = splashImage.getScaledInstance(scaledWidth, scaledHeight, Image.SCALE_SMOOTH);
ImageIcon splashIcon = new ImageIcon(scaledImage);
JLabel splashLabel = new JLabel(splashIcon);
splashLabel.setHorizontalAlignment(JLabel.CENTER);
getContentPane().add(splashLabel, BorderLayout.CENTER);
// Set window properties
setSize(scaledWidth, scaledHeight);
setLocationRelativeTo(null); // Center on screen
} catch (IOException e) {
// Fallback to text splash if image loading fails
showTextSplash();
}
}
/**
* Fallback text-based splash screen
*/
private void showTextSplash() {
JLabel textLabel = new JLabel("DS-Sim", JLabel.CENTER);
textLabel.setFont(new Font("Arial", Font.BOLD, 24));
textLabel.setPreferredSize(new Dimension(300, 100));
getContentPane().add(textLabel, BorderLayout.CENTER);
setSize(300, 100);
setLocationRelativeTo(null);
}
/**
* Shows the splash screen for the specified duration
*/
public void showSplash() {
setVisible(true);
// Use a timer to hide the splash screen after the specified time
Timer timer = new Timer(DISPLAY_TIME, e -> {
setVisible(false);
dispose();
});
timer.setRepeats(false);
timer.start();
}
}
|