Skip to content

Commit

Permalink
Fixes the issue "Non valid number as font size results in an uncaught…
Browse files Browse the repository at this point in the history
… exception." (#7438)

* Added a textformatter.

* Added a comment for the fontSizeFormatter.

* Added changes to change log.

* Removed newline.

* Checkstyle corrections.

* Checkstyle.

* Checkstyle.
  • Loading branch information
Landi29 authored Feb 15, 2021
1 parent f26e25b commit edcd711
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package org.jabref.gui.preferences.appearance;

import java.util.regex.Pattern;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.geometry.Pos;
import javafx.scene.control.CheckBox;
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;
Expand All @@ -27,6 +31,16 @@ public class AppearanceTab extends AbstractPreferenceTabView<AppearanceTabViewMo

private final ControlsFxVisualizer validationVisualizer = new ControlsFxVisualizer();

// The fontSizeFormatter formats the input given to the fontSize spinner so that non valid values cannot be entered.
private TextFormatter<Integer> fontSizeFormatter = new TextFormatter<Integer>(new IntegerStringConverter(), 9,
c -> {
if (Pattern.matches("\\d*", c.getText())) {
return c;
}
c.setText("0");
return c;
});

public AppearanceTab() {
ViewLoader.view(this)
.root(this)
Expand All @@ -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());
Expand Down

0 comments on commit edcd711

Please sign in to comment.