-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fixes the issue "Non valid number as font size results in an uncaught exception." #7438
Changes from all commits
0c18acf
731d05a
30be0c1
3020502
79505ab
afe14c7
7000688
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
|
@@ -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 -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please don't use abbreviations as variable names. Here |
||
if (Pattern.matches("\\d*", c.getText())) { | ||
return c; | ||
} | ||
c.setText("0"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the comments in this thread. Returning null will produce an exception in the spinner |
||
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()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this might be handy also in other places, I would propose to extract this to a static method in the a helper class
gui.util.TextFormatter