New launcher class to start all 3 modes:
[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.DefaultWindowManager;
11 import com.googlecode.lanterna.gui2.EmptySpace;
12 import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
13 import com.googlecode.lanterna.gui2.Window;
14 import com.googlecode.lanterna.screen.Screen;
15 import com.googlecode.lanterna.screen.TerminalScreen;
16 import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
17 import com.googlecode.lanterna.terminal.ResizeListener;
18 import com.googlecode.lanterna.terminal.Terminal;
19
20 /**
21 * Starting the TUI.
22 *
23 * @author niki
24 *
25 */
26 public class TuiLauncher {
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 }
44
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 */
57 static public void start(Boolean textMode, Window win) throws IOException {
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
70 if (win instanceof MainWindow) {
71 final MainWindow mwin = (MainWindow) win;
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
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 }