X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjexer%2Fdemos%2FDemoApplication.java;h=d9bbeb765db92d45aca5537fe274f9b288c42c92;hb=a043164fd1cc1b38f03bb104f8b5240cdf5705c6;hp=22609620b5f2d56979b53f9c4d2588710b76cf92;hpb=55b4f29bc5389d9ce185efa9f6e14c5f3882ac70;p=fanfix.git diff --git a/src/jexer/demos/DemoApplication.java b/src/jexer/demos/DemoApplication.java index 2260962..d9bbeb7 100644 --- a/src/jexer/demos/DemoApplication.java +++ b/src/jexer/demos/DemoApplication.java @@ -31,6 +31,7 @@ package jexer.demos; import java.io.*; +import java.util.*; import jexer.*; import jexer.event.*; @@ -39,7 +40,7 @@ import jexer.menu.*; /** * The demo application itself. */ -class DemoApplication extends TApplication { +public class DemoApplication extends TApplication { /** * Add all the widgets of the demo. @@ -75,7 +76,7 @@ class DemoApplication extends TApplication { addWindowMenu(); } - + /** * Public constructor. * @@ -94,7 +95,47 @@ class DemoApplication extends TApplication { super(input, output); addAllWidgets(); } - + + /** + * Handle menu events. + * + * @param menu menu event + * @return if true, the event was processed and should not be passed onto + * a window + */ + @Override + public boolean onMenu(TMenuEvent menu) { + if (menu.getId() == TMenu.MID_OPEN_FILE) { + try { + String filename = fileOpenBox("."); + if (filename != null) { + try { + File file = new File(filename); + StringBuilder fileContents = new StringBuilder(); + Scanner scanner = new Scanner(file); + String EOL = System.getProperty("line.separator"); + + try { + while(scanner.hasNextLine()) { + fileContents.append(scanner.nextLine() + EOL); + } + new DemoTextWindow(this, filename, + fileContents.toString()); + } finally { + scanner.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } + return super.onMenu(menu); + } + /** * Public constructor. *