manage remote and io exception in fanfix
[fanfix.git] / src / be / nikiroo / fanfix / reader / tui / TuiReader.java
CommitLineData
16a81ef7 1package be.nikiroo.fanfix.reader.tui;
c1873e56
NR
2
3import java.io.IOException;
c1873e56 4
6322ab64
NR
5import jexer.TApplication;
6import jexer.TApplication.BackendType;
c1873e56 7import be.nikiroo.fanfix.Instance;
16a81ef7
NR
8import be.nikiroo.fanfix.reader.BasicReader;
9import be.nikiroo.fanfix.reader.Reader;
91b82a5c 10import be.nikiroo.fanfix.supported.SupportType;
c1873e56 11
6322ab64
NR
12/**
13 * This {@link Reader}is based upon the TUI widget library 'jexer'
14 * (https://github.com/klamonte/jexer/) and offer, as its name suggest, a Text
15 * User Interface.
16 * <p>
17 * It is expected to be on par with the GUI version.
18 *
19 * @author niki
20 */
c1873e56 21class TuiReader extends BasicReader {
6322ab64
NR
22 /**
23 * Will detect the backend to use.
24 * <p>
25 * Swing is the default backend on Windows and MacOS while evreything else
26 * will use XTERM unless explicitly overridden by <tt>jexer.Swing</tt> =
27 * <tt>true</tt> or <tt>false</tt>.
28 *
29 * @return the backend to use
30 */
31 private static BackendType guessBackendType() {
32 // TODO: allow a config option to force one or the other?
33 TApplication.BackendType backendType = TApplication.BackendType.XTERM;
34 if (System.getProperty("os.name").startsWith("Windows")) {
35 backendType = TApplication.BackendType.SWING;
36 }
37
38 if (System.getProperty("os.name").startsWith("Mac")) {
39 backendType = TApplication.BackendType.SWING;
40 }
41
42 if (System.getProperty("jexer.Swing") != null) {
43 if (System.getProperty("jexer.Swing", "false").equals("true")) {
44 backendType = TApplication.BackendType.SWING;
45 } else {
46 backendType = TApplication.BackendType.XTERM;
47 }
c1873e56
NR
48 }
49
6322ab64 50 return backendType;
c1873e56
NR
51 }
52
211f7ddb 53 @Override
350bc060 54 public void read(boolean sync) throws IOException {
6322ab64 55 try {
bc2ea776 56 TuiReaderApplication app = new TuiReaderApplication(this,
6322ab64
NR
57 guessBackendType());
58 new Thread(app).start();
59 } catch (Exception e) {
62c63b07 60 Instance.getTraceHandler().error(e);
6322ab64
NR
61 }
62 }
63
211f7ddb 64 @Override
bc2ea776 65 public void browse(String source) {
c1873e56 66 try {
e2d017a3 67 TuiReaderApplication app = new TuiReaderApplication(this, source,
bc2ea776 68 guessBackendType());
c1873e56
NR
69 new Thread(app).start();
70 } catch (Exception e) {
62c63b07 71 Instance.getTraceHandler().error(e);
c1873e56
NR
72 }
73 }
f76de465 74
b31a0db0
NR
75 @Override
76 public void search(boolean sync) throws IOException {
77 // TODO
78 if (sync) {
79 throw new java.lang.IllegalStateException("Not implemented yet.");
80 }
81 }
82
91b82a5c 83 @Override
f76de465
NR
84 public void search(SupportType searchOn, String keywords, int page,
85 int item, boolean sync) {
86 // TODO
87 if (sync) {
88 throw new java.lang.IllegalStateException("Not implemented yet.");
89 }
91b82a5c 90 }
f76de465 91
91b82a5c 92 @Override
f76de465
NR
93 public void searchTag(SupportType searchOn, int page, int item,
94 boolean sync, Integer... tags) {
95 // TODO
96 if (sync) {
97 throw new java.lang.IllegalStateException("Not implemented yet.");
98 }
91b82a5c 99 }
c1873e56 100}