Commit | Line | Data |
---|---|---|
10dd1e38 NR |
1 | package be.nikiroo.jvcard.tui; |
2 | ||
3 | import java.io.IOException; | |
4 | import java.io.UnsupportedEncodingException; | |
5 | import java.util.List; | |
6 | ||
c8398c23 | 7 | import jexer.TAction; |
10dd1e38 | 8 | import jexer.TApplication; |
c8398c23 | 9 | import be.nikiroo.jvcard.tui.windows.TuiBrowserWindow; |
10dd1e38 NR |
10 | import be.nikiroo.jvcard.tui.windows.TuiFileListWindow; |
11 | ||
12 | /** | |
13 | * Starting the TUI. | |
14 | * | |
15 | * @author niki | |
16 | */ | |
17 | public class TuiLauncherJexer extends TApplication { | |
c8398c23 NR |
18 | /** |
19 | * Application is in fullscreen mode, no windows. | |
20 | */ | |
21 | static public final boolean FULLSCREEN = true; | |
10dd1e38 NR |
22 | |
23 | /** | |
24 | * @param textMode | |
25 | * TRUE to force text mode, FALSE to force the Swing terminal | |
26 | * emulator, null to automatically determine the best choice | |
27 | * @param files | |
28 | * the files to show at startup | |
29 | * @throws UnsupportedEncodingException | |
30 | */ | |
31 | public TuiLauncherJexer(final Boolean textMode, final List<String> files) | |
32 | throws UnsupportedEncodingException { | |
33 | super(backend(textMode)); | |
34 | ||
35 | addFileMenu(); | |
36 | addWindowMenu(); | |
37 | ||
c8398c23 NR |
38 | // TODO investigate why that is |
39 | if (backend(textMode) == BackendType.SWING) { | |
40 | new Thread(new Runnable() { | |
41 | @Override | |
42 | public void run() { | |
43 | showMainWindow(files); | |
44 | } | |
45 | }).start(); | |
46 | } else { | |
47 | showMainWindow(files); | |
48 | } | |
49 | } | |
50 | ||
51 | private void showMainWindow(final List<String> files) { | |
52 | TuiBrowserWindow main = new TuiFileListWindow(TuiLauncherJexer.this, | |
53 | files); | |
54 | main.addCloseListener(new TAction() { | |
55 | @Override | |
56 | public void DO() { | |
57 | TuiLauncherJexer.this.exit(false); | |
58 | } | |
59 | }); | |
10dd1e38 NR |
60 | } |
61 | ||
62 | /** | |
63 | * Start the TUI program. | |
64 | * | |
65 | * @throws IOException | |
66 | * in case of IO error | |
67 | */ | |
68 | public void start() throws IOException { | |
69 | (new Thread(this)).start(); | |
70 | } | |
71 | ||
72 | /** | |
73 | * Select the most appropriate backend. | |
74 | * | |
75 | * @param textMode | |
76 | * NULL for auto-dection | |
77 | * @return the backend type to use | |
78 | */ | |
79 | private static BackendType backend(Boolean textMode) { | |
80 | if (textMode == null) { | |
81 | boolean isMsWindows = System.getProperty("os.name", "") | |
82 | .toLowerCase().startsWith("windows"); | |
83 | boolean forceSwing = System.getProperty("jexer.Swing", "false") | |
84 | .equals("true"); | |
85 | boolean noConsole = System.console() == null; | |
86 | if (isMsWindows || forceSwing || noConsole) { | |
87 | return BackendType.SWING; | |
88 | } | |
89 | ||
90 | return BackendType.XTERM; | |
91 | } | |
92 | ||
93 | if (textMode) { | |
94 | return BackendType.XTERM; | |
95 | } | |
96 | ||
97 | return BackendType.SWING; | |
98 | } | |
99 | } |