f95cbf369f9518ae96cd311bbd131d8dec0c0e7f
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 @SuppressWarnings("unused")
51 public void read() throws IOException
{
52 MetaData meta
= getMeta();
55 throw new IOException("No story to read");
58 // TODO: open in editor + external option
59 if (!meta
.isImageDocument()) {
60 new TuiReaderStoryWindow(this, getLibrary(), meta
, getChapter());
63 BasicReader
.openExternal(getLibrary(), meta
.getLuid());
64 } catch (IOException e
) {
65 messageBox("Error when trying to open the story",
66 e
.getMessage(), TMessageBox
.Type
.OK
);
72 public MetaData
getMeta() {
73 return reader
.getMeta();
77 public Story
getStory(Progress pg
) {
78 return reader
.getStory(pg
);
82 public BasicLibrary
getLibrary() {
83 return reader
.getLibrary();
87 public void setLibrary(BasicLibrary lib
) {
88 reader
.setLibrary(lib
);
92 public void setMeta(MetaData meta
) throws IOException
{
97 public void setMeta(String luid
) throws IOException
{
102 public void setMeta(URL source
, Progress pg
) throws IOException
{
103 reader
.setMeta(source
, pg
);
107 public void browse(String source
) {
108 reader
.browse(source
);
112 public int getChapter() {
113 return reader
.getChapter();
117 public void setChapter(int chapter
) {
118 reader
.setChapter(chapter
);
121 private void init(Reader reader
) {
122 this.reader
= reader
;
130 getBackend().setTitle("Fanfix");