Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename formatters #1013

Merged
merged 3 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import net.sf.jabref.logic.cleanup.FieldFormatterCleanup;
import net.sf.jabref.logic.formatter.BibtexFieldFormatters;
import net.sf.jabref.logic.formatter.bibtexfields.*;
import net.sf.jabref.logic.formatter.casechanger.CaseKeeper;
import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.labelpattern.GlobalLabelPattern;
import net.sf.jabref.logic.openoffice.OpenOfficePreferences;
Expand Down Expand Up @@ -342,13 +342,13 @@ public class JabRefPreferences {
CleanupPreset.CleanupStep.CONVERT_TO_BIBLATEX);

List<FieldFormatterCleanup> activeFormatterCleanups = new ArrayList<>();
activeFormatterCleanups.add(new FieldFormatterCleanup("pages", BibtexFieldFormatters.PAGE_NUMBERS));
activeFormatterCleanups.add(new FieldFormatterCleanup("date", BibtexFieldFormatters.DATE));
activeFormatterCleanups.add(new FieldFormatterCleanup("month", new MonthFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new CaseKeeper()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new UnitFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new LatexFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("title", new HTMLToLatexFormatter()));
activeFormatterCleanups.add(new FieldFormatterCleanup("pages", BibtexFieldFormatters.NORMALIZE_PAGES));
activeFormatterCleanups.add(new FieldFormatterCleanup("date", BibtexFieldFormatters.NORMALIZE_DATE));
activeFormatterCleanups.add(new FieldFormatterCleanup("month", new NormalizeMonthFormatter()));
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()));
FieldFormatterCleanups formatterCleanups = new FieldFormatterCleanups(true, activeFormatterCleanups);
CLEANUP_DEFAULT_PRESET = new CleanupPreset(EnumSet.complementOf(deactivedJobs), formatterCleanups);
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/net/sf/jabref/exporter/FieldFormatterCleanups.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import net.sf.jabref.logic.formatter.CaseChangers;
import net.sf.jabref.logic.formatter.Formatter;
import net.sf.jabref.logic.formatter.IdentityFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.NormalizeMonthFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.OrdinalsToSuperscriptFormatter;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.model.entry.BibEntry;

Expand All @@ -27,8 +30,11 @@ public class FieldFormatterCleanups {
availableFormatters.addAll(BibtexFieldFormatters.ALL);
availableFormatters.addAll(CaseChangers.ALL);

String defaultFormatterString = "pages[PageNumbersFormatter]month[MonthFormatter]booktitle[SuperscriptFormatter]";
DEFAULT_SAVE_ACTIONS = new FieldFormatterCleanups(false, defaultFormatterString);
List<FieldFormatterCleanup> defaultFormatters = new ArrayList<>();
defaultFormatters.add(new FieldFormatterCleanup("pages", new NormalizePagesFormatter()));
defaultFormatters.add(new FieldFormatterCleanup("month", new NormalizeMonthFormatter()));
defaultFormatters.add(new FieldFormatterCleanup("booktitle", new OrdinalsToSuperscriptFormatter()));
DEFAULT_SAVE_ACTIONS = new FieldFormatterCleanups(false, defaultFormatters);
}

