diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java new file mode 100644 index 000000000..ffc00e2cd --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -0,0 +1,54 @@ +package org.cryptomator.ui.addvaultwizard; + +import dagger.Binds; +import dagger.Module; +import dagger.Provides; +import dagger.multibindings.IntoMap; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; +import javafx.stage.Window; +import org.cryptomator.ui.common.FXMLLoaderFactory; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxControllerKey; +import org.cryptomator.ui.mainwindow.MainWindow; +import org.cryptomator.ui.mainwindow.MainWindowController; +import org.cryptomator.ui.mainwindow.VaultDetailController; +import org.cryptomator.ui.mainwindow.VaultListController; + +import javax.inject.Named; +import javax.inject.Provider; +import java.util.Map; + +@Module +public abstract class AddVaultModule { + + @Provides + @AddVaultWizard + @AddVaultWizardScoped + static FXMLLoaderFactory provideFxmlLoaderFactory(Map, Provider> factories) { + return new FXMLLoaderFactory(factories); + } + + @Provides + @AddVaultWizard + @AddVaultWizardScoped + static Stage provideStage(@MainWindow Stage owner) { + Stage stage = new Stage(); + stage.setMinWidth(500); + stage.setMinHeight(500); + stage.initStyle(StageStyle.DECORATED); + stage.initModality(Modality.WINDOW_MODAL); + stage.initOwner(owner); + return stage; + } + + // ------------------ + + @Binds + @IntoMap + @FxControllerKey(AddVaultWelcomeController.class) + abstract FxController bindWelcomeController(AddVaultWelcomeController controller); + + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWelcomeController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWelcomeController.java new file mode 100644 index 000000000..69626b0fd --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWelcomeController.java @@ -0,0 +1,13 @@ +package org.cryptomator.ui.addvaultwizard; + +import org.cryptomator.ui.common.FxController; + +import javax.inject.Inject; + +@AddVaultWizardScoped +public class AddVaultWelcomeController implements FxController { + + @Inject + AddVaultWelcomeController() {} + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizard.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizard.java new file mode 100644 index 000000000..c876cede1 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizard.java @@ -0,0 +1,14 @@ +package org.cryptomator.ui.addvaultwizard; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface AddVaultWizard { + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizardComponent.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizardComponent.java new file mode 100644 index 000000000..dbb31d5f6 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizardComponent.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2017 Skymatic UG (haftungsbeschränkt). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the accompanying LICENSE file. + *******************************************************************************/ +package org.cryptomator.ui.addvaultwizard; + +import dagger.Subcomponent; +import javafx.stage.Stage; +import org.cryptomator.ui.common.FXMLLoaderFactory; + +@AddVaultWizardScoped +@Subcomponent(modules = {AddVaultModule.class}) +public interface AddVaultWizardComponent { + + @AddVaultWizard + Stage window(); + + @AddVaultWizard + FXMLLoaderFactory fxmlLoaders(); + + default void showAddVaultWizard() { + Stage stage = window(); + fxmlLoaders().setScene("/fxml/addvault_welcome.fxml", stage); + stage.sizeToScene(); + stage.show(); + } + + @Subcomponent.Builder + interface Builder { + + AddVaultWizardComponent build(); + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizardScoped.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizardScoped.java new file mode 100644 index 000000000..d8a15210b --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultWizardScoped.java @@ -0,0 +1,13 @@ +package org.cryptomator.ui.addvaultwizard; + +import javax.inject.Scope; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Scope +@Documented +@Retention(RetentionPolicy.RUNTIME) +@interface AddVaultWizardScoped { + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java b/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java index ef157b50c..b8b4a9745 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java @@ -1,12 +1,14 @@ package org.cryptomator.ui.common; import javafx.fxml.FXMLLoader; -import org.cryptomator.ui.FxApplicationScoped; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; -import javax.inject.Inject; import javax.inject.Provider; import java.io.IOException; import java.io.InputStream; +import java.io.UncheckedIOException; import java.util.Map; import java.util.ResourceBundle; @@ -20,6 +22,9 @@ public class FXMLLoaderFactory { this.resourceBundle = ResourceBundle.getBundle("i18n.strings"); } + /** + * @return A new FXMLLoader instance + */ public FXMLLoader construct() { FXMLLoader loader = new FXMLLoader(); loader.setControllerFactory(this::constructController); @@ -27,6 +32,12 @@ public class FXMLLoaderFactory { return loader; } + /** + * Loads the FXML given fxml resource in a new FXMLLoader instance. + * @param fxmlResourceName Name of the resource (as in {@link Class#getResource(String)}). + * @return The FXMLLoader used to load the file + * @throws IOException if an error occurs while loading the FXML file + */ public FXMLLoader load(String fxmlResourceName) throws IOException { FXMLLoader loader = construct(); try (InputStream in = getClass().getResourceAsStream(fxmlResourceName)) { @@ -35,6 +46,23 @@ public class FXMLLoaderFactory { return loader; } + /** + * {@link #load(String) Loads} the FXML file and sets the given stage's scene to a new Scene containing the loaded ui. + * @param fxmlResourceName Name of the resource (as in {@link Class#getResource(String)}). + * @param stage The stage which should get a new scene + * @throws UncheckedIOException wrapping any IOException thrown by {@link #load(String)). + */ + public void setScene(String fxmlResourceName, Stage stage) throws UncheckedIOException { + final FXMLLoader loader; + try { + loader = load(fxmlResourceName); + } catch (IOException e) { + throw new UncheckedIOException("Failed to load " + fxmlResourceName, e); + } Parent root = loader.getRoot(); + Scene scene = new Scene(root); + stage.setScene(scene); + } + private FxController constructController(Class aClass) { if (!factories.containsKey(aClass)) { throw new IllegalArgumentException("ViewController not registered: " + aClass); diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindow.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindow.java new file mode 100644 index 000000000..51143e1f6 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindow.java @@ -0,0 +1,14 @@ +package org.cryptomator.ui.mainwindow; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface MainWindow { + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowComponent.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowComponent.java index 14e36563d..8d107c8bf 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowComponent.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowComponent.java @@ -6,33 +6,23 @@ package org.cryptomator.ui.mainwindow; import dagger.Subcomponent; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.stage.Stage; -import javafx.stage.Window; import org.cryptomator.ui.common.FXMLLoaderFactory; -import org.cryptomator.ui.model.Vault; - -import java.io.IOException; -import java.io.UncheckedIOException; @MainWindowScoped @Subcomponent(modules = {MainWindowModule.class}) public interface MainWindowComponent { - Stage mainWindow(); + @MainWindow + Stage window(); + @MainWindow FXMLLoaderFactory fxmlLoaders(); default void showMainWindow() { - try { - Parent root = fxmlLoaders().load("/fxml/main_window.fxml").getRoot(); - Stage stage = mainWindow(); - stage.setScene(new Scene(root)); - stage.show(); - } catch (IOException e) { - throw new UncheckedIOException("Failed to load main_window.fxml", e); - } + Stage stage = window(); + fxmlLoaders().setScene("/fxml/main_window.fxml", stage); + stage.show(); } @Subcomponent.Builder diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowController.java index 02206174a..201c652ce 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowController.java @@ -29,7 +29,7 @@ public class MainWindowController implements FxController { private double yOffset; @Inject - public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, Stage window, FxApplication application) { + public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, @MainWindow Stage window, FxApplication application) { this.shutdownLatch = shutdownLatch; this.window = window; this.application = application; diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java index 492f6455f..8c3f103e8 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java @@ -6,6 +6,7 @@ import dagger.Provides; import dagger.multibindings.IntoMap; import javafx.stage.Stage; import javafx.stage.StageStyle; +import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent; import org.cryptomator.ui.common.FXMLLoaderFactory; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.FxControllerKey; @@ -13,16 +14,18 @@ import org.cryptomator.ui.common.FxControllerKey; import javax.inject.Provider; import java.util.Map; -@Module +@Module(subcomponents = {AddVaultWizardComponent.class}) public abstract class MainWindowModule { @Provides + @MainWindow @MainWindowScoped static FXMLLoaderFactory provideFxmlLoaderFactory(Map, Provider> factories) { return new FXMLLoaderFactory(factories); } @Provides + @MainWindow @MainWindowScoped static Stage provideStage() { Stage stage = new Stage(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java index 11ecf6073..d911a2c8f 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java @@ -3,9 +3,9 @@ package org.cryptomator.ui.mainwindow; import javafx.beans.binding.Bindings; import javafx.beans.property.ObjectProperty; import javafx.collections.ObservableList; -import javafx.event.ActionEvent; import javafx.scene.control.ListView; import javafx.scene.layout.AnchorPane; +import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.model.Vault; @@ -16,13 +16,15 @@ public class VaultListController implements FxController { private final ObservableList vaults; private final ObjectProperty selectedVault; + private final AddVaultWizardComponent.Builder addVaultWizard; public ListView vaultList; public AnchorPane onboardingOverlay; @Inject - public VaultListController(ObservableList vaults, ObjectProperty selectedVault) { + VaultListController(ObservableList vaults, ObjectProperty selectedVault, AddVaultWizardComponent.Builder addVaultWizard) { this.vaults = vaults; this.selectedVault = selectedVault; + this.addVaultWizard = addVaultWizard; } public void initialize() { @@ -31,9 +33,10 @@ public class VaultListController implements FxController { selectedVault.bind(vaultList.getSelectionModel().selectedItemProperty()); } - public void didClickAddVault(ActionEvent actionEvent) { + public void didClickAddVault() { + addVaultWizard.build().showAddVaultWizard(); } - public void didClickRemoveVault(ActionEvent actionEvent) { + public void didClickRemoveVault() { } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesComponent.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesComponent.java index 60ec75dcf..d7002b067 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesComponent.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesComponent.java @@ -6,32 +6,23 @@ package org.cryptomator.ui.preferences; import dagger.Subcomponent; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.stage.Stage; import org.cryptomator.ui.common.FXMLLoaderFactory; -import org.cryptomator.ui.mainwindow.MainWindowModule; - -import java.io.IOException; -import java.io.UncheckedIOException; @PreferencesScoped @Subcomponent(modules = {PreferencesModule.class}) public interface PreferencesComponent { - Stage preferencesWindow(); + @PreferencesWindow + Stage window(); + @PreferencesWindow FXMLLoaderFactory fxmlLoaders(); default void showPreferencesWindow() { - try { - Parent root = fxmlLoaders().load("/fxml/preferences.fxml").getRoot(); - Stage stage = preferencesWindow(); - stage.setScene(new Scene(root)); - stage.show(); - } catch (IOException e) { - throw new UncheckedIOException("Failed to load main_window.fxml", e); - } + Stage stage = window(); + fxmlLoaders().setScene("/fxml/preferences.fxml", stage); + stage.show(); } @Subcomponent.Builder diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesModule.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesModule.java index 619f13f37..c3fee4c10 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesModule.java @@ -17,12 +17,14 @@ import java.util.Map; public abstract class PreferencesModule { @Provides + @PreferencesWindow @PreferencesScoped static FXMLLoaderFactory provideFxmlLoaderFactory(Map, Provider> factories) { return new FXMLLoaderFactory(factories); } @Provides + @PreferencesWindow @PreferencesScoped static Stage provideStage() { Stage stage = new Stage(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesWindow.java b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesWindow.java new file mode 100644 index 000000000..0f0e335cb --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/preferences/PreferencesWindow.java @@ -0,0 +1,14 @@ +package org.cryptomator.ui.preferences; + +import javax.inject.Qualifier; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; + +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Qualifier +@Documented +@Retention(RUNTIME) +public @interface PreferencesWindow { + +} diff --git a/main/ui/src/main/resources/fxml/addvault_welcome.fxml b/main/ui/src/main/resources/fxml/addvault_welcome.fxml new file mode 100644 index 000000000..04f0b3917 --- /dev/null +++ b/main/ui/src/main/resources/fxml/addvault_welcome.fxml @@ -0,0 +1,12 @@ + + + + + + +