Skip to content

Commit

Permalink
Probably the last injections for now
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Jul 18, 2016
1 parent ac3158e commit fc2b5fa
Show file tree
Hide file tree
Showing 45 changed files with 213 additions and 149 deletions.
11 changes: 7 additions & 4 deletions src/jmh/java/net/sf/jabref/benchmarks/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void init() throws Exception {
entry.setField("rnd", "2" + randomizer.nextInt());
database.insertEntry(entry);
}
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new,
Globals.prefs);
StringSaveSession saveSession = databaseWriter.savePartOfDatabase(
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(),
new SavePreferences());
Expand All @@ -80,7 +81,8 @@ public ParserResult parse() throws IOException {

@Benchmark
public String write() throws Exception {
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
BibtexDatabaseWriter<StringSaveSession> databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new,
Globals.prefs);
StringSaveSession saveSession = databaseWriter.savePartOfDatabase(
new BibDatabaseContext(database, new MetaData(), new Defaults()), database.getEntries(),
new SavePreferences());
Expand Down Expand Up @@ -115,14 +117,15 @@ public String latexToHTMLConversion() {

@Benchmark
public String htmlToLatexConversion() {
HtmlToLatexFormatter f = new HtmlToLatexFormatter();
HtmlToLatexFormatter f = new HtmlToLatexFormatter(
Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION));
return f.format(htmlConversionString);
}

@Benchmark
public boolean keywordGroupContains() throws ParseException {
KeywordGroup group = new KeywordGroup("testGroup", "keyword", "testkeyword", false, false,
GroupHierarchyType.INDEPENDENT);
GroupHierarchyType.INDEPENDENT, Globals.prefs);
return group.containsAll(database.getEntries());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static void start(String[] args) {
Globals.prefs.setLanguageDependentDefaultValues();

// Update which fields should be treated as numeric, based on preferences:
InternalBibtexFields.setNumericFieldsFromPrefs(Globals.prefs);
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));

