Class SplashProgressWindow

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer

public final class SplashProgressWindow extends JWindow
Normally the SplashScreen that comes with AWT is good enough for an application, but if the app has some costly process to go through before the UI is shown, it is useful to be able to show a progress bar with the splash screen, to give the user some idea of how startup is going.
Since:
2022-05-10
Author:
scorbo2
See Also:
  • Constructor Details

    • SplashProgressWindow

      public SplashProgressWindow(String appName, LogoProperty config)
      If you don't have an application logo image at the ready, use this constructor to dynamically generate one on the fly (using LogoGenerator). You must supply enough information about the app to make this possible.
      Parameters:
      appName - The name of the application.
      config - The LogoConfig instance containing cosmetic parameters for the logo image.
    • SplashProgressWindow

      public SplashProgressWindow(Frame owner, String appName, LogoProperty config)
      Very generally, the SplashProgressWindow will never have a parent frame, as it is intended to be used as a standalone splash screen on application startup. But, for testing purposes (or perhaps for some custom scenario), this constructor is offered as a way to set a parent frame for it.
      Parameters:
      owner - The owning Frame (can be null for no owner).
      appName - The name of the application (used as logo text)
      config - The LogoConfig instance containing cosmetic parameters for the logo image.
    • SplashProgressWindow

      public SplashProgressWindow(Color fgColor, Color bgColor, BufferedImage splashImage)
      If you do have an application logo image at the ready, use this constructor to display a splash screen based on the given image. You must still supply a background and foreground color so the progress bar can be styled to match the logo image.
      Parameters:
      fgColor - The foreground colour for the progress bar.
      bgColor - The background colour for the progress bar.
      splashImage - The application logo image. Window dimensions will be based on this image's dimensions.
    • SplashProgressWindow

      public SplashProgressWindow(Frame owner, Color fgColor, Color bgColor, BufferedImage splashImage)
      Very generally, the SplashProgressWindow will never have a parent frame, as it is intended to be used as a standalone splash screen on application startup. But, for testing purposes (or perhaps for some custom scenario), this constructor is offered as a way to set a parent frame for it.
      Parameters:
      fgColor - The foreground colour for the progress bar.
      bgColor - The background colour for the progress bar.
      splashImage - The application logo image. Window dimensions will be based on this image's dimensions.
  • Method Details

    • showFakeProgress

      public void showFakeProgress(int steps, int stepDelay)
      Maybe you don't have a lengthy operation to perform on startup, but you still want to use the SplashProgressWindow to make it look like you're doing something. This method will show the window and start a dummy worker thread to simulate some activity, based on the desired number of progress steps and the given delay between steps. When the "work" completes, the splash window will be disposed automatically.

      This method returns immediately, while the "work" is still in progress. If you want to be notified when the splash window has finished, you can either do the math based on steps*stepDelay or instead invoke showFakeProgress(int,int,AbstractAction).

      Parameters:
      steps - How many steps of progress to fake.
      stepDelay - The desired delay, in milliseconds, between each work step.
    • runWorker

      public void runWorker(SimpleProgressWorker worker)
      Executes the given worker thread and listens to it for progress updates. Auto-wires the progress bar on this window and updates it as the work progresses. When the work completes, disposes this window. Progress errors are simply ignored here. You can add your own MultiProgressAdapter to the worker before passing it in here if you wish to respond to errors.
      Parameters:
      worker - Any SimpleProgressWorker implementation.
    • showFakeProgress

      public void showFakeProgress(int steps, int stepDelay, AbstractAction action)
      Maybe you don't have a lengthy operation to perform on startup, but you still want to use the SplashProgressWindow to make it look like you're doing something. This method will show the window and start a dummy worker thread to simulate some activity, based on the desired number of progress steps and the given delay between steps. When the "work" completes, the splash window will be disposed automatically.

      The AbstractAction that you supply will be triggered when the "work" is complete.

      Parameters:
      steps - How many steps of progress to fake.
      stepDelay - The desired delay, in milliseconds, between each work step.
      action - An AbstractAction to be fired when the fake work is done.
    • initializeProgressBar

      public void initializeProgressBar(int totalStepCount)
      Configures the progress bar for the given number of work steps. You must call this before showing the window.
      Parameters:
      totalStepCount - The total number of steps for the progress bar.
    • setProgress

      public void setProgress(int value)
      Updates the progress bar to the given step number. Make sure you invoke initializeProgressBar() first.
      Parameters:
      value - The current progress value.