From edcd71156427b2b569e1c75fffef6067ef761e97 Mon Sep 17 00:00:00 2001 From: Landi29 Date: Mon, 15 Feb 2021 20:44:14 +0100 Subject: [PATCH] Fixes the issue "Non valid number as font size results in an uncaught exception." (#7438) * Added a textformatter. * Added a comment for the fontSizeFormatter. * Added changes to change log. * Removed newline. * Checkstyle corrections. * Checkstyle. * Checkstyle. --- CHANGELOG.md | 1 + .../gui/preferences/appearance/AppearanceTab.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b56b38b1be2..69586759a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed an issue where changing the font size makes the font size field too small. [#7085](https://github.com/JabRef/jabref/issues/7085) - We fixed an issue with TexGroups on Linux systems, where the modification of an aux-file did not trigger an auto-update for TexGroups. Furthermore, the detection of file modifications is now more reliable. [#7412](https://github.com/JabRef/jabref/pull/7412) - We fixed an issue where the Unicode to Latex formatter produced wrong results for characters with a codepoint higher than Character.MAX_VALUE. [#7387](https://github.com/JabRef/jabref/issues/7387) +- We fixed an issue where a non valid value as font size results in an uncaught exception. [#7415](https://github.com/JabRef/jabref/issues/7415) ### Removed diff --git a/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTab.java b/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTab.java index a731fbf24db..d26d2985ab6 100644 --- a/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTab.java +++ b/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTab.java @@ -1,5 +1,7 @@ package org.jabref.gui.preferences.appearance; +import java.util.regex.Pattern; + import javafx.application.Platform; import javafx.fxml.FXML; import javafx.geometry.Pos; @@ -7,6 +9,8 @@ import javafx.scene.control.RadioButton; import javafx.scene.control.Spinner; import javafx.scene.control.TextField; +import javafx.scene.control.TextFormatter; +import javafx.util.converter.IntegerStringConverter; import org.jabref.gui.preferences.AbstractPreferenceTabView; import org.jabref.gui.preferences.PreferencesTab; @@ -27,6 +31,16 @@ public class AppearanceTab extends AbstractPreferenceTabView fontSizeFormatter = new TextFormatter(new IntegerStringConverter(), 9, + c -> { + if (Pattern.matches("\\d*", c.getText())) { + return c; + } + c.setText("0"); + return c; + }); + public AppearanceTab() { ViewLoader.view(this) .root(this) @@ -48,6 +62,7 @@ public void initialize() { fontSize.getEditor().setAlignment(Pos.CENTER_RIGHT); fontSize.setValueFactory(AppearanceTabViewModel.fontSizeValueFactory); fontSize.getEditor().textProperty().bindBidirectional(viewModel.fontSizeProperty()); + fontSize.getEditor().setTextFormatter(fontSizeFormatter); themeLight.selectedProperty().bindBidirectional(viewModel.themeLightProperty()); themeDark.selectedProperty().bindBidirectional(viewModel.themeDarkProperty());