Skip to content

Commit

Permalink
Moved some logic preference instantiation to JabRefPreferences (#1781)
Browse files Browse the repository at this point in the history
* Moved some logic preference instantiation to JabRefPreferences

* Some fixes

* And some removed Globals
  • Loading branch information
oscargus authored Aug 26, 2016
1 parent d6b5fe9 commit 7cb1e75
Show file tree
Hide file tree
Showing 107 changed files with 262 additions and 376 deletions.
3 changes: 1 addition & 2 deletions src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter;
import net.sf.jabref.logic.groups.GroupHierarchyType;
import net.sf.jabref.logic.groups.KeywordGroup;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.importer.util.ParseException;
Expand Down Expand Up @@ -76,7 +75,7 @@ public void init() throws Exception {
public ParserResult parse() throws IOException {
StringReader bibtexStringReader = new StringReader(bibtexString);
BibtexParser parser = new BibtexParser(bibtexStringReader,
ImportFormatPreferences.fromPreferences(Globals.prefs));
Globals.prefs.getImportFormatPreferences());
return parser.parse();
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/sf/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import net.sf.jabref.gui.importer.worker.AutosaveStartupPrompter;
import net.sf.jabref.gui.util.FocusRequester;
import net.sf.jabref.gui.worker.VersionWorker;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.OpenDatabase;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.l10n.Localization;
Expand Down Expand Up @@ -219,7 +218,7 @@ private void openLastEditedDatabases() {
}

ParserResult parsedDatabase = OpenDatabase.loadDatabaseOrAutoSave(fileName, false,
ImportFormatPreferences.fromPreferences(Globals.prefs));
Globals.prefs.getImportFormatPreferences());

if (parsedDatabase.isNullResult()) {
LOGGER.error(Localization.lang("Error opening file") + " '" + dbFile.getPath() + "'");
Expand Down
14 changes: 5 additions & 9 deletions src/main/java/net/sf/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
import net.sf.jabref.logic.exporter.ExportFormats;
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.net.ProxyAuthenticator;
import net.sf.jabref.logic.net.ProxyPreferences;
import net.sf.jabref.logic.net.ProxyRegisterer;
import net.sf.jabref.logic.protectedterms.ProtectedTermsLoader;
import net.sf.jabref.logic.protectedterms.ProtectedTermsPreferences;
import net.sf.jabref.logic.remote.RemotePreferences;
import net.sf.jabref.logic.remote.client.RemoteListenerClient;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.xmp.XMPPreferences;
import net.sf.jabref.model.entry.InternalBibtexFields;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -67,19 +64,18 @@ private static void start(String[] args) {
Globals.journalAbbreviationLoader = new JournalAbbreviationLoader();

/* Build list of Import and Export formats */
Globals.IMPORT_FORMAT_READER.resetImportFormats(ImportFormatPreferences.fromPreferences(Globals.prefs),
XMPPreferences.fromPreferences(Globals.prefs));
Globals.IMPORT_FORMAT_READER.resetImportFormats(Globals.prefs.getImportFormatPreferences(),
Globals.prefs.getXMPPreferences());
CustomEntryTypesManager.loadCustomEntryTypes(preferences);
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = LayoutFormatterPreferences.fromPreferences(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs
.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);

// Initialize protected terms loader
Globals.protectedTermsLoader = new ProtectedTermsLoader(
ProtectedTermsPreferences.fromPreferences(Globals.prefs));
Globals.protectedTermsLoader = new ProtectedTermsLoader(Globals.prefs.getProtectedTermsPreferences());
ProtectTermsFormatter.setProtectedTermsLoader(Globals.protectedTermsLoader);

// Check for running JabRef
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import net.sf.jabref.gui.importer.fetcher.EntryFetcher;
import net.sf.jabref.gui.importer.fetcher.EntryFetchers;
import net.sf.jabref.logic.CustomEntryTypesManager;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.exporter.BibDatabaseWriter;
import net.sf.jabref.logic.exporter.BibtexDatabaseWriter;
Expand All @@ -33,7 +32,6 @@
import net.sf.jabref.logic.exporter.SaveException;
import net.sf.jabref.logic.exporter.SavePreferences;
import net.sf.jabref.logic.exporter.SaveSession;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.ImportFormatReader;
import net.sf.jabref.logic.importer.OpenDatabase;
import net.sf.jabref.logic.importer.OutputPrinter;
Expand Down Expand Up @@ -242,7 +240,7 @@ private List<ParserResult> importAndOpenFiles() {
ParserResult pr = null;
if (bibExtension) {
pr = OpenDatabase.loadDatabaseOrAutoSave(aLeftOver, false,
ImportFormatPreferences.fromPreferences(Globals.prefs));
Globals.prefs.getImportFormatPreferences());
}

if (!bibExtension || (pr.isNullResult())) {
Expand Down Expand Up @@ -400,8 +398,8 @@ private void importPreferences() {
CustomEntryTypesManager.loadCustomEntryTypes(Globals.prefs);
Map<String, ExportFormat> customFormats = Globals.prefs.customExports.getCustomExportFormats(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = LayoutFormatterPreferences.fromPreferences(Globals.prefs,
Globals.journalAbbreviationLoader);
LayoutFormatterPreferences layoutPreferences = Globals.prefs
.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
SavePreferences savePreferences = SavePreferences.loadForExportFromPreferences(Globals.prefs);
ExportFormats.initAllExports(customFormats, layoutPreferences, savePreferences);
} catch (JabRefException ex) {
Expand Down Expand Up @@ -449,7 +447,7 @@ private void regenerateBibtexKeys(List<ParserResult> loaded) {
for (BibEntry entry : database.getEntries()) {
// try to make a new label
BibtexKeyPatternUtil.makeLabel(metaData, database, entry,
BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
Globals.prefs.getBibtexKeyPatternPreferences());
}
} else {
LOGGER.info(Localization.lang("No meta data present in BIB_file. Cannot regenerate BibTeX keys"));
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/sf/jabref/cli/CrossrefFetcherEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.concurrent.atomic.AtomicInteger;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.importer.fetcher.CrossRef;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
Expand All @@ -28,11 +27,11 @@ public class CrossrefFetcherEvaluator {
public static void main(String[] args) throws IOException, InterruptedException {
Globals.prefs = JabRefPreferences.getInstance();
try (FileReader reader = new FileReader(args[0])) {
BibtexParser parser = new BibtexParser(reader, ImportFormatPreferences.fromPreferences(Globals.prefs));
BibtexParser parser = new BibtexParser(new FileReader(args[0]), Globals.prefs.getImportFormatPreferences());
ParserResult result = parser.parse();
BibDatabase db = result.getDatabase();

int total = result.getDatabase().getEntryCount();
int total = db.getEntryCount();

AtomicInteger dois = new AtomicInteger();
AtomicInteger doiFound = new AtomicInteger();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/sf/jabref/cli/XMPUtilMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import net.sf.jabref.Globals;
import net.sf.jabref.logic.bibtex.BibEntryWriter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatter;
import net.sf.jabref.logic.bibtex.LatexFieldFormatterPreferences;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.ParserResult;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
Expand Down Expand Up @@ -60,8 +59,8 @@ public static void main(String[] args) throws IOException, TransformerException
Globals.prefs = JabRefPreferences.getInstance();
}

XMPPreferences xmpPreferences = XMPPreferences.fromPreferences(Globals.prefs);
ImportFormatPreferences importFormatPreferences = ImportFormatPreferences.fromPreferences(Globals.prefs);
XMPPreferences xmpPreferences = Globals.prefs.getXMPPreferences();
ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences();

switch (args.length) {
case 0:
Expand All @@ -74,7 +73,7 @@ public static void main(String[] args) throws IOException, TransformerException
List<BibEntry> l = XMPUtil.readXMP(new File(args[0]), xmpPreferences);

BibEntryWriter bibtexEntryWriter = new BibEntryWriter(
new LatexFieldFormatter(LatexFieldFormatterPreferences.fromPreferences(Globals.prefs)), false);
new LatexFieldFormatter(Globals.prefs.getLatexFieldFormatterPreferences()), false);

for (BibEntry entry : l) {
StringWriter sw = new StringWriter();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/sf/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ public void run() {

// Parse the temporary file.
Path tempFile = Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle());
ImportFormatPreferences importFormatPreferences = ImportFormatPreferences.fromPreferences(Globals.prefs);
ImportFormatPreferences importFormatPreferences = Globals.prefs.getImportFormatPreferences();
ParserResult result = OpenDatabase.loadDatabase(tempFile.toFile(), importFormatPreferences);
databaseInTemp = result.getDatabase();
metadataInTemp = result.getMetaData();

// Parse the modified file.
result = OpenDatabase.loadDatabase(file, importFormatPreferences);
BibDatabase databaseOnDisk = result.getDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.net.MonitoredURLDownload;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.net.URLDownload;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.io.FileUtil;
Expand Down Expand Up @@ -259,7 +258,7 @@ private String getSuggestedFileName(String suffix) {
String plannedName = FileUtil.createFileNameFromPattern(databaseContext.getDatabase(),
frame.getCurrentBasePanel().getSelectedEntries().get(0),
Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN),
LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader));
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader));

if (!suffix.isEmpty()) {
plannedName += "." + suffix;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/sf/jabref/external/DroppedFileHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import net.sf.jabref.gui.undo.UndoableFieldChange;
import net.sf.jabref.gui.undo.UndoableInsertEntry;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.util.OS;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.logic.xmp.XMPPreferences;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -224,7 +222,7 @@ private boolean tryXmpImport(String fileName, ExternalFileType fileType, NamedCo

List<BibEntry> xmpEntriesInFile;
try {
xmpEntriesInFile = XMPUtil.readXMP(fileName, XMPPreferences.fromPreferences(Globals.prefs));
xmpEntriesInFile = XMPUtil.readXMP(fileName, Globals.prefs.getXMPPreferences());
} catch (IOException e) {
LOGGER.warn("Problem reading XMP", e);
return false;
Expand Down Expand Up @@ -346,7 +344,7 @@ private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileTy
// Determine which name to suggest:
String targetName = FileUtil.createFileNameFromPattern(database, entry,
Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN),
LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader));
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader));

renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/sf/jabref/external/MoveFileAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import net.sf.jabref.gui.fieldeditors.FileListEditor;
import net.sf.jabref.gui.util.component.CheckBoxMessage;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.preferences.JabRefPreferences;

Expand Down Expand Up @@ -100,8 +99,7 @@ public void actionPerformed(ActionEvent event) {
String suggName = FileUtil
.createFileNameFromPattern(eEditor.getDatabase(), eEditor.getEntry(),
Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN),
LayoutFormatterPreferences.fromPreferences(Globals.prefs,
Globals.journalAbbreviationLoader))
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader))
.concat(entry.type.isPresent() ? "." + entry.type.get().getExtension() : "");
CheckBoxMessage cbm = new CheckBoxMessage(Localization.lang("Move file to file directory?"),
Localization.lang("Rename to '%0'", suggName),
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/sf/jabref/external/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.logic.xmp.XMPPreferences;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -153,7 +152,7 @@ public void run() {
for (File file : files) {
if (file.exists()) {
try {
XMPUtil.writeXMP(file, entry, database, XMPPreferences.fromPreferences(Globals.prefs));
XMPUtil.writeXMP(file, entry, database, Globals.prefs.getXMPPreferences());
SwingUtilities.invokeLater(
() -> optDiag.getProgressArea().append(" " + Localization.lang("OK") + ".\n"));
entriesChanged++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import net.sf.jabref.gui.worker.AbstractWorker;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.io.FileUtil;
import net.sf.jabref.logic.xmp.XMPPreferences;
import net.sf.jabref.logic.xmp.XMPUtil;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.FieldName;
Expand Down Expand Up @@ -115,8 +114,7 @@ public void run() {

} else {
try {
XMPUtil.writeXMP(file, entry, panel.getDatabase(),
XMPPreferences.fromPreferences(Globals.prefs));
XMPUtil.writeXMP(file, entry, panel.getDatabase(), Globals.prefs.getXMPPreferences());
if (files.size() == 1) {
message = Localization.lang("Wrote XMP-metadata");
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
import net.sf.jabref.logic.autocompleter.AutoCompleter;
import net.sf.jabref.logic.autocompleter.AutoCompleterFactory;
import net.sf.jabref.logic.autocompleter.ContentAutoCompleters;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
import net.sf.jabref.logic.bibtexkeypattern.BibtexKeyPatternUtil;
import net.sf.jabref.logic.exporter.BibtexDatabaseWriter;
import net.sf.jabref.logic.exporter.FileSaveSession;
Expand All @@ -106,7 +105,6 @@
import net.sf.jabref.logic.l10n.Encodings;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.layout.Layout;
import net.sf.jabref.logic.layout.LayoutFormatterPreferences;
import net.sf.jabref.logic.layout.LayoutHelper;
import net.sf.jabref.logic.util.FileExtensions;
import net.sf.jabref.logic.util.UpdateField;
Expand Down Expand Up @@ -479,7 +477,7 @@ public void run() {
for (BibEntry entry : entries) {
bes = entry;
BibtexKeyPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), bibDatabaseContext.getDatabase(),
bes, BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
bes, Globals.prefs.getBibtexKeyPatternPreferences());
ce.addEdit(new UndoableKeyChange(bibDatabaseContext.getDatabase(), bes, (String) oldvals.get(bes),
bes.getCiteKeyOptional().orElse(null)));
}
Expand Down Expand Up @@ -912,7 +910,7 @@ private void copyKeyAndTitle() {
Layout layout;
try {
layout = new LayoutHelper(sr,
LayoutFormatterPreferences.fromPreferences(Globals.prefs, Globals.journalAbbreviationLoader))
Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader))
.getLayoutFromText();
} catch (IOException e) {
LOGGER.info("Could not get layout", e);
Expand Down Expand Up @@ -1939,7 +1937,7 @@ public void autoGenerateKeysBeforeSaving() {
Optional<String> oldKey = bes.getCiteKeyOptional();
if (!(oldKey.isPresent()) || oldKey.get().isEmpty()) {
BibtexKeyPatternUtil.makeLabel(bibDatabaseContext.getMetaData(), bibDatabaseContext.getDatabase(),
bes, BibtexKeyPatternPreferences.fromPreferences(Globals.prefs));
bes, Globals.prefs.getBibtexKeyPatternPreferences());
ce.addEdit(new UndoableKeyChange(bibDatabaseContext.getDatabase(), bes, null,
bes.getCiteKeyOptional().get())); // Cite key is set here
any = true;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/net/sf/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Optional;

import net.sf.jabref.Globals;
import net.sf.jabref.logic.importer.ImportFormatPreferences;
import net.sf.jabref.logic.importer.fetcher.DOItoBibTeX;
import net.sf.jabref.logic.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.util.DOI;
Expand Down Expand Up @@ -88,12 +87,12 @@ public List<BibEntry> extractBibEntriesFromClipboard() {
if (DOI.build(data).isPresent()) {
LOGGER.info("Found DOI in clipboard");
Optional<BibEntry> entry = DOItoBibTeX.getEntryFromDOI(new DOI(data).getDOI(),
ImportFormatPreferences.fromPreferences(Globals.prefs));
Globals.prefs.getImportFormatPreferences());
entry.ifPresent(result::add);
} else {
// parse bibtex string
BibtexParser bp = new BibtexParser(new StringReader(data),
ImportFormatPreferences.fromPreferences(Globals.prefs));
Globals.prefs.getImportFormatPreferences());
BibDatabase db = bp.parse().getDatabase();
LOGGER.info("Parsed " + db.getEntryCount() + " entries from clipboard text");
if (db.hasEntries()) {
Expand Down
Loading

0 comments on commit 7cb1e75

Please sign in to comment.