Fix inclusion of lanterna's resources + fix warning
[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 9import com.googlecode.lanterna.TextColor;
a3b510ab
NR
10import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
11import com.googlecode.lanterna.gui2.Window;
12import com.googlecode.lanterna.screen.Screen;
13import com.googlecode.lanterna.screen.TerminalScreen;
14import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
296a0b75 15import com.googlecode.lanterna.terminal.ResizeListener;
a3b510ab
NR
16import com.googlecode.lanterna.terminal.Terminal;
17
668268fc
NR
18/**
19 * Starting the TUI.
a3b510ab 20 *
668268fc
NR
21 * @author niki
22 *
a3b510ab 23 */
a3b510ab 24public class TuiLauncher {
ed91f27a
NR
25 static private Screen screen = null;
26
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
ed91f27a
NR
45 /**
46 * Return the used {@link Screen}.
47 *
48 * @return the {@link Screen}
49 */
50 static public Screen getScreen() {
51 return screen;
52 }
53
7da41ecd
NR
54 /**
55 * Start the TUI program.
56 *
57 * @param textMode
58 * TRUE to force text mode, FALSE to force the Swing terminal
59 * emulator, null to automatically determine the best choice
60 * @param win
61 * the window to show at start
62 *
63 * @throws IOException
64 * in case of IO error
65 */
668268fc 66 static public void start(Boolean textMode, Window win) throws IOException {
a3b510ab
NR
67 Terminal terminal = null;
68
69 DefaultTerminalFactory factory = new DefaultTerminalFactory();
70 if (textMode == null) {
71 terminal = factory.createTerminal();
72 } else if (textMode) {
73 factory.setForceTextTerminal(true);
74 terminal = factory.createTerminal();
75 } else {
76 terminal = factory.createTerminalEmulator();
77 }
78
296a0b75 79 if (win instanceof MainWindow) {
6b6a62ca 80 final MainWindow mwin = (MainWindow) win;
296a0b75
NR
81 mwin.refresh(terminal.getTerminalSize());
82 terminal.addResizeListener(new ResizeListener() {
83 @Override
84 public void onResized(Terminal terminal, TerminalSize newSize) {
85 mwin.refresh(newSize);
86 }
87 });
88 }
89
ed91f27a 90 screen = new TerminalScreen(terminal);
a3b510ab
NR
91 screen.startScreen();
92
93 // Create gui and start gui
94 MultiWindowTextGUI gui = new MultiWindowTextGUI(screen,
ed91f27a 95 TextColor.ANSI.BLUE);
a3b510ab 96
ed91f27a
NR
97 gui.setTheme(UiColors.getCustomTheme());
98
99 gui.addWindowAndWait(win);
a3b510ab
NR
100 screen.stopScreen();
101 }
102}