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