445fc787895543a3ec9485436f35dc513181e847
[jvcard.git] / src / be / nikiroo / jvcard / tui / TuiLauncherJexer.java
1 package be.nikiroo.jvcard.tui;
2
3 import java.io.IOException;
4 import java.io.UnsupportedEncodingException;
5 import java.util.List;
6
7 import jexer.TApplication;
8 import jexer.TWindow;
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 {
17
18 /**
19 * @param textMode
20 * TRUE to force text mode, FALSE to force the Swing terminal
21 * emulator, null to automatically determine the best choice
22 * @param files
23 * the files to show at startup
24 * @throws UnsupportedEncodingException
25 */
26 public TuiLauncherJexer(final Boolean textMode, final List<String> files)
27 throws UnsupportedEncodingException {
28 super(backend(textMode));
29
30 addFileMenu();
31 addWindowMenu();
32
33 @SuppressWarnings("unused")
34 TWindow w = new TuiFileListWindow(this, files);
35 }
36
37 /**
38 * Start the TUI program.
39 *
40 * @throws IOException
41 * in case of IO error
42 */
43 public void start() throws IOException {
44 (new Thread(this)).start();
45 }
46
47 /**
48 * Select the most appropriate backend.
49 *
50 * @param textMode
51 * NULL for auto-dection
52 * @return the backend type to use
53 */
54 private static BackendType backend(Boolean textMode) {
55 if (textMode == null) {
56 boolean isMsWindows = System.getProperty("os.name", "")
57 .toLowerCase().startsWith("windows");
58 boolean forceSwing = System.getProperty("jexer.Swing", "false")
59 .equals("true");
60 boolean noConsole = System.console() == null;
61 if (isMsWindows || forceSwing || noConsole) {
62 return BackendType.SWING;
63 }
64
65 return BackendType.XTERM;
66 }
67
68 if (textMode) {
69 return BackendType.XTERM;
70 }
71
72 return BackendType.SWING;
73 }
74 }