22
33import java .awt .BorderLayout ;
44import java .awt .Dimension ;
5+ import java .io .IOException ;
6+ import java .util .ArrayList ;
57import java .util .HashMap ;
68import java .util .Optional ;
79
1517import net .sf .jabref .gui .BasePanel ;
1618import net .sf .jabref .gui .JabRefFrame ;
1719import net .sf .jabref .logic .pdf .PdfCommentImporter ;
20+ import net .sf .jabref .model .entry .BibEntry ;
1821import net .sf .jabref .model .entry .FieldName ;
1922
2023public class PdfCommentsTab extends JPanel {
@@ -43,6 +46,8 @@ public class PdfCommentsTab extends JPanel {
4346
4447 private JScrollPane siteScrollPane = new JScrollPane (siteArea );
4548
49+ DefaultListModel <String > listModel ;
50+
4651 private final EntryEditor parent ;
4752
4853 private final String tabTitle ;
@@ -57,18 +62,27 @@ public PdfCommentsTab(EntryEditor parent, JabRefFrame frame, BasePanel basePanel
5762 this .basePanel = basePanel ;
5863 this .tabTitle = "PDF comments" ;
5964 this .setUpInformationPanel ();
60- this .setUpPdfCommentsTab ();
65+ listModel = new DefaultListModel <>();
66+ try {
67+ this .setUpPdfCommentsTab ();
68+ } catch (IOException e ) {
69+ e .printStackTrace ();
70+ }
6171 }
6272
63- private void setUpPdfCommentsTab () {
73+ private void setUpPdfCommentsTab () throws IOException {
6474 Optional <String > field = parent .getEntry ().getField (FieldName .FILE );
6575 if (field .isPresent ()) {
66- DefaultListModel < String > listModel = new DefaultListModel <>();
76+
6777 commentList .setModel (listModel );
6878 PdfCommentImporter commentImporter = new PdfCommentImporter ();
69- String pdfPath = field .get ().replaceFirst (".*?:" , System .getProperty ("file.separator" )).replaceAll (":PDF" , "" );
70- HashMap <String , String > importedNotes = commentImporter .importNotes (pdfPath );
71- importedNotes .values ().stream ().forEach ((note ) -> listModel .addElement (note ));
79+ ArrayList <BibEntry > entries = new ArrayList <>();
80+ entries .add (parent .getEntry ());
81+ commentImporter .importPdfFile (entries , basePanel .getBibDatabaseContext ());
82+
83+ HashMap <String , String > importedNotes = commentImporter .importNotes (commentImporter .importPdfFile (entries ,
84+ basePanel .getBibDatabaseContext ()).get (0 ));
85+ updateShownComments (importedNotes );
7286 }
7387
7488 commentScrollPane .setPreferredSize (new Dimension (450 ,200 ));
@@ -77,6 +91,10 @@ private void setUpPdfCommentsTab() {
7791 this .add (informationPanel ,BorderLayout .WEST );
7892 }
7993
94+ private void updateShownComments (HashMap <String , String > importedNotes ){
95+ importedNotes .values ().stream ().forEach ((note ) -> listModel .addElement (note ));
96+ }
97+
8098
8199 private void setUpInformationPanel (){
82100 authorArea .setEditable (false );
0 commit comments