public FieldFormatterCleanups(boolean enabled, String formatterString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private JPanel getSelectorPanel() {
builder.add(selectFieldCombobox).xy(1, 1);

List<String> formatterNames = fieldFormatterCleanups.getAvailableFormatters().stream()
.map(formatter -> formatter.getKey()).collect(Collectors.toList());
.map(formatter -> formatter.getName()).collect(Collectors.toList());
List<String> formatterDescriptions = fieldFormatterCleanups.getAvailableFormatters().stream()
.map(formatter -> formatter.getDescription()).collect(Collectors.toList());
formattersCombobox = new JComboBox<>(formatterNames.toArray());
Expand Down Expand Up @@ -224,9 +224,9 @@ private FieldFormatterCleanup getFieldFormatterCleanup() {

private Formatter getFieldFormatter() {
Formatter selectedFormatter = null;
String selectedFormatterKey = formattersCombobox.getSelectedItem().toString();
String selectedFormatterName = formattersCombobox.getSelectedItem().toString();
for (Formatter formatter : fieldFormatterCleanups.getAvailableFormatters()) {
if (formatter.getKey().equals(selectedFormatterKey)) {
if (formatter.getName().equals(selectedFormatterName)) {
selectedFormatter = formatter;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/
package net.sf.jabref.gui.fieldeditors.contextmenu;

import net.sf.jabref.logic.formatter.BibtexFieldFormatters;
import net.sf.jabref.logic.formatter.Formatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.Converters;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
Expand All @@ -34,9 +35,9 @@ public class ConversionMenu extends JMenu {
public ConversionMenu(JTextComponent opener) {
super(Localization.lang("Convert"));
// create menu items, one for each case changer
for (final Converters.Converter converter : Converters.ALL) {
for (Formatter converter : BibtexFieldFormatters.CONVERTERS) {
JMenuItem menuItem = new JMenuItem(converter.getName());
menuItem.addActionListener(e -> opener.setText(converter.convert(opener.getText())));
menuItem.addActionListener(e -> opener.setText(converter.format(opener.getText())));
this.add(menuItem);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import net.sf.jabref.gui.actions.CopyAction;
import net.sf.jabref.gui.actions.PasteAction;
import net.sf.jabref.gui.fieldeditors.FieldEditor;
import net.sf.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.util.strings.StringUtil;
import net.sf.jabref.logic.formatter.bibtexfields.AuthorsFormatter;

public class FieldTextMenu implements MouseListener {
private final FieldEditor field;
Expand Down Expand Up @@ -109,7 +109,7 @@ public void actionPerformed(ActionEvent evt) {
return;
}
String input = field.getText();
field.setText(new AuthorsFormatter().format(input));
field.setText(new NormalizeNamesFormatter().format(input));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.sf.jabref.bibtex.BibtexSingleFieldProperties;
import net.sf.jabref.bibtex.InternalBibtexFields;
import net.sf.jabref.logic.layout.LayoutFormatter;
import net.sf.jabref.logic.layout.format.FormatChars;
import net.sf.jabref.logic.layout.format.LatexToUnicodeFormatter;
import net.sf.jabref.model.database.BibDatabase;
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.model.entry.EntryUtil;
Expand All @@ -22,7 +22,7 @@ public class MainTableColumn {

private final Optional<BibDatabase> database;

private final LayoutFormatter toUnicode = new FormatChars();
private final LayoutFormatter toUnicode = new LatexToUnicodeFormatter();

public MainTableColumn(String columnName) {
this.columnName = columnName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void initialize() {
int tmpLabelWidth;
for (String field : joint) {
jointStrings[row - 2] = field;
label = new JLabel(CaseChangers.UPPER_FIRST.format(field));
label = new JLabel(CaseChangers.TO_SENTENCE_CASE.format(field));
font = label.getFont();
label.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
mergePanel.add(label, cc.xy(1, row));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import net.sf.jabref.importer.ImportInspector;
import net.sf.jabref.importer.OutputPrinter;
import net.sf.jabref.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.formatter.bibtexfields.HTMLToLatexFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.UnitFormatter;
import net.sf.jabref.logic.formatter.casechanger.CaseKeeper;
import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter;
import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.net.URLDownload;
import net.sf.jabref.model.entry.BibEntry;
Expand Down Expand Up @@ -54,9 +54,9 @@ public class ACMPortalFetcher implements PreviewEntryFetcher {

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

private final HTMLToLatexFormatter htmlConverter = new HTMLToLatexFormatter();
private final CaseKeeper caseKeeper = new CaseKeeper();
private final UnitFormatter unitFormatter = new UnitFormatter();
private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter();
private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter();
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();
private String terms;

private static final String START_URL = "http://portal.acm.org/";
Expand Down Expand Up @@ -196,12 +196,12 @@ public void getEntries(Map<String, Boolean> selection, ImportInspector inspector

// Unit formatting
if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) {
title = unitFormatter.format(title);
title = unitsToLatexFormatter.format(title);
}

// Case keeping
if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) {
title = caseKeeper.format(title);
title = protectTermsFormatter.format(title);
}
entry.setField("title", title);
});
Expand Down Expand Up @@ -377,7 +377,7 @@ private static Optional<BibEntry> downloadEntryBibTeX(String id, boolean downloa
*/
private String convertHTMLChars(String text) {

return htmlConverter.format(text);
return htmlToLatexFormatter.format(text);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import net.sf.jabref.importer.ImportInspector;
import net.sf.jabref.importer.OutputPrinter;
import net.sf.jabref.logic.formatter.bibtexfields.NormalizeNamesFormatter;
import net.sf.jabref.model.entry.IdGenerator;
import net.sf.jabref.logic.net.URLDownload;
import net.sf.jabref.logic.formatter.bibtexfields.AuthorsFormatter;
import net.sf.jabref.model.entry.BibEntry;

import javax.swing.*;
Expand Down Expand Up @@ -159,7 +159,7 @@ private static BibEntry getSingleCitation(String urlString) throws IOException {
m = CiteSeerXFetcher.AUTHOR_PATTERN.matcher(cont);
if (m.find()) {
String authors = m.group(1);
entry.setField("author", new AuthorsFormatter().format(authors));
entry.setField("author", new NormalizeNamesFormatter().format(authors));
}

// Find year:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand All @@ -35,8 +36,7 @@
import net.sf.jabref.model.entry.BibEntry;
import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.logic.formatter.bibtexfields.UnitFormatter;
import net.sf.jabref.logic.formatter.casechanger.CaseKeeper;
import net.sf.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.net.URLDownload;
import net.sf.jabref.logic.util.DOI;
Expand All @@ -45,8 +45,8 @@ public class DOItoBibTeXFetcher implements EntryFetcher {

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

private final CaseKeeper caseKeeper = new CaseKeeper();
private final UnitFormatter unitFormatter = new UnitFormatter();
private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter();
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();


@Override
Expand Down Expand Up @@ -136,12 +136,12 @@ public BibEntry getEntryFromDOI(String doiStr, OutputPrinter status) {
entry.getFieldOptional("title").ifPresent(title -> {
// Unit formatting
if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) {
title = unitFormatter.format(title);
title = unitsToLatexFormatter.format(title);
}

// Case keeping
if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) {
title = caseKeeper.format(title);
title = protectTermsFormatter.format(title);
}
entry.setField("title", title);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand All @@ -34,8 +35,7 @@
import net.sf.jabref.Globals;
import net.sf.jabref.JabRefPreferences;
import net.sf.jabref.logic.formatter.bibtexfields.UnicodeToLatexFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.UnitFormatter;
import net.sf.jabref.logic.formatter.casechanger.CaseKeeper;
import net.sf.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.net.URLDownload;

Expand All @@ -44,8 +44,8 @@ public class DiVAtoBibTeXFetcher implements EntryFetcher {
private static final Log LOGGER = LogFactory.getLog(DiVAtoBibTeXFetcher.class);

private static final String URL_PATTERN = "http://www.diva-portal.org/smash/getreferences?referenceFormat=BibTex&pids=%s";
private final CaseKeeper caseKeeper = new CaseKeeper();
private final UnitFormatter unitFormatter = new UnitFormatter();
private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter();
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();

@Override
public void stopFetching() {
Expand Down Expand Up @@ -96,12 +96,12 @@ public boolean processQuery(String query, ImportInspector inspector, OutputPrint
entry.getFieldOptional("title").ifPresent(title -> {
// Unit formatting
if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) {
title = unitFormatter.format(title);
title = unitsToLatexFormatter.format(title);
}

// Case keeping
if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) {
title = caseKeeper.format(title);
title = protectTermsFormatter.format(title);
}
entry.setField("title", title);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import net.sf.jabref.logic.formatter.casechanger.ProtectTermsFormatter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
Expand All @@ -46,9 +47,8 @@
import net.sf.jabref.*;
import net.sf.jabref.importer.*;
import net.sf.jabref.importer.fileformat.BibtexParser;
import net.sf.jabref.logic.formatter.bibtexfields.HTMLToLatexFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.UnitFormatter;
import net.sf.jabref.logic.formatter.casechanger.CaseKeeper;
import net.sf.jabref.logic.formatter.bibtexfields.HtmlToLatexFormatter;
import net.sf.jabref.logic.formatter.bibtexfields.UnitsToLatexFormatter;
import net.sf.jabref.logic.journals.JournalAbbreviationLoader;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.logic.net.URLDownload;
Expand Down Expand Up @@ -78,9 +78,9 @@ public class IEEEXploreFetcher implements EntryFetcher {
private static final String SUPER_TEXT_RESULT = "\\\\textsuperscript\\{$1\\}";
private static final String SUPER_EQ_RESULT = "\\$\\^\\{$1\\}\\$";

private final CaseKeeper caseKeeper = new CaseKeeper();
private final UnitFormatter unitFormatter = new UnitFormatter();
private final HTMLToLatexFormatter htmlConverter = new HTMLToLatexFormatter();
private final ProtectTermsFormatter protectTermsFormatter = new ProtectTermsFormatter();
private final UnitsToLatexFormatter unitsToLatexFormatter = new UnitsToLatexFormatter();
private final HtmlToLatexFormatter htmlToLatexFormatter = new HtmlToLatexFormatter();
private final JCheckBox absCheckBox = new JCheckBox(Localization.lang("Include abstracts"), false);

private boolean shouldContinue;
Expand Down Expand Up @@ -259,7 +259,7 @@ private String preprocessBibtexResultsPage(String bibtexPage) {
result = result.replaceAll("(?<!\\\\)%", "\\\\%");

//Format the bibtexResults using the HTML formatter (clears up numerical and text escaped characters and remaining HTML tags)
result = htmlConverter.format(result);
result = htmlToLatexFormatter.format(result);

return result;
}
Expand Down Expand Up @@ -298,12 +298,12 @@ private BibEntry cleanup(BibEntry entry) {

// Unit formatting
if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) {
title = unitFormatter.format(title);
title = unitsToLatexFormatter.format(title);
}

// Automatic case keeping
if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) {
title = caseKeeper.format(title);
title = protectTermsFormatter.format(title);
}
// Write back
entry.setField("title", title);
Expand Down
Loading