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;
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;
*/
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 {
-package be.nikiroo.fanfix;
+package be.nikiroo.fanfix.library;
import java.awt.image.BufferedImage;
import java.io.File;
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;
-package be.nikiroo.fanfix;
+package be.nikiroo.fanfix.library;
import java.awt.image.BufferedImage;
import java.io.File;
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;
-package be.nikiroo.fanfix;
+package be.nikiroo.fanfix.library;
import java.awt.image.BufferedImage;
import java.io.File;
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;
-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;
--- /dev/null
+/**
+ * This package offer a Libraries to store stories into.
+ * <p>
+ * 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
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;
*
* @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.
}
}
- /**
- * 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;
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) {
}
}
- /**
- * 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) {
}
}
- /**
- * 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.
* <p>
*
* @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: "
* @author niki
*/
class CliReader extends BasicReader {
- @Override
public void read() throws IOException {
if (getStory() == null) {
throw new IOException("No story to read");
}
}
- @Override
public void read(int chapter) throws IOException {
if (getStory() == null) {
throw new IOException("No story to read");
}
}
- @Override
public void browse(String source) {
List<MetaData> stories;
stories = getLibrary().getListBySource(source);
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;
localLibrary = new LocalLibrary(dir, text, images);
}
- @Override
public void read() throws IOException {
if (getStory() == null) {
throw new IOException("No story to read");
open(getStory().getMeta().getLuid(), null);
}
- @Override
public void read(int chapter) throws IOException {
// TODO: show a special page?
read();
}
try {
- Story story = Instance.getLibrary().getStory(luid, pgGetStory);
+ Story story = getLibrary().getStory(luid, pgGetStory);
if (story != null) {
story = localLibrary.save(story, luid, pgSave);
} else {
return localLibrary.getInfo(luid) != null;
}
- @Override
public void browse(String type) {
// TODO: improve presentation of update message
final VersionCheck updates = VersionCheck.check();
}
}
- new GuiReaderFrame(GuiReader.this, typeFinal)
- .setVisible(true);
+ new GuiReaderFrame(GuiReader.this, typeFinal).setVisible(true);
}
});
}
void delete(String luid) {
try {
localLibrary.delete(luid);
- Instance.getLibrary().delete(luid);
+ getLibrary().delete(luid);
} catch (IOException e) {
Instance.syserr(e);
}
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);
}
private Date lastClick;
private List<BookActionListener> 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
* @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;
if (resizedImage == null) {
try {
- BufferedImage cover = Instance.getLibrary().getCover(
+ BufferedImage cover = reader.getLibrary().getCover(
meta.getLuid());
resizedImage = new BufferedImage(SPINE_WIDTH + COVER_WIDTH,
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;
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);
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);
}
*/
private void refreshBooks() {
for (GuiReaderGroup group : booksByType.keySet()) {
- List<MetaData> stories = Instance.getLibrary().getListBySource(
+ List<MetaData> stories = reader.getLibrary().getListBySource(
booksByType.get(group));
group.refreshBooks(stories, words);
}
for (GuiReaderGroup group : booksByAuthor.keySet()) {
- List<MetaData> stories = Instance.getLibrary().getListByAuthor(
+ List<MetaData> stories = reader.getLibrary().getListByAuthor(
booksByAuthor.get(group));
group.refreshBooks(stories, words);
}
JMenu sources = new JMenu("Sources");
sources.setMnemonic(KeyEvent.VK_S);
- List<String> tt = Instance.getLibrary().getSources();
+ List<String> tt = reader.getLibrary().getSources();
tt.add(0, null);
for (final String type : tt) {
JMenuItem item = new JMenuItem(type == null ? "All" : type);
JMenu authors = new JMenu("Authors");
authors.setMnemonic(KeyEvent.VK_A);
- List<String> aa = Instance.getLibrary().getAuthors();
+ List<String> aa = reader.getLibrary().getAuthors();
aa.add(0, null);
for (final String author : aa) {
JMenuItem item = new JMenuItem(author == null ? "All"
outOfUi(pg, new Runnable() {
public void run() {
try {
- Instance.getLibrary().export(
+ reader.getLibrary().export(
selectedBook.getMeta().getLuid(),
type, path, pg);
} catch (IOException e) {
List<String> types = new ArrayList<String>();
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);
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;
}
* 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;
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);
}
}
- public void popupRequested(GuiReaderBook book,
- MouseEvent e) {
+ public void popupRequested(GuiReaderBook book, MouseEvent e) {
}
public void action(GuiReaderBook book) {
--- /dev/null
+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);
+
+}
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");
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()
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;
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;