1 package be
.nikiroo
.fanfix
.reader
;
3 import java
.io
.IOException
;
7 import jexer
.TApplication
;
8 import jexer
.TMessageBox
;
10 import be
.nikiroo
.fanfix
.Instance
;
11 import be
.nikiroo
.fanfix
.Instance
.SyserrHandler
;
12 import be
.nikiroo
.fanfix
.Instance
.TraceHandler
;
13 import be
.nikiroo
.fanfix
.data
.MetaData
;
14 import be
.nikiroo
.fanfix
.data
.Story
;
15 import be
.nikiroo
.fanfix
.library
.BasicLibrary
;
16 import be
.nikiroo
.utils
.Progress
;
19 * Manages the TUI general mode and links and manages the {@link TWindow}s.
21 * It will also enclose a {@link Reader} and simply handle the reading part
22 * differently (it will create the required sub-windows and display them).
26 class TuiReaderApplication
extends TApplication
implements Reader
{
27 private Reader reader
;
29 // start reading if meta present
30 public TuiReaderApplication(Reader reader
, BackendType backend
)
35 MetaData meta
= getMeta();
37 new TuiReaderMainWindow(this).setMeta(meta
);
44 public TuiReaderApplication(List
<MetaData
> stories
, Reader reader
,
45 TApplication
.BackendType backend
) throws Exception
{
49 new TuiReaderMainWindow(this).setMetas(stories
);
52 @SuppressWarnings("unused")
54 public void read() throws IOException
{
55 MetaData meta
= getMeta();
58 throw new IOException("No story to read");
61 // TODO: open in editor + external option
62 if (!meta
.isImageDocument()) {
63 new TuiReaderStoryWindow(this, getLibrary(), meta
, getChapter());
66 BasicReader
.openExternal(getLibrary(), meta
.getLuid());
67 } catch (IOException e
) {
68 messageBox("Error when trying to open the story",
69 e
.getMessage(), TMessageBox
.Type
.OK
);
75 public MetaData
getMeta() {
76 return reader
.getMeta();
80 public Story
getStory(Progress pg
) {
81 return reader
.getStory(pg
);
85 public BasicLibrary
getLibrary() {
86 return reader
.getLibrary();
90 public void setLibrary(BasicLibrary lib
) {
91 reader
.setLibrary(lib
);
95 public void setMeta(MetaData meta
) throws IOException
{
100 public void setMeta(String luid
) throws IOException
{
101 reader
.setMeta(luid
);
105 public void setMeta(URL source
, Progress pg
) throws IOException
{
106 reader
.setMeta(source
, pg
);
110 public void browse(String source
) {
111 reader
.browse(source
);
115 public int getChapter() {
116 return reader
.getChapter();
120 public void setChapter(int chapter
) {
121 reader
.setChapter(chapter
);
124 private void init(Reader reader
) {
125 this.reader
= reader
;
127 // Do not allow traces/debug to pollute the screen:
128 Instance
.setSyserrHandler(new SyserrHandler() {
130 public void notify(Exception e
, boolean showDetails
) {
135 Instance
.setTraceHandler(new TraceHandler() {
137 public void trace(String message
) {
149 getBackend().setTitle("Fanfix");