allow changing of user interface orientation via settings

This commit is contained in:
Sebastian Stenzel
2019-10-18 12:51:41 +02:00
parent 7a1e20d732
commit aa61ab2b6e
6 changed files with 76 additions and 5 deletions
@@ -8,6 +8,7 @@ import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.ui.fxapp.FxApplicationScoped;
import javax.inject.Inject;
@@ -19,16 +20,25 @@ public class DefaultSceneFactory implements Function<Parent, Scene> {
protected static final KeyCodeCombination ALT_F4 = new KeyCodeCombination(KeyCode.F4, KeyCombination.ALT_DOWN);
protected static final KeyCodeCombination SHORTCUT_W = new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN);
protected final Settings settings;
@Inject
public DefaultSceneFactory() {}
public DefaultSceneFactory(Settings settings) {
this.settings = settings;
}
@Override
public Scene apply(Parent root) {
Scene scene = new Scene(root);
configureRoot(root);
configureScene(scene);
return scene;
}
protected void configureRoot(Parent root) {
root.nodeOrientationProperty().bind(settings.userInterfaceOrientation());
}
protected void configureScene(Scene scene) {
scene.windowProperty().addListener(observable -> {
Window window = scene.getWindow();
@@ -7,6 +7,7 @@ import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.stage.Stage;
import org.apache.commons.lang3.SystemUtils;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.ui.common.DefaultSceneFactory;
import javax.inject.Inject;
@@ -20,7 +21,8 @@ public class MainWindowSceneFactory extends DefaultSceneFactory {
private final Lazy<VaultListController> vaultListController;
@Inject
public MainWindowSceneFactory(Lazy<MainWindowController> mainWindowController, Lazy<VaultListController> vaultListController) {
public MainWindowSceneFactory(Settings settings, Lazy<MainWindowController> mainWindowController, Lazy<VaultListController> vaultListController) {
super(settings);
this.mainWindowController = mainWindowController;
this.vaultListController = vaultListController;
}
@@ -1,21 +1,33 @@
package org.cryptomator.ui.preferences;
import javafx.beans.value.ObservableValue;
import javafx.geometry.NodeOrientation;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup;
import javafx.util.StringConverter;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.UiTheme;
import org.cryptomator.ui.common.FxController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
@PreferencesScoped
public class GeneralPreferencesController implements FxController {
private static final Logger LOG = LoggerFactory.getLogger(GeneralPreferencesController.class);
private final Settings settings;
public ChoiceBox<UiTheme> themeChoiceBox;
public CheckBox startHiddenCheckbox;
public CheckBox debugModeCheckbox;
public ToggleGroup nodeOrientation;
public RadioButton nodeOrientationLtr;
public RadioButton nodeOrientationRtl;
@Inject
GeneralPreferencesController(Settings settings) {
@@ -30,6 +42,20 @@ public class GeneralPreferencesController implements FxController {
startHiddenCheckbox.selectedProperty().bindBidirectional(settings.startHidden());
debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode());
nodeOrientation.selectedToggleProperty().addListener(this::toggleNodeOrientation);
nodeOrientationLtr.setSelected(settings.userInterfaceOrientation().get() == NodeOrientation.LEFT_TO_RIGHT);
nodeOrientationRtl.setSelected(settings.userInterfaceOrientation().get() == NodeOrientation.RIGHT_TO_LEFT);
}
private void toggleNodeOrientation(@SuppressWarnings("unused") ObservableValue<? extends Toggle> observable, @SuppressWarnings("unused") Toggle oldValue, Toggle newValue) {
if (nodeOrientationLtr.equals(newValue)) {
settings.userInterfaceOrientation().set(NodeOrientation.LEFT_TO_RIGHT);
} else if (nodeOrientationRtl.equals(newValue)) {
settings.userInterfaceOrientation().set(NodeOrientation.RIGHT_TO_LEFT);
} else {
LOG.warn("Unexpected toggle option {}", newValue);
}
}
/* Helper classes */
@@ -6,10 +6,15 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ToggleGroup?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.preferences.GeneralPreferencesController"
spacing="6">
<fx:define>
<ToggleGroup fx:id="nodeOrientation"/>
</fx:define>
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
@@ -18,6 +23,12 @@
<Label text="%preferences.general.theme"/>
<ChoiceBox fx:id="themeChoiceBox"/>
</HBox>
<HBox spacing="6" alignment="CENTER_LEFT">
<Label text="Interface Orientation" HBox.hgrow="NEVER"/>
<RadioButton fx:id="nodeOrientationLtr" text="Left to Right" alignment="CENTER_LEFT" toggleGroup="${nodeOrientation}"/>
<RadioButton fx:id="nodeOrientationRtl" text="Right to Left" alignment="CENTER_RIGHT" toggleGroup="${nodeOrientation}"/>
</HBox>
<CheckBox fx:id="startHiddenCheckbox" text="%preferences.general.startHidden"/>