1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.io
.IOException
;
7 import jexer
.TApplication
;
8 import jexer
.TMessageBox
;
10 import be
.nikiroo
.fanfix
.data
.MetaData
;
11 import be
.nikiroo
.fanfix
.data
.Story
;
12 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
13 import be
.nikiroo
.utils
.Progress
;
16 * Manages the TUI general mode and links and manages the {@link TWindow}s.
18 * It will also enclose a {@link Reader} and simply handle the reading part
19 * differently (it will create the required sub-windows and display them).
23 class TuiReaderApplication
extends TApplication
implements Reader
{
24 private Reader reader
;
26 // start reading if meta present
27 public TuiReaderApplication(Reader reader
, BackendType backend
)
32 MetaData meta
= getMeta();
34 new TuiReaderMainWindow(this).setMeta(meta
);
41 public TuiReaderApplication(List
<MetaData
> stories
, Reader reader
,
42 TApplication
.BackendType backend
) throws Exception
{
46 new TuiReaderMainWindow(this).setMetas(stories
);
49 public void read() throws IOException
{
50 MetaData meta
= getMeta();
53 throw new IOException("No story to read");
56 // TODO: open in editor + external option
57 if (!meta
.isImageDocument()) {
58 new TuiReaderStoryWindow(this, getLibrary(), meta
, getChapter());
61 BasicReader
.openExternal(getLibrary(), meta
.getLuid());
62 } catch (IOException e
) {
63 messageBox("Error when trying to open the story",
64 e
.getMessage(), TMessageBox
.Type
.OK
);
69 public MetaData
getMeta() {
70 return reader
.getMeta();
73 public Story
getStory(Progress pg
) {
74 return reader
.getStory(pg
);
77 public BasicLibrary
getLibrary() {
78 return reader
.getLibrary();
81 public void setLibrary(BasicLibrary lib
) {
82 reader
.setLibrary(lib
);
85 public void setMeta(MetaData meta
) throws IOException
{
89 public void setMeta(String luid
) throws IOException
{
93 public void setMeta(URL source
, Progress pg
) throws IOException
{
94 reader
.setMeta(source
, pg
);
97 public void browse(String source
) {
98 reader
.browse(source
);
101 public int getChapter() {
102 return reader
.getChapter();
105 public void setChapter(int chapter
) {
106 reader
.setChapter(chapter
);
109 private void init(Reader reader
) {
110 this.reader
= reader
;
118 getBackend().setTitle("Fanfix");