X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDesktopDemoApplication.java;h=0393860a3b0addfebf0e3b25004d70ca31c2b7aa;hb=615a0d99fd0aa4437116dd083147f9150d5e6527;hp=c546aacaadaa63e6b6447be3b0d0563305afadd0;hpb=72fca17b02059ad7131406f89890a3875d3ed88b;p=fanfix.git diff --git a/src/jexer/demos/DesktopDemoApplication.java b/src/jexer/demos/DesktopDemoApplication.java index c546aac..0393860 100644 --- a/src/jexer/demos/DesktopDemoApplication.java +++ b/src/jexer/demos/DesktopDemoApplication.java @@ -40,6 +40,71 @@ import jexer.menu.*; */ public class DesktopDemoApplication extends TApplication { + // ------------------------------------------------------------------------ + // Constructors ----------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * Public constructor. + * + * @param backendType one of the TApplication.BackendType values + * @throws Exception if TApplication can't instantiate the Backend. + */ + public DesktopDemoApplication(final BackendType backendType) throws Exception { + super(backendType); + addAllWidgets(); + getBackend().setTitle("Jexer Demo Application"); + } + + // ------------------------------------------------------------------------ + // TApplication ----------------------------------------------------------- + // ------------------------------------------------------------------------ + + /** + * 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() == 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); + } + + // ------------------------------------------------------------------------ + // DesktopDemoApplication ------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Add all the widgets of the demo. */ @@ -189,56 +254,4 @@ public class DesktopDemoApplication extends TApplication { } - /** - * 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() == 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 DesktopDemoApplication(final BackendType backendType) throws Exception { - super(backendType); - addAllWidgets(); - getBackend().setTitle("Jexer Demo Application"); - } }