/* Build list of Import and Export formats */
Globals.IMPORT_FORMAT_READER.resetImportFormats();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public class JabRefPreferences {
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new ProtectTermsFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new UnitsToLatexFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new LatexCleanupFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HtmlToLatexFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HtmlToLatexFormatter(false))); // TODO: Get the actual value USE_CONVERT_TO_EQUATION
FieldFormatterCleanups formatterCleanups = new FieldFormatterCleanups(true, activeFormatterCleanups);
CLEANUP_DEFAULT_PRESET = new CleanupPreset(EnumSet.complementOf(deactivedJobs), formatterCleanups);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/cli/ArgumentProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private boolean generateAux(List<ParserResult> loaded, String[] data) {
try {
System.out.println(Localization.lang("Saving") + ": " + subName);
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs);
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs);
Defaults defaults = new Defaults(BibDatabaseMode
.fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)));
SaveSession session = databaseWriter.saveDatabase(new BibDatabaseContext(newBase, defaults),
Expand Down Expand Up @@ -332,7 +332,8 @@ private void exportFile(List<ParserResult> loaded, String[] data) {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs);
Defaults defaults = new Defaults(BibDatabaseMode.fromPreference(
Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)));
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new,
Globals.prefs);
SaveSession session = databaseWriter.saveDatabase(
new BibDatabaseContext(pr.getDatabase(), pr.getMetaData(), defaults), prefs);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jabref/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void storeTempDatabase() {

Defaults defaults = new Defaults(BibDatabaseMode
.fromPreference(Globals.prefs.getBoolean(JabRefPreferences.BIBLATEX_DEFAULT_MODE)));
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs);
SaveSession ss = databaseWriter.saveDatabase(new BibDatabaseContext(inTemp, mdInTemp, defaults), prefs);
ss.commit(Globals.getFileUpdateMonitor().getTempFile(panel.fileMonitorHandle()));
} catch (SaveException ex) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(enc)
.withSaveType(saveType);
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs);
if (selectedOnly) {
session = databaseWriter.savePartOfDatabase(bibDatabaseContext, mainTable.getSelectedEntries(), prefs);
} else {
Expand Down Expand Up @@ -1572,7 +1572,7 @@ public void setupMainPanel() {
// Set up AutoCompleters for this panel:
if (Globals.prefs.getBoolean(JabRefPreferences.AUTO_COMPLETE)) {
autoCompleters = new ContentAutoCompleters(getDatabase(), bibDatabaseContext.getMetaData(),
autoCompletePreferences, Globals.journalAbbreviationLoader);
autoCompletePreferences, Globals.journalAbbreviationLoader, Globals.prefs);
// ensure that the autocompleters are in sync with entries
this.getDatabase().registerListener(new AutoCompleteListener());
} else {
Expand All @@ -1598,7 +1598,7 @@ public void updateSearchManager() {
private void instantiateSearchAutoCompleter() {
AutoCompletePreferences autoCompletePreferences = new AutoCompletePreferences(Globals.prefs);
AutoCompleterFactory autoCompleterFactory = new AutoCompleterFactory(autoCompletePreferences,
Globals.journalAbbreviationLoader);
Globals.journalAbbreviationLoader, Globals.prefs);
searchAutoCompleter = autoCompleterFactory.getPersonAutoCompleter();
for (BibEntry entry : database.getEntries()) {
searchAutoCompleter.addBibtexEntry(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public static Optional<JComponent> getJournalExtraComponent(JabRefFrame frame, B
button.setToolTipText(ABBREVIATION_TOOLTIP_TEXT);
button.addActionListener(actionEvent -> {
String text = editor.getText();
JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader.getRepository();
JournalAbbreviationRepository abbreviationRepository = Globals.journalAbbreviationLoader
.getRepository(Globals.prefs);
if (abbreviationRepository.isKnownName(text)) {
String s = abbreviationRepository.getNextAbbreviation(text).orElse(text);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static boolean autoSave(BasePanel panel) {
.withMakeBackup(false)
.withEncoding(panel.getBibDatabaseContext().getMetaData().getEncoding());

BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
BibDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs);
SaveSession ss = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);
ss.commit(backupFile.toPath());
} catch (SaveException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding)
frame.block();
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding);
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new);
BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new, Globals.prefs);
if (selectedOnly) {
session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(),
prefs);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/sf/jabref/gui/groups/AutoGroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public void actionPerformed(ActionEvent e) {

try {
GroupTreeNode autoGroupsRoot = GroupTreeNode.fromGroup(
new ExplicitGroup(Localization.lang("Automatically created groups"), GroupHierarchyType.INCLUDING));
new ExplicitGroup(Localization.lang("Automatically created groups"),
GroupHierarchyType.INCLUDING, Globals.prefs));
Set<String> hs;
String fieldText = field.getText();
if (keywords.isSelected()) {
Expand All @@ -120,7 +121,7 @@ public void actionPerformed(ActionEvent e) {

for (String keyword : hs) {
KeywordGroup group = new KeywordGroup(keyword, fieldText, keyword, false, false,
GroupHierarchyType.INDEPENDENT);
GroupHierarchyType.INDEPENDENT, Globals.prefs);
autoGroupsRoot.addChild(GroupTreeNode.fromGroup(group));
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/net/sf/jabref/gui/groups/GroupDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,21 @@ public void actionPerformed(ActionEvent e) {
isOkPressed = true;
try {
if (explicitRadioButton.isSelected()) {
resultingGroup = new ExplicitGroup(nameField.getText().trim(), getContext());
resultingGroup = new ExplicitGroup(nameField.getText().trim(), getContext(), Globals.prefs);
} else if (keywordsRadioButton.isSelected()) {
// regex is correct, otherwise OK would have been disabled
// therefore I don't catch anything here
resultingGroup = new KeywordGroup(nameField.getText().trim(), keywordGroupSearchField.getText().trim(),
keywordGroupSearchTerm.getText().trim(), keywordGroupCaseSensitive.isSelected(), keywordGroupRegExp
.isSelected(),
getContext());
getContext(), Globals.prefs);
} else if (searchRadioButton.isSelected()) {
try {
// regex is correct, otherwise OK would have been
// disabled
// therefore I don't catch anything here
resultingGroup = new SearchGroup(nameField.getText().trim(), searchGroupSearchExpression.getText().trim(),
isCaseSensitive(), isRegex(), getContext());
isCaseSensitive(), isRegex(), getContext(), Globals.prefs);
} catch (Exception e1) {
// should never happen
}
Expand All @@ -317,7 +317,7 @@ public void actionPerformed(ActionEvent e) {
searchGroupCaseSensitive.addItemListener(itemListener);

// configure for current type
if (editedGroup != null && editedGroup.getClass() == KeywordGroup.class) {
if ((editedGroup != null) && (editedGroup.getClass() == KeywordGroup.class)) {
KeywordGroup group = (KeywordGroup) editedGroup;
nameField.setText(group.getName());
keywordGroupSearchField.setText(group.getSearchField());
Expand All @@ -326,15 +326,15 @@ public void actionPerformed(ActionEvent e) {
keywordGroupRegExp.setSelected(group.isRegExp());
keywordsRadioButton.setSelected(true);
setContext(editedGroup.getHierarchicalContext());
} else if (editedGroup != null && editedGroup.getClass() == SearchGroup.class) {
} else if ((editedGroup != null) && (editedGroup.getClass() == SearchGroup.class)) {
SearchGroup group = (SearchGroup) editedGroup;
nameField.setText(group.getName());
searchGroupSearchExpression.setText(group.getSearchExpression());
searchGroupCaseSensitive.setSelected(group.isCaseSensitive());
searchGroupRegExp.setSelected(group.isRegExp());
searchRadioButton.setSelected(true);
setContext(editedGroup.getHierarchicalContext());
} else if (editedGroup != null && editedGroup.getClass() == ExplicitGroup.class) {
} else if ((editedGroup != null) && (editedGroup.getClass() == ExplicitGroup.class)) {
nameField.setText(editedGroup.getName());
explicitRadioButton.setSelected(true);
setContext(editedGroup.getHierarchicalContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void run() {
}

UndoableAbbreviator undoableAbbreviator = new UndoableAbbreviator(
Globals.journalAbbreviationLoader.getRepository(), iso);
Globals.journalAbbreviationLoader.getRepository(Globals.prefs), iso);

NamedCompound ce = new NamedCompound(Localization.lang("Abbreviate journal names"));
int count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public ManageJournalsPanel(final JabRefFrame frame) {

viewBuiltin.addActionListener(e -> {
JTable table = new JTable(JournalAbbreviationsUtil
.getTableModel(Globals.journalAbbreviationLoader.getRepository().getAbbreviations()));
.getTableModel(Globals.journalAbbreviationLoader.getRepository(Globals.prefs).getAbbreviations()));
JScrollPane pane = new JScrollPane(table);
JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"),
JOptionPane.INFORMATION_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void run() {
}

UndoableUnabbreviator undoableAbbreviator = new UndoableUnabbreviator(
Globals.journalAbbreviationLoader.getRepository());
Globals.journalAbbreviationLoader.getRepository(Globals.prefs));

NamedCompound ce = new NamedCompound(Localization.lang("Unabbreviate journal names"));
int count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void storeSettings() {
}
if (!Objects.equals(oldVal, newVal)) {
prefs.put(JabRefPreferences.NUMERIC_FIELDS, newVal);
InternalBibtexFields.setNumericFieldsFromPrefs(Globals.prefs);
InternalBibtexFields.setNumericFields(Globals.prefs.getStringList(JabRefPreferences.NUMERIC_FIELDS));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static void mergeFromBibtex(JabRefFrame frame, BasePanel panel, ParserRe
// create a dummy group
ExplicitGroup group = null;
try {
group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT);
group = new ExplicitGroup("Imported", GroupHierarchyType.INDEPENDENT, Globals.prefs);
} catch (ParseException e) {
LOGGER.error(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public class ACMPortalFetcher implements PreviewEntryFetcher {

private static final Log LOGGER = LogFactory.getLog(ACMPortalFetcher.class);

private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter();
private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter(
Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION));
private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter();
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();
private String terms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public class IEEEXploreFetcher implements EntryFetcher {

private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter();
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();
private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter();
private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter(
Globals.prefs.getBoolean(JabRefPreferences.USE_CONVERT_TO_EQUATION));
private final JCheckBox absCheckBox = new JCheckBox(Localization.lang("Include abstracts"), false);

private boolean shouldContinue;
Expand Down Expand Up @@ -444,7 +445,8 @@ private BibEntry cleanup(BibEntry entry) {

fullName = fullName.trim();
if (Globals.prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) {
fullName = abbreviationLoader.getRepository().getMedlineAbbreviation(fullName).orElse(fullName);
fullName = abbreviationLoader.getRepository(Globals.prefs).getMedlineAbbreviation(fullName)
.orElse(fullName);
}
}
if ("inproceedings".equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.Objects;

import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;
import net.sf.jabref.model.entry.FieldProperties;
import net.sf.jabref.model.entry.InternalBibtexFields;
Expand All @@ -31,10 +32,13 @@ public class AutoCompleterFactory {

private final AutoCompletePreferences preferences;
private final JournalAbbreviationLoader abbreviationLoader;
private final JabRefPreferences jabRefPreferences;

public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader) {
public AutoCompleterFactory(AutoCompletePreferences preferences, JournalAbbreviationLoader abbreviationLoader,
JabRefPreferences jabRefPreferences) {
this.preferences = Objects.requireNonNull(preferences);
this.abbreviationLoader = Objects.requireNonNull(abbreviationLoader);
this.jabRefPreferences = Objects.requireNonNull(jabRefPreferences);
}

public AutoCompleter<String> getFor(String fieldName) {
Expand All @@ -45,7 +49,7 @@ public AutoCompleter<String> getFor(String fieldName) {
} else if ("crossref".equals(fieldName)) {
return new BibtexKeyAutoCompleter(preferences);
} else if ("journal".equals(fieldName) || "publisher".equals(fieldName)) {
return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader);
return new JournalAutoCompleter(fieldName, preferences, abbreviationLoader, jabRefPreferences);
} else {
return new DefaultAutoCompleter(fieldName, preferences);
}
Expand Down
Loading

0 comments on commit fc2b5fa

Please sign in to comment.