Commit | Line | Data |
---|---|---|
a3b510ab NR |
1 | package be.nikiroo.jvcard.tui; |
2 | ||
3 | import java.io.IOException; | |
7da41ecd NR |
4 | import java.util.List; |
5 | ||
6 | import be.nikiroo.jvcard.tui.panes.FileList; | |
a3b510ab | 7 | |
296a0b75 | 8 | import com.googlecode.lanterna.TerminalSize; |
a3b510ab | 9 | import com.googlecode.lanterna.TextColor; |
a3b510ab | 10 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; |
a3b510ab NR |
11 | import com.googlecode.lanterna.screen.Screen; |
12 | import com.googlecode.lanterna.screen.TerminalScreen; | |
13 | import com.googlecode.lanterna.terminal.DefaultTerminalFactory; | |
296a0b75 | 14 | import com.googlecode.lanterna.terminal.ResizeListener; |
a3b510ab NR |
15 | import com.googlecode.lanterna.terminal.Terminal; |
16 | ||
668268fc NR |
17 | /** |
18 | * Starting the TUI. | |
a3b510ab | 19 | * |
668268fc | 20 | * @author niki |
10dd1e38 | 21 | * |
a3b510ab | 22 | */ |
a3b510ab | 23 | public class TuiLauncher { |
10dd1e38 NR |
24 | static private Screen screen; |
25 | ||
26 | private Boolean textMode; | |
27 | private List<String> files; | |
ed91f27a | 28 | |
7da41ecd | 29 | /** |
7da41ecd NR |
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 | * | |
ed91f27a | 37 | */ |
10dd1e38 NR |
38 | public TuiLauncher(Boolean textMode, List<String> files) { |
39 | this.textMode = textMode; | |
40 | this.files = files; | |
ed91f27a NR |
41 | } |
42 | ||
7da41ecd NR |
43 | /** |
44 | * Start the TUI program. | |
45 | * | |
10dd1e38 | 46 | * |
7da41ecd NR |
47 | * |
48 | * @throws IOException | |
49 | * in case of IO error | |
50 | */ | |
10dd1e38 | 51 | public void start() throws IOException { |
a3b510ab NR |
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 | ||
10dd1e38 NR |
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 | }); | |
296a0b75 | 72 | |
ed91f27a | 73 | screen = new TerminalScreen(terminal); |
a3b510ab NR |
74 | screen.startScreen(); |
75 | ||
76 | // Create gui and start gui | |
77 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, | |
ed91f27a | 78 | TextColor.ANSI.BLUE); |
a3b510ab | 79 | |
ed91f27a NR |
80 | gui.setTheme(UiColors.getCustomTheme()); |
81 | ||
82 | gui.addWindowAndWait(win); | |
a3b510ab NR |
83 | screen.stopScreen(); |
84 | } | |
10dd1e38 NR |
85 | |
86 | /** | |
87 | * Return the used {@link Screen}. | |
88 | * | |
89 | * @return the {@link Screen} | |
90 | */ | |
91 | static public Screen getScreen() { | |
92 | return screen; | |
93 | } | |
a3b510ab | 94 | } |