Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion of prefs/bibtexkeygen and appearance to mvvm #5360

Merged
merged 21 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,3 @@ We want to have a look that matches our icons in the tool-bar */
.dialog-pane {
-fx-background-color: -fx-control-inner-background;
}

.preference-sidepane {
-fx-background-color: -jr-sidepane-background;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public BibtexKeyPatternPanel(BasePanel panel) {
buildGUI();
}

public void setDefaultPat(String pattern) { this.defaultPat.setText(pattern); }
calixtus marked this conversation as resolved.
Show resolved Hide resolved

public String getDefaultPat() { return this.defaultPat.getText(); }

private static void setValue(TextField tf, EntryType fieldName, AbstractBibtexKeyPattern keyPattern) {
if (keyPattern.isDefaultValue(fieldName)) {
tf.setText("");
Expand Down Expand Up @@ -118,7 +122,7 @@ private void buildGUI() {
gridPane.add(btnDefaultAll1, 2, rowIndex);
}

protected GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() {
public GlobalBibtexKeyPattern getKeyPatternAsGlobalBibtexKeyPattern() {
GlobalBibtexKeyPattern res = GlobalBibtexKeyPattern.fromPattern(Globals.prefs.get(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN));
fillPatternUsingPanelData(res);
return res;
Expand Down
136 changes: 0 additions & 136 deletions src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java

This file was deleted.

33 changes: 33 additions & 0 deletions src/main/java/org/jabref/gui/preferences/AppearanceTab.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.geometry.Insets?>
<fx:root prefWidth="650.0" spacing="10.0" type="VBox" xmlns="http://javafx.com/javafx/11.0.1"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.preferences.AppearanceTabView">
<fx:define>
<ToggleGroup fx:id="theme"/>
</fx:define>
<Label styleClass="titleHeader" text="%Appearance"/>

<Label styleClass="sectionHeader" text="%Font"/>
<CheckBox fx:id="fontOverride" text="%Override default font settings"/>
<HBox spacing="4.0" alignment="CENTER_LEFT">
<Label text="%Size:" disable="${!fontOverride.selected}"/>
<TextField fx:id="fontSize" prefWidth="40" alignment="CENTER_RIGHT" disable="${!fontOverride.selected}"/>
<padding>
<Insets left="20.0"/>
</padding>
</HBox>
<CheckBox fx:id="fontTweaksLinux" text="%Tweak font rendering for entry editor on Linux"/>

<Label styleClass="sectionHeader" text="%Visual theme"/>
<RadioButton fx:id="themeLight" text="%Light theme" toggleGroup="$theme"/>
<RadioButton fx:id="themeDark" text="%Dark theme" toggleGroup="$theme"/>
</fx:root>
52 changes: 52 additions & 0 deletions src/main/java/org/jabref/gui/preferences/AppearanceTabView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.jabref.gui.preferences;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;

import org.jabref.gui.util.ControlHelper;
import org.jabref.gui.util.IconValidationDecorator;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

import com.airhacks.afterburner.views.ViewLoader;
import de.saxsys.mvvmfx.utils.validation.visualization.ControlsFxVisualizer;

public class AppearanceTabView extends AbstractPreferenceTabView<AppearanceTabViewModel> implements PreferencesTab {

@FXML public CheckBox fontOverride;
@FXML public TextField fontSize;
@FXML public CheckBox fontTweaksLinux;
@FXML public RadioButton themeLight;
@FXML public RadioButton themeDark;

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

public AppearanceTabView(JabRefPreferences preferences) {
this.preferences = preferences;

ViewLoader.view(this)
.root(this)
.load();
}

@Override
public String getTabName() { return Localization.lang("Appearance"); }

public void initialize () {
this.viewModel = new AppearanceTabViewModel(dialogService, preferences);

fontOverride.selectedProperty().bindBidirectional(viewModel.fontOverrideProperty());
fontSize.setTextFormatter(ControlHelper.getIntegerTextFormatter());
fontSize.textProperty().bindBidirectional(viewModel.fontSizeProperty());
fontTweaksLinux.selectedProperty().bindBidirectional(viewModel.fontTweaksLinuxProperty());

themeLight.selectedProperty().bindBidirectional(viewModel.themeLightProperty());
themeDark.selectedProperty().bindBidirectional(viewModel.themeDarkProperty());

validationVisualizer.setDecoration(new IconValidationDecorator());
Platform.runLater(() -> validationVisualizer.initVisualization(viewModel.fontSizeValidationStatus(), fontSize));
}
}
131 changes: 131 additions & 0 deletions src/main/java/org/jabref/gui/preferences/AppearanceTabViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package org.jabref.gui.preferences;

import java.util.ArrayList;
import java.util.List;

import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

import org.jabref.gui.DialogService;
import org.jabref.gui.util.ThemeLoader;
import org.jabref.logic.l10n.Localization;
import org.jabref.preferences.JabRefPreferences;

import de.saxsys.mvvmfx.utils.validation.FunctionBasedValidator;
import de.saxsys.mvvmfx.utils.validation.ValidationMessage;
import de.saxsys.mvvmfx.utils.validation.ValidationStatus;

public class AppearanceTabViewModel implements PreferenceTabViewModel {

private final BooleanProperty fontOverrideProperty = new SimpleBooleanProperty();
private final StringProperty fontSizeProperty = new SimpleStringProperty();
private final BooleanProperty fontTweaksLinuxProperty = new SimpleBooleanProperty();
private final BooleanProperty themeLightProperty = new SimpleBooleanProperty();
private final BooleanProperty themeDarkProperty = new SimpleBooleanProperty();

private final DialogService dialogService;
private final JabRefPreferences preferences;

private FunctionBasedValidator fontSizeValidator;

private List<String> restartWarnings = new ArrayList<>();

public AppearanceTabViewModel(DialogService dialogService, JabRefPreferences preferences) {
this.dialogService = dialogService;
this.preferences = preferences;

fontSizeValidator = new FunctionBasedValidator<>(
fontSizeProperty,
input -> {
try {
int fontSize = Integer.parseInt(fontSizeProperty().getValue());
return (fontSize > 8) && (fontSize < 22);
calixtus marked this conversation as resolved.
Show resolved Hide resolved
} catch (NumberFormatException ex) {
return false;
}
},
ValidationMessage.error(String.format("%s > %s %n %n %s",
Localization.lang("Appearance"),
Localization.lang("Font settings"),
Localization.lang("You must enter an integer value in the interval 8-22."))));
}

@Override
public void setValues() {
fontOverrideProperty.setValue(preferences.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONT_SIZE));
fontSizeProperty.setValue(String.valueOf(preferences.getInt(JabRefPreferences.MAIN_FONT_SIZE)));
fontTweaksLinuxProperty.setValue(preferences.getBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK));

switch (preferences.get(JabRefPreferences.FX_THEME)) {
case ThemeLoader.MAIN_CSS:
themeLightProperty.setValue(true);
themeDarkProperty.setValue(false);
break;
case ThemeLoader.DARK_CSS:
themeLightProperty.setValue(false);
themeDarkProperty.setValue(true);
break;
default:
// select nothing if theme is unknown
themeLightProperty.setValue(false);
calixtus marked this conversation as resolved.
Show resolved Hide resolved
themeDarkProperty.setValue(false);
}
}

@Override
public void storeSettings() {
if (preferences.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONT_SIZE) != fontOverrideProperty.getValue()) {
restartWarnings.add(Localization.lang("Override font settings"));
preferences.putBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONT_SIZE, fontOverrideProperty.getValue());
}

int newFontSize = Integer.parseInt(fontSizeProperty.getValue());
if (preferences.getInt(JabRefPreferences.MAIN_FONT_SIZE) != newFontSize) {
restartWarnings.add(Localization.lang("Override font size"));
preferences.putInt(JabRefPreferences.MAIN_FONT_SIZE, newFontSize);
}

if (preferences.getBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK) != fontTweaksLinuxProperty.getValue()) {
restartWarnings.add(Localization.lang("Font rendering tweak for Linux"));
preferences.putBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK, fontTweaksLinuxProperty.getValue());
}

if (themeLightProperty.getValue() && !preferences.get(JabRefPreferences.FX_THEME).equals(ThemeLoader.MAIN_CSS)) {
restartWarnings.add(Localization.lang("Theme changed:") + " " + ThemeLoader.MAIN_CSS);
preferences.put(JabRefPreferences.FX_THEME, ThemeLoader.MAIN_CSS);
} else if (themeDarkProperty.getValue() && !preferences.get(JabRefPreferences.FX_THEME).equals(ThemeLoader.DARK_CSS)) {
restartWarnings.add(Localization.lang("Theme changed:") + " " + ThemeLoader.DARK_CSS);
preferences.put(JabRefPreferences.FX_THEME, ThemeLoader.DARK_CSS);
}
}

public ValidationStatus fontSizeValidationStatus() { return fontSizeValidator.getValidationStatus(); }

@Override
public boolean validateSettings() {
if (fontOverrideProperty.getValue()) {
if (!fontSizeValidator.getValidationStatus().isValid()) {
fontSizeValidator.getValidationStatus().getHighestMessage().ifPresent(message ->
dialogService.showErrorDialogAndWait(message.getMessage()));
return false;
}
}
return true;
}

@Override
public List<String> getRestartWarnings() { return restartWarnings; }

public BooleanProperty fontOverrideProperty() { return fontOverrideProperty; }

public StringProperty fontSizeProperty() { return fontSizeProperty; }

public BooleanProperty fontTweaksLinuxProperty() { return fontTweaksLinuxProperty; }

public BooleanProperty themeLightProperty() { return themeLightProperty; }

public BooleanProperty themeDarkProperty() { return themeDarkProperty; }

}
Loading