Skip to content

Commit 0500ff2

Browse files
committed
more cleanup of the Splash class
1 parent 785fe6b commit 0500ff2

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

app/src/processing/app/ui/Splash.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,54 +20,49 @@
2020
*/
2121
public class Splash extends JFrame {
2222
static private Splash instance;
23-
private Image image;
23+
private final Image image;
2424

2525

26-
private boolean paintCalled = false;
27-
2826
private Splash(File imageFile, boolean hidpi) {
2927
this.image =
3028
Toolkit.getDefaultToolkit().createImage(imageFile.getAbsolutePath());
3129

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);
3532
try {
36-
mt.waitForID(0);
37-
} catch(InterruptedException ie){}
33+
tracker.waitForID(0);
34+
} catch (InterruptedException ignored) { }
3835

39-
// Abort on failure
40-
if (mt.isErrorID(0)) {
36+
if (tracker.isErrorID(0)) {
37+
// Abort on failure
4138
setSize(0,0);
4239
System.err.println("Warning: SplashWindow couldn't load splash image.");
43-
synchronized(this) {
44-
paintCalled = true;
40+
synchronized (this) {
4541
notifyAll();
4642
}
4743
} else {
48-
// Center the window on the screen
4944
final int imgWidth = image.getWidth(this);
5045
final int imgHeight = image.getHeight(this);
5146
final int imgScale = hidpi ? 2 : 1;
5247

53-
setUndecorated(true);
54-
5548
JComponent comp = new JComponent() {
49+
final int wide = imgWidth / imgScale;
50+
final int high = imgHeight / imgScale;
51+
5652
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);
5954
}
6055

6156
public Dimension getPreferredSize() {
62-
return new Dimension(imgWidth / imgScale, imgHeight / imgScale);
57+
return new Dimension(wide, high);
6358
}
6459
};
6560
comp.setSize(imgWidth, imgHeight);
66-
setLayout(new FlowLayout());
61+
setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
6762
getContentPane().add(comp);
63+
setUndecorated(true); // before pack()
6864
pack();
69-
70-
setLocationRelativeTo(null);
65+
setLocationRelativeTo(null); // center on screen
7166
}
7267
}
7368

@@ -102,9 +97,7 @@ static void invokeMain(String className, String[] args) {
10297
.invoke(null, new Object[] { args });
10398

10499
} 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);
108101
}
109102
}
110103

0 commit comments

Comments
 (0)