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;
11 import net.sf.openrocket.util.BuildProperties;
14 * Helper methods for manipulating the Java runtime splash screen.
17 * SplashScreen.update() takes randomly between 4 and 500 ms to complete,
18 * even after it has been called ~100 times (and therefore pre-compiled).
19 * Therefore it cannot be relied upon to perform for example color fades.
20 * Care should be taken to call update() only once or twice per second.
22 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
26 // The right edge of the text base line for the version string
27 private static final int VERSION_POSITION_X = 617;
28 private static final int VERSION_POSITION_Y = 138;
29 private static final Font VERSION_FONT = new Font(Font.SANS_SERIF, Font.PLAIN, 9);
30 private static final Color VERSION_COLOR = Color.WHITE;
34 * Initialize the splash screen with additional information. This method should
35 * be called as soon as reasonably possible during program startup.
37 * @return <code>true</code> if the splash screen could be successfully initialized
39 public static boolean init() {
40 // Get the splash screen
41 SplashScreen s = getSplash();
45 // Create graphics context and set antialiasing on
46 Graphics2D g2 = s.createGraphics();
47 g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
48 RenderingHints.VALUE_STROKE_NORMALIZE);
49 g2.setRenderingHint(RenderingHints.KEY_RENDERING,
50 RenderingHints.VALUE_RENDER_QUALITY);
51 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
52 RenderingHints.VALUE_ANTIALIAS_ON);
54 // Draw the version number
55 drawVersionNumber(g2);
57 // Update the splash screen
64 private static void drawVersionNumber(Graphics2D g2) {
65 String text = "Version " + BuildProperties.getVersion();
66 GlyphVector gv = VERSION_FONT.createGlyphVector(g2.getFontRenderContext(), text);
68 Rectangle2D rect = gv.getVisualBounds();
69 double width = rect.getWidth();
71 g2.setColor(VERSION_COLOR);
72 g2.drawGlyphVector(gv, (float) (VERSION_POSITION_X - width), VERSION_POSITION_Y);
78 * Return the current splash screen or <code>null</code> if not available.
79 * This method catches the possible exceptions and returns null if they occur.
81 * @return the current splash screen, or <code>null</code>.
83 private static SplashScreen getSplash() {
85 return SplashScreen.getSplashScreen();
86 } catch (RuntimeException e) {