From: Niki Roo Date: Mon, 3 Jul 2017 17:54:47 +0000 (+0200) Subject: Code cleanup: Libraries/Readers X-Git-Tag: fanfix-1.6.0~21 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=e42573a004fac26378c693ce9ef0d6319713c682;p=fanfix.git Code cleanup: Libraries/Readers - Move libraries into a new package - Update readers to have a BasicReader and an interface --- diff --git a/src/be/nikiroo/fanfix/Instance.java b/src/be/nikiroo/fanfix/Instance.java index f9060f4..2231414 100644 --- a/src/be/nikiroo/fanfix/Instance.java +++ b/src/be/nikiroo/fanfix/Instance.java @@ -9,6 +9,8 @@ import be.nikiroo.fanfix.bundles.ConfigBundle; import be.nikiroo.fanfix.bundles.StringIdBundle; import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.bundles.UiConfigBundle; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.resources.Bundles; diff --git a/src/be/nikiroo/fanfix/Main.java b/src/be/nikiroo/fanfix/Main.java index a05df43..ee122bd 100644 --- a/src/be/nikiroo/fanfix/Main.java +++ b/src/be/nikiroo/fanfix/Main.java @@ -8,10 +8,14 @@ import java.net.URL; import be.nikiroo.fanfix.bundles.StringId; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.LocalLibrary; +import be.nikiroo.fanfix.library.RemoteLibrary; +import be.nikiroo.fanfix.library.RemoteLibraryServer; import be.nikiroo.fanfix.output.BasicOutput; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.fanfix.reader.BasicReader; -import be.nikiroo.fanfix.reader.BasicReader.ReaderType; +import be.nikiroo.fanfix.reader.Reader; +import be.nikiroo.fanfix.reader.Reader.ReaderType; import be.nikiroo.fanfix.supported.BasicSupport; import be.nikiroo.fanfix.supported.BasicSupport.SupportType; import be.nikiroo.utils.Progress; @@ -392,7 +396,7 @@ public class Main { */ private static int read(String story, String chapString, boolean library) { try { - BasicReader reader = BasicReader.getReader(); + Reader reader = BasicReader.getReader(); if (library) { reader.setStory(story, null); } else { diff --git a/src/be/nikiroo/fanfix/BasicLibrary.java b/src/be/nikiroo/fanfix/library/BasicLibrary.java similarity index 99% rename from src/be/nikiroo/fanfix/BasicLibrary.java rename to src/be/nikiroo/fanfix/library/BasicLibrary.java index 75cc8a6..9ac16ea 100644 --- a/src/be/nikiroo/fanfix/BasicLibrary.java +++ b/src/be/nikiroo/fanfix/library/BasicLibrary.java @@ -1,4 +1,4 @@ -package be.nikiroo.fanfix; +package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.output.BasicOutput; diff --git a/src/be/nikiroo/fanfix/LocalLibrary.java b/src/be/nikiroo/fanfix/library/LocalLibrary.java similarity index 99% rename from src/be/nikiroo/fanfix/LocalLibrary.java rename to src/be/nikiroo/fanfix/library/LocalLibrary.java index 35f13f0..e4dc5e9 100644 --- a/src/be/nikiroo/fanfix/LocalLibrary.java +++ b/src/be/nikiroo/fanfix/library/LocalLibrary.java @@ -1,4 +1,4 @@ -package be.nikiroo.fanfix; +package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; diff --git a/src/be/nikiroo/fanfix/RemoteLibrary.java b/src/be/nikiroo/fanfix/library/RemoteLibrary.java similarity index 98% rename from src/be/nikiroo/fanfix/RemoteLibrary.java rename to src/be/nikiroo/fanfix/library/RemoteLibrary.java index 5c111ca..6c1e56f 100644 --- a/src/be/nikiroo/fanfix/RemoteLibrary.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibrary.java @@ -1,4 +1,4 @@ -package be.nikiroo.fanfix; +package be.nikiroo.fanfix.library; import java.awt.image.BufferedImage; import java.io.File; @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; import be.nikiroo.fanfix.output.BasicOutput.OutputType; diff --git a/src/be/nikiroo/fanfix/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java similarity index 94% rename from src/be/nikiroo/fanfix/RemoteLibraryServer.java rename to src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index e47a591..566c70f 100644 --- a/src/be/nikiroo/fanfix/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -1,10 +1,9 @@ -package be.nikiroo.fanfix; +package be.nikiroo.fanfix.library; -import java.io.File; import java.io.IOException; import java.util.List; -import java.util.Map; +import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.utils.Version; import be.nikiroo.utils.serial.ConnectActionServer; diff --git a/src/be/nikiroo/fanfix/library/package-info.java b/src/be/nikiroo/fanfix/library/package-info.java new file mode 100644 index 0000000..1bb63ea --- /dev/null +++ b/src/be/nikiroo/fanfix/library/package-info.java @@ -0,0 +1,9 @@ +/** + * This package offer a Libraries to store stories into. + *

+ * It currently has a local library and a remote one, as well as the required + * remote server. + * + * @author niki + */ +package be.nikiroo.fanfix.library; \ No newline at end of file diff --git a/src/be/nikiroo/fanfix/reader/BasicReader.java b/src/be/nikiroo/fanfix/reader/BasicReader.java index baf3c7d..cbd4e03 100644 --- a/src/be/nikiroo/fanfix/reader/BasicReader.java +++ b/src/be/nikiroo/fanfix/reader/BasicReader.java @@ -6,13 +6,13 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; -import be.nikiroo.fanfix.BasicLibrary; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.LocalLibrary; import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.supported.BasicSupport; import be.nikiroo.utils.Progress; import be.nikiroo.utils.serial.SerialUtils; @@ -24,49 +24,12 @@ import be.nikiroo.utils.serial.SerialUtils; * * @author niki */ -public abstract class BasicReader { - /** - * A type of {@link BasicReader}. - * - * @author niki - */ - public enum ReaderType { - /** Simple reader that outputs everything on the console */ - CLI, - /** Reader that starts local programs to handle the stories */ - GUI, - /** A text (UTF-8) reader with menu and text windows */ - TUI, - - ; - - /** - * Return the full class name of a type that implements said - * {@link ReaderType}. - * - * @return the class name - */ - public String getTypeName() { - String pkg = "be.nikiroo.fanfix.reader."; - switch (this) { - case CLI: - return pkg + "CliReader"; - case TUI: - return pkg + "TuiReader"; - case GUI: - return pkg + "GuiReader"; - } - - return null; - } - } - +public abstract class BasicReader implements Reader { private static BasicLibrary defaultLibrary = Instance.getLibrary(); private static ReaderType defaultType = ReaderType.GUI; private BasicLibrary lib; private Story story; - private ReaderType type; /** * Take the default reader type configuration from the config file. @@ -83,43 +46,10 @@ public abstract class BasicReader { } } - /** - * The type of this reader. - * - * @return the type - */ - public ReaderType getType() { - return type; - } - - /** - * The type of this reader. - * - * @param type - * the new type - * - * @return the type - */ - protected BasicReader setType(ReaderType type) { - this.type = type; - return this; - } - - /** - * Return the current {@link Story}. - * - * @return the {@link Story} - */ public Story getStory() { return story; } - /** - * The {@link LocalLibrary} to load the stories from (by default, takes the - * default {@link LocalLibrary}). - * - * @return the {@link LocalLibrary} - */ public BasicLibrary getLibrary() { if (lib == null) { lib = defaultLibrary; @@ -128,29 +58,10 @@ public abstract class BasicReader { return lib; } - /** - * Change the {@link LocalLibrary} that will be managed by this - * {@link BasicReader}. - * - * @param lib - * the new {@link LocalLibrary} - */ public void setLibrary(LocalLibrary lib) { this.lib = lib; } - /** - * Create a new {@link BasicReader} for a {@link Story} in the - * {@link LocalLibrary}. - * - * @param luid - * the {@link Story} ID - * @param pg - * the optional progress reporter - * - * @throws IOException - * in case of I/O error - */ public void setStory(String luid, Progress pg) throws IOException { story = lib.getStory(luid, pg); if (story == null) { @@ -158,17 +69,6 @@ public abstract class BasicReader { } } - /** - * Create a new {@link BasicReader} for an external {@link Story}. - * - * @param source - * the {@link Story} {@link URL} - * @param pg - * the optional progress reporter - * - * @throws IOException - * in case of I/O error - */ public void setStory(URL source, Progress pg) throws IOException { BasicSupport support = BasicSupport.getSupport(source); if (support == null) { @@ -184,37 +84,6 @@ public abstract class BasicReader { } } - /** - * Start the {@link Story} Reading. - * - * @throws IOException - * in case of I/O error or if the {@link Story} was not - * previously set - */ - public abstract void read() throws IOException; - - /** - * Read the selected chapter (starting at 1). - * - * @param chapter - * the chapter - * - * @throws IOException - * in case of I/O error or if the {@link Story} was not - * previously set - */ - public abstract void read(int chapter) throws IOException; - - /** - * Start the reader in browse mode for the given source (or pass NULL for - * all sources). - * - * @param source - * the type of {@link Story} to take into account, or NULL for - * all - */ - public abstract void browse(String source); - /** * Return a new {@link BasicReader} ready for use if one is configured. *

@@ -222,11 +91,11 @@ public abstract class BasicReader { * * @return a {@link BasicReader}, or NULL if none configured */ - public static BasicReader getReader() { + public static Reader getReader() { try { if (defaultType != null) { - return ((BasicReader) SerialUtils.createObject(defaultType - .getTypeName())).setType(defaultType); + return (Reader) SerialUtils.createObject(defaultType + .getTypeName()); } } catch (Exception e) { Instance.syserr(new Exception("Cannot create a reader of type: " diff --git a/src/be/nikiroo/fanfix/reader/CliReader.java b/src/be/nikiroo/fanfix/reader/CliReader.java index 7ac69e8..de55bf9 100644 --- a/src/be/nikiroo/fanfix/reader/CliReader.java +++ b/src/be/nikiroo/fanfix/reader/CliReader.java @@ -18,7 +18,6 @@ import be.nikiroo.fanfix.data.Story; * @author niki */ class CliReader extends BasicReader { - @Override public void read() throws IOException { if (getStory() == null) { throw new IOException("No story to read"); @@ -57,7 +56,6 @@ class CliReader extends BasicReader { } } - @Override public void read(int chapter) throws IOException { if (getStory() == null) { throw new IOException("No story to read"); @@ -77,7 +75,6 @@ class CliReader extends BasicReader { } } - @Override public void browse(String source) { List stories; stories = getLibrary().getListBySource(source); diff --git a/src/be/nikiroo/fanfix/reader/GuiReader.java b/src/be/nikiroo/fanfix/reader/GuiReader.java index cdf80d0..06b3473 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReader.java +++ b/src/be/nikiroo/fanfix/reader/GuiReader.java @@ -13,10 +13,10 @@ import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.LocalLibrary; import be.nikiroo.fanfix.VersionCheck; import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.utils.Progress; import be.nikiroo.utils.Version; @@ -69,7 +69,6 @@ class GuiReader extends BasicReader { localLibrary = new LocalLibrary(dir, text, images); } - @Override public void read() throws IOException { if (getStory() == null) { throw new IOException("No story to read"); @@ -78,7 +77,6 @@ class GuiReader extends BasicReader { open(getStory().getMeta().getLuid(), null); } - @Override public void read(int chapter) throws IOException { // TODO: show a special page? read(); @@ -105,7 +103,7 @@ class GuiReader extends BasicReader { } try { - Story story = Instance.getLibrary().getStory(luid, pgGetStory); + Story story = getLibrary().getStory(luid, pgGetStory); if (story != null) { story = localLibrary.save(story, luid, pgSave); } else { @@ -131,7 +129,6 @@ class GuiReader extends BasicReader { return localLibrary.getInfo(luid) != null; } - @Override public void browse(String type) { // TODO: improve presentation of update message final VersionCheck updates = VersionCheck.check(); @@ -189,8 +186,7 @@ class GuiReader extends BasicReader { } } - new GuiReaderFrame(GuiReader.this, typeFinal) - .setVisible(true); + new GuiReaderFrame(GuiReader.this, typeFinal).setVisible(true); } }); } @@ -208,7 +204,7 @@ class GuiReader extends BasicReader { void delete(String luid) { try { localLibrary.delete(luid); - Instance.getLibrary().delete(luid); + getLibrary().delete(luid); } catch (IOException e) { Instance.syserr(e); } @@ -228,7 +224,7 @@ class GuiReader extends BasicReader { void changeType(String luid, String newType) { try { localLibrary.changeSource(luid, newType, null); - Instance.getLibrary().changeSource(luid, newType, null); + getLibrary().changeSource(luid, newType, null); } catch (IOException e) { Instance.syserr(e); } diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java index e6fe91b..2a4266d 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderBook.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderBook.java @@ -93,12 +93,15 @@ class GuiReaderBook extends JPanel { private Date lastClick; private List listeners; + private Reader reader; private MetaData meta; private boolean cached; /** * Create a new {@link GuiReaderBook} item for the given {@link Story}. * + * @param reader + * the associated reader * @param meta * the story {@link MetaData} * @param cached @@ -106,7 +109,9 @@ class GuiReaderBook extends JPanel { * @param seeWordCount * TRUE to see word counts, FALSE to see authors */ - public GuiReaderBook(MetaData meta, boolean cached, boolean seeWordCount) { + public GuiReaderBook(Reader reader, MetaData meta, boolean cached, + boolean seeWordCount) { + this.reader = reader; this.cached = cached; this.meta = meta; @@ -375,7 +380,7 @@ class GuiReaderBook extends JPanel { if (resizedImage == null) { try { - BufferedImage cover = Instance.getLibrary().getCover( + BufferedImage cover = reader.getLibrary().getCover( meta.getLuid()); resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH, diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java index 26ab23f..88eccf7 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderFrame.java @@ -34,11 +34,11 @@ import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; import be.nikiroo.fanfix.Instance; -import be.nikiroo.fanfix.LocalLibrary; import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.bundles.UiConfig; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.fanfix.reader.GuiReaderBook.BookActionListener; import be.nikiroo.utils.Progress; @@ -125,7 +125,7 @@ class GuiReaderFrame extends JFrame { final String typeF = type; outOfUi(pg, new Runnable() { public void run() { - Instance.getLibrary().refresh(false, pg); + GuiReaderFrame.this.reader.getLibrary().refresh(false, pg); invalidate(); setJMenuBar(createMenu()); addBookPane(typeF, true); @@ -151,13 +151,13 @@ class GuiReaderFrame extends JFrame { private void addBookPane(String value, boolean type) { if (value == null) { if (type) { - for (String tt : Instance.getLibrary().getSources()) { + for (String tt : reader.getLibrary().getSources()) { if (tt != null) { addBookPane(tt, type); } } } else { - for (String tt : Instance.getLibrary().getAuthors()) { + for (String tt : reader.getLibrary().getAuthors()) { if (tt != null) { addBookPane(tt, type); } @@ -220,13 +220,13 @@ class GuiReaderFrame extends JFrame { */ private void refreshBooks() { for (GuiReaderGroup group : booksByType.keySet()) { - List stories = Instance.getLibrary().getListBySource( + List stories = reader.getLibrary().getListBySource( booksByType.get(group)); group.refreshBooks(stories, words); } for (GuiReaderGroup group : booksByAuthor.keySet()) { - List stories = Instance.getLibrary().getListByAuthor( + List stories = reader.getLibrary().getListByAuthor( booksByAuthor.get(group)); group.refreshBooks(stories, words); } @@ -312,7 +312,7 @@ class GuiReaderFrame extends JFrame { JMenu sources = new JMenu("Sources"); sources.setMnemonic(KeyEvent.VK_S); - List tt = Instance.getLibrary().getSources(); + List tt = reader.getLibrary().getSources(); tt.add(0, null); for (final String type : tt) { JMenuItem item = new JMenuItem(type == null ? "All" : type); @@ -335,7 +335,7 @@ class GuiReaderFrame extends JFrame { JMenu authors = new JMenu("Authors"); authors.setMnemonic(KeyEvent.VK_A); - List aa = Instance.getLibrary().getAuthors(); + List aa = reader.getLibrary().getAuthors(); aa.add(0, null); for (final String author : aa) { JMenuItem item = new JMenuItem(author == null ? "All" @@ -463,7 +463,7 @@ class GuiReaderFrame extends JFrame { outOfUi(pg, new Runnable() { public void run() { try { - Instance.getLibrary().export( + reader.getLibrary().export( selectedBook.getMeta().getLuid(), type, path, pg); } catch (IOException e) { @@ -542,7 +542,7 @@ class GuiReaderFrame extends JFrame { List types = new ArrayList(); types.add(null); - types.addAll(Instance.getLibrary().getSources()); + types.addAll(reader.getLibrary().getSources()); for (String type : types) { JMenuItem item = new JMenuItem(type == null ? "New type..." : type); @@ -785,8 +785,7 @@ class GuiReaderFrame extends JFrame { public void run() { Exception ex = null; try { - Instance.getLibrary().imprt(BasicReader.getUrl(url), - pgImprt); + reader.getLibrary().imprt(BasicReader.getUrl(url), pgImprt); } catch (IOException e) { ex = e; } diff --git a/src/be/nikiroo/fanfix/reader/GuiReaderGroup.java b/src/be/nikiroo/fanfix/reader/GuiReaderGroup.java index 2161de5..ca3768d 100644 --- a/src/be/nikiroo/fanfix/reader/GuiReaderGroup.java +++ b/src/be/nikiroo/fanfix/reader/GuiReaderGroup.java @@ -33,15 +33,14 @@ public class GuiReaderGroup extends JPanel { * Create a new {@link GuiReaderGroup}. * * @param reader - * the {@link GuiReaderBook} used to probe some information - * about the stories + * the {@link GuiReaderBook} used to probe some information about + * the stories * @param title * the title of this group * @param backgroundColor * the background colour to use (or NULL for default) */ - public GuiReaderGroup(GuiReader reader, String title, - Color backgroundColor) { + public GuiReaderGroup(GuiReader reader, String title, Color backgroundColor) { this.reader = reader; this.backgroundColor = backgroundColor; @@ -101,7 +100,7 @@ public class GuiReaderGroup extends JPanel { if (stories != null) { for (MetaData meta : stories) { - GuiReaderBook book = new GuiReaderBook(meta, + GuiReaderBook book = new GuiReaderBook(reader, meta, reader.isCached(meta.getLuid()), seeWordcount); if (backgroundColor != null) { book.setBackground(backgroundColor); @@ -116,8 +115,7 @@ public class GuiReaderGroup extends JPanel { } } - public void popupRequested(GuiReaderBook book, - MouseEvent e) { + public void popupRequested(GuiReaderBook book, MouseEvent e) { } public void action(GuiReaderBook book) { diff --git a/src/be/nikiroo/fanfix/reader/Reader.java b/src/be/nikiroo/fanfix/reader/Reader.java new file mode 100644 index 0000000..d728578 --- /dev/null +++ b/src/be/nikiroo/fanfix/reader/Reader.java @@ -0,0 +1,130 @@ +package be.nikiroo.fanfix.reader; + +import java.io.IOException; +import java.net.URL; + +import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.library.LocalLibrary; +import be.nikiroo.utils.Progress; + +public interface Reader { + /** + * A type of {@link BasicReader}. + * + * @author niki + */ + public enum ReaderType { + /** Simple reader that outputs everything on the console */ + CLI, + /** Reader that starts local programs to handle the stories */ + GUI, + /** A text (UTF-8) reader with menu and text windows */ + TUI, + + ; + + /** + * Return the full class name of a type that implements said + * {@link ReaderType}. + * + * @return the class name + */ + public String getTypeName() { + String pkg = "be.nikiroo.fanfix.reader."; + switch (this) { + case CLI: + return pkg + "CliReader"; + case TUI: + return pkg + "TuiReader"; + case GUI: + return pkg + "GuiReader"; + } + + return null; + } + }; + + /** + * Return the current {@link Story}. + * + * @return the {@link Story} + */ + public Story getStory(); + + /** + * The {@link LocalLibrary} to load the stories from (by default, takes the + * default {@link LocalLibrary}). + * + * @return the {@link LocalLibrary} + */ + public BasicLibrary getLibrary(); + + /** + * Change the {@link LocalLibrary} that will be managed by this + * {@link BasicReader}. + * + * @param lib + * the new {@link LocalLibrary} + */ + public void setLibrary(LocalLibrary lib); + + /** + * Create a new {@link BasicReader} for a {@link Story} in the + * {@link LocalLibrary}. + * + * @param luid + * the {@link Story} ID + * @param pg + * the optional progress reporter + * + * @throws IOException + * in case of I/O error + */ + public void setStory(String luid, Progress pg) throws IOException; + + /** + * Create a new {@link BasicReader} for an external {@link Story}. + * + * @param source + * the {@link Story} {@link URL} + * @param pg + * the optional progress reporter + * + * @throws IOException + * in case of I/O error + */ + public void setStory(URL source, Progress pg) throws IOException; + + /** + * Start the {@link Story} Reading. + * + * @throws IOException + * in case of I/O error or if the {@link Story} was not + * previously set + */ + public void read() throws IOException; + + /** + * Read the selected chapter (starting at 1). + * + * @param chapter + * the chapter + * + * @throws IOException + * in case of I/O error or if the {@link Story} was not + * previously set + */ + public void read(int chapter) throws IOException; + + /** + * Start the reader in browse mode for the given source (or pass NULL for + * all sources). + * + * @param source + * the type of {@link Story} to take into account, or NULL for + * all + */ + public void browse(String source); + +} diff --git a/src/be/nikiroo/fanfix/reader/TuiReader.java b/src/be/nikiroo/fanfix/reader/TuiReader.java index 98130a9..e9f909d 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReader.java +++ b/src/be/nikiroo/fanfix/reader/TuiReader.java @@ -5,7 +5,6 @@ import java.io.IOException; import be.nikiroo.fanfix.Instance; class TuiReader extends BasicReader { - @Override public void read() throws IOException { if (getStory() == null) { throw new IOException("No story to read"); @@ -14,13 +13,11 @@ class TuiReader extends BasicReader { open(getLibrary(), getStory().getMeta().getLuid()); } - @Override public void read(int chapter) throws IOException { // TODO: show a special page? read(); } - @Override public void browse(String source) { try { TuiReaderApplication app = new TuiReaderApplication(getLibrary() diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java index 2b1cace..71b5b5e 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderStoryWindow.java @@ -12,11 +12,11 @@ import jexer.TLabel; import jexer.TText; import jexer.TWindow; import jexer.event.TResizeEvent; -import be.nikiroo.fanfix.BasicLibrary; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.BasicLibrary; class TuiReaderStoryWindow extends TWindow { private BasicLibrary lib; diff --git a/src/be/nikiroo/fanfix/test/LibraryTest.java b/src/be/nikiroo/fanfix/test/LibraryTest.java index f9d5299..43ca087 100644 --- a/src/be/nikiroo/fanfix/test/LibraryTest.java +++ b/src/be/nikiroo/fanfix/test/LibraryTest.java @@ -4,12 +4,12 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import be.nikiroo.fanfix.BasicLibrary; -import be.nikiroo.fanfix.LocalLibrary; import be.nikiroo.fanfix.data.Chapter; import be.nikiroo.fanfix.data.MetaData; import be.nikiroo.fanfix.data.Paragraph; import be.nikiroo.fanfix.data.Story; +import be.nikiroo.fanfix.library.BasicLibrary; +import be.nikiroo.fanfix.library.LocalLibrary; import be.nikiroo.fanfix.output.BasicOutput.OutputType; import be.nikiroo.utils.IOUtils; import be.nikiroo.utils.test.TestCase;