75fd40bd47f69cb969970ea6af7f90bb3b49b1bc
[nikiroo-utils.git] / src / jexer / demos / DemoTextWindow.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31 package jexer.demos;
32
33 import jexer.*;
34 import jexer.event.*;
35 import jexer.menu.*;
36
37 /**
38 * This window demonstates the TText, THScroller, and TVScroller widgets.
39 */
40 public class DemoTextWindow extends TWindow {
41
42 /**
43 * Hang onto my TText so I can resize it with the window.
44 */
45 private TText textField;
46
47 /**
48 * Public constructor makes a text window out of any string.
49 *
50 * @param parent the main application
51 * @param title the text string
52 * @param text the text string
53 */
54 public DemoTextWindow(final TApplication parent, final String title,
55 final String text) {
56
57 super(parent, title, 0, 0, 44, 20, RESIZABLE);
58 textField = addText(text, 1, 1, 40, 16);
59 }
60
61 /**
62 * Public constructor.
63 *
64 * @param parent the main application
65 */
66 public DemoTextWindow(final TApplication parent) {
67 this(parent, "Text Area",
68 "This is an example of a reflowable text field. Some example text follows.\n" +
69 "\n" +
70 "Notice that some menu items should be disabled when this window has focus.\n" +
71 "\n" +
72 "This library implements a text-based windowing system loosely\n" +
73 "reminiscient of Borland's [Turbo\n" +
74 "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those\n" +
75 "wishing to use the actual C++ Turbo Vision library, see [Sergio\n" +
76 "Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
77 "on many more platforms.\n" +
78 "\n" +
79 "This library is licensed LGPL (\"GNU Lesser General Public License\")\n" +
80 "version 3 or greater. See the file COPYING for the full license text,\n" +
81 "which includes both the GPL v3 and the LGPL supplemental terms.\n" +
82 "\n");
83
84 }
85
86 /**
87 * Handle window/screen resize events.
88 *
89 * @param event resize event
90 */
91 @Override
92 public void onResize(final TResizeEvent event) {
93 if (event.getType() == TResizeEvent.Type.WIDGET) {
94 // Resize the text field
95 textField.setWidth(event.getWidth() - 4);
96 textField.setHeight(event.getHeight() - 4);
97 textField.reflow();
98 return;
99 }
100
101 // Pass to children instead
102 for (TWidget widget: getChildren()) {
103 widget.onResize(event);
104 }
105 }
106
107 /**
108 * Play with menu items.
109 */
110 public void onFocus() {
111 getApplication().enableMenuItem(2001);
112 getApplication().disableMenuItem(TMenu.MID_SHELL);
113 getApplication().disableMenuItem(TMenu.MID_EXIT);
114 }
115
116 /**
117 * Called by application.switchWindow() when another window gets the
118 * focus.
119 */
120 public void onUnfocus() {
121 getApplication().disableMenuItem(2001);
122 getApplication().enableMenuItem(TMenu.MID_SHELL);
123 getApplication().enableMenuItem(TMenu.MID_EXIT);
124 }
125
126 }