New launcher class to start all 3 modes:
[jvcard.git] / src / be / nikiroo / jvcard / tui / TuiLauncher.java
CommitLineData
a3b510ab
NR
1package be.nikiroo.jvcard.tui;
2
3import java.io.IOException;
7da41ecd
NR
4import java.util.List;
5
6import be.nikiroo.jvcard.tui.panes.FileList;
a3b510ab 7
296a0b75 8import com.googlecode.lanterna.TerminalSize;
a3b510ab
NR
9import com.googlecode.lanterna.TextColor;
10import com.googlecode.lanterna.gui2.DefaultWindowManager;
11import com.googlecode.lanterna.gui2.EmptySpace;
12import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
13import com.googlecode.lanterna.gui2.Window;
14import com.googlecode.lanterna.screen.Screen;
15import com.googlecode.lanterna.screen.TerminalScreen;
16import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
296a0b75 17import com.googlecode.lanterna.terminal.ResizeListener;
a3b510ab
NR
18import com.googlecode.lanterna.terminal.Terminal;
19
668268fc
NR
20/**
21 * Starting the TUI.
a3b510ab 22 *
668268fc
NR
23 * @author niki
24 *
a3b510ab 25 */
a3b510ab 26public class TuiLauncher {
7da41ecd
NR
27 /**
28 * Start the TUI program.
29 *
30 * @param textMode
31 * TRUE to force text mode, FALSE to force the Swing terminal
32 * emulator, null to automatically determine the best choice
33 * @param files
34 * the files to show at startup
35 *
36 * @throws IOException
37 * in case of IO error
38 */
39 static public void start(Boolean textMode, List<String> files)
40 throws IOException {
41 Window win = new MainWindow(new FileList(files));
42 TuiLauncher.start(textMode, win);
43 }
668268fc 44
7da41ecd
NR
45 /**
46 * Start the TUI program.
47 *
48 * @param textMode
49 * TRUE to force text mode, FALSE to force the Swing terminal
50 * emulator, null to automatically determine the best choice
51 * @param win
52 * the window to show at start
53 *
54 * @throws IOException
55 * in case of IO error
56 */
668268fc 57 static public void start(Boolean textMode, Window win) throws IOException {
a3b510ab
NR
58 Terminal terminal = null;
59
60 DefaultTerminalFactory factory = new DefaultTerminalFactory();
61 if (textMode == null) {
62 terminal = factory.createTerminal();
63 } else if (textMode) {
64 factory.setForceTextTerminal(true);
65 terminal = factory.createTerminal();
66 } else {
67 terminal = factory.createTerminalEmulator();
68 }
69
296a0b75 70 if (win instanceof MainWindow) {
6b6a62ca 71 final MainWindow mwin = (MainWindow) win;
296a0b75
NR
72 mwin.refresh(terminal.getTerminalSize());
73 terminal.addResizeListener(new ResizeListener() {
74 @Override
75 public void onResized(Terminal terminal, TerminalSize newSize) {
76 mwin.refresh(newSize);
77 }
78 });
79 }
80
a3b510ab
NR
81 Screen screen = new TerminalScreen(terminal);
82 screen.startScreen();
83
84 // Create gui and start gui
85 MultiWindowTextGUI gui = new MultiWindowTextGUI(screen,
86 new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
87 gui.addWindowAndWait(win);
88
89 screen.stopScreen();
90 }
91}