Updated splash screen

This commit is contained in:
Federico Fissore 2015-11-03 13:09:30 +01:00
parent 9b070aa90f
commit 152aa595ec
4 changed files with 36 additions and 19 deletions

View File

@ -37,6 +37,11 @@ import java.util.Map;
public class SplashScreenHelper { public class SplashScreenHelper {
private static final int X_OFFSET = 0;
private static final int Y_OFFSET = 300;
private static final int TEXTAREA_HEIGHT = 30;
private static final int TEXTAREA_WIDTH = 475;
private final Map desktopHints; private final Map desktopHints;
private final SplashScreen splash; private final SplashScreen splash;
private Rectangle2D.Double splashTextArea; private Rectangle2D.Double splashTextArea;
@ -48,37 +53,28 @@ public class SplashScreenHelper {
desktopHints = (Map) tk.getDesktopProperty("awt.font.desktophints"); desktopHints = (Map) tk.getDesktopProperty("awt.font.desktophints");
} }
public void splashText(String str) { public void splashText(String text) {
if (splash == null) { if (splash == null) {
printText(str); printText(text);
return; return;
} }
if (!splash.isVisible()) { if (!splash.isVisible()) {
return; return;
} }
if (splashTextArea == null) { if (splashTextArea == null) {
// stake out some area for our status information prepareTextAreaAndGraphics();
splashTextArea = new Rectangle2D.Double(0, 300, 520, 30);
// create the Graphics environment for drawing status info
splashGraphics = splash.createGraphics();
if (desktopHints != null) {
splashGraphics.addRenderingHints(desktopHints);
}
} }
// erase the last status text eraseLastStatusText();
splashGraphics.setPaint(new Color(245, 245, 245));
splashGraphics.fill(splashTextArea);
// draw the text drawText(text);
splashGraphics.setPaint(Color.BLACK);
FontMetrics metrics = splashGraphics.getFontMetrics();
splashGraphics.drawString(str, (int) splashTextArea.getX() + 10, (int) splashTextArea.getY() + (30 - metrics.getHeight()) + 4);
// make sure it's displayed ensureTextIsDiplayed();
}
private void ensureTextIsDiplayed() {
synchronized (SplashScreen.class) { synchronized (SplashScreen.class) {
if (splash.isVisible()) { if (splash.isVisible()) {
splash.update(); splash.update();
@ -86,6 +82,27 @@ public class SplashScreenHelper {
} }
} }
private void drawText(String str) {
splashGraphics.setPaint(Color.BLACK);
FontMetrics metrics = splashGraphics.getFontMetrics();
splashGraphics.drawString(str, (int) splashTextArea.getX() + 10, (int) splashTextArea.getY() + (TEXTAREA_HEIGHT - metrics.getHeight()) + 5);
}
private void eraseLastStatusText() {
splashGraphics.setPaint(new Color(229, 229, 229));
splashGraphics.fill(splashTextArea);
}
private void prepareTextAreaAndGraphics() {
splashTextArea = new Rectangle2D.Double(X_OFFSET, Y_OFFSET, TEXTAREA_WIDTH, TEXTAREA_HEIGHT);
splashGraphics = splash.createGraphics();
if (desktopHints != null) {
splashGraphics.addRenderingHints(desktopHints);
}
}
public void close() { public void close() {
if (splash == null) { if (splash == null) {
return; return;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 KiB

After

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 20 KiB