From e597bb98cdf764b01c4bf7f154008820776b96d0 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 4 May 2017 11:38:28 +0200 Subject: [PATCH 01/38] Readd WhitespaceAround rule --- config/checkstyle/checkstyle.xml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 143efa1eb78..fa31823df20 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -27,13 +27,26 @@ - + + + + + + + From 45435927242d8b1de50e6651e57697290e44f4e5 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sat, 6 May 2017 21:21:31 +0200 Subject: [PATCH 02/38] Reimplement option field editors in JavaFX (#2824) * Reimplement option field editors in JavaFX * Update localization * Update EditorTypeEditorViewModel.java * Update GenderEditorViewModel.java * Update PaginationEditorViewModel.java * Update PatentTypeEditorViewModel.java * Update TypeEditorViewModel.java * Update YesNoEditorViewModel.java --- .../jabref/gui/entryeditor/EntryEditor.java | 13 -- .../gui/entryeditor/EntryEditorTab.java | 2 +- .../gui/entryeditor/FieldExtraComponents.java | 170 ------------------ .../EditorTypeEditorViewModel.java | 31 ++++ .../jabref/gui/fieldeditors/FieldEditors.java | 23 +-- .../fieldeditors/GenderEditorViewModel.java | 31 ++++ .../fieldeditors/MapBasedEditorViewModel.java | 44 +++++ .../fieldeditors/MonthEditorViewModel.java | 55 ++++++ .../jabref/gui/fieldeditors/OptionEditor.fxml | 7 + .../jabref/gui/fieldeditors/OptionEditor.java | 46 +++++ .../fieldeditors/OptionEditorViewModel.java | 14 ++ .../PaginationEditorViewModel.java | 31 ++++ .../PatentTypeEditorViewModel.java | 36 ++++ .../gui/fieldeditors/TypeEditorViewModel.java | 32 ++++ .../fieldeditors/YesNoEditorViewModel.java | 24 +++ src/main/resources/l10n/JabRef_da.properties | 4 - src/main/resources/l10n/JabRef_de.properties | 4 - src/main/resources/l10n/JabRef_en.properties | 4 - src/main/resources/l10n/JabRef_es.properties | 4 - src/main/resources/l10n/JabRef_fa.properties | 4 - src/main/resources/l10n/JabRef_fr.properties | 4 - src/main/resources/l10n/JabRef_in.properties | 4 - src/main/resources/l10n/JabRef_it.properties | 4 - src/main/resources/l10n/JabRef_ja.properties | 4 - src/main/resources/l10n/JabRef_nl.properties | 4 - src/main/resources/l10n/JabRef_no.properties | 4 - .../resources/l10n/JabRef_pt_BR.properties | 4 - src/main/resources/l10n/JabRef_ru.properties | 4 - src/main/resources/l10n/JabRef_sv.properties | 4 - src/main/resources/l10n/JabRef_tr.properties | 4 - src/main/resources/l10n/JabRef_vi.properties | 4 - src/main/resources/l10n/JabRef_zh.properties | 4 - 32 files changed, 364 insertions(+), 263 deletions(-) create mode 100644 src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/OptionEditor.fxml create mode 100644 src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java create mode 100644 src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java index 023448a6e96..826e3cac1cb 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.java @@ -588,19 +588,6 @@ public Optional getExtra(final FieldEditor editor) { if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) { return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction); - } else if (fieldExtras.contains(FieldProperty.YES_NO)) { - return FieldExtraComponents.getYesNoExtraComponent(editor, this); - } else if (fieldExtras.contains(FieldProperty.MONTH)) { - return FieldExtraComponents.getMonthExtraComponent(editor, this, - frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); - } else if (fieldExtras.contains(FieldProperty.GENDER)) { - return FieldExtraComponents.getGenderExtraComponent(editor, this); - } else if (fieldExtras.contains(FieldProperty.EDITOR_TYPE)) { - return FieldExtraComponents.getEditorTypeExtraComponent(editor, this); - } else if (fieldExtras.contains(FieldProperty.PAGINATION)) { - return FieldExtraComponents.getPaginationExtraComponent(editor, this); - } else if (fieldExtras.contains(FieldProperty.TYPE)) { - return FieldExtraComponents.getTypeExtraComponent(editor, this, "patent".equalsIgnoreCase(entry.getType())); } return Optional.empty(); } diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java index 1509c68c39e..f877e8f4b3b 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java @@ -153,7 +153,7 @@ private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField fieldEditor.setAutoCompleteListener(autoCompleteListener); */ - FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext()); + FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext(), entry.getType()); editors.put(fieldName, fieldEditor); /* // TODO: Reenable this diff --git a/src/main/java/org/jabref/gui/entryeditor/FieldExtraComponents.java b/src/main/java/org/jabref/gui/entryeditor/FieldExtraComponents.java index 123f5179158..5603aaa0b49 100644 --- a/src/main/java/org/jabref/gui/entryeditor/FieldExtraComponents.java +++ b/src/main/java/org/jabref/gui/entryeditor/FieldExtraComponents.java @@ -1,14 +1,8 @@ package org.jabref.gui.entryeditor; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; -import javax.swing.JComboBox; import javax.swing.JComponent; import org.jabref.gui.BasePanel; @@ -16,72 +10,14 @@ import org.jabref.gui.contentselector.FieldContentSelector; import org.jabref.gui.entryeditor.EntryEditor.StoreFieldAction; import org.jabref.gui.fieldeditors.FieldEditor; -import org.jabref.logic.l10n.Localization; -import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.FieldProperty; import org.jabref.model.entry.InternalBibtexFields; -import org.jabref.model.entry.Month; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; public class FieldExtraComponents { - private static final Log LOGGER = LogFactory.getLog(FieldExtraComponents.class); - private FieldExtraComponents() { } - /** - * Return a dropdown list containing Yes and No for fields with EXTRA_YES_NO - * - * @param fieldEditor - * @param entryEditor - * @return - */ - public static Optional getYesNoExtraComponent(FieldEditor fieldEditor, EntryEditor entryEditor) { - final String[] options = {"", "Yes", "No"}; - JComboBox yesno = new JComboBox<>(options); - yesno.addActionListener(actionEvent -> { - fieldEditor.setText(((String) yesno.getSelectedItem()).toLowerCase(Locale.ROOT)); - entryEditor.updateField(fieldEditor); - }); - return Optional.of(yesno); - - } - - /** - * Return a dropdown list with the month names for fields with EXTRA_MONTH - * - * @param fieldEditor - * @param entryEditor - * @param type - * @return - */ - public static Optional getMonthExtraComponent(FieldEditor fieldEditor, EntryEditor entryEditor, BibDatabaseMode type) { - List monthNames = Arrays.stream(Month.values()).map(Month::getFullName).collect(Collectors.toList()); - List options = new ArrayList<>(13); - options.add(Localization.lang("Select")); - options.addAll(monthNames); - - JComboBox month = new JComboBox<>(options.toArray(new String[0])); - month.addActionListener(actionEvent -> { - int monthNumber = month.getSelectedIndex(); - if (monthNumber >= 1) { - if (type == BibDatabaseMode.BIBLATEX) { - fieldEditor.setText(String.valueOf(monthNumber)); - } else { - fieldEditor.setText(Month.getMonthByNumber(monthNumber).get().getJabRefFormat()); - } - } else { - fieldEditor.setText(""); - } - entryEditor.updateField(fieldEditor); - month.setSelectedIndex(0); - }); - return Optional.of(month); - - } /** * Return a button opening a content selector for fields where one exists @@ -101,110 +37,4 @@ public static Optional getSelectorExtraComponent(JabRefFrame frame, contentSelectors.add(ws); return Optional.of(ws); } - - /** - * Return a dropdown list with the alternatives for editor type fields - * - * @param fieldEditor - * @param entryEditor - * @return - */ - - public static Optional getEditorTypeExtraComponent(FieldEditor fieldEditor, EntryEditor entryEditor) { - final String[] optionValues = {"", "editor", "compiler", "founder", "continuator", "redactor", "reviser", - "collaborator"}; - final String[] optionDescriptions = {Localization.lang("Select"), Localization.lang("Editor"), - Localization.lang("Compiler"), Localization.lang("Founder"), Localization.lang("Continuator"), - Localization.lang("Redactor"), Localization.lang("Reviser"), Localization.lang("Collaborator")}; - JComboBox editorType = new JComboBox<>(optionDescriptions); - editorType.addActionListener(actionEvent -> { - fieldEditor.setText(optionValues[editorType.getSelectedIndex()]); - entryEditor.updateField(fieldEditor); - }); - return Optional.of(editorType); - - } - - /** - * Return a dropdown list with the alternatives for pagination type fields - * - * @param fieldEditor - * @param entryEditor - * @return - */ - - public static Optional getPaginationExtraComponent(FieldEditor fieldEditor, EntryEditor entryEditor) { - final String[] optionValues = {"", "page", "column", "line", "verse", "section", "paragraph", "none"}; - final String[] optionDescriptions = {Localization.lang("Select"), Localization.lang("Page"), - Localization.lang("Column"), Localization.lang("Line"), Localization.lang("Verse"), - Localization.lang("Section"), Localization.lang("Paragraph"), Localization.lang("None")}; - JComboBox pagination = new JComboBox<>(optionDescriptions); - pagination.addActionListener(actionEvent -> { - fieldEditor.setText(optionValues[pagination.getSelectedIndex()]); - entryEditor.updateField(fieldEditor); - }); - return Optional.of(pagination); - } - - /** - * Return a dropdown list with the alternatives for pagination type fields - * - * @param fieldEditor - * @param entryEditor - * @return - */ - - public static Optional getTypeExtraComponent(FieldEditor fieldEditor, EntryEditor entryEditor, - boolean isPatent) { - String[] optionValues; - String[] optionDescriptions; - if (isPatent) { - optionValues = new String[] {"", "patent", "patentde", "patenteu", "patentfr", "patentuk", "patentus", - "patreq", "patreqde", "patreqeu", "patreqfr", "patrequk", "patrequs"}; - optionDescriptions = new String[] {Localization.lang("Select"), Localization.lang("Patent"), - Localization.lang("German patent"), Localization.lang("European patent"), - Localization.lang("French patent"), Localization.lang("British patent"), - Localization.lang("U.S. patent"), Localization.lang("Patent request"), - Localization.lang("German patent request"), Localization.lang("European patent request"), - Localization.lang("French patent request"), Localization.lang("British patent request"), - Localization.lang("U.S. patent request")}; - } else { - optionValues = new String[] {"", "mathesis", "phdthesis", "candthesis", "techreport", "resreport", - "software", "datacd", "audiocd"}; - optionDescriptions = new String[] {Localization.lang("Select"), Localization.lang("Master's thesis"), - Localization.lang("PhD thesis"), Localization.lang("Candidate thesis"), - Localization.lang("Technical report"), Localization.lang("Research report"), - Localization.lang("Software"), Localization.lang("Data CD"), Localization.lang("Audio CD")}; - } - JComboBox type = new JComboBox<>(optionDescriptions); - type.addActionListener(actionEvent -> { - fieldEditor.setText(optionValues[type.getSelectedIndex()]); - entryEditor.updateField(fieldEditor); - }); - return Optional.of(type); - } - - /** - * Return a dropdown list with the gender alternatives for fields with GENDER - * - * @param fieldEditor - * @param entryEditor - * @return - */ - - public static Optional getGenderExtraComponent(FieldEditor fieldEditor, EntryEditor entryEditor) { - final String[] optionValues = {"", "sf", "sm", "sp", "pf", "pm", "pn", "pp"}; - final String[] optionDescriptions = {Localization.lang("Select"), Localization.lang("Female name"), - Localization.lang("Male name"), - Localization.lang("Neuter name"), Localization.lang("Female names"), Localization.lang("Male names"), - Localization.lang("Neuter names"), Localization.lang("Mixed names")}; - JComboBox gender = new JComboBox<>(optionDescriptions); - gender.addActionListener(actionEvent -> { - fieldEditor.setText(optionValues[gender.getSelectedIndex()]); - entryEditor.updateField(fieldEditor); - }); - return Optional.of(gender); - - } - } diff --git a/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java new file mode 100644 index 00000000000..ea05ee521ae --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/EditorTypeEditorViewModel.java @@ -0,0 +1,31 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.logic.l10n.Localization; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +public class EditorTypeEditorViewModel extends MapBasedEditorViewModel { + + private BiMap itemMap = HashBiMap.create(7); + + public EditorTypeEditorViewModel() { + itemMap.put("editor", Localization.lang("Editor")); + itemMap.put("compiler", Localization.lang("Compiler")); + itemMap.put("founder", Localization.lang("Founder")); + itemMap.put("continuator", Localization.lang("Continuator")); + itemMap.put("redactor", Localization.lang("Redactor")); + itemMap.put("reviser", Localization.lang("Reviser")); + itemMap.put("collaborator", Localization.lang("Collaborator")); + } + + @Override + protected BiMap getItemMap() { + return itemMap; + } + + @Override + public String convertToDisplayText(String object) { + return object; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java index a41588603fe..9780e56f70c 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java +++ b/src/main/java/org/jabref/gui/fieldeditors/FieldEditors.java @@ -15,10 +15,9 @@ public class FieldEditors { - public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext) { + public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecutor, DialogService dialogService, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences, JabRefPreferences preferences, BibDatabaseContext databaseContext, String entryType) { final Set fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); - // TODO: Implement all of them if (Globals.prefs.get(JabRefPreferences.TIME_STAMP_FIELD).equals(fieldName) || fieldExtras.contains(FieldProperty.DATE)) { if (fieldExtras.contains(FieldProperty.ISO_DATE)) { return new DateEditor(fieldName, DateTimeFormatter.ofPattern("[uuuu][-MM][-dd]")); @@ -29,26 +28,28 @@ public static FieldEditorFX getForField(String fieldName, TaskExecutor taskExecu return new UrlEditor(fieldName, dialogService); } else if (fieldExtras.contains(FieldProperty.JOURNAL_NAME)) { return new JournalEditor(fieldName, journalAbbreviationLoader, journalAbbreviationPreferences); - } else if (fieldExtras.contains(FieldProperty.DOI) || - fieldExtras.contains(FieldProperty.EPRINT) || - fieldExtras.contains(FieldProperty.ISBN)) { + } else if (fieldExtras.contains(FieldProperty.DOI) || fieldExtras.contains(FieldProperty.EPRINT) || fieldExtras.contains(FieldProperty.ISBN)) { return new IdentifierEditor(fieldName, taskExecutor, dialogService); } else if (fieldExtras.contains(FieldProperty.OWNER)) { return new OwnerEditor(fieldName, preferences); } else if (fieldExtras.contains(FieldProperty.FILE_EDITOR)) { return new LinkedFilesEditor(fieldName, dialogService, databaseContext, taskExecutor); } else if (fieldExtras.contains(FieldProperty.YES_NO)) { - //return FieldExtraComponents.getYesNoExtraComponent(editor, this); + return new OptionEditor<>(fieldName, new YesNoEditorViewModel()); } else if (fieldExtras.contains(FieldProperty.MONTH)) { - //return FieldExtraComponents.getMonthExtraComponent(editor, this, frame.getCurrentBasePanel().getBibDatabaseContext().getMode()); + return new OptionEditor<>(fieldName, new MonthEditorViewModel(databaseContext.getMode())); } else if (fieldExtras.contains(FieldProperty.GENDER)) { - //return FieldExtraComponents.getGenderExtraComponent(editor, this); + return new OptionEditor<>(fieldName, new GenderEditorViewModel()); } else if (fieldExtras.contains(FieldProperty.EDITOR_TYPE)) { - //return FieldExtraComponents.getEditorTypeExtraComponent(editor, this); + return new OptionEditor<>(fieldName, new EditorTypeEditorViewModel()); } else if (fieldExtras.contains(FieldProperty.PAGINATION)) { - //return FieldExtraComponents.getPaginationExtraComponent(editor, this); + return new OptionEditor<>(fieldName, new PaginationEditorViewModel()); } else if (fieldExtras.contains(FieldProperty.TYPE)) { - //return FieldExtraComponents.getTypeExtraComponent(editor, this, "patent".equalsIgnoreCase(entry.getType())); + if ("patent".equalsIgnoreCase(entryType)) { + return new OptionEditor<>(fieldName, new PatentTypeEditorViewModel()); + } else { + return new OptionEditor<>(fieldName, new TypeEditorViewModel()); + } } // default diff --git a/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java new file mode 100644 index 00000000000..7df18b82bb7 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/GenderEditorViewModel.java @@ -0,0 +1,31 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.logic.l10n.Localization; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +public class GenderEditorViewModel extends MapBasedEditorViewModel { + + private BiMap itemMap = HashBiMap.create(7); + + public GenderEditorViewModel() { + itemMap.put("sf", Localization.lang("Female name")); + itemMap.put("sm", Localization.lang("Male name")); + itemMap.put("sn", Localization.lang("Neuter name")); + itemMap.put("pf", Localization.lang("Female names")); + itemMap.put("pm", Localization.lang("Male names")); + itemMap.put("pn", Localization.lang("Neuter names")); + itemMap.put("pp", Localization.lang("Mixed names")); + } + + @Override + protected BiMap getItemMap() { + return itemMap; + } + + @Override + public String convertToDisplayText(String object) { + return object; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java new file mode 100644 index 00000000000..0dd82a758f1 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/MapBasedEditorViewModel.java @@ -0,0 +1,44 @@ +package org.jabref.gui.fieldeditors; + +import java.util.ArrayList; +import java.util.List; + +import javafx.util.StringConverter; + +import com.google.common.collect.BiMap; + +/** + * View model for a field editor that shows various options backed by a map. + */ +public abstract class MapBasedEditorViewModel extends OptionEditorViewModel { + + protected abstract BiMap getItemMap(); + + @Override + public StringConverter getStringConverter() { + return new StringConverter() { + @Override + public String toString(T object) { + if (object == null) { + return null; + } else { + return getItemMap().inverse().getOrDefault(object, ""); + } + } + + @Override + public T fromString(String string) { + if (string == null) { + return null; + } else { + return getItemMap().getOrDefault(string, null); + } + } + }; + } + + @Override + public List getItems() { + return new ArrayList<>(getItemMap().values()); + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java new file mode 100644 index 00000000000..a9c0b3563f1 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/MonthEditorViewModel.java @@ -0,0 +1,55 @@ +package org.jabref.gui.fieldeditors; + +import java.util.Arrays; +import java.util.List; + +import javafx.util.StringConverter; + +import org.jabref.model.database.BibDatabaseMode; +import org.jabref.model.entry.Month; +import org.jabref.model.strings.StringUtil; + +public class MonthEditorViewModel extends OptionEditorViewModel { + private BibDatabaseMode databaseMode; + + public MonthEditorViewModel(BibDatabaseMode databaseMode) { + this.databaseMode = databaseMode; + } + + @Override + public StringConverter getStringConverter() { + return new StringConverter() { + @Override + public String toString(Month object) { + if (object == null) { + return null; + } else { + if (databaseMode == BibDatabaseMode.BIBLATEX) { + return String.valueOf(object.getNumber()); + } else { + return object.getJabRefFormat(); + } + } + } + + @Override + public Month fromString(String string) { + if (StringUtil.isNotBlank(string)) { + return Month.parse(string).orElse(null); + } else { + return null; + } + } + }; + } + + @Override + public List getItems() { + return Arrays.asList(Month.values()); + } + + @Override + public String convertToDisplayText(Month object) { + return object.getFullName(); + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.fxml b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.fxml new file mode 100644 index 00000000000..2fa6f262ed5 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.fxml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java new file mode 100644 index 00000000000..8718d4b1c49 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditor.java @@ -0,0 +1,46 @@ +package org.jabref.gui.fieldeditors; + +import javafx.fxml.FXML; +import javafx.scene.Parent; +import javafx.scene.control.ComboBox; +import javafx.scene.layout.HBox; + +import org.jabref.gui.util.ControlHelper; +import org.jabref.gui.util.ViewModelListCellFactory; +import org.jabref.model.entry.BibEntry; + +/** + * Field editor that provides various pre-defined options as a drop-down combobox. + */ +public class OptionEditor extends HBox implements FieldEditorFX { + + private final String fieldName; + @FXML private OptionEditorViewModel viewModel; + @FXML private ComboBox comboBox; + + public OptionEditor(String fieldName, OptionEditorViewModel viewModel) { + this.fieldName = fieldName; + this.viewModel = viewModel; + + ControlHelper.loadFXMLForControl(this); + + comboBox.setConverter(viewModel.getStringConverter()); + comboBox.setCellFactory(new ViewModelListCellFactory().withText(viewModel::convertToDisplayText)); + comboBox.getItems().setAll(viewModel.getItems()); + comboBox.getEditor().textProperty().bindBidirectional(viewModel.textProperty()); + } + + public OptionEditorViewModel getViewModel() { + return viewModel; + } + + @Override + public void bindToEntry(BibEntry entry) { + viewModel.bindToEntry(fieldName, entry); + } + + @Override + public Parent getNode() { + return this; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java new file mode 100644 index 00000000000..e899a541d20 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/OptionEditorViewModel.java @@ -0,0 +1,14 @@ +package org.jabref.gui.fieldeditors; + +import java.util.List; + +import javafx.util.StringConverter; + +public abstract class OptionEditorViewModel extends AbstractEditorViewModel { + + public abstract StringConverter getStringConverter(); + + public abstract List getItems(); + + public abstract String convertToDisplayText(T object); +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java new file mode 100644 index 00000000000..c30333c2fb9 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/PaginationEditorViewModel.java @@ -0,0 +1,31 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.logic.l10n.Localization; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +public class PaginationEditorViewModel extends MapBasedEditorViewModel { + + private BiMap itemMap = HashBiMap.create(7); + + public PaginationEditorViewModel() { + itemMap.put("page", Localization.lang("Page")); + itemMap.put("column", Localization.lang("Column")); + itemMap.put("line", Localization.lang("Line")); + itemMap.put("verse", Localization.lang("Verse")); + itemMap.put("section", Localization.lang("Section")); + itemMap.put("paragraph", Localization.lang("Paragraph")); + itemMap.put("none", Localization.lang("None")); + } + + @Override + protected BiMap getItemMap() { + return itemMap; + } + + @Override + public String convertToDisplayText(String object) { + return object; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java new file mode 100644 index 00000000000..8cc3c0a1df0 --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/PatentTypeEditorViewModel.java @@ -0,0 +1,36 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.logic.l10n.Localization; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +public class PatentTypeEditorViewModel extends MapBasedEditorViewModel { + + private BiMap itemMap = HashBiMap.create(12); + + public PatentTypeEditorViewModel() { + itemMap.put("patent", Localization.lang("Patent")); + itemMap.put("patentde", Localization.lang("German patent")); + itemMap.put("patenteu", Localization.lang("European patent")); + itemMap.put("patentfr", Localization.lang("French patent")); + itemMap.put("patentuk", Localization.lang("British patent")); + itemMap.put("patentus", Localization.lang("U.S. patent")); + itemMap.put("patreq", Localization.lang("Patent request")); + itemMap.put("patreqde", Localization.lang("German patent request")); + itemMap.put("patreqeu", Localization.lang("European patent request")); + itemMap.put("patreqfr", Localization.lang("French patent request")); + itemMap.put("patrequk", Localization.lang("British patent request")); + itemMap.put("patrequs", Localization.lang("U.S. patent request")); + } + + @Override + protected BiMap getItemMap() { + return itemMap; + } + + @Override + public String convertToDisplayText(String object) { + return object; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java new file mode 100644 index 00000000000..852c8c97c9b --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/TypeEditorViewModel.java @@ -0,0 +1,32 @@ +package org.jabref.gui.fieldeditors; + +import org.jabref.logic.l10n.Localization; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +public class TypeEditorViewModel extends MapBasedEditorViewModel { + + private BiMap itemMap = HashBiMap.create(8); + + public TypeEditorViewModel() { + itemMap.put("mathesis", Localization.lang("Master's thesis")); + itemMap.put("phdthesis", Localization.lang("PhD thesis")); + itemMap.put("candthesis", Localization.lang("Candidate thesis")); + itemMap.put("techreport", Localization.lang("Technical report")); + itemMap.put("resreport", Localization.lang("Research report")); + itemMap.put("software", Localization.lang("Software")); + itemMap.put("datacd", Localization.lang("Data CD")); + itemMap.put("audiocd", Localization.lang("Audio CD")); + } + + @Override + protected BiMap getItemMap() { + return itemMap; + } + + @Override + public String convertToDisplayText(String object) { + return object; + } +} diff --git a/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java new file mode 100644 index 00000000000..3220231982d --- /dev/null +++ b/src/main/java/org/jabref/gui/fieldeditors/YesNoEditorViewModel.java @@ -0,0 +1,24 @@ +package org.jabref.gui.fieldeditors; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +public class YesNoEditorViewModel extends MapBasedEditorViewModel { + + private BiMap itemMap = HashBiMap.create(2); + + public YesNoEditorViewModel() { + itemMap.put("yes", "Yes"); + itemMap.put("no", "No"); + } + + @Override + protected BiMap getItemMap() { + return itemMap; + } + + @Override + public String convertToDisplayText(String object) { + return object; + } +} diff --git a/src/main/resources/l10n/JabRef_da.properties b/src/main/resources/l10n/JabRef_da.properties index 428f8b28daa..b2cd3e0416c 100644 --- a/src/main/resources/l10n/JabRef_da.properties +++ b/src/main/resources/l10n/JabRef_da.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Søger_efter_filer Secondary_sort_criterion=Sekundært_sorteringskriterium -Select=Vælg - - - Select_all=Vælg_alle Select_encoding=Vælg_tegnkodning diff --git a/src/main/resources/l10n/JabRef_de.properties b/src/main/resources/l10n/JabRef_de.properties index 543487b122c..9ac956f6419 100644 --- a/src/main/resources/l10n/JabRef_de.properties +++ b/src/main/resources/l10n/JabRef_de.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Suche_nach_Dateien Secondary_sort_criterion=Zweites_Sortierkriterium -Select=Auswählen - - - Select_all=Alle_auswählen Select_encoding=Kodierung_wählen diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 386fbb8443b..bb2264f24cd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Searching_for_files Secondary_sort_criterion=Secondary_sort_criterion -Select=Select - - - Select_all=Select_all Select_encoding=Select_encoding diff --git a/src/main/resources/l10n/JabRef_es.properties b/src/main/resources/l10n/JabRef_es.properties index 4903090a848..8ddc2b2ed6c 100644 --- a/src/main/resources/l10n/JabRef_es.properties +++ b/src/main/resources/l10n/JabRef_es.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Buscando_archivos Secondary_sort_criterion=Criterio_secundario_de_ordenación -Select=Seleccionar - - - Select_all=Seleccionar_todo Select_encoding=Seleccionar_codificación diff --git a/src/main/resources/l10n/JabRef_fa.properties b/src/main/resources/l10n/JabRef_fa.properties index 769ec0afb75..ddbe5713999 100644 --- a/src/main/resources/l10n/JabRef_fa.properties +++ b/src/main/resources/l10n/JabRef_fa.properties @@ -1082,10 +1082,6 @@ Searching_for_files= Secondary_sort_criterion= -Select= - - - Select_all= Select_encoding= diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index 4c92cd66b42..fddc65b054b 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Recherche_de_fichiers... Secondary_sort_criterion=Critère_secondaire_de_tri -Select=Sélectionner - - - Select_all=Tout_sélectionner Select_encoding=Sélectionner_l'encodage diff --git a/src/main/resources/l10n/JabRef_in.properties b/src/main/resources/l10n/JabRef_in.properties index 1af40b6f247..63b8a115ce5 100644 --- a/src/main/resources/l10n/JabRef_in.properties +++ b/src/main/resources/l10n/JabRef_in.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Mencari_berkas Secondary_sort_criterion=Kriteria_kedua -Select=Pilih - - - Select_all=Pilih_semua Select_encoding=Pilih_enkoding diff --git a/src/main/resources/l10n/JabRef_it.properties b/src/main/resources/l10n/JabRef_it.properties index 2e763c8d2ec..8d9727cb899 100644 --- a/src/main/resources/l10n/JabRef_it.properties +++ b/src/main/resources/l10n/JabRef_it.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Ricerca_dei_file Secondary_sort_criterion=Criterio_di_ordinamento_secondario -Select=Seleziona - - - Select_all=Seleziona_tutto Select_encoding=Seleziona_la_codifica diff --git a/src/main/resources/l10n/JabRef_ja.properties b/src/main/resources/l10n/JabRef_ja.properties index a780970c196..5cf62087ac7 100644 --- a/src/main/resources/l10n/JabRef_ja.properties +++ b/src/main/resources/l10n/JabRef_ja.properties @@ -1082,10 +1082,6 @@ Searching_for_files=ファイルを検索しています Secondary_sort_criterion=第二整序基準 -Select=選択 - - - Select_all=すべて選択 Select_encoding=エンコーディングを選択 diff --git a/src/main/resources/l10n/JabRef_nl.properties b/src/main/resources/l10n/JabRef_nl.properties index 576d843ee30..ce725f8b4ea 100644 --- a/src/main/resources/l10n/JabRef_nl.properties +++ b/src/main/resources/l10n/JabRef_nl.properties @@ -1082,10 +1082,6 @@ Searching_for_files= Secondary_sort_criterion=Secundair_sorteercriterium -Select=Selecteer - - - Select_all=Alles_selecteren Select_encoding=Selecteer_encodering diff --git a/src/main/resources/l10n/JabRef_no.properties b/src/main/resources/l10n/JabRef_no.properties index 8aadaf14499..2e4512a0b40 100644 --- a/src/main/resources/l10n/JabRef_no.properties +++ b/src/main/resources/l10n/JabRef_no.properties @@ -1082,10 +1082,6 @@ Searching_for_files=S\u00f8ker_etter_filer Secondary_sort_criterion=Andre_sorteringskriterium -Select=Velg - - - Select_all=Velg_alle Select_encoding=Velg_koding diff --git a/src/main/resources/l10n/JabRef_pt_BR.properties b/src/main/resources/l10n/JabRef_pt_BR.properties index 2443ea15c8e..9a1a4f4be10 100644 --- a/src/main/resources/l10n/JabRef_pt_BR.properties +++ b/src/main/resources/l10n/JabRef_pt_BR.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Procurando_por_arquivos... Secondary_sort_criterion=Critério_de_ordenação_secundário -Select=Selecionar - - - Select_all=Selecionar_tudo Select_encoding=Selecionar_codificação diff --git a/src/main/resources/l10n/JabRef_ru.properties b/src/main/resources/l10n/JabRef_ru.properties index fbfca35cf39..7d1ca0bcb38 100644 --- a/src/main/resources/l10n/JabRef_ru.properties +++ b/src/main/resources/l10n/JabRef_ru.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Выполняется_поиск_файлов... Secondary_sort_criterion=Вторичный_критерий_сортировки -Select=Выбрать - - - Select_all=Выбрать_все Select_encoding=Выбрать_кодировку diff --git a/src/main/resources/l10n/JabRef_sv.properties b/src/main/resources/l10n/JabRef_sv.properties index c1fb6c621fb..ed60d53fdab 100644 --- a/src/main/resources/l10n/JabRef_sv.properties +++ b/src/main/resources/l10n/JabRef_sv.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Söker_efter_filer Secondary_sort_criterion=Andra_sorteringskriteriet -Select=Välj - - - Select_all=Välj_alla Select_encoding=Välj_teckenkodning diff --git a/src/main/resources/l10n/JabRef_tr.properties b/src/main/resources/l10n/JabRef_tr.properties index 6f4bb327f8e..703f9fc0e2b 100644 --- a/src/main/resources/l10n/JabRef_tr.properties +++ b/src/main/resources/l10n/JabRef_tr.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Dosyalar_aranıyor Secondary_sort_criterion=İkincil_sıralama_kriteri -Select=Seç - - - Select_all=Tümünü_seç Select_encoding=Kodlamayı_seç diff --git a/src/main/resources/l10n/JabRef_vi.properties b/src/main/resources/l10n/JabRef_vi.properties index 639ca87af3a..365cc9fa218 100644 --- a/src/main/resources/l10n/JabRef_vi.properties +++ b/src/main/resources/l10n/JabRef_vi.properties @@ -1082,10 +1082,6 @@ Searching_for_files=Đang_tìm_các_tập_tin Secondary_sort_criterion=Tiêu_chuẩn_phân_loại_thứ_cấp -Select=Chọn - - - Select_all=Chọn_tất_cả Select_encoding=Chọn_bộ_mã_hóa diff --git a/src/main/resources/l10n/JabRef_zh.properties b/src/main/resources/l10n/JabRef_zh.properties index ed97b6e785e..f176aebf8db 100644 --- a/src/main/resources/l10n/JabRef_zh.properties +++ b/src/main/resources/l10n/JabRef_zh.properties @@ -1082,10 +1082,6 @@ Searching_for_files=正在查找文件 Secondary_sort_criterion=次要依据 -Select=选择 - - - Select_all=全选 Select_encoding=选择编码 From c98120e3c851018023b158078e2a053522b2353f Mon Sep 17 00:00:00 2001 From: MLEP Date: Sun, 7 May 2017 17:49:26 +0200 Subject: [PATCH 03/38] Localization: General file: French: New entries translated --- src/main/resources/l10n/JabRef_fr.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/l10n/JabRef_fr.properties b/src/main/resources/l10n/JabRef_fr.properties index fddc65b054b..94f0d637875 100644 --- a/src/main/resources/l10n/JabRef_fr.properties +++ b/src/main/resources/l10n/JabRef_fr.properties @@ -2298,7 +2298,7 @@ Do_you_want_to_recover_the_library_from_the_backup_file?=Voulez-vous_récupérer Firstname_Lastname=Prénom_Nom Recommended_for_%0=Recommandé_pour_%0 -Show_'Related_Articles'_tab= +Show_'Related_Articles'_tab=Afficher_l'onglet_'Articles_liés' This_might_be_caused_by_reaching_the_traffic_limitation_of_Google_Scholar_(see_'Help'_for_details).=La_limitation_de_trafic_de_Google_Scholar_pourrait_avoir_été_atteinte_(voir_l'aide_pour_plus_de_détails). Could_not_open_website.=Le_site_internet_n'a_pas_pu_être_ouvert. @@ -2345,7 +2345,7 @@ Locked=Vérrouillé Show_document_viewer=Ouvre_l'afficheur_de_document Show_the_document_of_the_currently_selected_entry.=Affiche_le_document_de_l'entrée_sélectionnée. Show_this_document_until_unlocked.=Affiche_le_document_jusqu'à_déverrouillage. -Set_current_user_name_as_owner.= +Set_current_user_name_as_owner.=Définir_l'utilisateur_actuel_comme_propriétaire. Sort_all_subgroups_(recursively)=Trier_les_sous-groupes_(récursivement) Collect_and_share_telemetry_data_to_help_improve_JabRef.=Collecter_et_partager_les_données_de_télémétrie_pour_contribuer_à_l'amélioration_de_JabRef @@ -2353,4 +2353,4 @@ Don't_share=Ne_pas_partager Share_anonymous_statistics=Partager_anonymement_les_statistiques Telemetry\:_Help_make_JabRef_better=Télémétrie_:_contribue_à_l'amélioration_de_JabRef To_improve_the_user_experience,_we_would_like_to_collect_anonymous_statistics_on_the_features_you_use._We_will_only_record_what_features_you_access_and_how_often_you_do_it._We_will_neither_collect_any_personal_data_nor_the_content_of_bibliographic_items._If_you_choose_to_allow_data_collection,_you_can_later_disable_it_via_Options_->_Preferences_->_General.=Pour_améliorer_l'ergonomie_pour_l'utilisateur,_nous_souhaiterions_collecter_des_statistiques_anonymisées_sur_les_fonctionnalité_que_vous_utilisez._Nous_n'enregistrerons_que_les_fonctionnalités_que_vous_utilisés_et_leur_fréquence_d'utiliations._Nous_n'enregistrerons_jamais_des_données_personneles_ni_le_contenu_de_vos_entrées_bibliographiques._Si_vous_choisissez_d'autoriser_la_collecte_des_données,_vous_pourrez_plus_tard_l'interdire_via_Options_->_Préférences_->_Géneral. -This_file_was_found_automatically._Do_you_want_to_link_it_to_this_entry?= +This_file_was_found_automatically._Do_you_want_to_link_it_to_this_entry?=Ce_fichier_a_été_trouvé_automatiquement._Voulez-vous_le_lier_à_cette_entrée_? From 78185153be818bed63b350b52a145d270d9b84dc Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Tue, 9 May 2017 16:53:06 +0200 Subject: [PATCH 04/38] Editor tab goes JavaFX (#2813) * Convert entry tab to JavaFX * Style entry editor tab * Fix checkstyle.... * Implement feedback --- .../java/org/jabref/gui/PreambleEditor.java | 14 +- .../jabref/gui/entryeditor/EntryEditor.css | 15 ++ .../gui/entryeditor/EntryEditorTab.java | 179 +++++++++--------- .../gui/fieldeditors/EditorTextArea.css | 7 - .../gui/fieldeditors/EditorTextArea.java | 15 -- .../gui/fieldeditors/EntryLinkListEditor.java | 110 +++++------ .../jabref/gui/fieldeditors/FieldEditor.java | 5 - .../gui/fieldeditors/FieldNameLabel.java | 36 +--- .../gui/fieldeditors/FileListEditor.java | 14 -- .../org/jabref/gui/fieldeditors/TextArea.java | 15 -- .../jabref/gui/fieldeditors/TextField.java | 14 -- 11 files changed, 167 insertions(+), 257 deletions(-) create mode 100644 src/main/java/org/jabref/gui/entryeditor/EntryEditor.css delete mode 100644 src/main/java/org/jabref/gui/fieldeditors/EditorTextArea.css diff --git a/src/main/java/org/jabref/gui/PreambleEditor.java b/src/main/java/org/jabref/gui/PreambleEditor.java index f2c9232b55a..ffcfb095c7a 100644 --- a/src/main/java/org/jabref/gui/PreambleEditor.java +++ b/src/main/java/org/jabref/gui/PreambleEditor.java @@ -80,8 +80,8 @@ protected boolean accept(Component c) { // TODO: Reenable this //setupJTextComponent((TextArea) editor); - gbl.setConstraints(editor.getLabel(), con); - pan.add(editor.getLabel()); + //gbl.setConstraints(editor.getLabel(), con); + //pan.add(editor.getLabel()); con.weightx = 1; @@ -156,11 +156,11 @@ public void actionPerformed(ActionEvent e) { panel.getUndoManager().addEdit( new UndoablePreambleChange(database, panel, database.getPreamble().orElse(null), toSet)); database.setPreamble(toSet); - if ((toSet == null) || toSet.isEmpty()) { - editor.setLabelColor(GUIGlobals.NULL_FIELD_COLOR); - } else { - editor.setLabelColor(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); - } + //if ((toSet == null) || toSet.isEmpty()) { + // editor.setLabelColor(GUIGlobals.NULL_FIELD_COLOR); + //} else { + // editor.setLabelColor(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); + //} editor.setValidBackgroundColor(); if (editor.hasFocus()) { editor.setActiveBackgroundColor(); diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css new file mode 100644 index 00000000000..b2b5147a6e9 --- /dev/null +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditor.css @@ -0,0 +1,15 @@ +.text-area { + -fx-text-fill: text-area-foreground; + -fx-control-inner-background: text-area-background; +} + +.text-area *.text { + -fx-alignment: center-left; +} + +.editorPane { + -fx-hgap: 10; + -fx-vgap: 6; + -fx-background-color: text-area-background; + -fx-padding: 0 0 0 5; +} diff --git a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java index f877e8f4b3b..52050cd0e68 100644 --- a/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java +++ b/src/main/java/org/jabref/gui/entryeditor/EntryEditorTab.java @@ -6,23 +6,29 @@ import java.awt.event.FocusListener; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Stream; import javax.swing.ActionMap; import javax.swing.InputMap; import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JScrollPane; import javax.swing.KeyStroke; -import javax.swing.ScrollPaneConstants; import javafx.embed.swing.JFXPanel; +import javafx.scene.Node; +import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.layout.ColumnConstraints; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; +import javafx.scene.layout.Region; +import javafx.scene.layout.RowConstraints; import org.jabref.Globals; import org.jabref.gui.BasePanel; @@ -34,7 +40,6 @@ import org.jabref.gui.fieldeditors.FieldEditorFX; import org.jabref.gui.fieldeditors.FieldEditors; import org.jabref.gui.fieldeditors.FieldNameLabel; -import org.jabref.gui.fieldeditors.TextField; import org.jabref.gui.keyboard.KeyBinding; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.l10n.Localization; @@ -43,20 +48,15 @@ import org.jabref.model.entry.FieldProperty; import org.jabref.model.entry.InternalBibtexFields; -import com.jgoodies.forms.builder.DefaultFormBuilder; -import com.jgoodies.forms.layout.FormLayout; - /** * A single tab displayed in the EntryEditor holding several FieldEditors. */ class EntryEditorTab { - private final JPanel panel = new JPanel(); - private final JScrollPane scrollPane = new JScrollPane(panel, - ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + private final JFXPanel panel = new JFXPanel(); private final List fields; private final EntryEditor parent; - private final Map editors = new HashMap<>(); + private final Map editors = new LinkedHashMap<>(); private final FocusListener fieldListener = new EntryEditorTabFocusListener(this); private final String tabTitle; private final JabRefFrame frame; @@ -66,59 +66,67 @@ class EntryEditorTab { private boolean updating; - public EntryEditorTab(JabRefFrame frame, BasePanel panel, List fields, EntryEditor parent, - boolean addKeyField, boolean compressed, String tabTitle) { + public EntryEditorTab(JabRefFrame frame, BasePanel basePanel, List fields, EntryEditor parent, + boolean addKeyField, boolean compressed, String tabTitle) { if (fields == null) { this.fields = new ArrayList<>(); } else { this.fields = new ArrayList<>(fields); } + // Add the edit field for Bibtex-key. + if (addKeyField) { + this.fields.add(BibEntry.KEY_FIELD); + } this.parent = parent; this.tabTitle = tabTitle; this.frame = frame; - this.basePanel = panel; + this.basePanel = basePanel; + + // Execute on JavaFX Application Thread + DefaultTaskExecutor.runInJavaFXThread(() -> { + Region root = setupPanel(frame, basePanel, addKeyField, compressed, tabTitle); + + if (GUIGlobals.currentFont != null) { + root.setStyle( + "text-area-background: " + convertToHex(GUIGlobals.validFieldBackgroundColor) + ";" + + "text-area-foreground: " + convertToHex(GUIGlobals.editorTextColor) + ";" + + "text-area-highlight: " + convertToHex(GUIGlobals.activeBackgroundColor) + ";" + ); + } - setupPanel(frame, panel, addKeyField, compressed, tabTitle); + root.getStylesheets().add("org/jabref/gui/entryeditor/EntryEditor.css"); + + panel.setScene(new Scene(root)); + }); // The following line makes sure focus cycles inside tab instead of being lost to other parts of the frame: - scrollPane.setFocusCycleRoot(true); + panel.setFocusCycleRoot(true); } - private void setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, - boolean compressed, String title) { + private static void addColumn(GridPane gridPane, int columnIndex, List