X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fdemos%2FDesktopDemoApplication.java;h=0393860a3b0addfebf0e3b25004d70ca31c2b7aa;hb=0525b2ed026e0d510fdf23f6d8f4cb4562a17e0b;hp=2a2ca34cbf7719cf224c0f7aaf305273beb0ddb8;hpb=9245321388306b5b49d6385ce2f46ea6a82ab619;p=nikiroo-utils.git diff --git a/src/jexer/demos/DesktopDemoApplication.java b/src/jexer/demos/DesktopDemoApplication.java index 2a2ca34..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. */ @@ -69,8 +134,8 @@ public class DesktopDemoApplication extends TApplication { } ); - final TWindow windowA = addWindow("Window A", 20, 14); - final TWindow windowB = addWindow("Window B", 20, 14); + final TWindow windowA = addWindow("Window A", 25, 14); + final TWindow windowB = addWindow("Window B", 25, 14); windowA.addButton("&Show Window B", 2, 2, new TAction() { public void DO() { @@ -85,6 +150,20 @@ public class DesktopDemoApplication extends TApplication { } } ); + windowA.addButton("&Maximize Window B", 2, 6, + new TAction() { + public void DO() { + windowB.maximize(); + } + } + ); + windowA.addButton("&Restore Window B", 2, 8, + new TAction() { + public void DO() { + windowB.restore(); + } + } + ); windowB.addButton("&Show Window A", 2, 2, new TAction() { public void DO() { @@ -99,8 +178,22 @@ public class DesktopDemoApplication extends TApplication { } } ); + windowB.addButton("&Maximize Window A", 2, 6, + new TAction() { + public void DO() { + windowA.maximize(); + } + } + ); + windowB.addButton("&Restore Window A", 2, 8, + new TAction() { + public void DO() { + windowA.restore(); + } + } + ); - desktop.addButton("&Show Window B", 25, 2, + desktop.addButton("S&how Window B", 25, 2, new TAction() { public void DO() { windowB.show(); @@ -128,60 +221,37 @@ public class DesktopDemoApplication extends TApplication { } } ); + desktop.addButton("&Create Window C", 25, 15, + new TAction() { + public void DO() { + final TWindow windowC = desktop.getApplication().addWindow( + "Window C", 30, 20, TWindow.NOCLOSEBOX); + windowC.addButton("&Close Me", 5, 5, + new TAction() { + public void DO() { + windowC.close(); + } + } + ); + } + } + ); - - } - - /** - * 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(); + desktop.addButton("Enable focusFollowsMouse", 25, 18, + new TAction() { + public void DO() { + DesktopDemoApplication.this.setFocusFollowsMouse(true); + } } - return true; - } - return super.onMenu(menu); - } + ); + desktop.addButton("Disable focusFollowsMouse", 25, 21, + new TAction() { + public void DO() { + DesktopDemoApplication.this.setFocusFollowsMouse(false); + } + } + ); - /** - * 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"); } + }