| 1 | package be.nikiroo.jvcard.tui; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import com.googlecode.lanterna.TerminalSize; |
| 6 | import com.googlecode.lanterna.TextColor; |
| 7 | import com.googlecode.lanterna.gui2.DefaultWindowManager; |
| 8 | import com.googlecode.lanterna.gui2.EmptySpace; |
| 9 | import com.googlecode.lanterna.gui2.MultiWindowTextGUI; |
| 10 | import com.googlecode.lanterna.gui2.Window; |
| 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 | |
| 25 | static public void start(Boolean textMode, Window win) throws IOException { |
| 26 | Terminal terminal = null; |
| 27 | |
| 28 | DefaultTerminalFactory factory = new DefaultTerminalFactory(); |
| 29 | if (textMode == null) { |
| 30 | terminal = factory.createTerminal(); |
| 31 | } else if (textMode) { |
| 32 | factory.setForceTextTerminal(true); |
| 33 | terminal = factory.createTerminal(); |
| 34 | } else { |
| 35 | terminal = factory.createTerminalEmulator(); |
| 36 | } |
| 37 | |
| 38 | if (win instanceof MainWindow) { |
| 39 | MainWindow mwin = (MainWindow) win; |
| 40 | mwin.refresh(terminal.getTerminalSize()); |
| 41 | terminal.addResizeListener(new ResizeListener() { |
| 42 | @Override |
| 43 | public void onResized(Terminal terminal, TerminalSize newSize) { |
| 44 | mwin.refresh(newSize); |
| 45 | } |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | Screen screen = new TerminalScreen(terminal); |
| 50 | screen.startScreen(); |
| 51 | |
| 52 | // Create gui and start gui |
| 53 | MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, |
| 54 | new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); |
| 55 | gui.addWindowAndWait(win); |
| 56 | |
| 57 | screen.stopScreen(); |
| 58 | } |
| 59 | } |