1 /* 2 * ************************************************************************************************************************************************************* 3 * 4 * SteelBlue: DCI User Interfaces 5 * http://tidalwave.it/projects/steelblue 6 * 7 * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it) 8 * 9 * ************************************************************************************************************************************************************* 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 18 * 19 * ************************************************************************************************************************************************************* 20 * 21 * git clone https://bitbucket.org/tidalwave/steelblue-src 22 * git clone https://github.com/tidalwave-it/steelblue-src 23 * 24 * ************************************************************************************************************************************************************* 25 */ 26 package it.tidalwave.ui.javafx.impl; 27 28 import jakarta.annotation.Nonnull; 29 import java.util.function.Function; 30 import java.io.IOException; 31 import javafx.animation.KeyFrame; 32 import javafx.animation.KeyValue; 33 import javafx.animation.Timeline; 34 import javafx.fxml.FXMLLoader; 35 import javafx.scene.Parent; 36 import javafx.scene.Scene; 37 import javafx.scene.layout.Pane; 38 import javafx.stage.Stage; 39 import javafx.util.Duration; 40 import lombok.RequiredArgsConstructor; 41 import lombok.extern.slf4j.Slf4j; 42 43 /*************************************************************************************************************************************************************** 44 * 45 * @author Fabrizio Giudici 46 * 47 **************************************************************************************************************************************************************/ 48 @RequiredArgsConstructor @Slf4j 49 public class Splash 50 { 51 @Nonnull 52 private final Object application; 53 54 @Nonnull 55 private final String fxml; 56 57 @Nonnull 58 private final Function<Parent, Scene> sceneFactory; 59 60 private Pane splashPane; 61 62 private Stage splashStage; 63 64 /*********************************************************************************************************************************************************** 65 * 66 **********************************************************************************************************************************************************/ 67 public void init() 68 { 69 try 70 { 71 final var resource = application.getClass().getResource(fxml); 72 log.info("Loading Splash.fxml for application {}: {}", application, resource); 73 splashPane = FXMLLoader.load(resource); 74 } 75 catch (IOException e) 76 { 77 log.warn("No Splash.fxml", e); 78 } 79 } 80 81 /*********************************************************************************************************************************************************** 82 * 83 **********************************************************************************************************************************************************/ 84 public void show (@Nonnull final Stage splashStage) 85 { 86 this.splashStage = splashStage; 87 final var splashScene = sceneFactory.apply(splashPane); 88 splashStage.setScene(splashScene); 89 splashStage.show(); 90 } 91 92 /*********************************************************************************************************************************************************** 93 * 94 **********************************************************************************************************************************************************/ 95 public void dismiss() 96 { 97 // loadProgress.progressProperty().unbind(); 98 // loadProgress.setProgress(1); 99 // progressText.setText("Done."); 100 101 final var start = new KeyFrame(Duration.ZERO, new KeyValue(splashStage.opacityProperty(), 1.0)); 102 final var end = new KeyFrame(Duration.millis(500), new KeyValue(splashStage.opacityProperty(), 0.0)); 103 final var slideAnimation = new Timeline(start, end); 104 slideAnimation.setOnFinished(event -> splashStage.close()); 105 slideAnimation.play(); 106 107 // FIXME: fade transition really doesn't work: it fades out the pane, but the stage is opaque. 108 // final FadeTransition fadeSplash = new FadeTransition(Duration.seconds(0.5), splashPane); 109 // fadeSplash.setFromValue(1.0); 110 // fadeSplash.setToValue(0.0); 111 // fadeSplash.setOnFinished(event -> splashStage.close()); 112 // fadeSplash.play(); 113 } 114 }