Code cleanup 2 (a third one is pending)
[fanfix.git] / src / be / nikiroo / fanfix / reader / TuiReaderApplication.java
CommitLineData
c1873e56
NR
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
6322ab64 4import java.net.URL;
c1873e56
NR
5import java.util.List;
6
7import jexer.TApplication;
8import jexer.TMessageBox;
6322ab64 9import jexer.TWindow;
c1873e56 10import be.nikiroo.fanfix.data.MetaData;
6322ab64
NR
11import be.nikiroo.fanfix.data.Story;
12import be.nikiroo.fanfix.library.BasicLibrary;
13import be.nikiroo.fanfix.library.LocalLibrary;
14import be.nikiroo.utils.Progress;
c1873e56 15
6322ab64
NR
16/**
17 * Manages the TUI reader, links and manages the {@link TWindow}s, starts the
18 * correct output mode.
19 *
20 * @author niki
21 */
22class TuiReaderApplication extends TApplication implements Reader {
23 private Reader reader;
c1873e56 24
6322ab64
NR
25 public TuiReaderApplication(MetaData meta, int chapter, Reader reader,
26 BackendType backend) throws Exception {
27 this(reader, backend);
c1873e56 28
6322ab64 29 new TuiReaderMainWindow(this, meta, chapter);
c1873e56
NR
30 }
31
6322ab64 32 public TuiReaderApplication(List<MetaData> stories, Reader reader,
c1873e56 33 TApplication.BackendType backend) throws Exception {
6322ab64
NR
34 this(reader, backend);
35
36 new TuiReaderMainWindow(this, stories);
37 }
38
39 private TuiReaderApplication(Reader reader, TApplication.BackendType backend)
40 throws Exception {
c1873e56
NR
41 super(backend);
42
43 this.reader = reader;
44
45 // Add the menus
46 addFileMenu();
47 addEditMenu();
48 addWindowMenu();
49 addHelpMenu();
50
396e924c 51 getBackend().setTitle("Fanfix");
6322ab64 52 }
c1873e56 53
6322ab64
NR
54 public void read() throws IOException {
55 reader.read();
56 }
57
58 public void read(int chapter) throws IOException {
59 reader.read(chapter);
c1873e56
NR
60 }
61
62 public void open(MetaData meta) {
6322ab64
NR
63 open(meta, -1);
64 }
65
66 public void open(MetaData meta, int chapter) {
c1873e56 67 // TODO: open in editor + external option
b0e88ebd 68 if (!meta.isImageDocument()) {
6322ab64 69 new TuiReaderStoryWindow(this, getLibrary(), meta, chapter);
b0e88ebd
NR
70 } else {
71 try {
6322ab64 72 BasicReader.openExternal(getLibrary(), meta.getLuid());
b0e88ebd 73 } catch (IOException e) {
c1873e56 74 messageBox("Error when trying to open the story",
b0e88ebd 75 e.getMessage(), TMessageBox.Type.OK);
c1873e56 76 }
c1873e56
NR
77 }
78 }
6322ab64
NR
79
80 public Story getStory() {
81 return reader.getStory();
82 }
83
84 public BasicLibrary getLibrary() {
85 return reader.getLibrary();
86 }
87
88 public void setLibrary(LocalLibrary lib) {
89 reader.setLibrary(lib);
90 }
91
92 public void setStory(String luid, Progress pg) throws IOException {
93 reader.setStory(luid, pg);
94 }
95
96 public void setStory(URL source, Progress pg) throws IOException {
97 reader.setStory(source, pg);
98 }
99
100 public void browse(String source) {
101 reader.browse(source);
102 }
c1873e56 103}