X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Freader%2FTuiReaderApplication.java;h=b7f83085a636f79660443e1d1395b835025b43b2;hb=6322ab64949f9f4ae2b04b9504d58a301039d670;hp=3e9d1d77ed9be35cbb73c31a74096534cd6adb60;hpb=c1873e5678fabf306915c54f9c1736e03e027d60;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java b/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java index 3e9d1d7..b7f8308 100644 --- a/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java +++ b/src/be/nikiroo/fanfix/reader/TuiReaderApplication.java @@ -1,43 +1,43 @@ package be.nikiroo.fanfix.reader; import java.io.IOException; +import java.net.URL; import java.util.List; import jexer.TApplication; import jexer.TMessageBox; -import be.nikiroo.fanfix.Instance; +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; -public class TuiReaderApplication extends TApplication { - private BasicReader reader; +/** + * Manages the TUI reader, links and manages the {@link TWindow}s, starts the + * correct output mode. + * + * @author niki + */ +class TuiReaderApplication extends TApplication implements Reader { + private Reader reader; - private static BackendType guessBackendType() { - // Swing is the default backend on Windows unless explicitly - // overridden by jexer.Swing. - TApplication.BackendType backendType = TApplication.BackendType.XTERM; - if (System.getProperty("os.name").startsWith("Windows")) { - backendType = TApplication.BackendType.SWING; - } - if (System.getProperty("os.name").startsWith("Mac")) { - backendType = TApplication.BackendType.SWING; - } - if (System.getProperty("jexer.Swing") != null) { - if (System.getProperty("jexer.Swing", "false").equals("true")) { - backendType = TApplication.BackendType.SWING; - } else { - backendType = TApplication.BackendType.XTERM; - } - } - return backendType; - } + public TuiReaderApplication(MetaData meta, int chapter, Reader reader, + BackendType backend) throws Exception { + this(reader, backend); - public TuiReaderApplication(List stories, BasicReader reader) - throws Exception { - this(stories, reader, guessBackendType()); + new TuiReaderMainWindow(this, meta, chapter); } - public TuiReaderApplication(List stories, BasicReader reader, + public TuiReaderApplication(List stories, Reader reader, TApplication.BackendType backend) throws Exception { + this(reader, backend); + + new TuiReaderMainWindow(this, stories); + } + + private TuiReaderApplication(Reader reader, TApplication.BackendType backend) + throws Exception { super(backend); this.reader = reader; @@ -48,28 +48,56 @@ public class TuiReaderApplication extends TApplication { addWindowMenu(); addHelpMenu(); - getBackend().setTitle("Testy"); + getBackend().setTitle("Fanfix"); + } - new TuiReaderMainWindow(this, stories); + public void read() throws IOException { + reader.read(); + } + + public void read(int chapter) throws IOException { + reader.read(chapter); } public void open(MetaData meta) { + open(meta, -1); + } + + public void open(MetaData meta, int chapter) { // TODO: open in editor + external option - if (true) { - if (!meta.isImageDocument()) { - new TuiReaderStoryWindow(this, meta); - } else { + if (!meta.isImageDocument()) { + new TuiReaderStoryWindow(this, getLibrary(), meta, chapter); + } else { + try { + BasicReader.openExternal(getLibrary(), meta.getLuid()); + } catch (IOException e) { messageBox("Error when trying to open the story", - "Images document not yet supported.", - TMessageBox.Type.OK); + e.getMessage(), TMessageBox.Type.OK); } - return; - } - try { - reader.open(meta.getLuid()); - } catch (IOException e) { - messageBox("Error when trying to open the story", e.getMessage(), - TMessageBox.Type.OK); } } + + public Story getStory() { + return reader.getStory(); + } + + public BasicLibrary getLibrary() { + return reader.getLibrary(); + } + + public void setLibrary(LocalLibrary lib) { + reader.setLibrary(lib); + } + + public void setStory(String luid, Progress pg) throws IOException { + reader.setStory(luid, pg); + } + + public void setStory(URL source, Progress pg) throws IOException { + reader.setStory(source, pg); + } + + public void browse(String source) { + reader.browse(source); + } }