mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-04-20 09:36:55 -04:00
hook up preferences window
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.desktop.PreferencesEvent;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
@@ -17,29 +21,52 @@ public class FxApplication extends Application {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FxApplication.class);
|
||||
|
||||
private final Stage primaryStage;
|
||||
private final Stage mainWindow;
|
||||
private final Stage preferencesWindow;
|
||||
private final FXMLLoaderFactory fxmlLoaders;
|
||||
|
||||
@Inject
|
||||
FxApplication(@Named("mainWindow") Stage primaryStage, FXMLLoaderFactory fxmlLoaders) {
|
||||
this.primaryStage = primaryStage;
|
||||
FxApplication(@MainWindow Stage mainWindow, @PreferencesWindow Stage preferencesWindow, FXMLLoaderFactory fxmlLoaders) {
|
||||
this.mainWindow = mainWindow;
|
||||
this.preferencesWindow = preferencesWindow;
|
||||
this.fxmlLoaders = fxmlLoaders;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
try {
|
||||
LOG.info("Starting GUI...");
|
||||
start(primaryStage);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
LOG.trace("FxApplication.start()");
|
||||
if (Desktop.getDesktop().isSupported(Desktop.Action.APP_PREFERENCES)) {
|
||||
Desktop.getDesktop().setPreferencesHandler(this::handlePreferences);
|
||||
}
|
||||
|
||||
start(mainWindow);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
Parent root = fxmlLoaders.load("/fxml/main_window.fxml").getRoot();
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
public void start(Stage stage) {
|
||||
assert stage == mainWindow;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,16 +17,7 @@ import javax.inject.Named;
|
||||
@Module(includes = {UiModule.class})
|
||||
abstract class FxApplicationModule {
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
@Named("mainWindow")
|
||||
static Stage providePrimaryStage() {
|
||||
Stage stage = new Stage();
|
||||
stage.setMinWidth(652.0);
|
||||
stage.setMinHeight(440.0);
|
||||
stage.initStyle(StageStyle.UNDECORATED);
|
||||
return stage;
|
||||
}
|
||||
|
||||
|
||||
@Binds
|
||||
@FxApplicationScoped
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.cryptomator.frontend.webdav.WebDavServer;
|
||||
import org.cryptomator.keychain.KeychainModule;
|
||||
import org.cryptomator.ui.mainwindow.MainWindowModule;
|
||||
import org.cryptomator.ui.model.VaultComponent;
|
||||
import org.cryptomator.ui.preferences.PreferencesModule;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
import javax.inject.Named;
|
||||
@@ -27,7 +28,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Module(includes = {KeychainModule.class, MainWindowModule.class}, subcomponents = {VaultComponent.class})
|
||||
@Module(includes = {KeychainModule.class, MainWindowModule.class, PreferencesModule.class}, subcomponents = {VaultComponent.class})
|
||||
public class UiModule {
|
||||
|
||||
private static final int NUM_SCHEDULER_THREADS = 4;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MainWindow {
|
||||
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.FxApplication;
|
||||
import org.cryptomator.ui.FxApplicationScoped;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.slf4j.Logger;
|
||||
@@ -20,6 +21,7 @@ public class MainWindowController implements FxController {
|
||||
|
||||
private final CountDownLatch shutdownLatch;
|
||||
private final Stage mainWindow;
|
||||
private final FxApplication application;
|
||||
|
||||
@FXML
|
||||
public HBox titleBar;
|
||||
@@ -28,9 +30,10 @@ public class MainWindowController implements FxController {
|
||||
private double yOffset;
|
||||
|
||||
@Inject
|
||||
public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, @Named("mainWindow") Stage mainWindow) {
|
||||
public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, @MainWindow Stage mainWindow, FxApplication application) {
|
||||
this.shutdownLatch = shutdownLatch;
|
||||
this.mainWindow = mainWindow;
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
@FXML
|
||||
@@ -52,4 +55,9 @@ public class MainWindowController implements FxController {
|
||||
LOG.info("closed...");
|
||||
shutdownLatch.countDown();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void showPreferences() {
|
||||
application.showPreferencesWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import dagger.multibindings.IntoMap;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import org.cryptomator.ui.FxApplicationScoped;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.cryptomator.ui.FxControllerKey;
|
||||
@@ -33,8 +35,19 @@ public abstract class MainWindowModule {
|
||||
|
||||
// ------------------
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
@MainWindow
|
||||
static Stage providePrimaryStage() {
|
||||
Stage stage = new Stage();
|
||||
stage.setMinWidth(652.0);
|
||||
stage.setMinHeight(440.0);
|
||||
stage.initStyle(StageStyle.UNDECORATED);
|
||||
return stage;
|
||||
}
|
||||
|
||||
@Binds
|
||||
abstract ObservableList<Vault> provideVaults(VaultList vaultList);
|
||||
abstract ObservableList<Vault> bindVaultList(VaultList vaultList);
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import org.cryptomator.ui.FxController;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@PreferencesWindow
|
||||
public class PreferencesController implements FxController {
|
||||
|
||||
@Inject
|
||||
PreferencesController() {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.FxApplicationScoped;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.cryptomator.ui.FxControllerKey;
|
||||
import org.cryptomator.ui.mainwindow.MainWindow;
|
||||
|
||||
@Module
|
||||
public abstract class PreferencesModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FxControllerKey(PreferencesController.class)
|
||||
abstract FxController bindPreferencesController(PreferencesController controller);
|
||||
|
||||
@Provides
|
||||
@FxApplicationScoped
|
||||
@PreferencesWindow
|
||||
static Stage providePreferencesStage(@MainWindow Stage mainWindow) {
|
||||
Stage stage = new Stage();
|
||||
stage.setMinWidth(400);
|
||||
stage.setMinHeight(300);
|
||||
stage.initModality(Modality.APPLICATION_MODAL);
|
||||
stage.initOwner(mainWindow);
|
||||
return stage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.cryptomator.ui.preferences;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Qualifier
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PreferencesWindow {
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
<Insets bottom="6" left="12" right="12" top="6"/>
|
||||
</padding>
|
||||
<children>
|
||||
<Button contentDisplay="GRAPHIC_ONLY" mnemonicParsing="false" style="-fx-background-color: none;">
|
||||
<Button contentDisplay="GRAPHIC_ONLY" mnemonicParsing="false" onAction="#showPreferences" style="-fx-background-color: none;">
|
||||
<graphic>
|
||||
<FontAwesomeIconView fill="WHITE" glyphName="COGS"/>
|
||||
</graphic>
|
||||
|
||||
10
main/ui/src/main/resources/fxml/preferences.fxml
Normal file
10
main/ui/src/main/resources/fxml/preferences.fxml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.preferences.PreferencesController"
|
||||
styleClass="main-window">
|
||||
<Label text="preferences..."/>
|
||||
</VBox>
|
||||
Reference in New Issue
Block a user