|
@@ -2,34 +2,28 @@ package org.cryptomator.ui;
|
|
|
|
|
|
import javafx.application.Application;
|
|
|
import javafx.application.Platform;
|
|
|
-import javafx.scene.Parent;
|
|
|
-import javafx.scene.Scene;
|
|
|
import javafx.stage.Stage;
|
|
|
-import org.cryptomator.ui.mainwindow.MainWindow;
|
|
|
-import org.cryptomator.ui.preferences.PreferencesWindow;
|
|
|
+import org.cryptomator.ui.mainwindow.MainWindowComponent;
|
|
|
+import org.cryptomator.ui.preferences.PreferencesComponent;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
import java.awt.Desktop;
|
|
|
import java.awt.desktop.PreferencesEvent;
|
|
|
-import java.io.IOException;
|
|
|
-import java.io.UncheckedIOException;
|
|
|
|
|
|
@FxApplicationScoped
|
|
|
public class FxApplication extends Application {
|
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(FxApplication.class);
|
|
|
|
|
|
- private final Stage mainWindow;
|
|
|
- private final Stage preferencesWindow;
|
|
|
- private final FXMLLoaderFactory fxmlLoaders;
|
|
|
+ private final MainWindowComponent.Builder mainWindow;
|
|
|
+ private final PreferencesComponent.Builder preferencesWindow;
|
|
|
|
|
|
@Inject
|
|
|
- FxApplication(@MainWindow Stage mainWindow, @PreferencesWindow Stage preferencesWindow, FXMLLoaderFactory fxmlLoaders) {
|
|
|
+ FxApplication(MainWindowComponent.Builder mainWindow, PreferencesComponent.Builder preferencesWindow) {
|
|
|
this.mainWindow = mainWindow;
|
|
|
this.preferencesWindow = preferencesWindow;
|
|
|
- this.fxmlLoaders = fxmlLoaders;
|
|
|
}
|
|
|
|
|
|
public void start() {
|
|
@@ -37,36 +31,25 @@ public class FxApplication extends Application {
|
|
|
if (Desktop.getDesktop().isSupported(Desktop.Action.APP_PREFERENCES)) {
|
|
|
Desktop.getDesktop().setPreferencesHandler(this::handlePreferences);
|
|
|
}
|
|
|
-
|
|
|
- start(mainWindow);
|
|
|
+
|
|
|
+ start(null);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void start(Stage stage) {
|
|
|
- assert stage == mainWindow;
|
|
|
- showMainWindow();
|
|
|
+ assert stage == null;
|
|
|
+
|
|
|
+ mainWindow.build().showMainWindow();
|
|
|
}
|
|
|
|
|
|
private void handlePreferences(PreferencesEvent preferencesEvent) {
|
|
|
Platform.runLater(this::showPreferencesWindow);
|
|
|
}
|
|
|
|
|
|
- public void showMainWindow() {
|
|
|
- showViewInWindow("/fxml/main_window.fxml", mainWindow);
|
|
|
- }
|
|
|
|
|
|
public void showPreferencesWindow() {
|
|
|
- showViewInWindow("/fxml/preferences.fxml", preferencesWindow);
|
|
|
- }
|
|
|
-
|
|
|
- private void showViewInWindow(String fxmlResourceName, Stage window) {
|
|
|
- try {
|
|
|
- Parent root = fxmlLoaders.load(fxmlResourceName).getRoot();
|
|
|
- window.setScene(new Scene(root));
|
|
|
- window.show();
|
|
|
- } catch (IOException e) {
|
|
|
- LOG.error("Failed to load " + fxmlResourceName, e);
|
|
|
- }
|
|
|
+ preferencesWindow.build().showPreferencesWindow();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|