3737
3838public class SplashScreenHelper {
3939
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+
4045 private final Map desktopHints ;
4146 private final SplashScreen splash ;
4247 private Rectangle2D .Double splashTextArea ;
@@ -48,44 +53,56 @@ public SplashScreenHelper(SplashScreen splash) {
4853 desktopHints = (Map ) tk .getDesktopProperty ("awt.font.desktophints" );
4954 }
5055
51- public void splashText (String str ) {
56+ public void splashText (String text ) {
5257 if (splash == null ) {
53- printText (str );
58+ printText (text );
5459 return ;
5560 }
61+
5662 if (!splash .isVisible ()) {
5763 return ;
5864 }
5965
6066 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 ();
7068 }
7169
72- // erase the last status text
73- splashGraphics .setPaint (new Color (245 , 245 , 245 ));
74- splashGraphics .fill (splashTextArea );
70+ eraseLastStatusText ();
7571
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 );
8073
81- // make sure it's displayed
74+ ensureTextIsDiplayed ();
75+ }
76+
77+ private void ensureTextIsDiplayed () {
8278 synchronized (SplashScreen .class ) {
8379 if (splash .isVisible ()) {
8480 splash .update ();
8581 }
8682 }
8783 }
8884
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+
89106 public void close () {
90107 if (splash == null ) {
91108 return ;
0 commit comments