X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Ftui%2FTuiLauncher.java;h=52d244dafe9af65a4596aafb7b68307d02bdbde9;hb=24e66f8322565f83abd73cfddb6838cbd0f52f58;hp=7bee3e7bc87eb89163de7aebd677990f2641e867;hpb=296a0b75515b3a7424b98292c87cbbf2272b73f9;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/tui/TuiLauncher.java b/src/be/nikiroo/jvcard/tui/TuiLauncher.java index 7bee3e7..52d244d 100644 --- a/src/be/nikiroo/jvcard/tui/TuiLauncher.java +++ b/src/be/nikiroo/jvcard/tui/TuiLauncher.java @@ -1,32 +1,54 @@ package be.nikiroo.jvcard.tui; import java.io.IOException; +import java.util.List; + +import be.nikiroo.jvcard.tui.panes.FileList; import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.TextColor; -import com.googlecode.lanterna.gui2.DefaultWindowManager; -import com.googlecode.lanterna.gui2.EmptySpace; import com.googlecode.lanterna.gui2.MultiWindowTextGUI; -import com.googlecode.lanterna.gui2.Window; import com.googlecode.lanterna.screen.Screen; import com.googlecode.lanterna.screen.TerminalScreen; import com.googlecode.lanterna.terminal.DefaultTerminalFactory; import com.googlecode.lanterna.terminal.ResizeListener; import com.googlecode.lanterna.terminal.Terminal; -/* - * - * Change in Lanterna 3.0.0-beta2 (issue and fix reported to GitHub): - * - * java.lang.StringIndexOutOfBoundsException: String index out of range: 83 - * at java.lang.String.charAt(String.java:686) - * at com.googlecode.lanterna.TerminalTextUtils.getWordWrappedText(TerminalTextUtils.java:237) +/** + * Starting the TUI. * + * @author niki * */ - public class TuiLauncher { - public static void start(Boolean textMode, Window win) throws IOException { + static private Screen screen; + + private Boolean textMode; + private List files; + + /** + * + * @param textMode + * TRUE to force text mode, FALSE to force the Swing terminal + * emulator, null to automatically determine the best choice + * @param files + * the files to show at startup + * + */ + public TuiLauncher(Boolean textMode, List files) { + this.textMode = textMode; + this.files = files; + } + + /** + * Start the TUI program. + * + * + * + * @throws IOException + * in case of IO error + */ + public void start() throws IOException { Terminal terminal = null; DefaultTerminalFactory factory = new DefaultTerminalFactory(); @@ -39,25 +61,34 @@ public class TuiLauncher { terminal = factory.createTerminalEmulator(); } - if (win instanceof MainWindow) { - MainWindow mwin = (MainWindow) win; - mwin.refresh(terminal.getTerminalSize()); - terminal.addResizeListener(new ResizeListener() { - @Override - public void onResized(Terminal terminal, TerminalSize newSize) { - mwin.refresh(newSize); - } - }); - } + final MainWindow win = new MainWindow(new FileList(files)); + win.refresh(terminal.getTerminalSize()); + terminal.addResizeListener(new ResizeListener() { + @Override + public void onResized(Terminal terminal, TerminalSize newSize) { + win.refresh(newSize); + } + }); - Screen screen = new TerminalScreen(terminal); + screen = new TerminalScreen(terminal); screen.startScreen(); // Create gui and start gui MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, - new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE)); - gui.addWindowAndWait(win); + TextColor.ANSI.BLUE); + + gui.setTheme(UiColors.getCustomTheme()); + gui.addWindowAndWait(win); screen.stopScreen(); } + + /** + * Return the used {@link Screen}. + * + * @return the {@link Screen} + */ + static public Screen getScreen() { + return screen; + } }