Add basic splash screen functionality

This commit is contained in:
RequestPrivacy 2022-11-08 12:15:44 +01:00
parent a25b53bd44
commit d40e26845f
No known key found for this signature in database
GPG key ID: 5956AE3E072AEA4C
2 changed files with 49 additions and 0 deletions

View file

@ -1,11 +1,46 @@
package com.sparrowwallet.sparrow;
import javafx.application.Preloader;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class SparrowWalletPreloader extends Preloader {
private Stage preloaderStage;
private Scene splashscreen;
public static final int SPLASHSCREEN_TIME_DELAY_MS = 2_000;
@Override
public void init() throws Exception {
FXMLLoader splashLoader = new FXMLLoader(AppServices.class.getResource("splashscreen.fxml"));
splashscreen = new Scene(splashLoader.load());
}
@Override
public void start(Stage stage) {
com.sun.glass.ui.Application.GetApplication().setName("Sparrow");
preloaderStage = stage;
preloaderStage.setScene(splashscreen);
preloaderStage.initStyle(StageStyle.UNDECORATED);
preloaderStage.show();
}
@Override
public void handleStateChangeNotification(StateChangeNotification info) {
if (info.getType() == StateChangeNotification.Type.BEFORE_START) {
// put JavaFX-Application thread to sleep so that splashscreen gets the ability to show. Minimize or
// delete thread sleep time if time intensive work is done in the SparrowDesktop.init() method
try {
Thread.sleep(SPLASHSCREEN_TIME_DELAY_MS);
} catch (InterruptedException e) {
// Not critical if splashscreen is hidden to early
}
preloaderStage.hide();
}
}
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
prefHeight="400.0"
prefWidth="600.0">
<Label text="SplashScreen"/>
</AnchorPane>