mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
new class layout for viewcontrollers
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
<cryptomator.webdav.version>1.0.10</cryptomator.webdav.version>
|
||||
|
||||
<javafx.version>12</javafx.version>
|
||||
<fontawesomefx.version>4.7.0-9.1.2</fontawesomefx.version>
|
||||
|
||||
<commons-io.version>2.6</commons-io.version>
|
||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
||||
@@ -139,6 +140,11 @@
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>${javafx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.jensd</groupId>
|
||||
<artifactId>fontawesomefx-fontawesome</artifactId>
|
||||
<version>${fontawesomefx.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging -->
|
||||
<dependency>
|
||||
|
||||
@@ -55,6 +55,10 @@
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.jensd</groupId>
|
||||
<artifactId>fontawesomefx-fontawesome</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- EasyBind -->
|
||||
<dependency>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.cryptomator.ui;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
@FxApplicationScoped
|
||||
public class FXMLLoaderFactory {
|
||||
|
||||
private final Map<Class<? extends FxController>, Provider<FxController>> factories;
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
@Inject
|
||||
FXMLLoaderFactory(Map<Class<? extends FxController>, Provider<FxController>> factories) {
|
||||
this.factories = factories;
|
||||
this.resourceBundle = ResourceBundle.getBundle("i18n.strings");
|
||||
}
|
||||
|
||||
public FXMLLoader construct() {
|
||||
FXMLLoader loader = new FXMLLoader();
|
||||
loader.setControllerFactory(this::constructController);
|
||||
loader.setResources(resourceBundle);
|
||||
return loader;
|
||||
}
|
||||
|
||||
public FXMLLoader load(String fxmlResourceName) throws IOException {
|
||||
FXMLLoader loader = construct();
|
||||
try (InputStream in = getClass().getResourceAsStream(fxmlResourceName)) {
|
||||
loader.load(in);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
private FxController constructController(Class<?> aClass) {
|
||||
if (!factories.containsKey(aClass)) {
|
||||
throw new IllegalArgumentException("ViewController not registered: " + aClass);
|
||||
} else {
|
||||
return factories.get(aClass).get();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package org.cryptomator.ui;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.controllers.MainController;
|
||||
import org.cryptomator.ui.controllers.ViewControllerLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
@FxApplicationScoped
|
||||
public class FxApplication extends Application {
|
||||
@@ -16,24 +18,28 @@ public class FxApplication extends Application {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FxApplication.class);
|
||||
|
||||
private final Stage primaryStage;
|
||||
private final ViewControllerLoader fxmlLoader;
|
||||
private final FXMLLoaderFactory fxmlLoaders;
|
||||
|
||||
@Inject
|
||||
FxApplication(@Named("mainWindow") Stage primaryStage, ViewControllerLoader fxmlLoader) {
|
||||
FxApplication(@Named("mainWindow") Stage primaryStage, FXMLLoaderFactory fxmlLoaders) {
|
||||
this.primaryStage = primaryStage;
|
||||
this.fxmlLoader = fxmlLoader;
|
||||
this.fxmlLoaders = fxmlLoaders;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
LOG.info("Starting GUI...");
|
||||
start(primaryStage);
|
||||
try {
|
||||
LOG.info("Starting GUI...");
|
||||
start(primaryStage);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
MainController mainCtrl = fxmlLoader.load("/fxml/main.fxml");
|
||||
mainCtrl.initStage(primaryStage);
|
||||
primaryStage.show();
|
||||
public void start(Stage stage) throws IOException {
|
||||
Parent root = fxmlLoaders.load("/fxml/main_window.fxml").getRoot();
|
||||
stage.setScene(new Scene(root));
|
||||
stage.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
@@ -23,6 +24,7 @@ abstract class FxApplicationModule {
|
||||
Stage stage = new Stage();
|
||||
stage.setMinWidth(652.0);
|
||||
stage.setMinHeight(440.0);
|
||||
stage.initStyle(StageStyle.UNDECORATED);
|
||||
return stage;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
public interface FxController {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import dagger.MapKey;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
// TODO rename after refactoring
|
||||
@Documented
|
||||
@Target(METHOD)
|
||||
@Retention(RUNTIME)
|
||||
@MapKey
|
||||
public @interface FxControllerKey {
|
||||
Class<? extends FxController> value();
|
||||
}
|
||||
@@ -16,7 +16,9 @@ import org.cryptomator.common.settings.Settings;
|
||||
import org.cryptomator.frontend.webdav.WebDavServer;
|
||||
import org.cryptomator.keychain.KeychainModule;
|
||||
import org.cryptomator.ui.controllers.ViewControllerModule;
|
||||
import org.cryptomator.ui.mainwindow.MainWindowModule;
|
||||
import org.cryptomator.ui.model.VaultComponent;
|
||||
import org.cryptomator.ui.vaultlist.VaultListModule;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
import javax.inject.Named;
|
||||
@@ -27,7 +29,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Module(includes = {ViewControllerModule.class, KeychainModule.class}, subcomponents = {VaultComponent.class})
|
||||
@Module(includes = {ViewControllerModule.class, KeychainModule.class, VaultListModule.class, MainWindowModule.class}, subcomponents = {VaultComponent.class})
|
||||
public class UiModule {
|
||||
|
||||
private static final int NUM_SCHEDULER_THREADS = 4;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.stage.Stage;
|
||||
import org.cryptomator.ui.FxApplicationScoped;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
@FxApplicationScoped
|
||||
public class MainWindowController implements FxController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MainWindowController.class);
|
||||
|
||||
private final CountDownLatch shutdownLatch;
|
||||
private final Stage mainWindow;
|
||||
|
||||
@FXML
|
||||
public HBox titleBar;
|
||||
|
||||
private double xOffset;
|
||||
private double yOffset;
|
||||
|
||||
@Inject
|
||||
public MainWindowController(@Named("shutdownLatch") CountDownLatch shutdownLatch, @Named("mainWindow") Stage mainWindow) {
|
||||
this.shutdownLatch = shutdownLatch;
|
||||
this.mainWindow = mainWindow;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
LOG.debug("init MainWindowController");
|
||||
titleBar.setOnMousePressed(event -> {
|
||||
xOffset = event.getSceneX();
|
||||
yOffset = event.getSceneY();
|
||||
});
|
||||
titleBar.setOnMouseDragged(event -> {
|
||||
titleBar.getScene().getWindow().setX(event.getScreenX() - xOffset);
|
||||
titleBar.getScene().getWindow().setY(event.getScreenY() - yOffset);
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void close() {
|
||||
mainWindow.close();
|
||||
LOG.info("closed...");
|
||||
shutdownLatch.countDown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.cryptomator.ui.mainwindow;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.cryptomator.ui.FxControllerKey;
|
||||
import org.cryptomator.ui.vaultlist.VaultListController;
|
||||
|
||||
@Module
|
||||
public abstract class MainWindowModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FxControllerKey(MainWindowController.class)
|
||||
abstract FxController bindController(MainWindowController controller);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.cryptomator.ui.vaultlist;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import org.cryptomator.ui.FxApplicationScoped;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@FxApplicationScoped
|
||||
public class VaultListController implements FxController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(VaultListController.class);
|
||||
|
||||
@Inject
|
||||
public VaultListController() {
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
LOG.debug("init VaultListController");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.cryptomator.ui.vaultlist;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import org.cryptomator.ui.FxController;
|
||||
import org.cryptomator.ui.FxControllerKey;
|
||||
|
||||
@Module
|
||||
public abstract class VaultListModule {
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@FxControllerKey(VaultListController.class)
|
||||
abstract FxController bindController(VaultListController controller);
|
||||
|
||||
}
|
||||
38
main/ui/src/main/resources/fxml/main_window.fxml
Normal file
38
main/ui/src/main/resources/fxml/main_window.fxml
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Tooltip?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.mainwindow.MainWindowController">
|
||||
<children>
|
||||
<HBox fx:id="titleBar" alignment="CENTER_RIGHT" prefHeight="49.0" prefWidth="600.0" style="-fx-background-color: #79b01a;">
|
||||
<padding>
|
||||
<Insets bottom="6.0" left="6.0" right="6.0" top="6.0"/>
|
||||
</padding>
|
||||
<children>
|
||||
<Button contentDisplay="GRAPHIC_ONLY" mnemonicParsing="false" style="-fx-background-color: none;" text="Button">
|
||||
<graphic>
|
||||
<FontAwesomeIconView fill="WHITE" glyphName="COGS"/>
|
||||
</graphic>
|
||||
<tooltip>
|
||||
<Tooltip text="%main.settingsBtn.tooltip"/>
|
||||
</tooltip>
|
||||
</Button>
|
||||
<Button contentDisplay="GRAPHIC_ONLY" layoutX="612.0" layoutY="16.0" mnemonicParsing="false" onAction="#close" style="-fx-background-color: none;" text="Button">
|
||||
<graphic>
|
||||
<FontAwesomeIconView fill="WHITE" glyphName="CLOSE"/>
|
||||
</graphic>
|
||||
<tooltip>
|
||||
<Tooltip text="%main.closeBtn.tooltip"/>
|
||||
</tooltip>
|
||||
</Button>
|
||||
</children>
|
||||
</HBox>
|
||||
<fx:include source="/fxml/vaultlist.fxml"/>
|
||||
</children>
|
||||
</VBox>
|
||||
9
main/ui/src/main/resources/fxml/vaultlist.fxml
Normal file
9
main/ui/src/main/resources/fxml/vaultlist.fxml
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<VBox xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.vaultlist.VaultListController">
|
||||
<Label text="%title"/>
|
||||
</VBox>
|
||||
3
main/ui/src/main/resources/i18n/strings.properties
Normal file
3
main/ui/src/main/resources/i18n/strings.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
main.closeBtn.tooltip=Close
|
||||
main.settingsBtn.tooltip=Settings
|
||||
title=Cryptomator
|
||||
3
main/ui/src/main/resources/i18n/strings_de.properties
Normal file
3
main/ui/src/main/resources/i18n/strings_de.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
main.closeBtn.tooltip=Close
|
||||
main.settingsBtn.tooltip=Settings
|
||||
title=CryptomatorDE
|
||||
3
main/ui/src/main/resources/i18n/strings_en.properties
Normal file
3
main/ui/src/main/resources/i18n/strings_en.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
main.closeBtn.tooltip=Close
|
||||
main.settingsBtn.tooltip=Settings
|
||||
title=CryptomatorEN
|
||||
Reference in New Issue
Block a user