Add hasDirty check.
[sw/motorsim] / gui / Splash.java
1 import java.awt.Dimension;
2 import java.awt.Font;
3 import java.awt.Frame;
4 import java.awt.Graphics;
5 import java.awt.Toolkit;
6
7 import javax.swing.ImageIcon;
8 import javax.swing.JLabel;
9 import javax.swing.JWindow;
10 import javax.swing.SwingUtilities;
11
12 import com.billkuker.rocketry.motorsim.visual.workbench.MotorWorkbench;
13
14 class Splash extends JWindow {
15         private static final long serialVersionUID = 1L;
16
17         public Splash(String resName, Frame f, int waitTime) {
18                 super(f);
19                 JLabel l = new JLabel(new ImageIcon(this.getClass()
20                                 .getResource(resName)));
21                 add(l);
22                 pack();
23                 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
24                 Dimension labelSize = l.getPreferredSize();
25                 setLocation(screenSize.width / 2 - (labelSize.width / 2),
26                                 screenSize.height / 2 - (labelSize.height / 2));
27                 final int pause = waitTime;
28                 setVisible(true);
29                 new Thread(new Runnable() {
30                         public void run() {
31                                 try {
32                                         Thread.sleep(pause);
33                                         SwingUtilities.invokeAndWait(new Runnable() {
34                                                 public void run() {
35                                                         setVisible(false);
36                                                         dispose();
37                                                 }
38                                         });
39                                 } catch (Exception e) {
40                                         e.printStackTrace();
41                                 }
42                         }
43                 }, "SplashThread").start();
44         }
45
46         @Override
47         public void paint(Graphics g) {
48                 super.paint(g);
49                 g.setFont(new Font(Font.DIALOG, Font.BOLD, 14));
50                 g.drawString("Version " + MotorWorkbench.version, 140, 150);
51         }
52
53         public static void main(String args[]) {
54                  new Splash("splash.png", null, 1000);
55         }
56 }