1 package net.sf.openrocket.gui.main;
5 import java.awt.Graphics2D;
6 import java.awt.RenderingHints;
7 import java.awt.SplashScreen;
8 import java.awt.font.GlyphVector;
9 import java.awt.geom.Rectangle2D;
10 import java.io.IOException;
12 import net.sf.openrocket.util.Prefs;
15 * Helper methods for manipulating the Java runtime splash screen.
18 * SplashScreen.update() takes randomly between 4 and 500 ms to complete,
19 * even after it has been called ~100 times (and therefore pre-compiled).
20 * Therefore it cannot be relied upon to perform for example color fades.
21 * Care should be taken to call update() only once or twice per second.
23 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
27 // The right edge of the text base line for the version string
28 private static final int VERSION_POSITION_X = 617;
29 private static final int VERSION_POSITION_Y = 135;
30 private static final Font VERSION_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 9);
31 private static final Color VERSION_COLOR = Color.WHITE;
35 * Initialize the splash screen with additional information. This method should
36 * be called as soon as reasonably possible during program startup.
38 * @return <code>true</code> if the splash screen could be successfully initialized
40 public static boolean init() {
41 // Get the splash screen
42 SplashScreen s = getSplash();
46 // Create graphics context and set antialiasing on
47 Graphics2D g2 = s.createGraphics();
48 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
49 RenderingHints.VALUE_STROKE_NORMALIZE);
50 g2.setRenderingHint(RenderingHints.KEY_RENDERING,
51 RenderingHints.VALUE_RENDER_QUALITY);
52 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
53 RenderingHints.VALUE_ANTIALIAS_ON);
55 // Draw the version number
56 drawVersionNumber(g2);
58 // Update the splash screen
65 private static void drawVersionNumber(Graphics2D g2) {
66 String text = "Version " + Prefs.getVersion();
67 GlyphVector gv = VERSION_FONT.createGlyphVector(g2.getFontRenderContext(), text);
69 Rectangle2D rect = gv.getVisualBounds();
70 double width = rect.getWidth();
72 g2.setColor(VERSION_COLOR);
73 g2.drawGlyphVector(gv, (float)(VERSION_POSITION_X - width), (float)VERSION_POSITION_Y);
79 * Return the current splash screen or <code>null</code> if not available.
80 * This method catches the possible exceptions and returns null if they occur.
82 * @return the current splash screen, or <code>null</code>.
84 private static SplashScreen getSplash() {
86 return SplashScreen.getSplashScreen();
87 } catch (RuntimeException e) {
95 public static void main(String[] args) throws InterruptedException, IOException {
96 System.out.println("Calling init...");
97 System.out.println("Init returned " + Splash.init());
98 System.out.println("Press enter...");
100 System.out.println("Exiting...");