Commit | Line | Data |
---|---|---|
c1873e56 NR |
1 | package be.nikiroo.fanfix.reader; |
2 | ||
3 | import java.io.IOException; | |
4 | import java.util.List; | |
5 | ||
6 | import jexer.TApplication; | |
7 | import jexer.TMessageBox; | |
8 | import be.nikiroo.fanfix.Instance; | |
9 | import be.nikiroo.fanfix.data.MetaData; | |
10 | ||
11 | public class TuiReaderApplication extends TApplication { | |
12 | private BasicReader reader; | |
13 | ||
14 | private static BackendType guessBackendType() { | |
15 | // Swing is the default backend on Windows unless explicitly | |
16 | // overridden by jexer.Swing. | |
17 | TApplication.BackendType backendType = TApplication.BackendType.XTERM; | |
18 | if (System.getProperty("os.name").startsWith("Windows")) { | |
19 | backendType = TApplication.BackendType.SWING; | |
20 | } | |
21 | if (System.getProperty("os.name").startsWith("Mac")) { | |
22 | backendType = TApplication.BackendType.SWING; | |
23 | } | |
24 | if (System.getProperty("jexer.Swing") != null) { | |
25 | if (System.getProperty("jexer.Swing", "false").equals("true")) { | |
26 | backendType = TApplication.BackendType.SWING; | |
27 | } else { | |
28 | backendType = TApplication.BackendType.XTERM; | |
29 | } | |
30 | } | |
31 | return backendType; | |
32 | } | |
33 | ||
34 | public TuiReaderApplication(List<MetaData> stories, BasicReader reader) | |
35 | throws Exception { | |
36 | this(stories, reader, guessBackendType()); | |
37 | } | |
38 | ||
39 | public TuiReaderApplication(List<MetaData> stories, BasicReader reader, | |
40 | TApplication.BackendType backend) throws Exception { | |
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"); |
c1873e56 NR |
52 | |
53 | new TuiReaderMainWindow(this, stories); | |
54 | } | |
55 | ||
56 | public void open(MetaData meta) { | |
57 | // TODO: open in editor + external option | |
58 | if (true) { | |
59 | if (!meta.isImageDocument()) { | |
60 | new TuiReaderStoryWindow(this, meta); | |
61 | } else { | |
62 | messageBox("Error when trying to open the story", | |
63 | "Images document not yet supported.", | |
64 | TMessageBox.Type.OK); | |
65 | } | |
66 | return; | |
67 | } | |
68 | try { | |
69 | reader.open(meta.getLuid()); | |
70 | } catch (IOException e) { | |
71 | messageBox("Error when trying to open the story", e.getMessage(), | |
72 | TMessageBox.Type.OK); | |
73 | } | |
74 | } | |
75 | } |