Add more warnings source to 1.6) and fix warnings
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / TuiReaderApplication.java
1 package be.nikiroo.fanfix.reader;
2
3 import java.io.IOException;
4 import java.net.URL;
5 import java.util.List;
6
7 import jexer.TApplication;
8 import jexer.TMessageBox;
9 import jexer.TWindow;
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;
14
15 /**
16 * Manages the TUI general mode and links and manages the {@link TWindow}s.
17 * <p>
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).
20 *
21 * @author niki
22 */
23 class TuiReaderApplication extends TApplication implements Reader {
24 private Reader reader;
25
26 // start reading if meta present
27 public TuiReaderApplication(Reader reader, BackendType backend)
28 throws Exception {
29 super(backend);
30 init(reader);
31
32 MetaData meta = getMeta();
33
34 new TuiReaderMainWindow(this).setMeta(meta);
35
36 if (meta != null) {
37 read();
38 }
39 }
40
41 public TuiReaderApplication(List<MetaData> stories, Reader reader,
42 TApplication.BackendType backend) throws Exception {
43 super(backend);
44 init(reader);
45
46 new TuiReaderMainWindow(this).setMetas(stories);
47 }
48
49 @SuppressWarnings("unused")
50 @Override
51 public void read() throws IOException {
52 MetaData meta = getMeta();
53
54 if (meta == null) {
55 throw new IOException("No story to read");
56 }
57
58 // TODO: open in editor + external option
59 if (!meta.isImageDocument()) {
60 new TuiReaderStoryWindow(this, getLibrary(), meta, getChapter());
61 } else {
62 try {
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);
67 }
68 }
69 }
70
71 @Override
72 public MetaData getMeta() {
73 return reader.getMeta();
74 }
75
76 @Override
77 public Story getStory(Progress pg) {
78 return reader.getStory(pg);
79 }
80
81 @Override
82 public BasicLibrary getLibrary() {
83 return reader.getLibrary();
84 }
85
86 @Override
87 public void setLibrary(BasicLibrary lib) {
88 reader.setLibrary(lib);
89 }
90
91 @Override
92 public void setMeta(MetaData meta) throws IOException {
93 reader.setMeta(meta);
94 }
95
96 @Override
97 public void setMeta(String luid) throws IOException {
98 reader.setMeta(luid);
99 }
100
101 @Override
102 public void setMeta(URL source, Progress pg) throws IOException {
103 reader.setMeta(source, pg);
104 }
105
106 @Override
107 public void browse(String source) {
108 reader.browse(source);
109 }
110
111 @Override
112 public int getChapter() {
113 return reader.getChapter();
114 }
115
116 @Override
117 public void setChapter(int chapter) {
118 reader.setChapter(chapter);
119 }
120
121 private void init(Reader reader) {
122 this.reader = reader;
123
124 // Add the menus
125 addFileMenu();
126 addEditMenu();
127 addWindowMenu();
128 addHelpMenu();
129
130 getBackend().setTitle("Fanfix");
131 }
132 }