From f61e95594529a7db334a06e846c63d123e1095e9 Mon Sep 17 00:00:00 2001 From: Martin Beyer Date: Thu, 4 Jun 2020 12:28:45 +0200 Subject: [PATCH 01/33] First Dummy window to show statistics --- .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../ui/mainwindow/MainWindowModule.java | 7 +-- .../VaultDetailUnlockedController.java | 10 +++- .../VaultStatisticsComponent.java | 38 ++++++++++++ .../VaultStatisticsController.java | 20 +++++++ .../VaultStatisticsModule.java | 58 +++++++++++++++++++ .../VaultStatisticsScoped.java | 13 +++++ .../VaultStatisticsWindow.java | 14 +++++ .../resources/fxml/vault_detail_unlocked.fxml | 1 + .../main/resources/fxml/vault_statistics.fxml | 23 ++++++++ 10 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsComponent.java create mode 100644 main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java create mode 100644 main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java create mode 100644 main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsScoped.java create mode 100644 main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsWindow.java create mode 100644 main/ui/src/main/resources/fxml/vault_statistics.fxml diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 262af2283..3a3b47d1b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -28,6 +28,7 @@ public enum FxmlFile { UNLOCK_INVALID_MOUNT_POINT("/fxml/unlock_invalid_mount_point.fxml"), // UNLOCK_SUCCESS("/fxml/unlock_success.fxml"), // VAULT_OPTIONS("/fxml/vault_options.fxml"), // + VAULT_STATISTICS("/fxml/vault_statistics.fxml"), // WRONGFILEALERT("/fxml/wrongfilealert.fxml"); private final String ressourcePathString; 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 a34273f84..eca71c38e 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 @@ -7,7 +7,6 @@ import dagger.multibindings.IntoMap; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.scene.Scene; -import javafx.scene.image.Image; import javafx.stage.Stage; import javafx.stage.StageStyle; import org.cryptomator.common.vaults.Vault; @@ -18,19 +17,17 @@ import org.cryptomator.ui.common.FxControllerKey; import org.cryptomator.ui.common.FxmlFile; import org.cryptomator.ui.common.FxmlScene; import org.cryptomator.ui.common.StageFactory; -import org.cryptomator.ui.fxapp.FxApplicationScoped; import org.cryptomator.ui.migration.MigrationComponent; import org.cryptomator.ui.removevault.RemoveVaultComponent; import org.cryptomator.ui.vaultoptions.VaultOptionsComponent; +import org.cryptomator.ui.vaultstatistics.VaultStatisticsComponent; import org.cryptomator.ui.wrongfilealert.WrongFileAlertComponent; -import javax.inject.Named; import javax.inject.Provider; -import java.util.List; import java.util.Map; import java.util.ResourceBundle; -@Module(subcomponents = {AddVaultWizardComponent.class, MigrationComponent.class, RemoveVaultComponent.class, VaultOptionsComponent.class, WrongFileAlertComponent.class}) +@Module(subcomponents = {AddVaultWizardComponent.class, MigrationComponent.class, RemoveVaultComponent.class, VaultOptionsComponent.class, VaultStatisticsComponent.class, WrongFileAlertComponent.class}) abstract class MainWindowModule { @Provides diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java index 32f9bc9b0..e42b902e7 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java @@ -6,6 +6,7 @@ import javafx.fxml.FXML; import org.cryptomator.common.vaults.Vault; import org.cryptomator.ui.common.FxController; import org.cryptomator.ui.common.VaultService; +import org.cryptomator.ui.vaultstatistics.VaultStatisticsComponent; import javax.inject.Inject; @@ -14,11 +15,13 @@ public class VaultDetailUnlockedController implements FxController { private final ReadOnlyObjectProperty vault; private final VaultService vaultService; + private final VaultStatisticsComponent.Builder vaultStatisticsWindow; @Inject - public VaultDetailUnlockedController(ObjectProperty vault, VaultService vaultService) { + public VaultDetailUnlockedController(ObjectProperty vault, VaultService vaultService, VaultStatisticsComponent.Builder vaultStatisticsWindow) { this.vault = vault; this.vaultService = vaultService; + this.vaultStatisticsWindow = vaultStatisticsWindow; } @FXML @@ -32,6 +35,11 @@ public class VaultDetailUnlockedController implements FxController { // TODO count lock attempts, and allow forced lock } + @FXML + public void showVaultStatistics() { + vaultStatisticsWindow.vault(vault.get()).build().showVaultStatisticsWindow(); + } + /* Getter/Setter */ public ReadOnlyObjectProperty vaultProperty() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsComponent.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsComponent.java new file mode 100644 index 000000000..915f936f9 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsComponent.java @@ -0,0 +1,38 @@ +package org.cryptomator.ui.vaultstatistics; + +import dagger.BindsInstance; +import dagger.Lazy; +import dagger.Subcomponent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; + +@VaultStatisticsScoped +@Subcomponent(modules = {VaultStatisticsModule.class}) +public interface VaultStatisticsComponent { + + @VaultStatisticsWindow + Stage window(); + + @FxmlScene(FxmlFile.VAULT_STATISTICS) + Lazy scene(); + + default void showVaultStatisticsWindow() { + Stage stage = window(); + stage.setScene(scene().get()); + stage.sizeToScene(); + stage.show(); + } + + @Subcomponent.Builder + interface Builder { + + @BindsInstance + Builder vault(@VaultStatisticsWindow Vault vault); + + VaultStatisticsComponent build(); + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java new file mode 100644 index 000000000..30292f4c7 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsController.java @@ -0,0 +1,20 @@ +package org.cryptomator.ui.vaultstatistics; + +import javafx.stage.Stage; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.ui.common.FxController; + +import javax.inject.Inject; + +@VaultStatisticsScoped +public class VaultStatisticsController implements FxController { + + private final Stage window; + private final Vault vault; + + @Inject + public VaultStatisticsController(@VaultStatisticsWindow Stage window, @VaultStatisticsWindow Vault vault) { + this.window = window; + this.vault = vault; + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java new file mode 100644 index 000000000..a129c0eb7 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsModule.java @@ -0,0 +1,58 @@ +package org.cryptomator.ui.vaultstatistics; + +import dagger.Binds; +import dagger.Module; +import dagger.Provides; +import dagger.multibindings.IntoMap; +import javafx.scene.Scene; +import javafx.stage.Modality; +import javafx.stage.Stage; +import org.cryptomator.ui.common.DefaultSceneFactory; +import org.cryptomator.ui.common.FXMLLoaderFactory; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxControllerKey; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; +import org.cryptomator.ui.common.StageFactory; +import org.cryptomator.ui.mainwindow.MainWindow; + +import javax.inject.Provider; +import java.util.Map; +import java.util.ResourceBundle; + +@Module +abstract class VaultStatisticsModule { + + @Provides + @VaultStatisticsWindow + @VaultStatisticsScoped + static FXMLLoaderFactory provideFxmlLoaderFactory(Map, Provider> factories, DefaultSceneFactory sceneFactory, ResourceBundle resourceBundle) { + return new FXMLLoaderFactory(factories, sceneFactory, resourceBundle); + } + + @Provides + @VaultStatisticsWindow + @VaultStatisticsScoped + static Stage provideStage(StageFactory factory, @MainWindow Stage owner, ResourceBundle resourceBundle) { + Stage stage = factory.create(); + stage.setTitle(resourceBundle.getString("removeVault.title")); + stage.setResizable(false); + stage.initModality(Modality.APPLICATION_MODAL); + stage.initOwner(owner); + return stage; + } + + @Provides + @FxmlScene(FxmlFile.VAULT_STATISTICS) + @VaultStatisticsScoped + static Scene provideVaultStatisticsScene(@VaultStatisticsWindow FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/vault_statistics.fxml"); + } + + // ------------------ + + @Binds + @IntoMap + @FxControllerKey(VaultStatisticsController.class) + abstract FxController bindVaultStatisticsController(VaultStatisticsController controller); +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsScoped.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsScoped.java new file mode 100644 index 000000000..842e7e508 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsScoped.java @@ -0,0 +1,13 @@ +package org.cryptomator.ui.vaultstatistics; + +import javax.inject.Scope; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Scope +@Documented +@Retention(RetentionPolicy.RUNTIME) +public @interface VaultStatisticsScoped { + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsWindow.java b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsWindow.java new file mode 100644 index 000000000..4fe9174a1 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/vaultstatistics/VaultStatisticsWindow.java @@ -0,0 +1,14 @@ +package org.cryptomator.ui.vaultstatistics; + +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) +@interface VaultStatisticsWindow { + +} diff --git a/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml b/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml index 492c0336b..d7db563fa 100644 --- a/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml +++ b/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml @@ -45,4 +45,5 @@ + - - - - - - - + \ No newline at end of file diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index 53fe9f847..18f3f33d9 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -227,12 +227,12 @@ main.vaultDetail.unlockedStatus=UNLOCKED main.vaultDetail.accessLocation=Your vault's contents are accessible here: main.vaultDetail.revealBtn=Reveal Drive main.vaultDetail.lockBtn=Lock -main.vaultDetail.bytesPerSecondRead=read: -main.vaultDetail.bytesPerSecondWritten=written: +main.vaultDetail.bytesPerSecondRead=Read: +main.vaultDetail.bytesPerSecondWritten=Write: main.vaultDetail.throughput.idle=idle main.vaultDetail.throughput.kbps=%.1f kiB/s main.vaultDetail.throughput.mbps=%.1f MiB/s -main.vaultDetail.stats=Show Statistics +main.vaultDetail.stats=Vault Statistics ### Missing main.vaultDetail.missing.info=Cryptomator could not find a vault at this path. main.vaultDetail.missing.recheck=Recheck