X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReaderApplication.java;h=93a0167fe6be9e21b63718a4c2b0d326cc403065;hp=b7f83085a636f79660443e1d1395b835025b43b2;hb=bc2ea776b67cabcbdcbbc6d8a4e2df1aafa9101a;hpb=6322ab64949f9f4ae2b04b9504d58a301039d670 diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java b/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java index b7f8308..93a0167 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java @@ -10,63 +10,52 @@ import jexer.TWindow; 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.utils.Progress; /** - * Manages the TUI reader, links and manages the {@link TWindow}s, starts the - * correct output mode. + * Manages the TUI general mode and links and manages the {@link TWindow}s. + *

+ * It will also enclose a {@link Reader} and simply handle the reading part + * differently (it will create the required sub-windows and display them). * * @author niki */ class TuiReaderApplication extends TApplication implements Reader { private Reader reader; - public TuiReaderApplication(MetaData meta, int chapter, Reader reader, - BackendType backend) throws Exception { - this(reader, backend); + // start reading if meta present + public TuiReaderApplication(Reader reader, BackendType backend) + throws Exception { + super(backend); + init(reader); - new TuiReaderMainWindow(this, meta, chapter); - } + MetaData meta = getMeta(); - public TuiReaderApplication(List stories, Reader reader, - TApplication.BackendType backend) throws Exception { - this(reader, backend); + new TuiReaderMainWindow(this).setMeta(meta); - new TuiReaderMainWindow(this, stories); + if (meta != null) { + read(); + } } - private TuiReaderApplication(Reader reader, TApplication.BackendType backend) - throws Exception { + public TuiReaderApplication(List stories, Reader reader, + TApplication.BackendType backend) throws Exception { super(backend); + init(reader); - this.reader = reader; - - // Add the menus - addFileMenu(); - addEditMenu(); - addWindowMenu(); - addHelpMenu(); - - getBackend().setTitle("Fanfix"); + new TuiReaderMainWindow(this).setMetas(stories); } public void read() throws IOException { - reader.read(); - } - - public void read(int chapter) throws IOException { - reader.read(chapter); - } + MetaData meta = getMeta(); - public void open(MetaData meta) { - open(meta, -1); - } + if (meta == null) { + throw new IOException("No story to read"); + } - public void open(MetaData meta, int chapter) { // TODO: open in editor + external option if (!meta.isImageDocument()) { - new TuiReaderStoryWindow(this, getLibrary(), meta, chapter); + new TuiReaderStoryWindow(this, getLibrary(), meta, getChapter()); } else { try { BasicReader.openExternal(getLibrary(), meta.getLuid()); @@ -77,27 +66,55 @@ class TuiReaderApplication extends TApplication implements Reader { } } - public Story getStory() { - return reader.getStory(); + public MetaData getMeta() { + return reader.getMeta(); + } + + public Story getStory(Progress pg) { + return reader.getStory(pg); } public BasicLibrary getLibrary() { return reader.getLibrary(); } - public void setLibrary(LocalLibrary lib) { + public void setLibrary(BasicLibrary lib) { reader.setLibrary(lib); } - public void setStory(String luid, Progress pg) throws IOException { - reader.setStory(luid, pg); + public void setMeta(MetaData meta) throws IOException { + reader.setMeta(meta); + } + + public void setMeta(String luid) throws IOException { + reader.setMeta(luid); } - public void setStory(URL source, Progress pg) throws IOException { - reader.setStory(source, pg); + public void setMeta(URL source, Progress pg) throws IOException { + reader.setMeta(source, pg); } public void browse(String source) { reader.browse(source); } + + public int getChapter() { + return reader.getChapter(); + } + + public void setChapter(int chapter) { + reader.setChapter(chapter); + } + + private void init(Reader reader) { + this.reader = reader; + + // Add the menus + addFileMenu(); + addEditMenu(); + addWindowMenu(); + addHelpMenu(); + + getBackend().setTitle("Fanfix"); + } }