| 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.data.MetaData; |
| 9 | |
| 10 | 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 | |
| 50 | getBackend().setTitle("Fanfix"); |
| 51 | |
| 52 | new TuiReaderMainWindow(this, stories); |
| 53 | } |
| 54 | |
| 55 | public void open(MetaData meta) { |
| 56 | // TODO: open in editor + external option |
| 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) { |
| 63 | messageBox("Error when trying to open the story", |
| 64 | e.getMessage(), TMessageBox.Type.OK); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |