37
37
38
38
public class SplashScreenHelper {
39
39
40
+ private static final int X_OFFSET = 0 ;
41
+ private static final int Y_OFFSET = 300 ;
42
+ private static final int TEXTAREA_HEIGHT = 30 ;
43
+ private static final int TEXTAREA_WIDTH = 475 ;
44
+
40
45
private final Map desktopHints ;
41
46
private final SplashScreen splash ;
42
47
private Rectangle2D .Double splashTextArea ;
@@ -48,44 +53,56 @@ public SplashScreenHelper(SplashScreen splash) {
48
53
desktopHints = (Map ) tk .getDesktopProperty ("awt.font.desktophints" );
49
54
}
50
55
51
- public void splashText (String str ) {
56
+ public void splashText (String text ) {
52
57
if (splash == null ) {
53
- printText (str );
58
+ printText (text );
54
59
return ;
55
60
}
61
+
56
62
if (!splash .isVisible ()) {
57
63
return ;
58
64
}
59
65
60
66
if (splashTextArea == null ) {
61
- // stake out some area for our status information
62
- splashTextArea = new Rectangle2D .Double (0 , 300 , 520 , 30 );
63
-
64
- // create the Graphics environment for drawing status info
65
- splashGraphics = splash .createGraphics ();
66
-
67
- if (desktopHints != null ) {
68
- splashGraphics .addRenderingHints (desktopHints );
69
- }
67
+ prepareTextAreaAndGraphics ();
70
68
}
71
69
72
- // erase the last status text
73
- splashGraphics .setPaint (new Color (245 , 245 , 245 ));
74
- splashGraphics .fill (splashTextArea );
70
+ eraseLastStatusText ();
75
71
76
- // draw the text
77
- splashGraphics .setPaint (Color .BLACK );
78
- FontMetrics metrics = splashGraphics .getFontMetrics ();
79
- splashGraphics .drawString (str , (int ) splashTextArea .getX () + 10 , (int ) splashTextArea .getY () + (30 - metrics .getHeight ()) + 4 );
72
+ drawText (text );
80
73
81
- // make sure it's displayed
74
+ ensureTextIsDiplayed ();
75
+ }
76
+
77
+ private void ensureTextIsDiplayed () {
82
78
synchronized (SplashScreen .class ) {
83
79
if (splash .isVisible ()) {
84
80
splash .update ();
85
81
}
86
82
}
87
83
}
88
84
85
+ private void drawText (String str ) {
86
+ splashGraphics .setPaint (Color .BLACK );
87
+ FontMetrics metrics = splashGraphics .getFontMetrics ();
88
+ splashGraphics .drawString (str , (int ) splashTextArea .getX () + 10 , (int ) splashTextArea .getY () + (TEXTAREA_HEIGHT - metrics .getHeight ()) + 5 );
89
+ }
90
+
91
+ private void eraseLastStatusText () {
92
+ splashGraphics .setPaint (new Color (229 , 229 , 229 ));
93
+ splashGraphics .fill (splashTextArea );
94
+ }
95
+
96
+ private void prepareTextAreaAndGraphics () {
97
+ splashTextArea = new Rectangle2D .Double (X_OFFSET , Y_OFFSET , TEXTAREA_WIDTH , TEXTAREA_HEIGHT );
98
+
99
+ splashGraphics = splash .createGraphics ();
100
+
101
+ if (desktopHints != null ) {
102
+ splashGraphics .addRenderingHints (desktopHints );
103
+ }
104
+ }
105
+
89
106
public void close () {
90
107
if (splash == null ) {
91
108
return ;
0 commit comments