From d16065ecb5ab854a71f385ed8c47012184139783 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Mon, 15 Apr 2019 22:59:20 +0200 Subject: [PATCH] GUI search, step 2 --- src/be/nikiroo/fanfix/reader/BasicReader.java | 41 +++++++++++-------- .../fanfix/reader/ui/GuiReaderSearch.java | 20 ++++++++- .../reader/ui/GuiReaderViewerPanel.java | 19 +++++++-- .../nikiroo/fanfix/searchable/Fanfiction.java | 3 ++ .../nikiroo/fanfix/searchable/MangaLel.java | 7 ++++ 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/src/be/nikiroo/fanfix/reader/BasicReader.java b/src/be/nikiroo/fanfix/reader/BasicReader.java index e0970e3e..584bc7cb 100644 --- a/src/be/nikiroo/fanfix/reader/BasicReader.java +++ b/src/be/nikiroo/fanfix/reader/BasicReader.java @@ -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 = ""; } // :( diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java index d9490ff0..04c1dad1 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderSearch.java @@ -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); diff --git a/src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerPanel.java b/src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerPanel.java index 08a9c9c3..724f5520 100644 --- a/src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerPanel.java +++ b/src/be/nikiroo/fanfix/reader/ui/GuiReaderViewerPanel.java @@ -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()); } /** diff --git a/src/be/nikiroo/fanfix/searchable/Fanfiction.java b/src/be/nikiroo/fanfix/searchable/Fanfiction.java index d25153eb..f392bf15 100644 --- a/src/be/nikiroo/fanfix/searchable/Fanfiction.java +++ b/src/be/nikiroo/fanfix/searchable/Fanfiction.java @@ -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? diff --git a/src/be/nikiroo/fanfix/searchable/MangaLel.java b/src/be/nikiroo/fanfix/searchable/MangaLel.java index 879b1638..60e25917 100644 --- a/src/be/nikiroo/fanfix/searchable/MangaLel.java +++ b/src/be/nikiroo/fanfix/searchable/MangaLel.java @@ -103,6 +103,12 @@ class MangaLel extends BasicSearchable { if (infos != null) { String[] tab = infos.outerHtml().split("
"); + 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); } } -- 2.27.0