package hello;

import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Stage;

@SpringBootApplication
public class MainApplication extends Application {

	private static final Logger logger = LoggerFactory.getLogger(MainApplication.class);

	private ConfigurableApplicationContext springContext;
	private static String[] mainArgs;

	public static void main(String[] args) {
		Locale.setDefault(new Locale("zh", "CN"));
		MainApplication.mainArgs = args;
		Application.launch(MainApplication.class, args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		Task<Object> worker = new Task<Object>() {
			@Override
			protected Object call() throws Exception {
				springContext = SpringApplication.run(MainApplication.class, MainApplication.mainArgs);
				return null;
			}
		};
		worker.run();

		worker.setOnSucceeded(event -> {
			try {
				logger.info("Spring content is loading successful! Application will come soon.");

				Alert alert = new Alert(AlertType.INFORMATION);
				alert.setTitle("Info");
				// alert.setHeaderText("HeaderText");
				alert.setContentText("ContentText");
				alert.show();

			} catch (Exception ex) {
				logger.error("Gagal load JavaFX Application", ex);
			}
		});

		worker.setOnFailed(event -> {
			try {
				logger.error("Spring 容器加载失败，开始退出程序 ......");

				Alert alert = new Alert(AlertType.ERROR);
				alert.setTitle("Error");
				// alert.setHeaderText("HeaderText");
				alert.setContentText("ContentText");
				alert.show();

			} catch (Exception ex) {
				logger.error("退出程序出现异常 ......", ex);
			}
		});
	}

	@Override
	public void stop() throws Exception {
		super.stop();
		Platform.exit();
		springContext.close();
	}

}

@@ -1298,30 +1298,19 @@
 fo(%22
-Spring content is load
+Loading Spr
 ing 
@@ -1585,25 +1585,15 @@
 or(%22
-Gagal load JavaFX
+Loading
  App
@@ -1600,16 +1600,23 @@
 lication
+ Error.
 %22, ex);%0A
@@ -1690,34 +1690,61 @@
 or(%22
-Spring %E5%AE%B9%E5%99%A8%E5%8A%A0%E8%BD%BD%E5%A4%B1%E8%B4%A5%EF%BC%8C%E5%BC%80%E5%A7%8B%E9%80%80%E5%87%BA%E7%A8%8B%E5%BA%8F .....
+Loading Spring Failing! Application will shutdown now
 .%22);
@@ -1884,35 +1884,78 @@
 ontentText(%22
-ContentText
+Loading Spring Failing! Application will shutdown now.
 %22);%0A%09%09%09%09aler
@@ -2015,22 +2015,34 @@
 or(%22
-%E9%80%80%E5%87%BA%E7%A8%8B%E5%BA%8F%E5%87%BA%E7%8E%B0%E5%BC%82%E5%B8%B8 .....
+Shutdown Application Error
 .%22, 

change tip message