From 9a3efb7401d712500cb6289bc946df7de5807a53 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 16 Feb 2017 17:06:54 +0100 Subject: [PATCH 1/7] Refactored quite much around the FileAnnotationCache. The Cache now works as intended, i.e., fully automatically instead of manual maintenance. --- .../java/net/sf/jabref/gui/BasePanel.java | 2 +- .../jabref/gui/entryeditor/EntryEditor.java | 63 ++++----- .../gui/entryeditor/FileAnnotationTab.java | 121 +++++++----------- ...Interface.java => AnnotationImporter.java} | 2 +- .../logic/pdf/EntryAnnotationImporter.java | 54 ++++++++ .../jabref/logic/pdf/FileAnnotationCache.java | 27 +--- ...erImpl.java => PdfAnnotationImporter.java} | 11 +- 7 files changed, 150 insertions(+), 130 deletions(-) rename src/main/java/net/sf/jabref/logic/pdf/{AnnotationImporterInterface.java => AnnotationImporter.java} (84%) create mode 100644 src/main/java/net/sf/jabref/logic/pdf/EntryAnnotationImporter.java rename src/main/java/net/sf/jabref/logic/pdf/{PdfAnnotationImporterImpl.java => PdfAnnotationImporter.java} (95%) diff --git a/src/main/java/net/sf/jabref/gui/BasePanel.java b/src/main/java/net/sf/jabref/gui/BasePanel.java index 8911b85bf95..fd25e45f7e3 100644 --- a/src/main/java/net/sf/jabref/gui/BasePanel.java +++ b/src/main/java/net/sf/jabref/gui/BasePanel.java @@ -206,7 +206,7 @@ public BasePanel(JabRefFrame frame, BibDatabaseContext bibDatabaseContext) { this.tableModel = new MainTableDataModel(getBibDatabaseContext()); citationStyleCache = new CitationStyleCache(bibDatabaseContext); - annotationCache = new FileAnnotationCache(); + annotationCache = new FileAnnotationCache(bibDatabaseContext); setupMainPanel(); diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 9b3b3e0dee6..955712ea2e0 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -26,6 +26,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; import javax.swing.AbstractAction; @@ -57,7 +58,6 @@ import javafx.scene.layout.StackPane; import net.sf.jabref.Globals; - import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.EntryContainer; import net.sf.jabref.gui.GUIGlobals; @@ -335,7 +335,7 @@ private void setupFieldPanels() { addSpecialTabs(); // pdf annotations tab - addPdfTab(); + addPDFAnnotationTab(); //related articles if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_RECOMMENDATIONS)) { @@ -450,12 +450,12 @@ private void addOptionalTab(EntryType type) { /** * Add a tab for displaying comments from a PDF */ - private void addPdfTab() { + private void addPDFAnnotationTab() { tabbed.remove(fileAnnotationTab); tabs.remove(fileAnnotationTab); Optional field = entry.getField(FieldName.FILE); if (field.isPresent()) { - fileAnnotationTab = new FileAnnotationTab(this, panel, tabbed); + fileAnnotationTab = new FileAnnotationTab(this); tabbed.addTab(Localization.lang("File annotations"), IconTheme.JabRefIcon.COMMENT.getSmallIcon(), fileAnnotationTab, Localization.lang("Show file annotations")); tabs.add(fileAnnotationTab); @@ -597,7 +597,7 @@ public void rebuildPanels() { * @param editor Field editor * @return Component to show, or null if none. */ - public Optional getExtra(final FieldEditor editor) { + Optional getExtra(final FieldEditor editor) { final String fieldName = editor.getFieldName(); final Set fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); @@ -1007,7 +1007,7 @@ private void unregisterListeners() { } private class TypeButton extends JButton { - public TypeButton() { + TypeButton() { super(IconTheme.JabRefIcon.EDIT.getIcon()); setToolTipText(Localization.lang("Change entry type")); addActionListener(e -> showChangeEntryTypePopupMenu()); @@ -1020,7 +1020,7 @@ private void showChangeEntryTypePopupMenu() { } private class TypeLabel extends JLabel { - public TypeLabel(String type) { + TypeLabel(String type) { super(type); setUI(new VerticalLabelUI(false)); setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); @@ -1081,9 +1081,14 @@ public void stateChanged(ChangeEvent event) { Object activeTab = tabs.get(tabbed.getSelectedIndex()); if (activeTab instanceof FileAnnotationTab && !((FileAnnotationTab) activeTab).isInitialized()) { //Initialize by getting notes from cache if they are cached - FileAnnotationTab.initializeTab((FileAnnotationTab) activeTab, - panel.getAnnotationCache().getFromCache(Optional.of(entry))); - panel.getAnnotationCache().addToCache(entry, ((FileAnnotationTab) activeTab).getAllNotes()); + + FileAnnotationTab tab = (FileAnnotationTab) activeTab; + try { + tab.initializeTab(tab, + panel.getAnnotationCache().getFromCache(entry)); + } catch (ExecutionException e) { + tab.initializeTab((FileAnnotationTab) activeTab); + } } if (activeTab instanceof EntryEditorTab) { @@ -1102,7 +1107,7 @@ public void stateChanged(ChangeEvent event) { class DeleteAction extends AbstractAction { - public DeleteAction() { + DeleteAction() { super(Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Delete entry")); } @@ -1144,7 +1149,7 @@ public void close() { } class CloseAction extends AbstractAction { - public CloseAction() { + CloseAction() { super(Localization.lang("Close window"), IconTheme.JabRefIcon.CLOSE.getSmallIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close window")); } @@ -1157,7 +1162,7 @@ public void actionPerformed(ActionEvent e) { class StoreFieldAction extends AbstractAction { - public StoreFieldAction() { + StoreFieldAction() { super("Store field value"); putValue(Action.SHORT_DESCRIPTION, "Store field value"); } @@ -1322,7 +1327,7 @@ public void actionPerformed(ActionEvent event) { } class SwitchLeftAction extends AbstractAction { - public SwitchLeftAction() { + SwitchLeftAction() { super("Switch to the panel to the left"); } @@ -1336,7 +1341,7 @@ public void actionPerformed(ActionEvent e) { } class SwitchRightAction extends AbstractAction { - public SwitchRightAction() { + SwitchRightAction() { super("Switch to the panel to the right"); } @@ -1350,7 +1355,7 @@ public void actionPerformed(ActionEvent e) { } class NextEntryAction extends AbstractAction { - public NextEntryAction() { + NextEntryAction() { super(Localization.lang("Next entry"), IconTheme.JabRefIcon.DOWN.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Next entry")); @@ -1363,7 +1368,7 @@ public void actionPerformed(ActionEvent e) { } class PrevEntryAction extends AbstractAction { - public PrevEntryAction() { + PrevEntryAction() { super(Localization.lang("Previous entry"), IconTheme.JabRefIcon.UP.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Previous entry")); @@ -1377,7 +1382,7 @@ public void actionPerformed(ActionEvent e) { class GenerateKeyAction extends AbstractAction { - public GenerateKeyAction() { + GenerateKeyAction() { super(Localization.lang("Generate BibTeX key"), IconTheme.JabRefIcon.MAKE_KEY.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Generate BibTeX key")); @@ -1434,7 +1439,7 @@ public void actionPerformed(ActionEvent e) { } class UndoAction extends AbstractAction { - public UndoAction() { + UndoAction() { super("Undo", IconTheme.JabRefIcon.UNDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, "Undo"); } @@ -1446,7 +1451,7 @@ public void actionPerformed(ActionEvent e) { } class RedoAction extends AbstractAction { - public RedoAction() { + RedoAction() { super("Redo", IconTheme.JabRefIcon.REDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, "Redo"); } @@ -1458,7 +1463,7 @@ public void actionPerformed(ActionEvent e) { } class SaveDatabaseAction extends AbstractAction { - public SaveDatabaseAction() { + SaveDatabaseAction() { super("Save library"); } @@ -1492,32 +1497,32 @@ private void warnEmptyBibtexkey() { } - public AbstractAction getNextEntryAction() { + AbstractAction getNextEntryAction() { return nextEntryAction; } - public AbstractAction getPrevEntryAction() { + AbstractAction getPrevEntryAction() { return prevEntryAction; } - public SwitchLeftAction getSwitchLeftAction() { + SwitchLeftAction getSwitchLeftAction() { return switchLeftAction; } - public SwitchRightAction getSwitchRightAction() { + SwitchRightAction getSwitchRightAction() { return switchRightAction; } - public SaveDatabaseAction getSaveDatabaseAction() { + SaveDatabaseAction getSaveDatabaseAction() { return saveDatabaseAction; } - public HelpAction getHelpAction() { + HelpAction getHelpAction() { return helpAction; } @@ -1527,13 +1532,13 @@ public GenerateKeyAction getGenerateKeyAction() { } - public StoreFieldAction getStoreFieldAction() { + StoreFieldAction getStoreFieldAction() { return storeFieldAction; } private class AutoLinkAction extends AbstractAction { - public AutoLinkAction() { + AutoLinkAction() { putValue(Action.SMALL_ICON, IconTheme.JabRefIcon.AUTO_FILE_LINK.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Automatically set file links for this entry") + " (Alt-F)"); } diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index 94b213d84f5..631bf679b8f 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -6,12 +6,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Comparator; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.StringJoiner; -import java.util.stream.Collectors; import javax.swing.BoxLayout; import javax.swing.DefaultListCellRenderer; @@ -22,27 +19,23 @@ import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import net.sf.jabref.gui.BasePanel; import net.sf.jabref.gui.ClipBoardManager; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.IconTheme; import net.sf.jabref.logic.l10n.Localization; -import net.sf.jabref.logic.pdf.PdfAnnotationImporterImpl; +import net.sf.jabref.logic.pdf.EntryAnnotationImporter; import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.model.entry.FileField; -import net.sf.jabref.model.entry.ParsedFileField; import net.sf.jabref.model.pdf.FileAnnotation; import com.jgoodies.forms.builder.FormBuilder; import com.jgoodies.forms.factories.Paddings; import org.apache.pdfbox.pdmodel.fdf.FDFAnnotationHighlight; -public class FileAnnotationTab extends JPanel { +class FileAnnotationTab extends JPanel { private final JList commentList = new JList<>(); private final JScrollPane commentScrollPane = new JScrollPane(); @@ -66,78 +59,73 @@ public class FileAnnotationTab extends JPanel { private final JScrollPane highlightScrollPane = new JScrollPane(); private final JButton copyToClipboardButton = new JButton(); private final JButton reloadAnnotationsButton = new JButton(); - DefaultListModel listModel; + private DefaultListModel listModel; private final EntryEditor parent; - private final BasePanel basePanel; - private final JTabbedPane tabbed; - private int commentListSelectedIndex = 0; + private Map> annotationsOfFiles; private boolean isInitialized; - private Map> allNotes = new HashMap<>(); - - public FileAnnotationTab(EntryEditor parent, BasePanel basePanel, JTabbedPane tabbed) { + FileAnnotationTab(EntryEditor parent) { this.parent = parent; - this.basePanel = basePanel; - this.tabbed = tabbed; setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); listModel = new DefaultListModel<>(); this.isInitialized = false; } - public static FileAnnotationTab initializeTab(FileAnnotationTab tab, Optional>> notes){ + FileAnnotationTab initializeTab(FileAnnotationTab tab) { + if (tab.isInitialized) { + return tab; + } + + tab.setUpGui(); + tab.isInitialized = true; + tab.parent.repaint(); + return tab; + } + + FileAnnotationTab initializeTab(FileAnnotationTab tab, Map> cachedFileAnnotations) { + this.annotationsOfFiles = cachedFileAnnotations; + + if (tab.isInitialized) { + return tab; + } - if(!tab.isInitialized) { - try { - tab.addComments(notes); + tab.addAnnotations(); } catch (IOException e) { e.printStackTrace(); } - tab.setUpGui(); + tab.setUpGui(); tab.isInitialized = true; tab.parent.repaint(); return tab; - } - return tab; + } /** - * Adds pdf comments from all attached pdf files belonging to the entry selected in the main table and - * shows those from the first file in the comments tab + * Adds pdf annotationsOfFiles from all attached pdf files belonging to the entry selected in the main table and + * shows those from the first file in the file annotationsOfFiles tab * @throws IOException */ - public void addComments(Optional>> notes) throws IOException { - Optional field = parent.getEntry().getField(FieldName.FILE); - if (field.isPresent()) { + private void addAnnotations() throws IOException { + if (parent.getEntry().getField(FieldName.FILE).isPresent()) { if (!commentList.getModel().equals(listModel)) { commentList.setModel(listModel); commentList.addListSelectionListener(new CommentListSelectionListener()); commentList.setCellRenderer(new CommentsListCellRenderer()); } - PdfAnnotationImporterImpl annotationImporter; - - if(notes.isPresent()) { - allNotes = notes.get(); - } else { - annotationImporter = new PdfAnnotationImporterImpl(); - //import notes if the selected file is a pdf - getFilteredFileList().forEach(parsedFileField -> allNotes.put( - parsedFileField.getLink(), - annotationImporter.importAnnotations(parsedFileField.getLink(), basePanel.getDatabaseContext()))); - } //set up the comboBox for representing the selected file fileNameComboBox.removeAllItems(); - getFilteredFileList() - .forEach(((parsedField) -> fileNameComboBox.addItem(parsedField.getLink()))); - //show the annotations attached to the selected file - updateShownAnnotations(allNotes.get(fileNameComboBox.getSelectedItem() == null ? - fileNameComboBox.getItemAt(0).toString() : fileNameComboBox.getSelectedItem().toString())); + new EntryAnnotationImporter(parent.getEntry()).getFilteredFileList(). + forEach(((parsedField) -> fileNameComboBox.addItem(parsedField.getLink()))); + //show the annotationsOfFiles attached to the selected file + updateShownAnnotations(annotationsOfFiles.get(fileNameComboBox.getSelectedItem() == null ? + fileNameComboBox.getItemAt(0) : fileNameComboBox.getSelectedItem().toString())); //select the first annotation if(commentList.isSelectionEmpty()){ commentList.setSelectedIndex(0); @@ -147,15 +135,15 @@ public void addComments(Optional>> notes) throw /** * Updates the list model to show the given notes without those with no content - * @param importedNotes value is the comments name and the value is a pdfComment object to add to the list model + * @param annotations value is the comments name and the value is a pdfComment object to add to the list model */ - private void updateShownAnnotations(List importedNotes){ + private void updateShownAnnotations(List annotations) { listModel.clear(); - if(importedNotes.isEmpty()){ - listModel.addElement(new FileAnnotation("", "", "", 0, Localization.lang("File has no attached annotations"), "")); + if (annotations.isEmpty()) { + listModel.addElement(new FileAnnotation("", "", "", 0, Localization.lang("File has no attached annotationsOfFiles"), "")); } else { - Comparator byPage = (annotation1, annotation2) -> Integer.compare(annotation1.getPage(), annotation2.getPage()); - importedNotes.stream() + Comparator byPage = Comparator.comparingInt(FileAnnotation::getPage); + annotations.stream() .filter(annotation -> !(null == annotation.getContent())) .filter(annotation -> annotation.getAnnotationType().equals(FDFAnnotationHighlight.SUBTYPE) || (null == annotation.getLinkedFileAnnotation())) @@ -187,10 +175,10 @@ private void updateFileNameComboBox() { indexSelectedByComboBox = fileNameComboBox.getSelectedIndex(); } fileNameComboBox.removeAllItems(); - getFilteredFileList().stream().filter(parsedFileField -> parsedFileField.getLink().toLowerCase().endsWith(".pdf") ) + new EntryAnnotationImporter(parent.getEntry()).getFilteredFileList().stream().filter(parsedFileField -> parsedFileField.getLink().toLowerCase().endsWith(".pdf")) .forEach(((parsedField) -> fileNameComboBox.addItem(parsedField.getLink()))); fileNameComboBox.setSelectedIndex(indexSelectedByComboBox); - updateShownAnnotations(allNotes.get(fileNameComboBox.getSelectedItem().toString())); + updateShownAnnotations(annotationsOfFiles.get(fileNameComboBox.getSelectedItem().toString())); } private void setUpGui() { @@ -261,7 +249,7 @@ private JPanel setUpButtons(){ copyToClipboardButton.setText(Localization.lang("Copy to clipboard")); copyToClipboardButton.addActionListener(e -> copyToClipboard()); - reloadAnnotationsButton.setText(Localization.lang("Reload annotations")); + reloadAnnotationsButton.setText(Localization.lang("Reload annotationsOfFiles")); reloadAnnotationsButton.addActionListener(e -> reloadAnnotations()); buttonConstraints.gridy = 10; @@ -293,11 +281,12 @@ private void copyToClipboard(){ private void reloadAnnotations() { isInitialized = false; - Arrays.stream(this.getComponents()).forEach(component -> this.remove(component)); - initializeTab(this, Optional.empty()); + Arrays.stream(this.getComponents()).forEach(this::remove); + initializeTab(this); this.repaint(); } + /** * Fills the highlight and comment texts and enables/disables the highlight area if there is no highlighted text * @@ -327,21 +316,13 @@ private void updateContentAndHighlightTextfields(final FileAnnotation comment){ } } - /** - * Filter files with a web address containing "www." - * @return a list of file parsed files - */ - private List getFilteredFileList(){ - return FileField.parse(parent.getEntry().getField(FieldName.FILE).get()).stream() - .filter(parsedFileField -> parsedFileField.getLink().toLowerCase().endsWith(".pdf")) - .filter(parsedFileField -> !parsedFileField.getLink().contains("www.")).collect(Collectors.toList()); - } private class CommentListSelectionListener implements ListSelectionListener { @Override public void valueChanged(ListSelectionEvent e) { int index; + int commentListSelectedIndex; if (commentList.getSelectedIndex() >= 0) { index = commentList.getSelectedIndex(); updateTextFields(listModel.get(index)); @@ -391,11 +372,7 @@ public Component getListCellRendererComponent(JList list, Object value, int i } } - public boolean isInitialized() { + boolean isInitialized() { return isInitialized; } - - public Map> getAllNotes() { - return allNotes; - } -} \ No newline at end of file +} diff --git a/src/main/java/net/sf/jabref/logic/pdf/AnnotationImporterInterface.java b/src/main/java/net/sf/jabref/logic/pdf/AnnotationImporter.java similarity index 84% rename from src/main/java/net/sf/jabref/logic/pdf/AnnotationImporterInterface.java rename to src/main/java/net/sf/jabref/logic/pdf/AnnotationImporter.java index 6f9e8793610..f849afa72e6 100644 --- a/src/main/java/net/sf/jabref/logic/pdf/AnnotationImporterInterface.java +++ b/src/main/java/net/sf/jabref/logic/pdf/AnnotationImporter.java @@ -5,7 +5,7 @@ import net.sf.jabref.model.database.BibDatabaseContext; import net.sf.jabref.model.pdf.FileAnnotation; -public interface AnnotationImporterInterface { +public interface AnnotationImporter { List importAnnotations(final String path, final BibDatabaseContext context); } diff --git a/src/main/java/net/sf/jabref/logic/pdf/EntryAnnotationImporter.java b/src/main/java/net/sf/jabref/logic/pdf/EntryAnnotationImporter.java new file mode 100644 index 00000000000..c2209f84132 --- /dev/null +++ b/src/main/java/net/sf/jabref/logic/pdf/EntryAnnotationImporter.java @@ -0,0 +1,54 @@ +package net.sf.jabref.logic.pdf; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.sf.jabref.model.database.BibDatabaseContext; +import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.model.entry.FieldName; +import net.sf.jabref.model.entry.FileField; +import net.sf.jabref.model.entry.ParsedFileField; +import net.sf.jabref.model.pdf.FileAnnotation; + + +/** + * Here all PDF files attached to a BibEntry are scanned for annotations using a PdfAnnotationImporter. + */ +public class EntryAnnotationImporter { + + private final BibEntry entry; + + /** + * @param entry The BibEntry whose attached files are scanned for annotations. + */ + public EntryAnnotationImporter(BibEntry entry) { + this.entry = entry; + } + + /** + * Filter files with a web address containing "www." + * + * @return a list of file parsed files + */ + public List getFilteredFileList() { + return FileField.parse(this.entry.getField(FieldName.FILE).get()).stream() + .filter(parsedFileField -> parsedFileField.getLink().toLowerCase().endsWith(".pdf")) + .filter(parsedFileField -> !parsedFileField.getLink().contains("www.")).collect(Collectors.toList()); + } + + /** + * Reads the annotations from the files that are attached to a BibEntry. + * + * @param context The context is needed for the importer. + * @return Map from each PDF to a list of file annotations + */ + Map> importAnnotationsFromFiles(BibDatabaseContext context) { + Map> annotations = new HashMap<>(); + AnnotationImporter importer = new PdfAnnotationImporter(); + //import annotationsOfFiles if the selected files are valid which is checked in getFilteredFileList() + this.getFilteredFileList().forEach(parsedFileField -> annotations.put(parsedFileField.getLink(), importer.importAnnotations(parsedFileField.getLink(), context))); + return annotations; + } +} diff --git a/src/main/java/net/sf/jabref/logic/pdf/FileAnnotationCache.java b/src/main/java/net/sf/jabref/logic/pdf/FileAnnotationCache.java index 71131886083..94bd96146d2 100644 --- a/src/main/java/net/sf/jabref/logic/pdf/FileAnnotationCache.java +++ b/src/main/java/net/sf/jabref/logic/pdf/FileAnnotationCache.java @@ -1,11 +1,10 @@ package net.sf.jabref.logic.pdf; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ExecutionException; +import net.sf.jabref.model.database.BibDatabaseContext; import net.sf.jabref.model.entry.BibEntry; import net.sf.jabref.model.pdf.FileAnnotation; @@ -13,6 +12,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; + public class FileAnnotationCache { //cache size in entries @@ -20,35 +20,22 @@ public class FileAnnotationCache { //the inner list holds the annotations per file, the outer collection maps this to a BibEntry. private LoadingCache>> annotationCache; - public FileAnnotationCache() { + public FileAnnotationCache(BibDatabaseContext context) { annotationCache = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE).build(new CacheLoader>>() { @Override - public Map> load(BibEntry notUsed) throws Exception { - // Automated reloading of entries is not supported. - return new HashMap<>(); + public Map> load(BibEntry entry) throws Exception { + return new EntryAnnotationImporter(entry).importAnnotationsFromFiles(context); } }); } - public void addToCache(BibEntry entry, final Map> annotations) { - annotationCache.put(entry, annotations); - } - /** * Note that entry becomes the most recent entry in the cache * * @param entry entry for which to get the annotations * @return Map containing a list of annotations in a list for each file */ - public Optional>> getFromCache(Optional entry) { - Optional>> emptyAnnotation = Optional.empty(); - try { - if (entry.isPresent() && annotationCache.get(entry.get()).size() > 0) { - return Optional.of(annotationCache.get(entry.get())); - } - } catch (ExecutionException failure) { - return emptyAnnotation; - } - return emptyAnnotation; + public Map> getFromCache(BibEntry entry) throws ExecutionException { + return annotationCache.get(entry); } } diff --git a/src/main/java/net/sf/jabref/logic/pdf/PdfAnnotationImporterImpl.java b/src/main/java/net/sf/jabref/logic/pdf/PdfAnnotationImporter.java similarity index 95% rename from src/main/java/net/sf/jabref/logic/pdf/PdfAnnotationImporterImpl.java rename to src/main/java/net/sf/jabref/logic/pdf/PdfAnnotationImporter.java index 3776f28306f..b48556ef44b 100644 --- a/src/main/java/net/sf/jabref/logic/pdf/PdfAnnotationImporterImpl.java +++ b/src/main/java/net/sf/jabref/logic/pdf/PdfAnnotationImporter.java @@ -24,13 +24,10 @@ import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; import org.apache.pdfbox.util.PDFTextStripperByArea; -public class PdfAnnotationImporterImpl implements AnnotationImporterInterface { +public class PdfAnnotationImporter implements AnnotationImporter { - private List pdfPages; - private PDPage page; - - public PdfAnnotationImporterImpl() { + public PdfAnnotationImporter() { } /** @@ -65,9 +62,9 @@ public List importAnnotations(final String path, final BibDataba e.printStackTrace(); } - pdfPages = document.getDocumentCatalog().getAllPages(); + List pdfPages = document.getDocumentCatalog().getAllPages(); for (int i = 0; i < pdfPages.size(); i++) { - page = (PDPage) pdfPages.get(i); + PDPage page = (PDPage) pdfPages.get(i); try { for (PDAnnotation annotation : page.getAnnotations()) { From 67841585065fe38be61fa15fda9a2abbaa749dfa Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 16 Feb 2017 17:10:01 +0100 Subject: [PATCH 2/7] Reverted an incorrect renaming. --- .../java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index 631bf679b8f..c80ca97f5a6 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -140,7 +140,7 @@ private void addAnnotations() throws IOException { private void updateShownAnnotations(List annotations) { listModel.clear(); if (annotations.isEmpty()) { - listModel.addElement(new FileAnnotation("", "", "", 0, Localization.lang("File has no attached annotationsOfFiles"), "")); + listModel.addElement(new FileAnnotation("", "", "", 0, Localization.lang("File has no attached annotations!"), "")); } else { Comparator byPage = Comparator.comparingInt(FileAnnotation::getPage); annotations.stream() From f19c4150526f470be423fb381cdd6a32fa3647fc Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 16 Feb 2017 17:11:25 +0100 Subject: [PATCH 3/7] Reverted an incorrect renaming to the original --- .../java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index c80ca97f5a6..5b64608f650 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -140,7 +140,7 @@ private void addAnnotations() throws IOException { private void updateShownAnnotations(List annotations) { listModel.clear(); if (annotations.isEmpty()) { - listModel.addElement(new FileAnnotation("", "", "", 0, Localization.lang("File has no attached annotations!"), "")); + listModel.addElement(new FileAnnotation("", "", "", 0, Localization.lang("File has no attached annotations"), "")); } else { Comparator byPage = Comparator.comparingInt(FileAnnotation::getPage); annotations.stream() From f9b2e72b13c6b5c980dfb1dd707aa6472d4204a2 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 16 Feb 2017 17:14:12 +0100 Subject: [PATCH 4/7] Fixed wrong locale message --- .../net/sf/jabref/gui/entryeditor/FileAnnotationTab.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index 5b64608f650..46b610947de 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -107,8 +107,8 @@ FileAnnotationTab initializeTab(FileAnnotationTab tab, Map copyToClipboard()); - reloadAnnotationsButton.setText(Localization.lang("Reload annotationsOfFiles")); + reloadAnnotationsButton.setText(Localization.lang("Reload annotations")); reloadAnnotationsButton.addActionListener(e -> reloadAnnotations()); buttonConstraints.gridy = 10; From f7b0c9f43d0061e1b2eb100b3362efe23bb70aa5 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 16 Feb 2017 23:38:23 +0100 Subject: [PATCH 5/7] fixing @koppor's remarks --- .../jabref/gui/entryeditor/EntryEditor.java | 199 +++++------------- .../gui/entryeditor/FileAnnotationTab.java | 53 ++--- 2 files changed, 68 insertions(+), 184 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 955712ea2e0..48efcac4e89 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -1,76 +1,16 @@ package net.sf.jabref.gui.entryeditor; -import java.awt.AWTKeyStroke; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.KeyboardFocusManager; -import java.awt.RenderingHints; -import java.awt.event.ActionEvent; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextArea; -import javax.swing.JToolBar; -import javax.swing.KeyStroke; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.text.JTextComponent; - +import com.google.common.eventbus.Subscribe; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.layout.StackPane; - import net.sf.jabref.Globals; -import net.sf.jabref.gui.BasePanel; -import net.sf.jabref.gui.EntryContainer; -import net.sf.jabref.gui.GUIGlobals; -import net.sf.jabref.gui.IconTheme; -import net.sf.jabref.gui.JabRefFrame; -import net.sf.jabref.gui.OSXCompatibleToolbar; +import net.sf.jabref.gui.*; import net.sf.jabref.gui.actions.Actions; import net.sf.jabref.gui.contentselector.FieldContentSelector; import net.sf.jabref.gui.externalfiles.WriteXMPEntryEditorAction; -import net.sf.jabref.gui.fieldeditors.FieldEditor; -import net.sf.jabref.gui.fieldeditors.FieldEditorFocusListener; -import net.sf.jabref.gui.fieldeditors.FileListEditor; -import net.sf.jabref.gui.fieldeditors.JTextAreaWithHighlighting; +import net.sf.jabref.gui.fieldeditors.*; import net.sf.jabref.gui.fieldeditors.TextField; import net.sf.jabref.gui.help.HelpAction; import net.sf.jabref.gui.importer.fetcher.EntryFetchers; @@ -78,11 +18,7 @@ import net.sf.jabref.gui.menus.ChangeEntryTypeMenu; import net.sf.jabref.gui.mergeentries.EntryFetchAndMergeWorker; import net.sf.jabref.gui.specialfields.SpecialFieldUpdateListener; -import net.sf.jabref.gui.undo.NamedCompound; -import net.sf.jabref.gui.undo.UndoableChangeType; -import net.sf.jabref.gui.undo.UndoableFieldChange; -import net.sf.jabref.gui.undo.UndoableKeyChange; -import net.sf.jabref.gui.undo.UndoableRemoveEntry; +import net.sf.jabref.gui.undo.*; import net.sf.jabref.gui.util.component.CheckBoxMessage; import net.sf.jabref.gui.util.component.VerticalLabelUI; import net.sf.jabref.logic.TypedBibEntry; @@ -101,20 +37,29 @@ import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.database.BibDatabaseMode; -import net.sf.jabref.model.entry.BibEntry; -import net.sf.jabref.model.entry.EntryConverter; -import net.sf.jabref.model.entry.EntryType; -import net.sf.jabref.model.entry.FieldName; -import net.sf.jabref.model.entry.FieldProperty; -import net.sf.jabref.model.entry.InternalBibtexFields; -import net.sf.jabref.model.entry.MathSciNetId; +import net.sf.jabref.model.entry.*; import net.sf.jabref.model.entry.event.FieldChangedEvent; import net.sf.jabref.preferences.JabRefPreferences; - -import com.google.common.eventbus.Subscribe; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.swing.*; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.text.JTextComponent; +import java.awt.*; +import java.awt.event.*; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.List; +import java.util.Map.Entry; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + /** * GUI component that allows editing of the fields of a BibEntry (i.e. the @@ -496,21 +441,21 @@ private void setupToolBar() { inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_ENTRY_EDITOR), "close"); actionMap.put("close", closeAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); - actionMap.put("store", getStoreFieldAction()); + actionMap.put("store", storeFieldAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOGENERATE_BIBTEX_KEYS), "generateKey"); - actionMap.put("generateKey", getGenerateKeyAction()); + actionMap.put("generateKey", generateKeyAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.AUTOMATICALLY_LINK_FILES), "autoLink"); actionMap.put("autoLink", autoLinkAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_ENTRY), "prev"); - actionMap.put("prev", getPrevEntryAction()); + actionMap.put("prev", prevEntryAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_ENTRY), "next"); - actionMap.put("next", getNextEntryAction()); + actionMap.put("next", nextEntryAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo"); actionMap.put("undo", undoAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo"); actionMap.put("redo", redoAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); - actionMap.put("help", getHelpAction()); + actionMap.put("help", helpAction); toolBar.setFloatable(false); @@ -527,7 +472,7 @@ private void setupToolBar() { TypeButton typeButton = new TypeButton(); toolBar.add(typeButton); - toolBar.add(getGenerateKeyAction()); + toolBar.add(generateKeyAction); toolBar.add(autoLinkAction); toolBar.add(writeXmp); @@ -556,12 +501,12 @@ public void mousePressed(MouseEvent e) { toolBar.addSeparator(); toolBar.add(deleteAction); - toolBar.add(getPrevEntryAction()); - toolBar.add(getNextEntryAction()); + toolBar.add(prevEntryAction); + toolBar.add(nextEntryAction); toolBar.addSeparator(); - toolBar.add(getHelpAction()); + toolBar.add(helpAction); Component[] comps = toolBar.getComponents(); @@ -597,7 +542,7 @@ public void rebuildPanels() { * @param editor Field editor * @return Component to show, or null if none. */ - Optional getExtra(final FieldEditor editor) { + private Optional getExtra(final FieldEditor editor) { final String fieldName = editor.getFieldName(); final Set fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); @@ -614,10 +559,10 @@ Optional getExtra(final FieldEditor editor) { // Add controls for switching between abbreviated and full journal names. // If this field also has a FieldContentSelector, we need to combine these. return FieldExtraComponents.getJournalExtraComponent(frame, panel, editor, entry, contentSelectors, - getStoreFieldAction()); + storeFieldAction); } else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) { return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, - getStoreFieldAction()); + storeFieldAction); } else if (fieldExtras.contains(FieldProperty.DOI)) { return FieldExtraComponents.getDoiExtraComponent(panel, this, editor); @@ -626,7 +571,7 @@ Optional getExtra(final FieldEditor editor) { } else if (fieldExtras.contains(FieldProperty.ISBN)) { return FieldExtraComponents.getIsbnExtraComponent(panel, this, editor); } else if (fieldExtras.contains(FieldProperty.OWNER)) { - return FieldExtraComponents.getSetOwnerExtraComponent(editor, getStoreFieldAction()); + return FieldExtraComponents.getSetOwnerExtraComponent(editor, storeFieldAction); } else if (fieldExtras.contains(FieldProperty.YES_NO)) { return FieldExtraComponents.getYesNoExtraComponent(editor, this); } else if (fieldExtras.contains(FieldProperty.MONTH)) { @@ -663,7 +608,7 @@ private void setupSourcePanel() { srcPanel.add(scrollPane, BorderLayout.CENTER); } - void addSearchListener(SearchQueryHighlightListener listener) { + private void addSearchListener(SearchQueryHighlightListener listener) { searchListeners.add(listener); panel.frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(listener); } @@ -715,18 +660,18 @@ private void setupJTextComponent(JTextComponent textComponent) { ActionMap actionMap = textComponent.getActionMap(); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_STORE_FIELD), "store"); - actionMap.put("store", getStoreFieldAction()); + actionMap.put("store", storeFieldAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL), "right"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_NEXT_PANEL_2), "right"); - actionMap.put("right", getSwitchRightAction()); + actionMap.put("right", switchRightAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL), "left"); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.ENTRY_EDITOR_PREVIOUS_PANEL_2), "left"); - actionMap.put("left", getSwitchLeftAction()); + actionMap.put("left", switchLeftAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.HELP), "help"); - actionMap.put("help", getHelpAction()); + actionMap.put("help", helpAction); inputMap.put(Globals.getKeyPrefs().getKey(KeyBinding.NEXT_TAB), "nexttab"); actionMap.put("nexttab", frame.nextTab); @@ -794,7 +739,7 @@ public void storeCurrentEdit() { if (comp instanceof FieldEditor) { ((FieldEditor) comp).clearAutoCompleteSuggestion(); } - getStoreFieldAction().actionPerformed(new ActionEvent(comp, 0, "")); + storeFieldAction.actionPerformed(new ActionEvent(comp, 0, "")); } } @@ -993,7 +938,7 @@ public void listen(FieldChangedEvent fieldChangedEvent) { } public void updateField(final Object sourceObject) { - getStoreFieldAction().actionPerformed(new ActionEvent(sourceObject, 0, "")); + storeFieldAction.actionPerformed(new ActionEvent(sourceObject, 0, "")); } public void setMovingToDifferentEntry() { @@ -1106,7 +1051,7 @@ public void stateChanged(ChangeEvent event) { } - class DeleteAction extends AbstractAction { + private class DeleteAction extends AbstractAction { DeleteAction() { super(Localization.lang("Delete"), IconTheme.JabRefIcon.DELETE_ENTRY.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Delete entry")); @@ -1148,7 +1093,7 @@ public void close() { } } - class CloseAction extends AbstractAction { + private class CloseAction extends AbstractAction { CloseAction() { super(Localization.lang("Close window"), IconTheme.JabRefIcon.CLOSE.getSmallIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Close window")); @@ -1160,7 +1105,7 @@ public void actionPerformed(ActionEvent e) { } } - class StoreFieldAction extends AbstractAction { + private class StoreFieldAction extends AbstractAction { StoreFieldAction() { super("Store field value"); @@ -1326,7 +1271,7 @@ public void actionPerformed(ActionEvent event) { } } - class SwitchLeftAction extends AbstractAction { + private class SwitchLeftAction extends AbstractAction { SwitchLeftAction() { super("Switch to the panel to the left"); } @@ -1340,7 +1285,7 @@ public void actionPerformed(ActionEvent e) { } } - class SwitchRightAction extends AbstractAction { + private class SwitchRightAction extends AbstractAction { SwitchRightAction() { super("Switch to the panel to the right"); } @@ -1354,7 +1299,7 @@ public void actionPerformed(ActionEvent e) { } } - class NextEntryAction extends AbstractAction { + private class NextEntryAction extends AbstractAction { NextEntryAction() { super(Localization.lang("Next entry"), IconTheme.JabRefIcon.DOWN.getIcon()); @@ -1367,7 +1312,7 @@ public void actionPerformed(ActionEvent e) { } } - class PrevEntryAction extends AbstractAction { + private class PrevEntryAction extends AbstractAction { PrevEntryAction() { super(Localization.lang("Previous entry"), IconTheme.JabRefIcon.UP.getIcon()); @@ -1380,7 +1325,7 @@ public void actionPerformed(ActionEvent e) { } } - class GenerateKeyAction extends AbstractAction { + private class GenerateKeyAction extends AbstractAction { GenerateKeyAction() { super(Localization.lang("Generate BibTeX key"), IconTheme.JabRefIcon.MAKE_KEY.getIcon()); @@ -1438,7 +1383,7 @@ public void actionPerformed(ActionEvent e) { } } - class UndoAction extends AbstractAction { + private class UndoAction extends AbstractAction { UndoAction() { super("Undo", IconTheme.JabRefIcon.UNDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, "Undo"); @@ -1450,7 +1395,7 @@ public void actionPerformed(ActionEvent e) { } } - class RedoAction extends AbstractAction { + private class RedoAction extends AbstractAction { RedoAction() { super("Redo", IconTheme.JabRefIcon.REDO.getIcon()); putValue(Action.SHORT_DESCRIPTION, "Redo"); @@ -1462,7 +1407,7 @@ public void actionPerformed(ActionEvent e) { } } - class SaveDatabaseAction extends AbstractAction { + private class SaveDatabaseAction extends AbstractAction { SaveDatabaseAction() { super("Save library"); } @@ -1497,44 +1442,6 @@ private void warnEmptyBibtexkey() { } - AbstractAction getNextEntryAction() { - return nextEntryAction; - } - - - AbstractAction getPrevEntryAction() { - return prevEntryAction; - } - - - SwitchLeftAction getSwitchLeftAction() { - return switchLeftAction; - } - - - SwitchRightAction getSwitchRightAction() { - return switchRightAction; - } - - - SaveDatabaseAction getSaveDatabaseAction() { - return saveDatabaseAction; - } - - - HelpAction getHelpAction() { - return helpAction; - } - - - public GenerateKeyAction getGenerateKeyAction() { - return generateKeyAction; - } - - - StoreFieldAction getStoreFieldAction() { - return storeFieldAction; - } private class AutoLinkAction extends AbstractAction { diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index 46b610947de..9c1ce2eec3e 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -1,28 +1,7 @@ package net.sf.jabref.gui.entryeditor; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.io.IOException; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.StringJoiner; - -import javax.swing.BoxLayout; -import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.factories.Paddings; import net.sf.jabref.gui.ClipBoardManager; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.IconTheme; @@ -30,11 +9,15 @@ import net.sf.jabref.logic.pdf.EntryAnnotationImporter; import net.sf.jabref.model.entry.FieldName; import net.sf.jabref.model.pdf.FileAnnotation; - -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.factories.Paddings; import org.apache.pdfbox.pdmodel.fdf.FDFAnnotationHighlight; +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.util.*; +import java.util.List; + class FileAnnotationTab extends JPanel { private final JList commentList = new JList<>(); @@ -93,25 +76,19 @@ FileAnnotationTab initializeTab(FileAnnotationTab tab, Map Date: Fri, 17 Feb 2017 00:14:14 +0100 Subject: [PATCH 6/7] fixed imports, consitent naming --- .../java/net/sf/jabref/gui/IconTheme.java | 2 +- .../jabref/gui/entryeditor/EntryEditor.java | 222 +++++++++++++----- .../gui/entryeditor/FileAnnotationTab.java | 142 ++++++----- .../sf/jabref/model/pdf/FileAnnotation.java | 2 +- .../importer/fileformat/BibtexParserTest.java | 2 +- 5 files changed, 242 insertions(+), 128 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/IconTheme.java b/src/main/java/net/sf/jabref/gui/IconTheme.java index 4b4984dd612..4ee5a805e90 100644 --- a/src/main/java/net/sf/jabref/gui/IconTheme.java +++ b/src/main/java/net/sf/jabref/gui/IconTheme.java @@ -85,7 +85,7 @@ public enum JabRefIcon { PASTE("\uf192") /*css: content-paste*/, CUT("\uf190") /*css: content-cut*/, COPY("\uf18f") /*css: content-copy */, - COMMENT("\uF188") /*css: comment*/, + ANNOTATION("\uF188") /*css: comment*/, REDO("\uf44e") /*css: redo*/, UNDO("\uf54c") /*css: undo*/, MARK_ENTRIES("\uf0c0") /*css: bookmark */, diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java index 48efcac4e89..b8fe7c4769c 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/EntryEditor.java @@ -1,16 +1,76 @@ package net.sf.jabref.gui.entryeditor; -import com.google.common.eventbus.Subscribe; +import java.awt.AWTKeyStroke; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.KeyboardFocusManager; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JMenuItem; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JTextArea; +import javax.swing.JToolBar; +import javax.swing.KeyStroke; +import javax.swing.ScrollPaneConstants; +import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.text.JTextComponent; + import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.layout.StackPane; + import net.sf.jabref.Globals; -import net.sf.jabref.gui.*; +import net.sf.jabref.gui.BasePanel; +import net.sf.jabref.gui.EntryContainer; +import net.sf.jabref.gui.GUIGlobals; +import net.sf.jabref.gui.IconTheme; +import net.sf.jabref.gui.JabRefFrame; +import net.sf.jabref.gui.OSXCompatibleToolbar; import net.sf.jabref.gui.actions.Actions; import net.sf.jabref.gui.contentselector.FieldContentSelector; import net.sf.jabref.gui.externalfiles.WriteXMPEntryEditorAction; -import net.sf.jabref.gui.fieldeditors.*; +import net.sf.jabref.gui.fieldeditors.FieldEditor; +import net.sf.jabref.gui.fieldeditors.FieldEditorFocusListener; +import net.sf.jabref.gui.fieldeditors.FileListEditor; +import net.sf.jabref.gui.fieldeditors.JTextAreaWithHighlighting; import net.sf.jabref.gui.fieldeditors.TextField; import net.sf.jabref.gui.help.HelpAction; import net.sf.jabref.gui.importer.fetcher.EntryFetchers; @@ -18,7 +78,11 @@ import net.sf.jabref.gui.menus.ChangeEntryTypeMenu; import net.sf.jabref.gui.mergeentries.EntryFetchAndMergeWorker; import net.sf.jabref.gui.specialfields.SpecialFieldUpdateListener; -import net.sf.jabref.gui.undo.*; +import net.sf.jabref.gui.undo.NamedCompound; +import net.sf.jabref.gui.undo.UndoableChangeType; +import net.sf.jabref.gui.undo.UndoableFieldChange; +import net.sf.jabref.gui.undo.UndoableKeyChange; +import net.sf.jabref.gui.undo.UndoableRemoveEntry; import net.sf.jabref.gui.util.component.CheckBoxMessage; import net.sf.jabref.gui.util.component.VerticalLabelUI; import net.sf.jabref.logic.TypedBibEntry; @@ -37,29 +101,20 @@ import net.sf.jabref.model.FieldChange; import net.sf.jabref.model.database.BibDatabase; import net.sf.jabref.model.database.BibDatabaseMode; -import net.sf.jabref.model.entry.*; +import net.sf.jabref.model.entry.BibEntry; +import net.sf.jabref.model.entry.EntryConverter; +import net.sf.jabref.model.entry.EntryType; +import net.sf.jabref.model.entry.FieldName; +import net.sf.jabref.model.entry.FieldProperty; +import net.sf.jabref.model.entry.InternalBibtexFields; +import net.sf.jabref.model.entry.MathSciNetId; import net.sf.jabref.model.entry.event.FieldChangedEvent; import net.sf.jabref.preferences.JabRefPreferences; + +import com.google.common.eventbus.Subscribe; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import javax.swing.*; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.text.JTextComponent; -import java.awt.*; -import java.awt.event.*; -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.List; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; -import java.util.stream.Collectors; - /** * GUI component that allows editing of the fields of a BibEntry (i.e. the @@ -74,30 +129,50 @@ public class EntryEditor extends JPanel implements EntryContainer { private static final Log LOGGER = LogFactory.getLog(EntryEditor.class); - /** A reference to the entry this object works on. */ + /** + * A reference to the entry this object works on. + */ private final BibEntry entry; - /** The currently displayed type */ + /** + * The currently displayed type + */ private final String displayedBibEntryType; - /** The action concerned with closing the window. */ + /** + * The action concerned with closing the window. + */ private final CloseAction closeAction = new CloseAction(); - /** The action that deletes the current entry, and closes the editor. */ + /** + * The action that deletes the current entry, and closes the editor. + */ private final DeleteAction deleteAction = new DeleteAction(); - /** The action for switching to the next entry. */ + /** + * The action for switching to the next entry. + */ private final AbstractAction nextEntryAction = new NextEntryAction(); - /** The action for switching to the previous entry. */ + /** + * The action for switching to the previous entry. + */ private final AbstractAction prevEntryAction = new PrevEntryAction(); - /** The action concerned with storing a field value. */ + /** + * The action concerned with storing a field value. + */ private final StoreFieldAction storeFieldAction = new StoreFieldAction(); - /** The action for switching to the next tab */ + /** + * The action for switching to the next tab + */ private final SwitchLeftAction switchLeftAction = new SwitchLeftAction(); - /** The action for switching to the previous tab */ + /** + * The action for switching to the previous tab + */ private final SwitchRightAction switchRightAction = new SwitchRightAction(); - /** The action which generates a BibTeX key for this entry. */ + /** + * The action which generates a BibTeX key for this entry. + */ private final GenerateKeyAction generateKeyAction = new GenerateKeyAction(); // UGLY HACK to have a pointer to the fileListEditor to call autoSetLinks() @@ -106,8 +181,6 @@ public class EntryEditor extends JPanel implements EntryContainer { private final AbstractAction writeXmp; - private final SaveDatabaseAction saveDatabaseAction = new SaveDatabaseAction(); - private final JPanel srcPanel = new JPanel(); private final JPanel relatedArticlePanel = new JPanel(); @@ -130,7 +203,9 @@ public class EntryEditor extends JPanel implements EntryContainer { * source couldn't be parsed, and the user is given the option to edit it. */ private boolean updateSource = true; - /** Indicates that we are about to go to the next or previous entry */ + /** + * Indicates that we are about to go to the next or previous entry + */ private boolean movingToDifferentEntry; private boolean validEntry = true; @@ -140,16 +215,20 @@ public class EntryEditor extends JPanel implements EntryContainer { private boolean lastFieldAccepted = true; /** - * This indicates whether the last attempt at parsing the source was successful. It is used to determine whether - * the dialog should close; it should stay open if the user received an error message about the source, - * whatever he or she chose to do about it. + * This indicates whether the last attempt at parsing the source was successful. It is used to determine whether + * the dialog should close; it should stay open if the user received an error message about the source, + * whatever he or she chose to do about it. */ private boolean lastSourceAccepted = true; - /** This is used to prevent double updates after editing source. */ + /** + * This is used to prevent double updates after editing source. + */ private String lastSourceStringAccepted; - /** The index the source panel has in tabbed. */ + /** + * The index the source panel has in tabbed. + */ private int sourceIndex = -1; private final HelpAction helpAction = new HelpAction(HelpFile.ENTRY_EDITOR, IconTheme.JabRefIcon.HELP.getIcon()); @@ -161,6 +240,7 @@ public class EntryEditor extends JPanel implements EntryContainer { private final TabListener tabListener = new TabListener(); private final List searchListeners = new ArrayList<>(); + private Action saveDatabaseAction; public EntryEditor(JabRefFrame frame, BasePanel panel, BibEntry entry) { @@ -187,7 +267,7 @@ public EntryEditor(JabRefFrame frame, BasePanel panel, BibEntry entry) { } updateAllFields(); - if (this.fileListEditor != null){ + if (this.fileListEditor != null) { this.fileListEditor.adjustColumnWidth(); } } @@ -206,7 +286,6 @@ private void setupFieldPanels() { Set usedOptionalFieldsDeprecated = new HashSet<>(deprecatedFields); - if ((type.getOptionalFields() != null) && !type.getOptionalFields().isEmpty()) { if (!frame.getCurrentBasePanel().getBibDatabaseContext().isBiblatexMode()) { addOptionalTab(type); @@ -388,7 +467,7 @@ private void addOptionalTab(EntryType type) { } tabbed.addTab(Localization.lang("Optional fields"), IconTheme.JabRefIcon.OPTIONAL.getSmallIcon(), optionalPanel - .getPane(), Localization.lang("Show optional fields")); + .getPane(), Localization.lang("Show optional fields")); tabs.add(optionalPanel); } @@ -401,11 +480,10 @@ private void addPDFAnnotationTab() { Optional field = entry.getField(FieldName.FILE); if (field.isPresent()) { fileAnnotationTab = new FileAnnotationTab(this); - tabbed.addTab(Localization.lang("File annotations"), IconTheme.JabRefIcon.COMMENT.getSmallIcon(), fileAnnotationTab, + tabbed.addTab(Localization.lang("File annotations"), IconTheme.JabRefIcon.ANNOTATION.getSmallIcon(), fileAnnotationTab, Localization.lang("Show file annotations")); tabs.add(fileAnnotationTab); } - } public String getDisplayedBibEntryType() { @@ -478,7 +556,7 @@ private void setupToolBar() { toolBar.add(writeXmp); JPopupMenu fetcherPopup = new JPopupMenu(); - for(EntryBasedFetcher fetcher : EntryFetchers.getEntryBasedFetchers(Globals.prefs.getImportFormatPreferences())) { + for (EntryBasedFetcher fetcher : EntryFetchers.getEntryBasedFetchers(Globals.prefs.getImportFormatPreferences())) { fetcherPopup.add(new JMenuItem(new AbstractAction(fetcher.getName()) { @Override @@ -542,7 +620,7 @@ public void rebuildPanels() { * @param editor Field editor * @return Component to show, or null if none. */ - private Optional getExtra(final FieldEditor editor) { + Optional getExtra(final FieldEditor editor) { final String fieldName = editor.getFieldName(); final Set fieldExtras = InternalBibtexFields.getFieldProperties(fieldName); @@ -563,7 +641,6 @@ private Optional getExtra(final FieldEditor editor) { } else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) { return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction); - } else if (fieldExtras.contains(FieldProperty.DOI)) { return FieldExtraComponents.getDoiExtraComponent(panel, this, editor); } else if (fieldExtras.contains(FieldProperty.EPRINT)) { @@ -608,7 +685,7 @@ private void setupSourcePanel() { srcPanel.add(scrollPane, BorderLayout.CENTER); } - private void addSearchListener(SearchQueryHighlightListener listener) { + void addSearchListener(SearchQueryHighlightListener listener) { searchListeners.add(listener); panel.frame().getGlobalSearchBar().getSearchQueryHighlightObservable().addSearchListener(listener); } @@ -636,7 +713,6 @@ public void updateSource() { source.setEditable(false); LOGGER.debug("Incorrect entry", ex); } - } } @@ -702,7 +778,7 @@ private void activateVisible() { if (activeTab instanceof EntryEditorTab) { ((EntryEditorTab) activeTab).focus(); } else if (activeTab instanceof FileAnnotationTab) { - ((FileAnnotationTab)activeTab).requestFocus(); + ((FileAnnotationTab) activeTab).requestFocus(); } else { source.requestFocus(); } @@ -727,7 +803,6 @@ public void setEnabled(boolean enabled) { } } source.setEnabled(enabled); - } /** @@ -919,7 +994,6 @@ public void updateAllContentSelectors() { for (FieldContentSelector contentSelector : contentSelectors) { contentSelector.rebuildComboBox(); } - } } @@ -951,6 +1025,38 @@ private void unregisterListeners() { removeSearchListeners(); } + public GenerateKeyAction getGenerateKeyAction() { + return generateKeyAction; + } + + AbstractAction getPrevEntryAction() { + return prevEntryAction; + } + + AbstractAction getNextEntryAction() { + return nextEntryAction; + } + + StoreFieldAction getStoreFieldAction() { + return storeFieldAction; + } + + SwitchLeftAction getSwitchLeftAction() { + return switchLeftAction; + } + + SwitchRightAction getSwitchRightAction() { + return switchRightAction; + } + + HelpAction getHelpAction() { + return helpAction; + } + + Action getSaveDatabaseAction() { + return saveDatabaseAction; + } + private class TypeButton extends JButton { TypeButton() { super(IconTheme.JabRefIcon.EDIT.getIcon()); @@ -1105,7 +1211,7 @@ public void actionPerformed(ActionEvent e) { } } - private class StoreFieldAction extends AbstractAction { + class StoreFieldAction extends AbstractAction { StoreFieldAction() { super("Store field value"); @@ -1239,7 +1345,6 @@ public void actionPerformed(ActionEvent event) { ce.end(); panel.getUndoManager().addEdit(ce); - } else { panel.getUndoManager().addEdit(undoableFieldChange); } @@ -1295,7 +1400,6 @@ public void actionPerformed(ActionEvent e) { int i = tabbed.getSelectedIndex(); tabbed.setSelectedIndex(i < (tabbed.getTabCount() - 1) ? i + 1 : 0); activateVisible(); - } } @@ -1331,7 +1435,6 @@ private class GenerateKeyAction extends AbstractAction { super(Localization.lang("Generate BibTeX key"), IconTheme.JabRefIcon.MAKE_KEY.getIcon()); putValue(Action.SHORT_DESCRIPTION, Localization.lang("Generate BibTeX key")); - } @Override @@ -1367,7 +1470,7 @@ public void actionPerformed(ActionEvent e) { } BibtexKeyPatternUtil.makeAndSetLabel(panel.getBibDatabaseContext().getMetaData() - .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), panel.getDatabase(), entry, + .getCiteKeyPattern(Globals.prefs.getBibtexKeyPatternPreferences().getKeyPattern()), panel.getDatabase(), entry, Globals.prefs.getBibtexKeyPatternPreferences()); // Store undo information: @@ -1442,8 +1545,6 @@ private void warnEmptyBibtexkey() { } - - private class AutoLinkAction extends AbstractAction { AutoLinkAction() { putValue(Action.SMALL_ICON, IconTheme.JabRefIcon.AUTO_FILE_LINK.getIcon()); @@ -1476,5 +1577,4 @@ private Optional doUpdateTimeStamp() { String timestamp = DateTimeFormatter.ofPattern(timeStampFormat).format(LocalDateTime.now()); return UpdateField.updateField(entry, timeStampField, timestamp); } - } diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index 9c1ce2eec3e..ec866814eff 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -1,7 +1,27 @@ package net.sf.jabref.gui.entryeditor; -import com.jgoodies.forms.builder.FormBuilder; -import com.jgoodies.forms.factories.Paddings; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.StringJoiner; + +import javax.swing.BoxLayout; +import javax.swing.DefaultListCellRenderer; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; + import net.sf.jabref.gui.ClipBoardManager; import net.sf.jabref.gui.GUIGlobals; import net.sf.jabref.gui.IconTheme; @@ -9,19 +29,16 @@ import net.sf.jabref.logic.pdf.EntryAnnotationImporter; import net.sf.jabref.model.entry.FieldName; import net.sf.jabref.model.pdf.FileAnnotation; + +import com.jgoodies.forms.builder.FormBuilder; +import com.jgoodies.forms.factories.Paddings; import org.apache.pdfbox.pdmodel.fdf.FDFAnnotationHighlight; -import javax.swing.*; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import java.awt.*; -import java.util.*; -import java.util.List; class FileAnnotationTab extends JPanel { - private final JList commentList = new JList<>(); - private final JScrollPane commentScrollPane = new JScrollPane(); + private final JList annotationList = new JList<>(); + private final JScrollPane annotationScrollPane = new JScrollPane(); private final JLabel fileNameLabel = new JLabel(Localization.lang("Filename"),JLabel.CENTER); private final JComboBox fileNameComboBox = new JComboBox<>(); private final JScrollPane fileNameScrollPane = new JScrollPane(); @@ -34,11 +51,11 @@ class FileAnnotationTab extends JPanel { private final JLabel pageLabel = new JLabel(Localization.lang("Page"), JLabel.CENTER); private final JTextArea pageArea = new JTextArea("page"); private final JScrollPane pageScrollPane = new JScrollPane(); - private final JLabel commentTxtLabel = new JLabel(Localization.lang("Content"),JLabel.CENTER); + private final JLabel annotationTextLabel = new JLabel(Localization.lang("Content"), JLabel.CENTER); private final JTextArea contentTxtArea = new JTextArea(); private final JLabel highlightTxtLabel = new JLabel(Localization.lang("Highlight"), JLabel.CENTER); private final JTextArea highlightTxtArea = new JTextArea(); - private final JScrollPane commentTxtScrollPane = new JScrollPane(); + private final JScrollPane annotationTextScrollPane = new JScrollPane(); private final JScrollPane highlightScrollPane = new JScrollPane(); private final JButton copyToClipboardButton = new JButton(); private final JButton reloadAnnotationsButton = new JButton(); @@ -90,10 +107,10 @@ FileAnnotationTab initializeTab(FileAnnotationTab tab, Map annotations) { listModel.clear(); @@ -130,15 +147,14 @@ private void updateShownAnnotations(List annotations) { } /** - * Updates the text fields showing meta data and the content from the selected comment - * @param comment pdf comment which data should be shown in the text fields + * Updates the text fields showing meta data and the content from the selected annotation + * @param annotation pdf annotation which data should be shown in the text fields */ - private void updateTextFields(FileAnnotation comment) { - authorArea.setText(comment.getAuthor()); - dateArea.setText(comment.getDate()); - pageArea.setText(String.valueOf(comment.getPage())); - updateContentAndHighlightTextfields(comment); - + private void updateTextFields(FileAnnotation annotation) { + authorArea.setText(annotation.getAuthor()); + dateArea.setText(annotation.getDate()); + pageArea.setText(String.valueOf(annotation.getPage())); + updateContentAndHighlightTextfields(annotation); } /** @@ -159,15 +175,15 @@ private void updateFileNameComboBox() { } private void setUpGui() { - JPanel commentListPanel = FormBuilder.create() + JPanel annotationPanel = FormBuilder.create() .columns("pref, $lcgap, pref:grow") .rows("pref, $lg, fill:pref:grow, $lg, pref") .padding(Paddings.DIALOG) .add(fileNameLabel).xy(1,1, "left, top") .add(fileNameScrollPane).xyw(2, 1, 2) - .add(commentScrollPane).xyw(1, 3, 3) + .add(annotationScrollPane).xyw(1, 3, 3) .build(); - commentScrollPane.setViewportView(commentList); + annotationScrollPane.setViewportView(annotationList); JPanel informationPanel = FormBuilder.create() .columns("pref, $lcgap, pref:grow") @@ -179,8 +195,8 @@ private void setUpGui() { .add(dateScrollPane).xy(3,5) .add(pageLabel).xy(1,7, "left, top") .add(pageScrollPane).xy(3,7) - .add(commentTxtLabel).xy(1,9, "left, top") - .add(commentTxtScrollPane).xywh(3,9, 1, 2) + .add(annotationTextLabel).xy(1, 9, "left, top") + .add(annotationTextScrollPane).xywh(3, 9, 1, 2) .add(highlightTxtLabel).xy(1, 11, "left, top") .add(highlightScrollPane).xywh(3, 11, 1, 2) .add(this.setUpButtons()).xyw(1, 13, 3) @@ -191,7 +207,7 @@ private void setUpGui() { authorLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); dateLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); pageLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); - commentTxtLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); + annotationTextLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); highlightTxtLabel.setForeground(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR); fileNameScrollPane.setBorder(null); authorScrollPane.setViewportView(authorArea); @@ -200,7 +216,7 @@ private void setUpGui() { dateScrollPane.setBorder(null); pageScrollPane.setViewportView(pageArea); pageScrollPane.setBorder(null); - commentTxtScrollPane.setViewportView(contentTxtArea); + annotationTextScrollPane.setViewportView(contentTxtArea); highlightScrollPane.setViewportView(highlightTxtArea); authorArea.setEditable(false); dateArea.setEditable(false); @@ -215,7 +231,7 @@ private void setUpGui() { this.add(FormBuilder.create() .columns("0:grow, $lcgap, 0:grow") .rows("fill:pref:grow") - .add(commentListPanel).xy(1, 1) + .add(annotationPanel).xy(1, 1) .add(informationPanel).xy(3, 1) .build()); } @@ -265,85 +281,83 @@ private void reloadAnnotations() { /** - * Fills the highlight and comment texts and enables/disables the highlight area if there is no highlighted text + * Fills the highlight and annotation texts and enables/disables the highlight area if there is no highlighted text * - * @param comment either a text comment or a highlighting from a pdf + * @param annotation either a text annotation or a highlighting from a pdf */ - private void updateContentAndHighlightTextfields(final FileAnnotation comment){ + private void updateContentAndHighlightTextfields(final FileAnnotation annotation) { - if(comment.hasLinkedComment()){ - String textComment = ""; + if (annotation.hasLinkedAnnotation()) { + String annotationText = ""; String highlightedText = ""; - if(comment.getAnnotationType().equals(FDFAnnotationHighlight.SUBTYPE)){ - highlightedText = comment.getContent(); - textComment = comment.getLinkedFileAnnotation().getContent(); + if (annotation.getAnnotationType().equals(FDFAnnotationHighlight.SUBTYPE)) { + highlightedText = annotation.getContent(); + annotationText = annotation.getLinkedFileAnnotation().getContent(); } else { - highlightedText = comment.getLinkedFileAnnotation().getContent(); - textComment = comment.getContent(); + highlightedText = annotation.getLinkedFileAnnotation().getContent(); + annotationText = annotation.getContent(); } highlightTxtArea.setEnabled(true); - contentTxtArea.setText(textComment); + contentTxtArea.setText(annotationText); highlightTxtArea.setText(highlightedText); } else { - contentTxtArea.setText(comment.getContent()); + contentTxtArea.setText(annotation.getContent()); highlightTxtArea.setText("N/A"); highlightTxtArea.setEnabled(false); } } - private class CommentListSelectionListener implements ListSelectionListener { + private class AnnotationListSelectionListener implements ListSelectionListener { @Override public void valueChanged(ListSelectionEvent e) { int index; - int commentListSelectedIndex; - if (commentList.getSelectedIndex() >= 0) { - index = commentList.getSelectedIndex(); + int annotationListSelectedIndex = 0; + if (annotationList.getSelectedIndex() >= 0) { + index = annotationList.getSelectedIndex(); updateTextFields(listModel.get(index)); - commentListSelectedIndex = index; - } else { - commentListSelectedIndex = 0; + annotationListSelectedIndex = index; } - commentList.setSelectedIndex(commentListSelectedIndex); + annotationList.setSelectedIndex(annotationListSelectedIndex); //repaint the list to refresh the linked annotation highlighting - commentList.repaint(); + annotationList.repaint(); } } /** * Cell renderer that shows different icons dependent on the annotation subtype */ - class CommentsListCellRenderer extends DefaultListCellRenderer { + class AnnotationListCellRenderer extends DefaultListCellRenderer { JLabel label; - CommentsListCellRenderer() { + AnnotationListCellRenderer() { this.label = new JLabel(); } @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - FileAnnotation comment = (FileAnnotation) value; + FileAnnotation annotation = (FileAnnotation) value; //call the super method so that the cell selection is done as usual label = (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - //If more different comment types should be reflected by icons in the list, add them here - switch(comment.getAnnotationType()){ + //If more different annotation types should be reflected by icons in the list, add them here + switch (annotation.getAnnotationType()) { case FDFAnnotationHighlight.SUBTYPE: label.setIcon(IconTheme.JabRefIcon.MARKER.getSmallIcon()); break; default: - label.setIcon(IconTheme.JabRefIcon.COMMENT.getSmallIcon()); + label.setIcon(IconTheme.JabRefIcon.ANNOTATION.getSmallIcon()); break; } - label.setToolTipText(comment.getAnnotationType()); - label.setText(comment.toString()); + label.setToolTipText(annotation.getAnnotationType()); + label.setText(annotation.toString()); return label; } diff --git a/src/main/java/net/sf/jabref/model/pdf/FileAnnotation.java b/src/main/java/net/sf/jabref/model/pdf/FileAnnotation.java index 598feac8730..0f7e3ec363c 100644 --- a/src/main/java/net/sf/jabref/model/pdf/FileAnnotation.java +++ b/src/main/java/net/sf/jabref/model/pdf/FileAnnotation.java @@ -117,7 +117,7 @@ public String getAnnotationType() { return annotationType; } - public boolean hasLinkedComment() { + public boolean hasLinkedAnnotation() { return linkedComment; } diff --git a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java index e191ee3be16..c68192abb6f 100644 --- a/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java +++ b/src/test/java/net/sf/jabref/logic/importer/fileformat/BibtexParserTest.java @@ -1032,7 +1032,7 @@ public void parseIgnoresComments() throws IOException { public void parseIgnoresUpercaseComments() throws IOException { ParserResult result = parser - .parse(new StringReader("@COMMENT{some text and \\latex}")); + .parse(new StringReader("@ANNOTATION{some text and \\latex}")); assertEquals(0, result.getDatabase().getEntries().size()); } From 944bde1008a1e77cb42bfcabd19f4b4cb966a041 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Fri, 17 Feb 2017 00:35:22 +0100 Subject: [PATCH 7/7] minor change --- .../java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java index ec866814eff..8eb0cb255f9 100644 --- a/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java +++ b/src/main/java/net/sf/jabref/gui/entryeditor/FileAnnotationTab.java @@ -288,8 +288,8 @@ private void reloadAnnotations() { private void updateContentAndHighlightTextfields(final FileAnnotation annotation) { if (annotation.hasLinkedAnnotation()) { - String annotationText = ""; - String highlightedText = ""; + String annotationText; + String highlightedText; if (annotation.getAnnotationType().equals(FDFAnnotationHighlight.SUBTYPE)) { highlightedText = annotation.getContent();