Search in sources :

Example 1 with ExitWithSaveService

use of com.helospark.tactview.ui.javafx.save.ExitWithSaveService in project tactview by helospark.

the class JavaFXUiMain method start.

@Override
public void start(Stage stage) throws IOException {
    DirtyRepository dirtyRepository = lightDi.getBean(DirtyRepository.class);
    ExitWithSaveService exitWithSaveService = lightDi.getBean(ExitWithSaveService.class);
    StylesheetAdderService styleSheetAdder = lightDi.getBean(StylesheetAdderService.class);
    styleSheetAdder.setTactviewIconForStage(stage);
    JavaFXUiMain.STAGE = stage;
    lightDi.getListOfBeans(MainWindowStageAware.class).forEach(listener -> listener.setMainWindowStage(stage));
    NotificationPane notificationPane = new NotificationPane();
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 650, 550, Color.GREY);
    styleSheetAdder.addStyleSheets(root, "stylesheet.css");
    MenuBar menuBar = lightDi.getBean(MenuProcessor.class).createMenuBar();
    if (SystemUtils.IS_OS_MAC_OSX) {
        // https://stackoverflow.com/a/28874063
        menuBar.useSystemMenuBarProperty().set(true);
    }
    stage.setOnCloseRequest(e -> {
        exitApplication(exitWithSaveService, e);
    });
    root.setTop(menuBar);
    stage.setScene(scene);
    stage.setTitle("TactView - Video editor");
    dirtyRepository.addUiChangeListener(value -> {
        Platform.runLater(() -> {
            String title = "";
            if (value) {
                title += "* ";
            }
            title += "TactView - Video editor";
            stage.setTitle(title);
        });
    });
    stage.setMaximized(true);
    if (SystemUtils.IS_OS_MAC) {
        SwingFXUtils.toFXImage(new BufferedImage(100, 100, TYPE_INT_BGR), null);
    }
    // spacing between child nodes only.
    SplitPane mainContentPane = new SplitPane();
    mainContentPane.setId("content-area");
    mainContentPane.setPrefWidth(scene.getWidth());
    // space between vbox border and child nodes column
    mainContentPane.setPadding(new Insets(1));
    mainContentPane.setDividerPositions(0.6);
    canvas = new Canvas();
    lightDi.getBean(CanvasStateHolder.class).setCanvas(canvas);
    lightDi.getBean(DefaultCanvasTranslateSetter.class).setDefaultCanvasTranslate(uiProjectRepository.getPreviewWidth(), uiProjectRepository.getPreviewHeight());
    InputModeRepository inputModeRepository = lightDi.getBean(InputModeRepository.class);
    inputModeRepository.setCanvas(canvas);
    displayUpdateService.setCanvas(canvas);
    displayUpdateService.updateCurrentPositionWithInvalidatedCache();
    Tooltip tooltip = new Tooltip();
    StringProperty statusTextProperty = lightDi.getBean(VideoStatusBarUpdater.class).getTextProperty();
    tooltip.textProperty().bind(statusTextProperty);
    tooltip.setHideOnEscape(false);
    tooltip.setAutoHide(false);
    tooltip.setAnchorLocation(AnchorLocation.CONTENT_TOP_LEFT);
    statusTextProperty.addListener((e, oldV, newV) -> {
        if (newV.length() > 0) {
            Bounds canvasBottom = canvas.localToScene(canvas.getBoundsInLocal());
            double x = canvasBottom.getMinX();
            double y = canvasBottom.getMaxY() + 60;
            tooltip.show(canvas, x, y);
        } else {
            tooltip.hide();
        }
    });
    tooltip.setWrapText(true);
    HBox upperPane = new HBox();
    upperPane.setId("upper-content-area");
    upperPane.setMinHeight(300);
    upperPane.setFillHeight(true);
    DetachableTabPaneLoadModel layoutToLoad = lightDi.getBean(DefaultLayoutProvider.class).provideDefaultLayout();
    DockableTabRepository dockableTabRepository = lightDi.getBean(DockableTabRepository.class);
    dockableTabRepository.setParentPane(upperPane);
    dockableTabRepository.loadAndSetModelToParent(layoutToLoad);
    TiwulFXUtil.setTiwulFXStyleSheet(scene);
    VBox lower = new VBox(5);
    lower.setPrefWidth(scene.getWidth());
    lower.setPrefHeight(300);
    lower.setId("timeline-view");
    BorderPane timeline = uiTimeline.createTimeline(lower, root);
    lower.getChildren().add(timeline);
    VBox.setVgrow(timeline, Priority.ALWAYS);
    mainContentPane.getItems().add(upperPane);
    mainContentPane.getItems().add(lower);
    mainContentPane.setOrientation(Orientation.VERTICAL);
    root.setCenter(mainContentPane);
    notificationPane.setContent(root);
    inputModeRepository.registerInputModeChangeConsumerr(onClassChangeDisableTabs());
    inputModeRepository.registerInputModeChangeConsumerr(onClassChange(timeline));
    lightDi.getListOfBeans(ScenePostProcessor.class).stream().forEach(processor -> processor.postProcess(scene));
    lightDi.getListOfBeans(PostInitializationArgsCallback.class).forEach(postInitCallback -> postInitCallback.call(mainArgs));
    if (splashStage.isShowing()) {
        stage.show();
        splashStage.toFront();
        FadeTransition fadeSplash = new FadeTransition(Duration.seconds(0.5), splasViewh);
        fadeSplash.setDelay(Duration.millis(800));
        fadeSplash.setFromValue(1.0);
        fadeSplash.setToValue(0.0);
        fadeSplash.setOnFinished(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent actionEvent) {
                splashStage.hide();
            }
        });
        fadeSplash.play();
    }
}
Also used : BorderPane(javafx.scene.layout.BorderPane) HBox(javafx.scene.layout.HBox) NotificationPane(org.controlsfx.control.NotificationPane) Insets(javafx.geometry.Insets) ActionEvent(javafx.event.ActionEvent) ExitWithSaveService(com.helospark.tactview.ui.javafx.save.ExitWithSaveService) MenuBar(javafx.scene.control.MenuBar) StringProperty(javafx.beans.property.StringProperty) SplitPane(javafx.scene.control.SplitPane) BufferedImage(java.awt.image.BufferedImage) DefaultLayoutProvider(com.helospark.tactview.ui.javafx.layout.DefaultLayoutProvider) DirtyRepository(com.helospark.tactview.core.save.DirtyRepository) MainWindowStageAware(com.helospark.tactview.ui.javafx.aware.MainWindowStageAware) MenuProcessor(com.helospark.tactview.ui.javafx.menu.MenuProcessor) DetachableTabPaneLoadModel(com.helospark.tactview.ui.javafx.tiwulfx.com.panemu.tiwulfx.control.DetachableTabPaneLoadModel) FadeTransition(javafx.animation.FadeTransition) Canvas(javafx.scene.canvas.Canvas) Tooltip(javafx.scene.control.Tooltip) Bounds(javafx.geometry.Bounds) DefaultCanvasTranslateSetter(com.helospark.tactview.ui.javafx.uicomponents.DefaultCanvasTranslateSetter) StylesheetAdderService(com.helospark.tactview.ui.javafx.stylesheet.StylesheetAdderService) Scene(javafx.scene.Scene) PostInitializationArgsCallback(com.helospark.tactview.core.init.PostInitializationArgsCallback) DockableTabRepository(com.helospark.tactview.ui.javafx.tabs.dockabletab.DockableTabRepository) VideoStatusBarUpdater(com.helospark.tactview.ui.javafx.uicomponents.VideoStatusBarUpdater) InputModeRepository(com.helospark.tactview.ui.javafx.inputmode.InputModeRepository) VBox(javafx.scene.layout.VBox)

