X-Git-Url: http://git.nikiroo.be/?p=jvcard.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FTuiLauncherJexer.java;fp=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FTuiLauncherJexer.java;h=445fc787895543a3ec9485436f35dc513181e847;hp=0000000000000000000000000000000000000000;hb=10dd1e387d6a1834596ae70f48cf905d7b302131;hpb=d5260eeb873fcf2ef9855dedcd9e2a3a3a990582 diff --git a/src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java b/src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java new file mode 100644 index 0000000..445fc78 --- /dev/null +++ b/src/be/nikiroo/jvcard/tui/TuiLauncherJexer.java @@ -0,0 +1,74 @@ +package be.nikiroo.jvcard.tui; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.List; + +import jexer.TApplication; +import jexer.TWindow; +import be.nikiroo.jvcard.tui.windows.TuiFileListWindow; + +/** + * Starting the TUI. + * + * @author niki + */ +public class TuiLauncherJexer extends TApplication { + + /** + * @param textMode + * TRUE to force text mode, FALSE to force the Swing terminal + * emulator, null to automatically determine the best choice + * @param files + * the files to show at startup + * @throws UnsupportedEncodingException + */ + public TuiLauncherJexer(final Boolean textMode, final List files) + throws UnsupportedEncodingException { + super(backend(textMode)); + + addFileMenu(); + addWindowMenu(); + + @SuppressWarnings("unused") + TWindow w = new TuiFileListWindow(this, files); + } + + /** + * Start the TUI program. + * + * @throws IOException + * in case of IO error + */ + public void start() throws IOException { + (new Thread(this)).start(); + } + + /** + * Select the most appropriate backend. + * + * @param textMode + * NULL for auto-dection + * @return the backend type to use + */ + private static BackendType backend(Boolean textMode) { + if (textMode == null) { + boolean isMsWindows = System.getProperty("os.name", "") + .toLowerCase().startsWith("windows"); + boolean forceSwing = System.getProperty("jexer.Swing", "false") + .equals("true"); + boolean noConsole = System.console() == null; + if (isMsWindows || forceSwing || noConsole) { + return BackendType.SWING; + } + + return BackendType.XTERM; + } + + if (textMode) { + return BackendType.XTERM; + } + + return BackendType.SWING; + } +}