|
@@ -3,6 +3,7 @@ package org.cryptomator.ui.vaultstatistics;
|
|
|
import javafx.animation.Animation;
|
|
|
import javafx.animation.KeyFrame;
|
|
|
import javafx.animation.Timeline;
|
|
|
+import javafx.beans.binding.LongBinding;
|
|
|
import javafx.event.ActionEvent;
|
|
|
import javafx.event.EventHandler;
|
|
|
import javafx.fxml.FXML;
|
|
@@ -12,7 +13,9 @@ import javafx.scene.chart.XYChart.Series;
|
|
|
import javafx.stage.Stage;
|
|
|
import javafx.util.Duration;
|
|
|
import org.cryptomator.common.vaults.Vault;
|
|
|
+import org.cryptomator.common.vaults.VaultStats;
|
|
|
import org.cryptomator.ui.common.FxController;
|
|
|
+import org.cryptomator.ui.common.WeakBindings;
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
@@ -22,31 +25,38 @@ public class VaultStatisticsController implements FxController {
|
|
|
private static final int IO_SAMPLING_STEPS = 100;
|
|
|
private static final double IO_SAMPLING_INTERVAL = 0.5;
|
|
|
|
|
|
- private final Stage window;
|
|
|
- private final Vault vault;
|
|
|
- @FXML
|
|
|
- private LineChart<Number, Number> lineGraph;
|
|
|
+ private final VaultStats stats;
|
|
|
private final Series<Number, Number> readData;
|
|
|
private final Series<Number, Number> writeData;
|
|
|
- private Timeline ioAnimation;
|
|
|
+ private final Timeline ioAnimation;
|
|
|
+ private final LongBinding bpsRead;
|
|
|
+ private final LongBinding bpsWritten;
|
|
|
|
|
|
+ public LineChart<Number, Number> lineGraph;
|
|
|
|
|
|
@Inject
|
|
|
public VaultStatisticsController(@VaultStatisticsWindow Stage window, @VaultStatisticsWindow Vault vault) {
|
|
|
- this.window = window;
|
|
|
- this.vault = vault;
|
|
|
+ this.stats = vault.getStats();
|
|
|
+ this.bpsRead = WeakBindings.bindLong(stats.bytesPerSecondReadProperty());
|
|
|
+ this.bpsWritten = WeakBindings.bindLong(stats.bytesPerSecondWrittenProperty());
|
|
|
|
|
|
- readData = new Series<>();
|
|
|
+ this.readData = new Series<>();
|
|
|
readData.setName("Read Data"); // For Legend
|
|
|
//TODO Add Name to strings.properties
|
|
|
- writeData = new Series<>();
|
|
|
+ this.writeData = new Series<>();
|
|
|
writeData.setName("Write Data");
|
|
|
//TODO Add Name to strings.properties
|
|
|
|
|
|
- ioAnimation = new Timeline(); //TODO Research better timer
|
|
|
+ this.ioAnimation = new Timeline(); //TODO Research better timer
|
|
|
ioAnimation.getKeyFrames().add(new KeyFrame(Duration.seconds(IO_SAMPLING_INTERVAL), new IoSamplingAnimationHandler(readData, writeData)));
|
|
|
ioAnimation.setCycleCount(Animation.INDEFINITE);
|
|
|
ioAnimation.play();
|
|
|
+
|
|
|
+ // make sure to stop animating,
|
|
|
+ // otherwise a global timer (GC root) will keep a strong reference to animation
|
|
|
+ window.setOnHiding(evt -> {
|
|
|
+ ioAnimation.stop();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
@@ -84,20 +94,30 @@ public class VaultStatisticsController implements FxController {
|
|
|
}
|
|
|
|
|
|
// add latest value:
|
|
|
- final long decBytes = vault.getStats().bytesPerSecondReadProperty().get();
|
|
|
+ final long decBytes = stats.bytesPerSecondReadProperty().get();
|
|
|
final double decMb = decBytes * BYTES_TO_MEGABYTES_FACTOR;
|
|
|
- final long encBytes = vault.getStats().bytesPerSecondWrittenProperty().get();
|
|
|
+ final long encBytes = stats.bytesPerSecondWrittenProperty().get();
|
|
|
final double encMb = encBytes * BYTES_TO_MEGABYTES_FACTOR;
|
|
|
decryptedBytesRead.getData().get(IO_SAMPLING_STEPS - 1).setYValue(decMb);
|
|
|
encryptedBytesWrite.getData().get(IO_SAMPLING_STEPS - 1).setYValue(encMb);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Vault getVault() {
|
|
|
- return vault;
|
|
|
+ /* Getter/Setter */
|
|
|
+
|
|
|
+ public LongBinding bpsReadProperty() {
|
|
|
+ return bpsRead;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getBpsRead() {
|
|
|
+ return bpsRead.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public LongBinding bpsWrittenProperty() {
|
|
|
+ return bpsWritten;
|
|
|
+ }
|
|
|
+
|
|
|
+ public long getBpsWritten() {
|
|
|
+ return bpsWritten.get();
|
|
|
}
|
|
|
- /*
|
|
|
- public ReadOnlyObjectProperty<Vault> vaultProperty() {
|
|
|
- return vault;
|
|
|
- }*/
|
|
|
}
|