window focus events and enable/disable menu items
[fanfix.git] / src / jexer / demos / DemoTextWindow.java
index 265c45db7f6f73ae1d8666f78d1772a2b519b6b5..75fd40bd47f69cb969970ea6af7f90bb3b49b1bc 100644 (file)
@@ -32,6 +32,7 @@ package jexer.demos;
 
 import jexer.*;
 import jexer.event.*;
+import jexer.menu.*;
 
 /**
  * This window demonstates the TText, THScroller, and TVScroller widgets.
@@ -56,7 +57,7 @@ public class DemoTextWindow extends TWindow {
         super(parent, title, 0, 0, 44, 20, RESIZABLE);
         textField = addText(text, 1, 1, 40, 16);
     }
-    
+
     /**
      * Public constructor.
      *
@@ -66,6 +67,8 @@ public class DemoTextWindow extends TWindow {
         this(parent, "Text Area",
 "This is an example of a reflowable text field.  Some example text follows.\n" +
 "\n" +
+"Notice that some menu items should be disabled when this window has focus.\n" +
+"\n" +
 "This library implements a text-based windowing system loosely\n" +
 "reminiscient of Borland's [Turbo\n" +
 "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library.  For those\n" +
@@ -73,11 +76,6 @@ public class DemoTextWindow extends TWindow {
 "Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
 "on many more platforms.\n" +
 "\n" +
-"Currently the only console platform supported is Posix (tested on\n" +
-"Linux).  Input/output is handled through terminal escape sequences\n" +
-"generated by the library itself: ncurses is not required or linked to. \n" +
-"xterm mouse tracking using UTF8 coordinates is supported.\n" +
-"\n" +
 "This library is licensed LGPL (\"GNU Lesser General Public License\")\n" +
 "version 3 or greater.  See the file COPYING for the full license text,\n" +
 "which includes both the GPL v3 and the LGPL supplemental terms.\n" +
@@ -105,5 +103,24 @@ public class DemoTextWindow extends TWindow {
             widget.onResize(event);
         }
     }
-}
 
+    /**
+     * Play with menu items.
+     */
+    public void onFocus() {
+        getApplication().enableMenuItem(2001);
+        getApplication().disableMenuItem(TMenu.MID_SHELL);
+        getApplication().disableMenuItem(TMenu.MID_EXIT);
+    }
+
+    /**
+     * Called by application.switchWindow() when another window gets the
+     * focus.
+     */
+    public void onUnfocus() {
+        getApplication().disableMenuItem(2001);
+        getApplication().enableMenuItem(TMenu.MID_SHELL);
+        getApplication().enableMenuItem(TMenu.MID_EXIT);
+    }
+
+}