Giter Club home page Giter Club logo

Comments (6)

roskenet avatar roskenet commented on May 13, 2024

Yes, I agree. Good thing to have!

from springboot-javafx-support.

jonydog avatar jonydog commented on May 13, 2024

Nice, thanks

from springboot-javafx-support.

ajesh123 avatar ajesh123 commented on May 13, 2024

Thank you for the recommendation. We have make some changes for the functionality. Its now working.

Usage:
** Main.java
launchApp(Main.class, HelloworldView.class, args, true);

** AbstractJavaFxApplicationSupport.java

       private static boolean savedHasPreloader;
       @Override
	public void start(Stage stage) throws Exception {
    	
    	if(savedHasPreloader)	{
	    	notifyPreloader(new Preloader.StateChangeNotification(
					Preloader.StateChangeNotification.Type.BEFORE_START));
			stage.toFront();
    	}
	    
	    String stageStyle = applicationContext.getEnvironment().getProperty("javafx.stage.style");
	    // User requests a different StageStyle?
        // Then we need a new one:
        if(stageStyle != null) {
            StageStyle style = StageStyle.valueOf(stageStyle.toUpperCase());
            stage = new Stage(style);
        }
	    
		AbstractJavaFxApplicationSupport.stage = stage;
		showView(savedInitialView);
	}

        protected static void launchApp(Class<? extends AbstractJavaFxApplicationSupport> appClass,
			Class<? extends AbstractFxmlView> view, String[] args, boolean hasPreloader) {
		savedInitialView = view;
		savedArgs = args;
		savedHasPreloader = hasPreloader;
		if(savedHasPreloader)
			LauncherImpl.launchApplication(appClass, Splash.class, args);
		else
			Application.launch(appClass, args);
	}

** Splash.java

import javafx.animation.FadeTransition;
import javafx.application.Preloader;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;

/**
 * @author Ajesh - Inspired by https://gist.github.com/jewelsea/1588531
 */

public class Splash extends Preloader {
	
  private Stage stage;
  private Pane splashLayout;
  private ProgressBar loadProgress;
  private Label progressText;
  public static final String SPLASH_IMAGE = "http://fxexperience.com/wp-content/uploads/2010/06/logo.png";
  private static final int SPLASH_WIDTH = 676;
  private static final int SPLASH_HEIGHT = 227;

  @Override public void init() {
    ImageView splash = new ImageView(new Image(SPLASH_IMAGE));
    loadProgress = new ProgressBar();
    loadProgress.setPrefWidth(SPLASH_WIDTH - 20);
    progressText = new Label("Loading STODA-fx 1.0 . . . . .");
    splashLayout = new VBox();
    splashLayout.getChildren().addAll(splash, loadProgress, progressText);
    progressText.setAlignment(Pos.CENTER);
    splashLayout.setStyle("-fx-padding: 5; -fx-background-color: cornsilk; -fx-border-width:5; -fx-border-color: linear-gradient(to bottom, chocolate, derive(chocolate, 50%));");
    splashLayout.setEffect(new DropShadow());
  }
  
  @Override public void start(final Stage initStage) throws Exception {
  	Scene splashScene = new Scene(splashLayout);
    initStage.initStyle(StageStyle.UNDECORATED);
    final Rectangle2D bounds = Screen.getPrimary().getBounds();
    initStage.setScene(splashScene);
    initStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
    initStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
    initStage.show();
    this.stage = initStage;
  }
  
  @Override
  public void handleApplicationNotification(Preloader.PreloaderNotification notification) {
      if (notification instanceof StateChangeNotification) {
          FadeTransition fadeSplash = new FadeTransition(Duration.seconds(0.4), splashLayout);
          fadeSplash.setFromValue(1.0);
          fadeSplash.setToValue(0.0);
          fadeSplash.setOnFinished(actionEvent -> stage.hide());
          fadeSplash.play();
      }
  }

}

Final step under working

Spring environment variables:
javafx.splash.image=logo.png
javafx.splash.text=Spring Loading...

Auto identify splash preferred width and height.

from springboot-javafx-support.

roskenet avatar roskenet commented on May 13, 2024

Problem is that we can't use Spring environment at that time because the application context is not up yet.
My first approach is in the branch SplashScreen.
I am thinking of overloading the launchApp method accepting a config class that returns some nodes (getSplashImage , getSplashLoadingIndicator) or something like that as strategies - and maybe providing a default implementation.

from springboot-javafx-support.

ajesh123 avatar ajesh123 commented on May 13, 2024

Yes sure, we can't identify spring environment properties for setting SplashScreen prerequisites. getSplashLoadingIndicator is interesting! I agree your strategy. Good Luck

from springboot-javafx-support.

roskenet avatar roskenet commented on May 13, 2024

Added with 1.3.13.
Shows at least now a standard screen. Needs still more documentation (as everything).

from springboot-javafx-support.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.