From 7414b3caa5b1ebf4addaa53d5611b12dff6cf2a6 Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Sat, 21 May 2016 18:28:20 +0200 Subject: [PATCH] Better code for loading file (still broken) --- .../estraba/controller/SplashController.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/es/kauron/estraba/controller/SplashController.java b/src/main/java/es/kauron/estraba/controller/SplashController.java index 2150abf..b5399ce 100644 --- a/src/main/java/es/kauron/estraba/controller/SplashController.java +++ b/src/main/java/es/kauron/estraba/controller/SplashController.java @@ -5,7 +5,6 @@ import com.jfoenix.controls.JFXSnackbar; import com.jfoenix.controls.JFXSpinner; import es.kauron.estraba.App; import es.kauron.estraba.model.DataBundle; -import javafx.application.Platform; import javafx.concurrent.Task; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -66,38 +65,34 @@ public class SplashController implements Initializable{ errorLoading(); return; } - Task task = new Task() { + Task task = new Task() { @Override - protected Void call() throws Exception { + protected DataBundle call() throws Exception { try { - DataBundle bundle = DataBundle.loadFrom(file); - FXMLLoader loader = new FXMLLoader( - App.class.getResource("fxml/Dashboard.fxml"), App.GENERAL_BUNDLE); - Parent root = loader.load(); - - Stage stage = new Stage(); - stage.getIcons().add(new Image(App.class.getResource("img/icon.png").toString())); - stage.setTitle(App.GENERAL_BUNDLE.getString("app.title")); - stage.setResizable(false); - stage.setScene(new Scene(root)); - - // Begin awesomewm code - stage.setMinHeight(500); - stage.setMinWidth(800); - stage.setResizable(false); - // End awesomewm code - stage.show(); - loader.getController().postInit(bundle); - Platform.runLater(() -> ((Stage) root.getScene().getWindow()).close()); + updateValue(DataBundle.loadFrom(file)); + succeeded(); } catch (IOException e) { + updateValue(null); errorLoading(); } - return null; + return getValue(); } }; Thread t = new Thread(task); t.setDaemon(true); t.start(); + task.setOnSucceeded(state -> { + DataBundle bundle = (DataBundle) state.getSource().getValue(); + if (bundle == null) errorLoading(); + FXMLLoader loader = new FXMLLoader( + App.class.getResource("fxml/Dashboard.fxml"), App.GENERAL_BUNDLE); + Parent parent = null; + try { + parent = loader.load(); + } catch (IOException e) {errorLoading();} + loader.getController().postInit(bundle); + ((Stage) root.getScene().getWindow()).setScene(new Scene(parent)); + }); } @Override