Class SplashScreen

java.lang.Object
ch.autumo.ui.fx.view.SplashScreen

public class SplashScreen extends Object
The splash screen an application shows while it starts.

The screen is a small, transparent window with the application's logo and a scanner bar below it: a light that sweeps from left to right and back, like the one of the reference design. The window has rounded corners and a thin frame; background, frame colour, corner radius, logo and an optional jingle are configurable, everything else follows the standard design of the framework.

An application activates it in BaseApp:

@Override
protected boolean isSplashScreenEnabled() {
    return true;
}

@Override
protected SplashScreen createSplashScreen() {
    return new SplashScreen()
            .setLogo(getClass().getResource("icons/app-256.png"))
            .setJingle(getClass().getResource("sounds/start.wav"));
}

The framework shows the screen at the beginning of the start-up and hides it as soon as the main window is up. Without the activation (isSplashScreenEnabled() is false by default) no splash screen is shown at all.

The jingle is played with the Java Sound API, so it has to be a sound file the JDK can play (WAV, AU or AIFF) - the application does not need the JavaFX media module for it.

  • Field Details

    • DEFAULT_BACKGROUND

      public static final Color DEFAULT_BACKGROUND
      Background of the splash window (standard design).
    • DEFAULT_FRAME_COLOR

      public static final Color DEFAULT_FRAME_COLOR
      Colour of the frame around the splash window (standard design).
    • DEFAULT_CORNER_RADIUS

      public static final double DEFAULT_CORNER_RADIUS
      Radius of the rounded corners of the splash window (standard design).
      See Also:
    • DEFAULT_SCANNER_TRACK

      public static final Color DEFAULT_SCANNER_TRACK
      Colour of the scanner track (standard design).
    • DEFAULT_SCANNER_START

      public static final Color DEFAULT_SCANNER_START
      Colour of the scanner light at its start (standard design).
    • DEFAULT_SCANNER_END

      public static final Color DEFAULT_SCANNER_END
      Colour of the scanner light at its end (standard design).
    • LOGO_SIZE

      public static final double LOGO_SIZE
      Edge length of the logo.
      See Also:
    • SCANNER_WIDTH

      public static final double SCANNER_WIDTH
      Width of the scanner bar.
      See Also:
    • SCANNER_HEIGHT

      public static final double SCANNER_HEIGHT
      Height of the scanner bar.
      See Also:
    • SCANNER_LIGHT_WIDTH

      public static final double SCANNER_LIGHT_WIDTH
      Width of the scanning light.
      See Also:
    • SCAN_DURATION

      public static final Duration SCAN_DURATION
      Duration of one sweep of the scanner light.
  • Constructor Details

    • SplashScreen

      public SplashScreen()
      Creates a splash screen with the standard design and the framework's logo.
  • Method Details

    • setLogo

      public SplashScreen setLogo(Image logo)
      Sets the logo of the application.
      Parameters:
      logo - the logo, or null for no logo
      Returns:
      this splash screen
    • setLogo

      public SplashScreen setLogo(URL logo)
      Sets the logo of the application from a resource.
      Parameters:
      logo - the resource of the logo, or null for no logo
      Returns:
      this splash screen
    • setBackgroundColor

      public SplashScreen setBackgroundColor(Color background)
      Sets the background colour of the splash window.
      Parameters:
      background - the colour
      Returns:
      this splash screen
    • setFrameColor

      public SplashScreen setFrameColor(Color frameColor)
      Sets the colour of the frame around the splash window.
      Parameters:
      frameColor - the colour
      Returns:
      this splash screen
    • setCornerRadius

      public SplashScreen setCornerRadius(double cornerRadius)
      Sets the radius of the rounded corners of the splash window.
      Parameters:
      cornerRadius - the radius in pixels
      Returns:
      this splash screen
    • setJingle

      public SplashScreen setJingle(URL jingle)
      Sets the jingle that is played when the splash screen appears.

      Setting the jingle while the splash screen is already up plays it right away - the framework does it that way, because the application decides with its configuration whether there is a jingle at all, and the configuration is read while the splash screen is running.

      Parameters:
      jingle - the resource of the sound file, or null for no jingle
      Returns:
      this splash screen
    • setDuration

      public SplashScreen setDuration(Duration duration)
      Sets the minimum time the splash screen stays up.

      Without a duration the splash screen goes away as soon as the main window is up. With a duration it stays at least that long - a short start-up would otherwise flash the splash screen up for a fraction of a second only.

      Parameters:
      duration - the minimum display time, or null for none
      Returns:
      this splash screen
    • getDuration

      public Duration getDuration()
      The minimum time the splash screen stays up, or null if it goes away with the main window.
      Returns:
      the minimum display time or null
    • remainingDuration

      public Duration remainingDuration()
      The time the splash screen still has to stay up.
      Returns:
      the remaining time, zero if there is no duration or it is over
    • show

      public void show()
      Shows the splash screen.

      The window appears centred on the screen, the scanner starts and the jingle is played. Calling the method again while the splash screen is up does nothing.

    • hide

      public void hide()
      Hides the splash screen: the window fades out and closes.

      The window is closed in any case - the fade is a nice touch, but it only runs while the JavaFX thread is free. A splash screen that stays open would keep the application alive, so a second timer closes the window in any case.

    • isShowing

      public boolean isShowing()
      Whether the splash screen is currently shown.
      Returns:
      true if splash screen is visible