GUI search, step 2
authorNiki Roo <niki@nikiroo.be>
Mon, 15 Apr 2019 20:59:20 +0000 (22:59 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 15 Apr 2019 20:59:20 +0000 (22:59 +0200)
src/be/nikiroo/fanfix/reader/BasicReader.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java
src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerPanel.java
src/be/nikiroo/fanfix/searchable/Fanfiction.java
src/be/nikiroo/fanfix/searchable/MangaLel.java

index e0970e3ef09621e9f8c582d65fb7e4a2c2afba13..584bc7cb3b8f8c64a4586fe5dba4ebbe17935fc0 100644 (file)
@@ -227,16 +227,19 @@ public abstract class BasicReader implements Reader {
                        tags.append(tag);
                }
 
+               // TODO: i18n
                metaDesc.put("Author", meta.getAuthor());
                metaDesc.put("Publication date", formatDate(meta.getDate()));
                metaDesc.put("Published on", meta.getPublisher());
                metaDesc.put("URL", meta.getUrl());
+               String count = "";
+               if (meta.getWords() > 0) {
+                       count = StringUtils.formatNumber(meta.getWords());
+               }
                if (meta.isImageDocument()) {
-                       metaDesc.put("Number of images",
-                                       StringUtils.formatNumber(meta.getWords()));
+                       metaDesc.put("Number of images", count);
                } else {
-                       metaDesc.put("Number of words",
-                                       StringUtils.formatNumber(meta.getWords()));
+                       metaDesc.put("Number of words", count);
                }
                metaDesc.put("Source", meta.getSource());
                metaDesc.put("Subject", meta.getSubject());
@@ -356,23 +359,29 @@ public abstract class BasicReader implements Reader {
        static private String formatDate(String date) {
                long ms = 0;
 
-               try {
-                       ms = StringUtils.toTime(date);
-               } catch (ParseException e) {
-               }
-
-               if (ms <= 0) {
-                       SimpleDateFormat sdf = new SimpleDateFormat(
-                                       "yyyy-MM-dd'T'HH:mm:ssSSS");
+               if (date != null && !date.isEmpty()) {
                        try {
-                               ms = sdf.parse(date).getTime();
+                               ms = StringUtils.toTime(date);
                        } catch (ParseException e) {
                        }
+
+                       if (ms <= 0) {
+                               SimpleDateFormat sdf = new SimpleDateFormat(
+                                               "yyyy-MM-dd'T'HH:mm:ssSSS");
+                               try {
+                                       ms = sdf.parse(date).getTime();
+                               } catch (ParseException e) {
+                               }
+                       }
+
+                       if (ms > 0) {
+                               SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+                               return sdf.format(new Date(ms));
+                       }
                }
 
-               if (ms > 0) {
-                       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-                       return sdf.format(new Date(ms));
+               if (date == null) {
+                       date = "";
                }
 
                // :(
index d9490ff0b8cc9480f96fc04e11be5f5950f8e09b..04c1dad1071b89ef5d1e3a9c794be4c5b187ca3d 100644 (file)
@@ -1,6 +1,7 @@
 package be.nikiroo.fanfix.reader.ui;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.EventQueue;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
@@ -19,6 +20,7 @@ import javax.swing.JTextField;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.fanfix.reader.ui.GuiReaderBook.BookActionListener;
 import be.nikiroo.fanfix.searchable.BasicSearchable;
 import be.nikiroo.fanfix.searchable.SearchableTag;
 import be.nikiroo.fanfix.supported.SupportType;
@@ -45,7 +47,7 @@ public class GuiReaderSearch extends JFrame {
        private boolean seeWordcount;
        private GuiReaderGroup books;
 
-       public GuiReaderSearch(GuiReader reader) {
+       public GuiReaderSearch(final GuiReader reader) {
                // TODO: i18n
                super("Browse stories");
                setLayout(new BorderLayout());
@@ -85,6 +87,22 @@ public class GuiReaderSearch extends JFrame {
                add(top, BorderLayout.NORTH);
 
                books = new GuiReaderGroup(reader, null, null);
+               books.setActionListener(new BookActionListener() {
+                       @Override
+                       public void select(GuiReaderBook book) {
+                       }
+
+                       @Override
+                       public void popupRequested(GuiReaderBook book, Component target,
+                                       int x, int y) {
+                       }
+
+                       @Override
+                       public void action(GuiReaderBook book) {
+                               new GuiReaderSearchAction(reader.getLibrary(), book.getInfo())
+                                               .setVisible(true);
+                       }
+               });
                JScrollPane scroll = new JScrollPane(books);
                scroll.getVerticalScrollBar().setUnitIncrement(16);
                add(scroll, BorderLayout.CENTER);
index 08a9c9c34e10901fcb5bce3644c9057b0eb991b4..724f552093942fdf42cb68347bdcaa4d71aa3aaf 100644 (file)
@@ -20,6 +20,7 @@ import javax.swing.SwingConstants;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.bundles.StringIdGui;
 import be.nikiroo.fanfix.data.Chapter;
+import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.data.Story;
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.ui.ImageUtilsAwt;
@@ -51,12 +52,24 @@ public class GuiReaderViewerPanel extends JPanel {
         * Create a new viewer.
         * 
         * @param story
-        *            the {@link Story} to work on.
+        *            the {@link Story} to work on
         */
        public GuiReaderViewerPanel(Story story) {
+               this(story.getMeta(), story.getMeta().isImageDocument());
+       }
+
+       /**
+        * Create a new viewer.
+        * 
+        * @param meta
+        *            the {@link MetaData} of the story to show
+        * @param isImageDocument
+        *            TRUE if it is an image document, FALSE if not
+        */
+       public GuiReaderViewerPanel(MetaData meta, boolean isImageDocument) {
                super(new BorderLayout());
 
-               this.imageDocument = story.getMeta().isImageDocument();
+               this.imageDocument = isImageDocument;
 
                this.text = new JEditorPane("text/html", "");
                text.setEditable(false);
@@ -102,7 +115,7 @@ public class GuiReaderViewerPanel extends JPanel {
                        main.invalidate();
                }
 
-               setChapter(story.getMeta().getResume());
+               setChapter(meta.getResume());
        }
 
        /**
index d25153eb28f6921ea7c4bc64410f384b6e812dd7..f392bf15cd09a4da7a8877db42dd924b48f3f194 100644 (file)
@@ -260,12 +260,15 @@ class Fanfiction extends BasicSearchable {
                        MetaData meta = new MetaData();
                        meta.setImageDocument(false);
                        meta.setSource(getType().getSourceName());
+                       meta.setPublisher(getType().getSourceName());
+                       meta.setType(getType().toString());
 
                        // Title, URL, Cover
                        Element stitle = story.getElementsByClass("stitle").first();
                        if (stitle != null) {
                                meta.setTitle(stitle.text());
                                meta.setUrl(stitle.absUrl("href"));
+                               meta.setUuid(meta.getUrl());
                                Element cover = stitle.getElementsByTag("img").first();
                                if (cover != null) {
                                        // note: see data-original if needed?
index 879b163888db05fb9ab309a1bd87a0b8ea4c4602..60e25917e889c3d61b0919b903138be5acdbc6ec 100644 (file)
@@ -103,6 +103,12 @@ class MangaLel extends BasicSearchable {
                                if (infos != null) {
                                        String[] tab = infos.outerHtml().split("<br>");
 
+                                       meta.setLang("fr");
+                                       meta.setSource(getType().getSourceName());
+                                       meta.setPublisher(getType().getSourceName());
+                                       meta.setType(getType().toString());
+                                       meta.setSubject("manga");
+                                       meta.setImageDocument(true);
                                        meta.setTitle(getVal(tab, 0));
                                        meta.setAuthor(getVal(tab, 1));
                                        meta.setTags(Arrays.asList(getVal(tab, 2).split(" ")));
@@ -151,6 +157,7 @@ class MangaLel extends BasicSearchable {
                                if (projectId >= 0) {
                                        meta.setUrl("http://mangas-lecture-en-ligne.fr/index_lel.php?page=presentationProjet&idProjet="
                                                        + projectId);
+                                       meta.setUuid(meta.getUrl());
                                        metas.add(meta);
                                }
                        }