Aggregations

PostInitializationArgsCallback (com.helospark.tactview.core.init.PostInitializationArgsCallback)1 DirtyRepository (com.helospark.tactview.core.save.DirtyRepository)1 MainWindowStageAware (com.helospark.tactview.ui.javafx.aware.MainWindowStageAware)1 InputModeRepository (com.helospark.tactview.ui.javafx.inputmode.InputModeRepository)1 DefaultLayoutProvider (com.helospark.tactview.ui.javafx.layout.DefaultLayoutProvider)1 MenuProcessor (com.helospark.tactview.ui.javafx.menu.MenuProcessor)1 ExitWithSaveService (com.helospark.tactview.ui.javafx.save.ExitWithSaveService)1 StylesheetAdderService (com.helospark.tactview.ui.javafx.stylesheet.StylesheetAdderService)1 DockableTabRepository (com.helospark.tactview.ui.javafx.tabs.dockabletab.DockableTabRepository)1 DetachableTabPaneLoadModel (com.helospark.tactview.ui.javafx.tiwulfx.com.panemu.tiwulfx.control.DetachableTabPaneLoadModel)1 DefaultCanvasTranslateSetter (com.helospark.tactview.ui.javafx.uicomponents.DefaultCanvasTranslateSetter)1 VideoStatusBarUpdater (com.helospark.tactview.ui.javafx.uicomponents.VideoStatusBarUpdater)1 BufferedImage (java.awt.image.BufferedImage)1 FadeTransition (javafx.animation.FadeTransition)1 StringProperty (javafx.beans.property.StringProperty)1 ActionEvent (javafx.event.ActionEvent)1 Bounds (javafx.geometry.Bounds)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 Canvas (javafx.scene.canvas.Canvas)1