|
20 | 20 | */ |
21 | 21 | public class Splash extends JFrame { |
22 | 22 | static private Splash instance; |
23 | | - private Image image; |
| 23 | + private final Image image; |
24 | 24 |
|
25 | 25 |
|
26 | | - private boolean paintCalled = false; |
27 | | - |
28 | 26 | private Splash(File imageFile, boolean hidpi) { |
29 | 27 | this.image = |
30 | 28 | Toolkit.getDefaultToolkit().createImage(imageFile.getAbsolutePath()); |
31 | 29 |
|
32 | | - // Load the image |
33 | | - MediaTracker mt = new MediaTracker(this); |
34 | | - mt.addImage(image,0); |
| 30 | + MediaTracker tracker = new MediaTracker(this); |
| 31 | + tracker.addImage(image,0); |
35 | 32 | try { |
36 | | - mt.waitForID(0); |
37 | | - } catch(InterruptedException ie){} |
| 33 | + tracker.waitForID(0); |
| 34 | + } catch (InterruptedException ignored) { } |
38 | 35 |
|
39 | | - // Abort on failure |
40 | | - if (mt.isErrorID(0)) { |
| 36 | + if (tracker.isErrorID(0)) { |
| 37 | + // Abort on failure |
41 | 38 | setSize(0,0); |
42 | 39 | System.err.println("Warning: SplashWindow couldn't load splash image."); |
43 | | - synchronized(this) { |
44 | | - paintCalled = true; |
| 40 | + synchronized (this) { |
45 | 41 | notifyAll(); |
46 | 42 | } |
47 | 43 | } else { |
48 | | - // Center the window on the screen |
49 | 44 | final int imgWidth = image.getWidth(this); |
50 | 45 | final int imgHeight = image.getHeight(this); |
51 | 46 | final int imgScale = hidpi ? 2 : 1; |
52 | 47 |
|
53 | | - setUndecorated(true); |
54 | | - |
55 | 48 | JComponent comp = new JComponent() { |
| 49 | + final int wide = imgWidth / imgScale; |
| 50 | + final int high = imgHeight / imgScale; |
| 51 | + |
56 | 52 | public void paintComponent(Graphics g) { |
57 | | - System.out.println("drawing " + getSize() + " " + Splash.this.getSize()); |
58 | | - g.drawImage(image, 0, 0, imgWidth / imgScale, imgHeight / imgScale, this); |
| 53 | + g.drawImage(image, 0, 0, wide, high, this); |
59 | 54 | } |
60 | 55 |
|
61 | 56 | public Dimension getPreferredSize() { |
62 | | - return new Dimension(imgWidth / imgScale, imgHeight / imgScale); |
| 57 | + return new Dimension(wide, high); |
63 | 58 | } |
64 | 59 | }; |
65 | 60 | comp.setSize(imgWidth, imgHeight); |
66 | | - setLayout(new FlowLayout()); |
| 61 | + setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); |
67 | 62 | getContentPane().add(comp); |
| 63 | + setUndecorated(true); // before pack() |
68 | 64 | pack(); |
69 | | - |
70 | | - setLocationRelativeTo(null); |
| 65 | + setLocationRelativeTo(null); // center on screen |
71 | 66 | } |
72 | 67 | } |
73 | 68 |
|
@@ -102,9 +97,7 @@ static void invokeMain(String className, String[] args) { |
102 | 97 | .invoke(null, new Object[] { args }); |
103 | 98 |
|
104 | 99 | } catch (Exception e) { |
105 | | - InternalError error = new InternalError("Failed to invoke main method"); |
106 | | - error.initCause(e); |
107 | | - throw error; |
| 100 | + throw new InternalError("Failed to invoke main method", e); |
108 | 101 | } |
109 | 102 | } |
110 | 103 |
|
|
0 commit comments