diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index ca566313ffe..59f4e10bb35 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -491,7 +491,7 @@ private Node createToolbar() { new HBox( factory.createIconButton(StandardActions.NEW_ARTICLE, new NewEntryAction(this, StandardEntryType.Article, dialogService, prefs, stateManager)), factory.createIconButton(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)), - factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)), + factory.createIconButton(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, prefs, stateManager)), factory.createIconButton(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager)) ), @@ -753,7 +753,7 @@ private MenuBar createMenu() { // @formatter:off library.getItems().addAll( factory.createMenuItem(StandardActions.NEW_ENTRY, new NewEntryAction(this, dialogService, prefs, stateManager)), - factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(stateManager)), + factory.createMenuItem(StandardActions.NEW_ENTRY_FROM_PLAIN_TEXT, new ExtractBibtexAction(dialogService, prefs, stateManager)), factory.createMenuItem(StandardActions.DELETE_ENTRY, new EditAction(StandardActions.DELETE_ENTRY, this, stateManager)), new SeparatorMenuItem(), diff --git a/src/main/java/org/jabref/gui/JabRefMain.java b/src/main/java/org/jabref/gui/JabRefMain.java index ca1074ead05..2468cb94819 100644 --- a/src/main/java/org/jabref/gui/JabRefMain.java +++ b/src/main/java/org/jabref/gui/JabRefMain.java @@ -124,7 +124,7 @@ private static void applyPreferences(PreferencesService preferences) { Globals.journalAbbreviationRepository = JournalAbbreviationLoader.loadRepository(preferences.getJournalAbbreviationPreferences()); // Build list of Import and Export formats - Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImportSettingsPreferences(), preferences.getImportFormatPreferences(), + Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImporterPreferences(), preferences.getImportFormatPreferences(), preferences.getXmpPreferences(), Globals.getFileUpdateMonitor()); Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX), preferences.getBibEntryTypes(BibDatabaseMode.BIBLATEX)); diff --git a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java index 1e45cc5d989..aee3adde536 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java @@ -62,7 +62,7 @@ public StringProperty inputTextProperty() { } public void startParsing() { - if (preferencesService.getImportSettingsPreferences().isGrobidEnabled()) { + if (preferencesService.getImporterPreferences().isGrobidEnabled()) { parseUsingGrobid(); } else { parseUsingBibtexExtractor(); @@ -76,7 +76,7 @@ private void parseUsingBibtexExtractor() { } private void parseUsingGrobid() { - GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getImportSettingsPreferences(), preferencesService.getImportFormatPreferences()); + GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences()); BackgroundTask.wrap(() -> grobidCitationFetcher.performSearch(inputTextProperty.getValue())) .onRunning(() -> dialogService.notify(Localization.lang("Your text is being parsed..."))) .onFailure((e) -> { diff --git a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java index 86a080f73ff..ce198561af4 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexAction.java @@ -4,6 +4,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.actions.SimpleCommand; import org.jabref.gui.importer.GrobidOptInDialogHelper; +import org.jabref.preferences.PreferencesService; import com.airhacks.afterburner.injection.Injector; @@ -11,14 +12,19 @@ public class ExtractBibtexAction extends SimpleCommand { - public ExtractBibtexAction(StateManager stateManager) { + PreferencesService preferencesService; + DialogService dialogService; + + public ExtractBibtexAction(DialogService dialogService, PreferencesService preferencesService, StateManager stateManager) { + this.preferencesService = preferencesService; + this.dialogService = dialogService; this.executable.bind(needsDatabase(stateManager)); } @Override public void execute() { DialogService dialogService = Injector.instantiateModelOrService(DialogService.class); - GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService); + GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences()); dialogService.showCustomDialogAndWait(new ExtractBibtexDialog()); } } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 51822fc2adb..a64fea8cc7d 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -359,7 +359,7 @@ private void setupToolBar() { // Add menu for fetching bibliographic information ContextMenu fetcherMenu = new ContextMenu(); SortedSet entryBasedFetchers = WebFetchers.getEntryBasedFetchers( - preferencesService.getImportSettingsPreferences(), + preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), databaseContext, @@ -369,10 +369,10 @@ private void setupToolBar() { if (fetcher instanceof PdfMergeMetadataImporter.EntryBasedFetcherWrapper) { // Handle Grobid Opt-In in case of the PdfMergeMetadataImporter fetcherMenuItem.setOnAction(event -> { - GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService); + GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences()); PdfMergeMetadataImporter.EntryBasedFetcherWrapper pdfMergeMetadataImporter = new PdfMergeMetadataImporter.EntryBasedFetcherWrapper( - preferencesService.getImportSettingsPreferences(), + preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences(), preferencesService.getFilePreferences(), databaseContext, @@ -395,8 +395,8 @@ private void fetchAndMerge(EntryBasedFetcher fetcher) { public void setFocusToField(Field field) { DefaultTaskExecutor.runInJavaFXThread(() -> { for (Tab tab : tabbed.getTabs()) { - if ((tab instanceof FieldsEditorTab) && ((FieldsEditorTab) tab).getShownFields().contains(field)) { - FieldsEditorTab fieldsEditorTab = (FieldsEditorTab) tab; + if ((tab instanceof FieldsEditorTab fieldsEditorTab) && fieldsEditorTab.getShownFields() + .contains(field)) { tabbed.getSelectionModel().select(tab); fieldsEditorTab.requestFocus(field); } diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 8cb13336e63..d42c9a3a02e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -58,7 +58,7 @@ public ImportHandler(BibDatabaseContext database, this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database); this.contentImporter = new ExternalFilesContentImporter( - preferencesService.getImportSettingsPreferences(), + preferencesService.getImporterPreferences(), preferencesService.getImportFormatPreferences()); this.undoManager = undoManager; } @@ -161,7 +161,7 @@ public void importEntries(List entries) { preferencesService.getTimestampPreferences()); // Generate citation keys - if (preferencesService.getImportSettingsPreferences().generateNewKeyOnImport()) { + if (preferencesService.getImporterPreferences().isGenerateNewKeyOnImport()) { generateKeys(entries); } @@ -171,8 +171,7 @@ public void importEntries(List entries) { private void addToGroups(List entries, Collection groups) { for (GroupTreeNode node : groups) { - if (node.getGroup() instanceof GroupEntryChanger) { - GroupEntryChanger entryChanger = (GroupEntryChanger) node.getGroup(); + if (node.getGroup() instanceof GroupEntryChanger entryChanger) { List undo = entryChanger.add(entries); // TODO: Add undo // if (!undo.isEmpty()) { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java index 8e275a61921..af72d5c6482 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java @@ -552,7 +552,9 @@ public void parsePdfMetadataAndShowMergeDialog() { dialog.addSource(Localization.lang("Entry"), entry); dialog.addSource(Localization.lang("Verbatim"), wrapImporterToSupplier(new PdfVerbatimBibTextImporter(preferences.getImportFormatPreferences()), filePath)); dialog.addSource(Localization.lang("Embedded"), wrapImporterToSupplier(new PdfEmbeddedBibFileImporter(preferences.getImportFormatPreferences()), filePath)); - dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImportSettingsPreferences(), preferences.getImportFormatPreferences()), filePath)); + if (preferences.getImporterPreferences().isGrobidEnabled()) { + dialog.addSource("Grobid", wrapImporterToSupplier(new PdfGrobidImporter(preferences.getImporterPreferences(), preferences.getImportFormatPreferences()), filePath)); + } dialog.addSource(Localization.lang("XMP metadata"), wrapImporterToSupplier(new PdfXmpImporter(preferences.getXmpPreferences()), filePath)); dialog.addSource(Localization.lang("Content"), wrapImporterToSupplier(new PdfContentImporter(preferences.getImportFormatPreferences()), filePath)); dialog.showAndWait().ifPresent(newEntry -> { diff --git a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java index 138e4ecec13..a13eeb6a310 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java +++ b/src/main/java/org/jabref/gui/fieldeditors/LinkedFilesEditor.java @@ -185,7 +185,7 @@ private Node createFileDisplay(LinkedFileViewModel linkedFile) { parsePdfMetadata.setTooltip(new Tooltip(Localization.lang("Parse Metadata from PDF."))); parsePdfMetadata.visibleProperty().bind(linkedFile.isOfflinePdfProperty()); parsePdfMetadata.setOnAction(event -> { - GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService); + GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(dialogService, preferencesService.getImporterPreferences()); linkedFile.parsePdfMetadataAndShowMergeDialog(); }); parsePdfMetadata.getStyleClass().setAll("icon-button"); diff --git a/src/main/java/org/jabref/gui/importer/GrobidOptInDialogHelper.java b/src/main/java/org/jabref/gui/importer/GrobidOptInDialogHelper.java index 84ad1db02cf..4809acfc5a2 100644 --- a/src/main/java/org/jabref/gui/importer/GrobidOptInDialogHelper.java +++ b/src/main/java/org/jabref/gui/importer/GrobidOptInDialogHelper.java @@ -1,9 +1,8 @@ package org.jabref.gui.importer; import org.jabref.gui.DialogService; -import org.jabref.gui.Globals; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.l10n.Localization; -import org.jabref.preferences.PreferencesService; /** * Metadata extraction from PDFs and plaintext works very well using Grobid, but we do not want to enable it by default @@ -18,21 +17,19 @@ public class GrobidOptInDialogHelper { * @param dialogService the DialogService to use * @return if the user enabled Grobid, either in the past or after being asked by the dialog. */ - public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService) { - PreferencesService preferences = Globals.prefs; - if (preferences.getImportSettingsPreferences().isGrobidEnabled()) { + public static boolean showAndWaitIfUserIsUndecided(DialogService dialogService, ImporterPreferences preferences) { + if (preferences.isGrobidEnabled()) { return true; } - if (preferences.getImportSettingsPreferences().isGrobidOptOut()) { + if (preferences.isGrobidOptOut()) { return false; } boolean grobidEnabled = dialogService.showConfirmationDialogWithOptOutAndWait( Localization.lang("Remote services"), Localization.lang("Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results."), Localization.lang("Do not ask again"), - (optOut) -> preferences.storeImportSettingsPreferences(preferences.getImportSettingsPreferences().withGrobidOptOut(optOut)) - ); - preferences.storeImportSettingsPreferences(preferences.getImportSettingsPreferences().withGrobidEnabled(grobidEnabled)); + (optOut) -> preferences.grobidOptOutProperty().setValue(optOut)); + preferences.grobidEnabledProperty().setValue(grobidEnabled); return grobidEnabled; } } diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index e67b9ed94b0..9d91d07839d 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -117,8 +117,8 @@ private List doImport(List files) if (importer.isEmpty()) { // Unknown format: DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> { - if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService())) { - Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImportSettingsPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); + if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) { + Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); } frame.getDialogService().notify(Localization.lang("Importing in unknown format") + "..."); }); @@ -126,8 +126,8 @@ private List doImport(List files) imports.add(Globals.IMPORT_FORMAT_READER.importUnknownFormat(filename, Globals.getFileUpdateMonitor())); } else { DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> { - if (importer.get() instanceof PdfGrobidImporter || importer.get() instanceof PdfMergeMetadataImporter && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService())) { - Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImportSettingsPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); + if (importer.get() instanceof PdfGrobidImporter || importer.get() instanceof PdfMergeMetadataImporter && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) { + Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); } frame.getDialogService().notify(Localization.lang("Importing in %0 format", importer.get().getName()) + "..."); }); diff --git a/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTabViewModel.java b/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTabViewModel.java index e67f7cc0c20..bf57b813a4f 100644 --- a/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/appearance/AppearanceTabViewModel.java @@ -41,7 +41,7 @@ public class AppearanceTabViewModel implements PreferenceTabViewModel { private final DialogService dialogService; private final PreferencesService preferences; - private final AppearancePreferences initialAppearancePreferences; + private final AppearancePreferences appearancePreferences; private final Validator fontSizeValidator; private final Validator customPathToThemeValidator; @@ -51,7 +51,7 @@ public class AppearanceTabViewModel implements PreferenceTabViewModel { public AppearanceTabViewModel(DialogService dialogService, PreferencesService preferences) { this.dialogService = dialogService; this.preferences = preferences; - this.initialAppearancePreferences = preferences.getAppearancePreferences(); + this.appearancePreferences = preferences.getAppearancePreferences(); fontSizeValidator = new FunctionBasedValidator<>( fontSizeProperty, @@ -78,10 +78,10 @@ public AppearanceTabViewModel(DialogService dialogService, PreferencesService pr @Override public void setValues() { - fontOverrideProperty.setValue(initialAppearancePreferences.shouldOverrideDefaultFontSize()); - fontSizeProperty.setValue(String.valueOf(initialAppearancePreferences.getMainFontSize())); + fontOverrideProperty.setValue(appearancePreferences.shouldOverrideDefaultFontSize()); + fontSizeProperty.setValue(String.valueOf(appearancePreferences.getMainFontSize())); - Theme currentTheme = initialAppearancePreferences.getTheme(); + Theme currentTheme = appearancePreferences.getTheme(); if (currentTheme.getType() == Theme.Type.LIGHT) { themeLightProperty.setValue(true); themeDarkProperty.setValue(false); @@ -100,35 +100,34 @@ public void setValues() { @Override public void storeSettings() { - if (initialAppearancePreferences.shouldOverrideDefaultFontSize() != fontOverrideProperty.getValue()) { + if (appearancePreferences.shouldOverrideDefaultFontSize() != fontOverrideProperty.getValue()) { restartWarnings.add(Localization.lang("Override font settings")); } int newFontSize = Integer.parseInt(fontSizeProperty.getValue()); - if (initialAppearancePreferences.getMainFontSize() != newFontSize) { + if (appearancePreferences.getMainFontSize() != newFontSize) { restartWarnings.add(Localization.lang("Override font size")); } - Theme newTheme = initialAppearancePreferences.getTheme(); - if (themeLightProperty.getValue() && initialAppearancePreferences.getTheme().getType() != Theme.Type.LIGHT) { + Theme newTheme = appearancePreferences.getTheme(); + if (themeLightProperty.getValue() && appearancePreferences.getTheme().getType() != Theme.Type.LIGHT) { restartWarnings.add(Localization.lang("Theme changed to light theme.")); newTheme = new Theme("", preferences); - } else if (themeDarkProperty.getValue() && initialAppearancePreferences.getTheme().getType() != Theme.Type.DARK) { + } else if (themeDarkProperty.getValue() && appearancePreferences.getTheme().getType() != Theme.Type.DARK) { restartWarnings.add(Localization.lang("Theme changed to dark theme.")); newTheme = new Theme(EMBEDDED_DARK_THEME_CSS, preferences); } else if (themeCustomProperty.getValue() && - (!initialAppearancePreferences.getTheme().getCssPathString() - .equalsIgnoreCase(customPathToThemeProperty.getValue()) - || initialAppearancePreferences.getTheme().getType() != Theme.Type.CUSTOM)) { + (!appearancePreferences.getTheme().getCssPathString() + .equalsIgnoreCase(customPathToThemeProperty.getValue()) + || appearancePreferences.getTheme().getType() != Theme.Type.CUSTOM)) { restartWarnings.add(Localization.lang("Theme changed to a custom theme:") + " " + customPathToThemeProperty().getValue()); newTheme = new Theme(customPathToThemeProperty.getValue(), preferences); } - preferences.storeAppearancePreference(new AppearancePreferences( - fontOverrideProperty.getValue(), - newFontSize, - newTheme)); + appearancePreferences.setShouldOverrideDefaultFontSize(fontOverrideProperty.getValue()); + appearancePreferences.setMainFontSize(newFontSize); + appearancePreferences.setTheme(newTheme); preferences.updateTheme(); } diff --git a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java index a0cb014e5d3..f6a1b3a5c0c 100644 --- a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java @@ -54,7 +54,7 @@ public void storeSettings() { .map(ImporterViewModel::getLogic) .collect(Collectors.toSet())); Globals.IMPORT_FORMAT_READER.resetImportFormats( - preferences.getImportSettingsPreferences(), + preferences.getImporterPreferences(), preferences.getImportFormatPreferences(), preferences.getXmpPreferences(), Globals.getFileUpdateMonitor()); diff --git a/src/main/java/org/jabref/gui/preferences/importexport/ImportExportTabViewModel.java b/src/main/java/org/jabref/gui/preferences/importexport/ImportExportTabViewModel.java index 2fe9eaf4913..94d3a082c37 100644 --- a/src/main/java/org/jabref/gui/preferences/importexport/ImportExportTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/importexport/ImportExportTabViewModel.java @@ -15,7 +15,7 @@ import org.jabref.gui.commonfxcontrols.SortCriterionViewModel; import org.jabref.gui.preferences.PreferenceTabViewModel; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.preferences.DOIPreferences; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.FieldFactory; @@ -41,19 +41,19 @@ public class ImportExportTabViewModel implements PreferenceTabViewModel { private final PreferencesService preferencesService; private final DOIPreferences initialDOIPreferences; - private final ImportSettingsPreferences initialImportSettingsPreferences; + private final ImporterPreferences importerPreferences; private final SaveOrderConfig initialExportOrder; public ImportExportTabViewModel(PreferencesService preferencesService) { this.preferencesService = preferencesService; - this.initialImportSettingsPreferences = preferencesService.getImportSettingsPreferences(); + this.importerPreferences = preferencesService.getImporterPreferences(); this.initialDOIPreferences = preferencesService.getDOIPreferences(); this.initialExportOrder = preferencesService.getExportSaveOrder(); } @Override public void setValues() { - generateKeyOnImportProperty.setValue(initialImportSettingsPreferences.generateNewKeyOnImport()); + generateKeyOnImportProperty.setValue(importerPreferences.isGenerateNewKeyOnImport()); useCustomDOIProperty.setValue(initialDOIPreferences.isUseCustom()); useCustomDOINameProperty.setValue(initialDOIPreferences.getDefaultBaseURI()); @@ -71,14 +71,16 @@ public void setValues() { .map(SortCriterionViewModel::new) .collect(Collectors.toList())); - grobidEnabledProperty.setValue(initialImportSettingsPreferences.isGrobidEnabled()); - grobidURLProperty.setValue(initialImportSettingsPreferences.getGrobidURL()); + grobidEnabledProperty.setValue(importerPreferences.isGrobidEnabled()); + grobidURLProperty.setValue(importerPreferences.getGrobidURL()); } @Override public void storeSettings() { - preferencesService.storeImportSettingsPreferences(new ImportSettingsPreferences( - generateKeyOnImportProperty.getValue(), grobidEnabledProperty.getValue(), preferencesService.getImportSettingsPreferences().isGrobidOptOut(), grobidURLProperty.getValue())); + importerPreferences.setGenerateNewKeyOnImport(generateKeyOnImportProperty.getValue()); + importerPreferences.setGrobidEnabled(grobidEnabledProperty.getValue()); + importerPreferences.setGrobidOptOut(importerPreferences.isGrobidOptOut()); + importerPreferences.setGrobidURL(grobidURLProperty.getValue()); preferencesService.storeDOIPreferences(new DOIPreferences( useCustomDOIProperty.getValue(), diff --git a/src/main/java/org/jabref/logic/externalfiles/ExternalFilesContentImporter.java b/src/main/java/org/jabref/logic/externalfiles/ExternalFilesContentImporter.java index e2c21050c34..7c0265bc8a6 100644 --- a/src/main/java/org/jabref/logic/externalfiles/ExternalFilesContentImporter.java +++ b/src/main/java/org/jabref/logic/externalfiles/ExternalFilesContentImporter.java @@ -5,25 +5,25 @@ import java.nio.file.Path; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.OpenDatabase; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.model.util.FileUpdateMonitor; public class ExternalFilesContentImporter { - private final ImportSettingsPreferences importSettingsPreferences; + private final ImporterPreferences importerPreferences; private final ImportFormatPreferences importFormatPreferences; - public ExternalFilesContentImporter(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences) { - this.importSettingsPreferences = importSettingsPreferences; + public ExternalFilesContentImporter(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences) { + this.importerPreferences = importerPreferences; this.importFormatPreferences = importFormatPreferences; } public ParserResult importPDFContent(Path file) { try { - return new PdfMergeMetadataImporter(importSettingsPreferences, importFormatPreferences).importDatabase(file, StandardCharsets.UTF_8); + return new PdfMergeMetadataImporter(importerPreferences, importFormatPreferences).importDatabase(file, StandardCharsets.UTF_8); } catch (IOException e) { return ParserResult.fromError(e); } diff --git a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java index 92ce2a7848b..57ed4b8c039 100644 --- a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java +++ b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java @@ -31,7 +31,6 @@ import org.jabref.logic.importer.fileformat.RepecNepImporter; import org.jabref.logic.importer.fileformat.RisImporter; import org.jabref.logic.importer.fileformat.SilverPlatterImporter; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.l10n.Localization; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.database.BibDatabases; @@ -51,7 +50,7 @@ public class ImportFormatReader { private ImportFormatPreferences importFormatPreferences; - public void resetImportFormats(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences newImportFormatPreferences, XmpPreferences xmpPreferences, FileUpdateMonitor fileMonitor) { + public void resetImportFormats(ImporterPreferences importerPreferences, ImportFormatPreferences newImportFormatPreferences, XmpPreferences xmpPreferences, FileUpdateMonitor fileMonitor) { this.importFormatPreferences = newImportFormatPreferences; formats.clear(); @@ -67,12 +66,12 @@ public void resetImportFormats(ImportSettingsPreferences importSettingsPreferenc formats.add(new ModsImporter(importFormatPreferences)); formats.add(new MsBibImporter()); formats.add(new OvidImporter()); - formats.add(new PdfMergeMetadataImporter(importSettingsPreferences, importFormatPreferences)); + formats.add(new PdfMergeMetadataImporter(importerPreferences, importFormatPreferences)); formats.add(new PdfVerbatimBibTextImporter(importFormatPreferences)); formats.add(new PdfContentImporter(importFormatPreferences)); formats.add(new PdfEmbeddedBibFileImporter(importFormatPreferences)); - if (importSettingsPreferences.isGrobidEnabled()) { - formats.add(new PdfGrobidImporter(importSettingsPreferences, importFormatPreferences)); + if (importerPreferences.isGrobidEnabled()) { + formats.add(new PdfGrobidImporter(importerPreferences, importFormatPreferences)); } formats.add(new PdfXmpImporter(xmpPreferences)); formats.add(new RepecNepImporter(importFormatPreferences)); @@ -106,7 +105,7 @@ private Optional getByCliId(String cliId) { public ParserResult importFromFile(String format, Path file) throws ImportException { Optional importer = getByCliId(format); - if (!importer.isPresent()) { + if (importer.isEmpty()) { throw new ImportException(Localization.lang("Unknown import format") + ": " + format); } diff --git a/src/main/java/org/jabref/logic/importer/ImporterPreferences.java b/src/main/java/org/jabref/logic/importer/ImporterPreferences.java new file mode 100644 index 00000000000..d2da57015f6 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/ImporterPreferences.java @@ -0,0 +1,69 @@ +package org.jabref.logic.importer; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class ImporterPreferences { + + private final BooleanProperty generateNewKeyOnImport; + private final BooleanProperty grobidEnabled; + private final BooleanProperty grobidOptOut; + private final StringProperty grobidURL; + + public ImporterPreferences(boolean generateNewKeyOnImport, boolean grobidEnabled, boolean grobidOptOut, String grobidURL) { + this.generateNewKeyOnImport = new SimpleBooleanProperty(generateNewKeyOnImport); + this.grobidEnabled = new SimpleBooleanProperty(grobidEnabled); + this.grobidOptOut = new SimpleBooleanProperty(grobidOptOut); + this.grobidURL = new SimpleStringProperty(grobidURL); + } + + public boolean isGenerateNewKeyOnImport() { + return generateNewKeyOnImport.get(); + } + + public BooleanProperty generateNewKeyOnImportProperty() { + return generateNewKeyOnImport; + } + + public boolean isGrobidEnabled() { + return grobidEnabled.get(); + } + + public BooleanProperty grobidEnabledProperty() { + return grobidEnabled; + } + + public boolean isGrobidOptOut() { + return grobidOptOut.get(); + } + + public BooleanProperty grobidOptOutProperty() { + return grobidOptOut; + } + + public String getGrobidURL() { + return grobidURL.get(); + } + + public StringProperty grobidURLProperty() { + return grobidURL; + } + + public void setGenerateNewKeyOnImport(boolean generateNewKeyOnImport) { + this.generateNewKeyOnImport.set(generateNewKeyOnImport); + } + + public void setGrobidEnabled(boolean grobidEnabled) { + this.grobidEnabled.set(grobidEnabled); + } + + public void setGrobidOptOut(boolean grobidOptOut) { + this.grobidOptOut.set(grobidOptOut); + } + + public void setGrobidURL(String grobidURL) { + this.grobidURL.set(grobidURL); + } +} diff --git a/src/main/java/org/jabref/logic/importer/WebFetchers.java b/src/main/java/org/jabref/logic/importer/WebFetchers.java index 617393abd35..7ad07379070 100644 --- a/src/main/java/org/jabref/logic/importer/WebFetchers.java +++ b/src/main/java/org/jabref/logic/importer/WebFetchers.java @@ -39,7 +39,6 @@ import org.jabref.logic.importer.fetcher.TitleFetcher; import org.jabref.logic.importer.fetcher.ZbMATH; import org.jabref.logic.importer.fileformat.PdfMergeMetadataImporter; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; @@ -138,7 +137,7 @@ public static SortedSet getIdBasedFetchers(ImportFormatPreferenc /** * @return sorted set containing entry based fetchers */ - public static SortedSet getEntryBasedFetchers(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences, FilePreferences filePreferences, BibDatabaseContext databaseContext, Charset defaultEncoding) { + public static SortedSet getEntryBasedFetchers(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences, FilePreferences filePreferences, BibDatabaseContext databaseContext, Charset defaultEncoding) { SortedSet set = new TreeSet<>(Comparator.comparing(WebFetcher::getName)); set.add(new AstrophysicsDataSystem(importFormatPreferences)); set.add(new DoiFetcher(importFormatPreferences)); @@ -146,7 +145,7 @@ public static SortedSet getEntryBasedFetchers(ImportSettingsP set.add(new MathSciNet(importFormatPreferences)); set.add(new CrossRef()); set.add(new ZbMATH(importFormatPreferences)); - set.add(new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(importSettingsPreferences, importFormatPreferences, filePreferences, databaseContext, defaultEncoding)); + set.add(new PdfMergeMetadataImporter.EntryBasedFetcherWrapper(importerPreferences, importFormatPreferences, filePreferences, databaseContext, defaultEncoding)); return set; } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java index 7f6ff838cdf..4dccde35980 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcher.java @@ -10,9 +10,9 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.SearchBasedFetcher; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.importer.util.GrobidService; import org.jabref.model.entry.BibEntry; @@ -27,8 +27,8 @@ public class GrobidCitationFetcher implements SearchBasedFetcher { private ImportFormatPreferences importFormatPreferences; private GrobidService grobidService; - public GrobidCitationFetcher(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences) { - this(importFormatPreferences, new GrobidService(importSettingsPreferences)); + public GrobidCitationFetcher(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences) { + this(importFormatPreferences, new GrobidService(importerPreferences)); } GrobidCitationFetcher(ImportFormatPreferences importFormatPreferences, GrobidService grobidService) { diff --git a/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java index 37b848aa823..6b680640d1a 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/PdfGrobidImporter.java @@ -10,8 +10,8 @@ import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Importer; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.ParserResult; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.importer.util.GrobidService; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; @@ -26,8 +26,8 @@ public class PdfGrobidImporter extends Importer { private final GrobidService grobidService; private final ImportFormatPreferences importFormatPreferences; - public PdfGrobidImporter(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences) { - this.grobidService = new GrobidService(importSettingsPreferences); + public PdfGrobidImporter(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences) { + this.grobidService = new GrobidService(importerPreferences); this.importFormatPreferences = importFormatPreferences; } diff --git a/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java index fa3e79e5b06..9d8e62cd08a 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporter.java @@ -16,10 +16,10 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.logic.importer.Importer; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.importer.fetcher.IsbnFetcher; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.importer.util.FileFieldParser; import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; @@ -42,13 +42,13 @@ public class PdfMergeMetadataImporter extends Importer { private final List metadataImporters; private final ImportFormatPreferences importFormatPreferences; - public PdfMergeMetadataImporter(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences) { + public PdfMergeMetadataImporter(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences) { this.importFormatPreferences = importFormatPreferences; this.metadataImporters = new ArrayList<>(); this.metadataImporters.add(new PdfVerbatimBibTextImporter(importFormatPreferences)); this.metadataImporters.add(new PdfEmbeddedBibFileImporter(importFormatPreferences)); - if (importSettingsPreferences.isGrobidEnabled()) { - this.metadataImporters.add(new PdfGrobidImporter(importSettingsPreferences, importFormatPreferences)); + if (importerPreferences.isGrobidEnabled()) { + this.metadataImporters.add(new PdfGrobidImporter(importerPreferences, importFormatPreferences)); } this.metadataImporters.add(new PdfXmpImporter(importFormatPreferences.getXmpPreferences())); this.metadataImporters.add(new PdfContentImporter(importFormatPreferences)); @@ -91,14 +91,14 @@ public ParserResult importDatabase(Path filePath, Charset defaultEncoding) throw for (BibEntry candidate : candidates) { if (candidate.hasField(StandardField.DOI)) { try { - new DoiFetcher(importFormatPreferences).performSearchById(candidate.getField(StandardField.DOI).get()).ifPresent((fromDoi) -> fetchedCandidates.add(fromDoi)); + new DoiFetcher(importFormatPreferences).performSearchById(candidate.getField(StandardField.DOI).get()).ifPresent(fetchedCandidates::add); } catch (FetcherException e) { LOGGER.error("Fetching failed for DOI \"{}\".", candidate.getField(StandardField.DOI).get(), e); } } if (candidate.hasField(StandardField.ISBN)) { try { - new IsbnFetcher(importFormatPreferences).performSearchById(candidate.getField(StandardField.ISBN).get()).ifPresent((fromISBN) -> fetchedCandidates.add(fromISBN)); + new IsbnFetcher(importFormatPreferences).performSearchById(candidate.getField(StandardField.ISBN).get()).ifPresent(fetchedCandidates::add); } catch (FetcherException e) { LOGGER.error("Fetching failed for ISBN \"{}\".", candidate.getField(StandardField.ISBN).get(), e); } @@ -115,7 +115,7 @@ public ParserResult importDatabase(Path filePath, Charset defaultEncoding) throw // Don't merge FILE fields that point to a stored file as we set that to filePath anyway. // Nevertheless, retain online links. if (StandardField.FILE.equals(fieldEntry.getKey()) && - !FileFieldParser.parse(fieldEntry.getValue()).stream().anyMatch((linkedFile) -> linkedFile.isOnlineLink())) { + FileFieldParser.parse(fieldEntry.getValue()).stream().noneMatch(LinkedFile::isOnlineLink)) { continue; } // Only overwrite non-present fields @@ -151,8 +151,8 @@ public static class EntryBasedFetcherWrapper extends PdfMergeMetadataImporter im private final BibDatabaseContext databaseContext; private final Charset defaultEncoding; - public EntryBasedFetcherWrapper(ImportSettingsPreferences importSettingsPreferences, ImportFormatPreferences importFormatPreferences, FilePreferences filePreferences, BibDatabaseContext context, Charset defaultEncoding) { - super(importSettingsPreferences, importFormatPreferences); + public EntryBasedFetcherWrapper(ImporterPreferences importerPreferences, ImportFormatPreferences importFormatPreferences, FilePreferences filePreferences, BibDatabaseContext context, Charset defaultEncoding) { + super(importerPreferences, importFormatPreferences); this.filePreferences = filePreferences; this.databaseContext = context; this.defaultEncoding = defaultEncoding; diff --git a/src/main/java/org/jabref/logic/importer/importsettings/ImportSettingsPreferences.java b/src/main/java/org/jabref/logic/importer/importsettings/ImportSettingsPreferences.java deleted file mode 100644 index 535e5efb514..00000000000 --- a/src/main/java/org/jabref/logic/importer/importsettings/ImportSettingsPreferences.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.jabref.logic.importer.importsettings; - -public class ImportSettingsPreferences { - - private final boolean shouldGenerateNewKeyOnImport; - private final boolean grobidEnabled; - private final boolean grobidOptOut; - private final String grobidURL; - - public ImportSettingsPreferences(boolean shouldGenerateNewKeyOnImport, boolean grobidEnabled, boolean grobidOptOut, String grobidURL) { - this.shouldGenerateNewKeyOnImport = shouldGenerateNewKeyOnImport; - this.grobidEnabled = grobidEnabled; - this.grobidOptOut = grobidOptOut; - this.grobidURL = grobidURL; - } - - public boolean generateNewKeyOnImport() { - return shouldGenerateNewKeyOnImport; - } - - public boolean isGrobidEnabled() { - return grobidEnabled; - } - - public boolean isGrobidOptOut() { - return grobidOptOut; - } - - public String getGrobidURL() { - return grobidURL; - } - - public ImportSettingsPreferences withGrobidEnabled(boolean grobidEnabled) { - return new ImportSettingsPreferences(shouldGenerateNewKeyOnImport, grobidEnabled, grobidOptOut, grobidURL); - } - - public ImportSettingsPreferences withGrobidOptOut(boolean grobidOptOut) { - return new ImportSettingsPreferences(shouldGenerateNewKeyOnImport, grobidEnabled, grobidOptOut, grobidURL); - } -} diff --git a/src/main/java/org/jabref/logic/importer/util/GrobidService.java b/src/main/java/org/jabref/logic/importer/util/GrobidService.java index f381c54a8a0..fb465bad592 100644 --- a/src/main/java/org/jabref/logic/importer/util/GrobidService.java +++ b/src/main/java/org/jabref/logic/importer/util/GrobidService.java @@ -7,9 +7,9 @@ import java.util.Optional; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.fileformat.BibtexParser; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.util.DummyFileUpdateMonitor; @@ -41,11 +41,11 @@ public int getCode() { } } - private final ImportSettingsPreferences importSettingsPreferences; + private final ImporterPreferences importerPreferences; - public GrobidService(ImportSettingsPreferences importSettingsPreferences) { - this.importSettingsPreferences = importSettingsPreferences; - if (!importSettingsPreferences.isGrobidEnabled()) { + public GrobidService(ImporterPreferences importerPreferences) { + this.importerPreferences = importerPreferences; + if (!importerPreferences.isGrobidEnabled()) { throw new UnsupportedOperationException("Grobid was used but not enabled."); } } @@ -57,7 +57,7 @@ public GrobidService(ImportSettingsPreferences importSettingsPreferences) { * @throws IOException if an I/O excecption during the call ocurred or no BibTeX entry could be determiend */ public Optional processCitation(String rawCitation, ImportFormatPreferences importFormatPreferences, ConsolidateCitations consolidateCitations) throws IOException, ParseException { - Connection.Response response = Jsoup.connect(importSettingsPreferences.getGrobidURL() + "/api/processCitation") + Connection.Response response = Jsoup.connect(importerPreferences.getGrobidURL() + "/api/processCitation") .header("Accept", MediaTypes.APPLICATION_BIBTEX) .data("citations", rawCitation) .data("consolidateCitations", String.valueOf(consolidateCitations.getCode())) @@ -75,7 +75,7 @@ public Optional processCitation(String rawCitation, ImportFormatPrefer } public List processPDF(Path filePath, ImportFormatPreferences importFormatPreferences) throws IOException, ParseException { - Connection.Response response = Jsoup.connect(importSettingsPreferences.getGrobidURL() + "/api/processHeaderDocument") + Connection.Response response = Jsoup.connect(importerPreferences.getGrobidURL() + "/api/processHeaderDocument") .header("Accept", MediaTypes.APPLICATION_BIBTEX) .data("input", filePath.toString(), Files.newInputStream(filePath)) .method(Connection.Method.POST) @@ -91,7 +91,7 @@ public List processPDF(Path filePath, ImportFormatPreferences importFo BibtexParser parser = new BibtexParser(importFormatPreferences, new DummyFileUpdateMonitor()); List result = parser.parseEntries(httpResponse); - result.stream().forEach((entry) -> entry.setCitationKey("")); + result.forEach((entry) -> entry.setCitationKey("")); return result; } } diff --git a/src/main/java/org/jabref/preferences/AppearancePreferences.java b/src/main/java/org/jabref/preferences/AppearancePreferences.java index 09b399536c6..c0becda5194 100644 --- a/src/main/java/org/jabref/preferences/AppearancePreferences.java +++ b/src/main/java/org/jabref/preferences/AppearancePreferences.java @@ -1,27 +1,58 @@ package org.jabref.preferences; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; + import org.jabref.gui.util.Theme; public class AppearancePreferences { - private final boolean shouldOverrideDefaultFontSize; - private final int mainFontSize; - private final Theme theme; + private final BooleanProperty shouldOverrideDefaultFontSize; + private final IntegerProperty mainFontSize; + private final ObjectProperty theme; public AppearancePreferences(boolean shouldOverrideDefaultFontSize, int mainFontSize, Theme theme) { - this.shouldOverrideDefaultFontSize = shouldOverrideDefaultFontSize; - this.mainFontSize = mainFontSize; - this.theme = theme; + this.shouldOverrideDefaultFontSize = new SimpleBooleanProperty(shouldOverrideDefaultFontSize); + this.mainFontSize = new SimpleIntegerProperty(mainFontSize); + this.theme = new SimpleObjectProperty<>(theme); } public boolean shouldOverrideDefaultFontSize() { + return shouldOverrideDefaultFontSize.get(); + } + + public void setShouldOverrideDefaultFontSize(boolean newValue) { + shouldOverrideDefaultFontSize.set(newValue); + } + + public BooleanProperty shouldOverrideDefaultFontSizeProperty() { return shouldOverrideDefaultFontSize; } public int getMainFontSize() { + return mainFontSize.get(); + } + + public void setMainFontSize(int mainFontSize) { + this.mainFontSize.set(mainFontSize); + } + + public IntegerProperty mainFontSizeProperty() { return mainFontSize; } public Theme getTheme() { + return theme.get(); + } + + public void setTheme(Theme theme) { + this.theme.set(theme); + } + + public ObjectProperty themeProperty() { return theme; } } diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index f3773c5526d..602f237630d 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -68,9 +68,9 @@ import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.importer.fileformat.CustomImporter; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Language; @@ -108,6 +108,7 @@ import org.jabref.model.push.PushToApplicationConstants; import org.jabref.model.strings.StringUtil; +import com.tobiasdiez.easybind.EasyBind; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -414,6 +415,8 @@ public class JabRefPreferences implements PreferencesService { private Theme globalTheme; private Set customImporters; private String userName; + private AppearancePreferences appearancePreferences; + private ImporterPreferences importerPreferences; // The constructor is made private to enforce this as a singleton class: private JabRefPreferences() { @@ -1991,17 +1994,21 @@ public void updateTheme() { @Override public AppearancePreferences getAppearancePreferences() { - return new AppearancePreferences( + if (appearancePreferences != null) { + return appearancePreferences; + } + + appearancePreferences = new AppearancePreferences( getBoolean(OVERRIDE_DEFAULT_FONT_SIZE), getInt(MAIN_FONT_SIZE), - getTheme()); - } + getTheme() + ); - @Override - public void storeAppearancePreference(AppearancePreferences preferences) { - putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, preferences.shouldOverrideDefaultFontSize()); - putInt(MAIN_FONT_SIZE, preferences.getMainFontSize()); - put(FX_THEME, preferences.getTheme().getCssPathString()); + EasyBind.subscribe(appearancePreferences.shouldOverrideDefaultFontSizeProperty(), newValue -> putBoolean(OVERRIDE_DEFAULT_FONT_SIZE, newValue)); + EasyBind.subscribe(appearancePreferences.mainFontSizeProperty(), newValue -> putInt(MAIN_FONT_SIZE, newValue)); + EasyBind.subscribe(appearancePreferences.themeProperty(), newValue -> put(FX_THEME, newValue.getCssPathString())); + + return appearancePreferences; } //************************************************************************************************************* @@ -2716,24 +2723,23 @@ public void storeProtectedTermsPreferences(ProtectedTermsPreferences preferences } //************************************************************************************************************* - // Import preferences + // Importer preferences //************************************************************************************************************* @Override - public void storeImportSettingsPreferences(ImportSettingsPreferences preferences) { - putBoolean(GENERATE_KEY_ON_IMPORT, preferences.generateNewKeyOnImport()); - putBoolean(GROBID_ENABLED, preferences.isGrobidEnabled()); - putBoolean(GROBID_OPT_OUT, preferences.isGrobidOptOut()); - put(GROBID_URL, preferences.getGrobidURL()); - } - - @Override - public ImportSettingsPreferences getImportSettingsPreferences() { - return new ImportSettingsPreferences( + public ImporterPreferences getImporterPreferences() { + importerPreferences = Objects.requireNonNullElseGet(importerPreferences, () -> new ImporterPreferences( getBoolean(GENERATE_KEY_ON_IMPORT), getBoolean(GROBID_ENABLED), getBoolean(GROBID_OPT_OUT), get(GROBID_URL) - ); + )); + + EasyBind.subscribe(importerPreferences.generateNewKeyOnImportProperty(), newValue -> putBoolean(GENERATE_KEY_ON_IMPORT, newValue)); + EasyBind.subscribe(importerPreferences.grobidEnabledProperty(), newValue -> putBoolean(GROBID_ENABLED, newValue)); + EasyBind.subscribe(importerPreferences.grobidOptOutProperty(), newValue -> putBoolean(GROBID_OPT_OUT, newValue)); + EasyBind.subscribe(importerPreferences.grobidURLProperty(), newValue -> put(GROBID_URL, newValue)); + + return importerPreferences; } } diff --git a/src/main/java/org/jabref/preferences/PreferencesService.java b/src/main/java/org/jabref/preferences/PreferencesService.java index 7c25d7cf7a6..e5ce77b258f 100644 --- a/src/main/java/org/jabref/preferences/PreferencesService.java +++ b/src/main/java/org/jabref/preferences/PreferencesService.java @@ -28,8 +28,8 @@ import org.jabref.logic.exporter.SavePreferences; import org.jabref.logic.exporter.TemplateExporter; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.fileformat.CustomImporter; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.journals.JournalAbbreviationPreferences; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.l10n.Language; @@ -259,8 +259,6 @@ public interface PreferencesService { AppearancePreferences getAppearancePreferences(); - void storeAppearancePreference(AppearancePreferences preferences); - //************************************************************************************************************* // File preferences //************************************************************************************************************* @@ -301,9 +299,7 @@ public interface PreferencesService { void storeCustomImportFormats(Set customImporters); - ImportSettingsPreferences getImportSettingsPreferences(); - - void storeImportSettingsPreferences(ImportSettingsPreferences preferences); + ImporterPreferences getImporterPreferences(); //************************************************************************************************************* // Preview preferences diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java index 7233ef6c55a..a9567095d44 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java @@ -8,7 +8,6 @@ import java.util.Set; import java.util.stream.Stream; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.util.DummyFileUpdateMonitor; @@ -31,7 +30,7 @@ void setUp() { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getEncoding()).thenReturn(StandardCharsets.UTF_8); when(importFormatPreferences.getCustomImportList()).thenReturn(Set.of()); - reader.resetImportFormats(mock(ImportSettingsPreferences.class), importFormatPreferences, mock(XmpPreferences.class), new DummyFileUpdateMonitor()); + reader.resetImportFormats(mock(ImporterPreferences.class), importFormatPreferences, mock(XmpPreferences.class), new DummyFileUpdateMonitor()); } @ParameterizedTest diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java index e49adfd00a8..ba25256bf2e 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java @@ -4,7 +4,6 @@ import java.nio.file.Path; import java.util.Set; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.xmp.XmpPreferences; import org.jabref.model.util.DummyFileUpdateMonitor; import org.jabref.model.util.FileUpdateMonitor; @@ -28,7 +27,7 @@ void setUp() { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getEncoding()).thenReturn(StandardCharsets.UTF_8); when(importFormatPreferences.getCustomImportList()).thenReturn(Set.of()); - reader.resetImportFormats(mock(ImportSettingsPreferences.class), importFormatPreferences, mock(XmpPreferences.class), fileMonitor); + reader.resetImportFormats(mock(ImporterPreferences.class), importFormatPreferences, mock(XmpPreferences.class), fileMonitor); } @Test diff --git a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java index 9f36a346b74..6c1aa5aeb4d 100644 --- a/src/test/java/org/jabref/logic/importer/WebFetchersTest.java +++ b/src/test/java/org/jabref/logic/importer/WebFetchersTest.java @@ -14,7 +14,6 @@ import org.jabref.logic.importer.fetcher.IsbnViaOttoBibFetcher; import org.jabref.logic.importer.fetcher.JstorFetcher; import org.jabref.logic.importer.fetcher.MrDLibFetcher; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.model.database.BibDatabaseContext; import org.jabref.preferences.FilePreferences; @@ -31,7 +30,7 @@ class WebFetchersTest { private ImportFormatPreferences importFormatPreferences; - private final ClassGraph classGraph = new ClassGraph().enableAllInfo().whitelistPackages("org.jabref"); + private final ClassGraph classGraph = new ClassGraph().enableAllInfo().acceptPackages("org.jabref"); @BeforeEach void setUp() throws Exception { @@ -66,7 +65,7 @@ void getIdBasedFetchersReturnsAllFetcherDerivingFromIdBasedFetcher() throws Exce @Test void getEntryBasedFetchersReturnsAllFetcherDerivingFromEntryBasedFetcher() throws Exception { - Set idFetchers = WebFetchers.getEntryBasedFetchers(mock(ImportSettingsPreferences.class), importFormatPreferences, mock(FilePreferences.class), mock(BibDatabaseContext.class), Charset.defaultCharset()); + Set idFetchers = WebFetchers.getEntryBasedFetchers(mock(ImporterPreferences.class), importFormatPreferences, mock(FilePreferences.class), mock(BibDatabaseContext.class), Charset.defaultCharset()); try (ScanResult scanResult = classGraph.scan()) { ClassInfoList controlClasses = scanResult.getClassesImplementing(EntryBasedFetcher.class.getCanonicalName()); diff --git a/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java index d0540fc4865..a2bac4b6ce8 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/GrobidCitationFetcherTest.java @@ -8,8 +8,8 @@ import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.ParseException; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.logic.importer.util.GrobidService; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -33,8 +33,8 @@ public class GrobidCitationFetcherTest { static ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); - static ImportSettingsPreferences importSettingsPreferences = new ImportSettingsPreferences(false, true, false, "http://grobid.jabref.org:8070"); - static GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(importSettingsPreferences, importFormatPreferences); + static ImporterPreferences importerPreferences = new ImporterPreferences(false, true, false, "http://grobid.jabref.org:8070"); + static GrobidCitationFetcher grobidCitationFetcher = new GrobidCitationFetcher(importerPreferences, importFormatPreferences); static String example1 = "Derwing, T. M., Rossiter, M. J., & Munro, M. J. (2002). Teaching native speakers to listen to foreign-accented speech. Journal of Multilingual and Multicultural Development, 23(4), 245-259."; static BibEntry example1AsBibEntry = new BibEntry(StandardEntryType.Article).withCitationKey("-1") @@ -124,8 +124,7 @@ public void performSearchThrowsExceptionInCaseOfConnectionIssues() throws IOExce when(grobidServiceMock.processCitation(anyString(), any(), any())).thenThrow(new SocketTimeoutException("Timeout")); grobidCitationFetcher = new GrobidCitationFetcher(importFormatPreferences, grobidServiceMock); - assertThrows(FetcherException.class, () -> { - grobidCitationFetcher.performSearch("any text"); - }, "performSearch should throw an FetcherException, when there are underlying IOException."); + assertThrows(FetcherException.class, () -> + grobidCitationFetcher.performSearch("any text"), "performSearch should throw an FetcherException, when there are underlying IOException."); } } diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java index 16976058572..3577ffedaa7 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfGrobidImporterTest.java @@ -8,7 +8,7 @@ import java.util.Optional; import org.jabref.logic.importer.ImportFormatPreferences; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -30,12 +30,12 @@ public class PdfGrobidImporterTest { @BeforeEach public void setUp() { - ImportSettingsPreferences importSettingsPreferences = mock(ImportSettingsPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importSettingsPreferences.isGrobidEnabled()).thenReturn(true); - when(importSettingsPreferences.getGrobidURL()).thenReturn("http://grobid.jabref.org:8070"); + ImporterPreferences importerPreferences = mock(ImporterPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importerPreferences.isGrobidEnabled()).thenReturn(true); + when(importerPreferences.getGrobidURL()).thenReturn("http://grobid.jabref.org:8070"); importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); - importer = new PdfGrobidImporter(importSettingsPreferences, importFormatPreferences); + importer = new PdfGrobidImporter(importerPreferences, importFormatPreferences); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java b/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java index 29a45c09ad5..282a809a378 100644 --- a/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java +++ b/src/test/java/org/jabref/logic/importer/fileformat/PdfMergeMetadataImporterTest.java @@ -6,7 +6,7 @@ import java.util.List; import org.jabref.logic.importer.ImportFormatPreferences; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.util.StandardFileType; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -28,12 +28,12 @@ class PdfMergeMetadataImporterTest { @BeforeEach void setUp() { - ImportSettingsPreferences importSettingsPreferences = mock(ImportSettingsPreferences.class, Answers.RETURNS_DEEP_STUBS); - when(importSettingsPreferences.isGrobidEnabled()).thenReturn(true); - when(importSettingsPreferences.getGrobidURL()).thenReturn("http://grobid.jabref.org:8070"); + ImporterPreferences importerPreferences = mock(ImporterPreferences.class, Answers.RETURNS_DEEP_STUBS); + when(importerPreferences.isGrobidEnabled()).thenReturn(true); + when(importerPreferences.getGrobidURL()).thenReturn("http://grobid.jabref.org:8070"); importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getFieldContentFormatterPreferences().getNonWrappableFields()).thenReturn(List.of()); - importer = new PdfMergeMetadataImporter(importSettingsPreferences, importFormatPreferences); + importer = new PdfMergeMetadataImporter(importerPreferences, importFormatPreferences); } @Test diff --git a/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java b/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java index cc97c94e5f5..1dc4fc551c7 100644 --- a/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java +++ b/src/test/java/org/jabref/logic/importer/util/GrobidServiceTest.java @@ -7,9 +7,9 @@ import java.util.Optional; import org.jabref.logic.importer.ImportFormatPreferences; +import org.jabref.logic.importer.ImporterPreferences; import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.fileformat.PdfGrobidImporterTest; -import org.jabref.logic.importer.importsettings.ImportSettingsPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; @@ -30,12 +30,12 @@ public class GrobidServiceTest { private static GrobidService grobidService; - private static ImportSettingsPreferences importSettingsPreferences = new ImportSettingsPreferences(false, true, false, "http://grobid.jabref.org:8070"); + private static ImporterPreferences importerPreferences = new ImporterPreferences(false, true, false, "http://grobid.jabref.org:8070"); private static ImportFormatPreferences importFormatPreferences; @BeforeAll public static void setup() { - grobidService = new GrobidService(importSettingsPreferences); + grobidService = new GrobidService(importerPreferences); importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getKeywordSeparator()).thenReturn(','); } @@ -75,7 +75,7 @@ public void processInvalidCitationTest() { @Test public void failsWhenGrobidDisabled() { - ImportSettingsPreferences importSettingsWithGrobidDisabled = importSettingsPreferences.withGrobidEnabled(false); + ImporterPreferences importSettingsWithGrobidDisabled = new ImporterPreferences(false, true, false, "http://grobid.jabref.org:8070"); assertThrows(UnsupportedOperationException.class, () -> new GrobidService(importSettingsWithGrobidDisabled)); }