diff --git a/src/main/java/io/bitsquare/BitSquare.java b/src/main/java/io/bitsquare/BitSquare.java index e06916bbb6..098e4a52a5 100644 --- a/src/main/java/io/bitsquare/BitSquare.java +++ b/src/main/java/io/bitsquare/BitSquare.java @@ -129,7 +129,6 @@ public class BitSquare extends Application { primaryStage.show(); - Profiler.printMsgWithTime("BitSquare: start finished"); } catch (IOException e) { log.error(e.getMessage()); } diff --git a/src/main/java/io/bitsquare/gui/model/MainModel.java b/src/main/java/io/bitsquare/gui/model/MainModel.java index bbdc4bbefe..17901192d3 100644 --- a/src/main/java/io/bitsquare/gui/model/MainModel.java +++ b/src/main/java/io/bitsquare/gui/model/MainModel.java @@ -182,8 +182,6 @@ public class MainModel extends UIModel { /////////////////////////////////////////////////////////////////////////////////////////// private void onFacadesInitialised() { - Profiler.printMsgWithTime("MainModel.onFacadesInitialised"); - // TODO Check this: never called on regtest // Consider to use version from Mike Hearn walletFacade.addDownloadListener(new WalletFacade.DownloadListener() { diff --git a/src/main/java/io/bitsquare/gui/util/Profiler.java b/src/main/java/io/bitsquare/gui/util/Profiler.java index 56e194b85f..e718724bcc 100644 --- a/src/main/java/io/bitsquare/gui/util/Profiler.java +++ b/src/main/java/io/bitsquare/gui/util/Profiler.java @@ -38,13 +38,16 @@ public class Profiler { public static void printMsgWithTime(String msg) { final long elapsed = threadStopwatch.get().elapsed(TimeUnit.MILLISECONDS); - log.trace("Msg: {} elapsed: {}ms / total time:[globalStopwatch: {}ms / threadStopwatch: {}ms / " + + log.trace("\n\nCalled by: {} \nElapsed time: {}ms \nTotal time: {}ms\n\n", + msg, elapsed - last.get(), globalStopwatch.elapsed(TimeUnit.MILLISECONDS)); + /* log.trace("Msg: {} elapsed: {}ms / total time:[globalStopwatch: {}ms / threadStopwatch: {}ms / " + "currentTimeMillis: {}ms]", msg, elapsed - last.get(), globalStopwatch.elapsed(TimeUnit.MILLISECONDS), elapsed, - System.currentTimeMillis() - lastCurrentTimeMillis); + System.currentTimeMillis() - lastCurrentTimeMillis);*/ + lastCurrentTimeMillis = System.currentTimeMillis(); last.set(elapsed); } diff --git a/src/main/java/io/bitsquare/gui/util/Transitions.java b/src/main/java/io/bitsquare/gui/util/Transitions.java index f398d9db10..456dd0057c 100644 --- a/src/main/java/io/bitsquare/gui/util/Transitions.java +++ b/src/main/java/io/bitsquare/gui/util/Transitions.java @@ -17,11 +17,11 @@ package io.bitsquare.gui.util; -import javafx.animation.Animation; import javafx.animation.FadeTransition; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; +import javafx.application.Platform; import javafx.scene.*; import javafx.scene.effect.*; import javafx.scene.layout.*; @@ -39,36 +39,37 @@ public class Transitions { fadeIn(node, DURATION); } - public static void fadeIn(Node node, int duration) { - FadeTransition ft = new FadeTransition(Duration.millis(duration), node); - ft.setFromValue(0.0); - ft.setToValue(1.0); - ft.play(); + public static FadeTransition fadeIn(Node node, int duration) { + FadeTransition fade = new FadeTransition(Duration.millis(duration), node); + fade.setFromValue(node.getOpacity()); + fade.setToValue(1.0); + fade.play(); + return fade; } - public static Animation fadeOut(Node node) { + public static FadeTransition fadeOut(Node node) { return fadeOut(node, DURATION); } - public static Animation fadeOut(Node node, int duration) { - FadeTransition ft = new FadeTransition(Duration.millis(duration), node); - ft.setFromValue(node.getOpacity()); - ft.setToValue(0.0); - ft.play(); - return ft; + public static FadeTransition fadeOut(Node node, int duration) { + FadeTransition fade = new FadeTransition(Duration.millis(duration), node); + fade.setFromValue(node.getOpacity()); + fade.setToValue(0.0); + fade.play(); + return fade; } - public static Animation fadeOutAndRemove(Node node) { + public static FadeTransition fadeOutAndRemove(Node node) { return fadeOutAndRemove(node, DURATION); } - public static Animation fadeOutAndRemove(Node node, int duration) { - Animation animation = fadeOut(node, duration); - animation.setOnFinished(actionEvent -> { + public static FadeTransition fadeOutAndRemove(Node node, int duration) { + FadeTransition fade = fadeOut(node, duration); + fade.setOnFinished(actionEvent -> { ((Pane) (node.getParent())).getChildren().remove(node); Profiler.printMsgWithTime("fadeOutAndRemove"); }); - return animation; + return fade; } public static void blur(Node node) { @@ -94,7 +95,8 @@ public class Transitions { timeline.getKeyFrames().addAll(kf1); } node.setEffect(blur); - if (removeNode) timeline.setOnFinished(actionEvent -> ((Pane) (node.getParent())).getChildren().remove(node)); + if (removeNode) timeline.setOnFinished(actionEvent -> Platform.runLater(() -> ((Pane) (node.getParent())) + .getChildren().remove(node))); timeline.play(); return timeline; } diff --git a/src/main/java/io/bitsquare/gui/view/MainViewCB.java b/src/main/java/io/bitsquare/gui/view/MainViewCB.java index 15aab57ea4..5c171c0c9d 100644 --- a/src/main/java/io/bitsquare/gui/view/MainViewCB.java +++ b/src/main/java/io/bitsquare/gui/view/MainViewCB.java @@ -38,7 +38,7 @@ import java.util.ResourceBundle; import javax.inject.Inject; -import javafx.application.Platform; +import javafx.animation.Interpolator; import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -50,18 +50,12 @@ import javafx.scene.layout.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Holds the splash screen and the application views. It builds up all the views and initializes the facades. - * We use a sequence of Platform.runLater cascaded calls to make the startup more smooth, otherwise the rendering is - * frozen for too long. Pre-loading of views is not implemented yet, and after a quick test it seemed that it does not - * give much improvements. - */ + public class MainViewCB extends CachedCodeBehind { private static final Logger log = LoggerFactory.getLogger(MainViewCB.class); //TODO private static MainViewCB instance; - private boolean showNetworkSyncPaneRequested; private VBox baseOverlayContainer; private final ToggleGroup navButtonsGroup = new ToggleGroup(); private NavigationItem previousNavigationItem; @@ -215,40 +209,24 @@ public class MainViewCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// private void startup() { - buildBaseContainers(); - } - - private void buildBaseContainers() { - Profiler.printMsgWithTime("MainController.ViewBuilder.buildBaseContainers"); - baseContentContainer = getBaseContentContainer(); - baseContentContainer.setOpacity(0); baseOverlayContainer = getSplashScreen(); ((StackPane) root).getChildren().addAll(baseContentContainer, baseOverlayContainer); - Platform.runLater(this::buildContentView); + onBaseContainersCreated(); } - private void buildContentView() { - Profiler.printMsgWithTime("MainController.ViewBuilder.buildContentView"); + private void onBaseContainersCreated() { + Profiler.printMsgWithTime("MainController.onBaseContainersCreated"); menuBar = getMenuBar(); contentScreen = getContentScreen(); - - if (showNetworkSyncPaneRequested) - addNetworkSyncPane(); + addNetworkSyncPane(); baseContentContainer.setTop(menuBar); baseContentContainer.setCenter(contentScreen); - Platform.runLater(this::onBaseContainersCreated); - } - - // We need to wait until the backend is initialized as we need it for menu items like the balance field - private void onBaseContainersCreated() { - Profiler.printMsgWithTime("MainController.onBaseContainersCreated"); - presentationModel.backendInited.addListener((ov, oldValue, newValue) -> { if (newValue) onBackendInited(); @@ -264,12 +242,6 @@ public class MainViewCB extends CachedCodeBehind { private void onMainNavigationAdded() { Profiler.printMsgWithTime("MainController.ondMainNavigationAdded"); - triggerMainMenuButton(presentationModel.getSelectedNavigationItem()); - Platform.runLater(this::onContentAdded); - } - - private void onContentAdded() { - Profiler.printMsgWithTime("MainController.onContentAdded"); presentationModel.takeOfferRequested.addListener((ov, olaValue, newValue) -> { final Button alertButton = new Button("", ImageUtil.getIconImageView(ImageUtil.MSG_ALERT)); @@ -286,13 +258,13 @@ public class MainViewCB extends CachedCodeBehind { AWTSystemTray.setAlert(); }); - Platform.runLater(this::fadeOutSplash); + triggerMainMenuButton(presentationModel.getSelectedNavigationItem()); + onContentAdded(); } - private void fadeOutSplash() { - Profiler.printMsgWithTime("MainController.fadeOutSplash"); - Transitions.blur(baseOverlayContainer, 700, false, true); - Transitions.fadeIn(baseContentContainer); + private void onContentAdded() { + Profiler.printMsgWithTime("MainController.onContentAdded"); + Transitions.fadeOutAndRemove(baseOverlayContainer, 1500).setInterpolator(Interpolator.EASE_IN); }