Network server and Library + nikiroo-utils update
[fanfix.git] / src / be / nikiroo / fanfix / reader / TuiReaderApplication.java
CommitLineData
c1873e56
NR
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
4import java.util.List;
5
6import jexer.TApplication;
7import jexer.TMessageBox;
c1873e56
NR
8import be.nikiroo.fanfix.data.MetaData;
9
10public class TuiReaderApplication extends TApplication {
11 private BasicReader reader;
12
13 private static BackendType guessBackendType() {
14 // Swing is the default backend on Windows unless explicitly
15 // overridden by jexer.Swing.
16 TApplication.BackendType backendType = TApplication.BackendType.XTERM;
17 if (System.getProperty("os.name").startsWith("Windows")) {
18 backendType = TApplication.BackendType.SWING;
19 }
20 if (System.getProperty("os.name").startsWith("Mac")) {
21 backendType = TApplication.BackendType.SWING;
22 }
23 if (System.getProperty("jexer.Swing") != null) {
24 if (System.getProperty("jexer.Swing", "false").equals("true")) {
25 backendType = TApplication.BackendType.SWING;
26 } else {
27 backendType = TApplication.BackendType.XTERM;
28 }
29 }
30 return backendType;
31 }
32
33 public TuiReaderApplication(List<MetaData> stories, BasicReader reader)
34 throws Exception {
35 this(stories, reader, guessBackendType());
36 }
37
38 public TuiReaderApplication(List<MetaData> stories, BasicReader reader,
39 TApplication.BackendType backend) throws Exception {
40 super(backend);
41
42 this.reader = reader;
43
44 // Add the menus
45 addFileMenu();
46 addEditMenu();
47 addWindowMenu();
48 addHelpMenu();
49
396e924c 50 getBackend().setTitle("Fanfix");
c1873e56
NR
51
52 new TuiReaderMainWindow(this, stories);
53 }
54
55 public void open(MetaData meta) {
56 // TODO: open in editor + external option
b0e88ebd
NR
57 if (!meta.isImageDocument()) {
58 new TuiReaderStoryWindow(this, reader.getLibrary(), meta);
59 } else {
60 try {
61 BasicReader.open(reader.getLibrary(), meta.getLuid());
62 } catch (IOException e) {
c1873e56 63 messageBox("Error when trying to open the story",
b0e88ebd 64 e.getMessage(), TMessageBox.Type.OK);
c1873e56 65 }
c1873e56
NR
66 }
67 }
68}