X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDemoApplication.java;h=dd25f023f8bbbd7f6b778de5c68b6e986c5d96c1;hb=3649b9210ea425f398ba8c24f9509669cf72aa96;hp=4b31c717a0a89c5a9ac746cf2c50de9eb7360769;hpb=d09767633248d79d1abc85f94d03b4102fae3f64;p=nikiroo-utils.git diff --git a/src/jexer/demos/DemoApplication.java b/src/jexer/demos/DemoApplication.java index 4b31c71..dd25f02 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.*; @@ -59,6 +60,7 @@ public class DemoApplication extends TApplication { item = demoMenu.addItem(2002, "&Normal"); TSubMenu subMenu = demoMenu.addSubMenu("Sub-&Menu"); item = demoMenu.addItem(2010, "N&ormal A&&D"); + item = demoMenu.addItem(2050, "Co&lors..."); item = subMenu.addItem(2000, "&Checkable (sub)"); item.setCheckable(true); @@ -75,7 +77,7 @@ public class DemoApplication extends TApplication { addWindowMenu(); } - + /** * Public constructor. * @@ -94,14 +96,60 @@ public 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(final TMenuEvent menu) { + + if (menu.getId() == 2050) { + new TEditColorThemeWindow(this); + return true; + } + + 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. * * @param backendType one of the TApplication.BackendType values * @throws Exception if TApplication can't instantiate the Backend. */ - public DemoApplication(BackendType backendType) throws Exception { + public DemoApplication(final BackendType backendType) throws Exception { super(backendType); addAllWidgets(); }