Add more warnings source to 1.6) and fix warnings
[nikiroo-utils.git] / src / be / nikiroo / fanfix / reader / TuiReader.java
CommitLineData
c1873e56
NR
1package be.nikiroo.fanfix.reader;
2
3import java.io.IOException;
6322ab64 4import java.util.List;
c1873e56 5
6322ab64
NR
6import jexer.TApplication;
7import jexer.TApplication.BackendType;
c1873e56 8import be.nikiroo.fanfix.Instance;
6322ab64 9import be.nikiroo.fanfix.data.MetaData;
c1873e56 10
6322ab64
NR
11/**
12 * This {@link Reader}is based upon the TUI widget library 'jexer'
13 * (https://github.com/klamonte/jexer/) and offer, as its name suggest, a Text
14 * User Interface.
15 * <p>
16 * It is expected to be on par with the GUI version.
17 *
18 * @author niki
19 */
c1873e56 20class TuiReader extends BasicReader {
6322ab64
NR
21 /**
22 * Will detect the backend to use.
23 * <p>
24 * Swing is the default backend on Windows and MacOS while evreything else
25 * will use XTERM unless explicitly overridden by <tt>jexer.Swing</tt> =
26 * <tt>true</tt> or <tt>false</tt>.
27 *
28 * @return the backend to use
29 */
30 private static BackendType guessBackendType() {
31 // TODO: allow a config option to force one or the other?
32 TApplication.BackendType backendType = TApplication.BackendType.XTERM;
33 if (System.getProperty("os.name").startsWith("Windows")) {
34 backendType = TApplication.BackendType.SWING;
35 }
36
37 if (System.getProperty("os.name").startsWith("Mac")) {
38 backendType = TApplication.BackendType.SWING;
39 }
40
41 if (System.getProperty("jexer.Swing") != null) {
42 if (System.getProperty("jexer.Swing", "false").equals("true")) {
43 backendType = TApplication.BackendType.SWING;
44 } else {
45 backendType = TApplication.BackendType.XTERM;
46 }
c1873e56
NR
47 }
48
6322ab64 49 return backendType;
c1873e56
NR
50 }
51
211f7ddb 52 @Override
bc2ea776 53 public void read() throws IOException {
6322ab64 54 try {
bc2ea776 55 TuiReaderApplication app = new TuiReaderApplication(this,
6322ab64
NR
56 guessBackendType());
57 new Thread(app).start();
58 } catch (Exception e) {
59 Instance.syserr(e);
60 }
61 }
62
211f7ddb 63 @Override
bc2ea776
NR
64 public void browse(String source) {
65 List<MetaData> metas = getLibrary().getListBySource(source);
c1873e56 66 try {
bc2ea776
NR
67 TuiReaderApplication app = new TuiReaderApplication(metas, this,
68 guessBackendType());
c1873e56
NR
69 new Thread(app).start();
70 } catch (Exception e) {
71 Instance.syserr(e);
72 }
73 }
74}