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