LICENSE CHANGED TO MIT
[nikiroo-utils.git] / src / jexer / demos / DemoTextWindow.java
CommitLineData
e3dfbd23
KL
1/*
2 * Jexer - Java Text User Interface
3 *
e16dda65 4 * The MIT License (MIT)
e3dfbd23 5 *
e16dda65 6 * Copyright (C) 2016 Kevin Lamonte
e3dfbd23 7 *
e16dda65
KL
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
e3dfbd23 14 *
e16dda65
KL
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
e3dfbd23 17 *
e16dda65
KL
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
e3dfbd23
KL
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29package jexer.demos;
30
31import jexer.*;
32import jexer.event.*;
efb7af1f 33import jexer.menu.*;
e3dfbd23
KL
34
35/**
36 * This window demonstates the TText, THScroller, and TVScroller widgets.
37 */
7668cb45 38public class DemoTextWindow extends TWindow {
e3dfbd23
KL
39
40 /**
41 * Hang onto my TText so I can resize it with the window.
42 */
43 private TText textField;
44
a043164f
KL
45 /**
46 * Public constructor makes a text window out of any string.
47 *
48 * @param parent the main application
49 * @param title the text string
50 * @param text the text string
51 */
52 public DemoTextWindow(final TApplication parent, final String title,
53 final String text) {
54
55 super(parent, title, 0, 0, 44, 20, RESIZABLE);
56 textField = addText(text, 1, 1, 40, 16);
57 }
efb7af1f 58
e3dfbd23
KL
59 /**
60 * Public constructor.
61 *
62 * @param parent the main application
63 */
64 public DemoTextWindow(final TApplication parent) {
a043164f 65 this(parent, "Text Area",
e3dfbd23
KL
66"This is an example of a reflowable text field. Some example text follows.\n" +
67"\n" +
efb7af1f
KL
68"Notice that some menu items should be disabled when this window has focus.\n" +
69"\n" +
e3dfbd23
KL
70"This library implements a text-based windowing system loosely\n" +
71"reminiscient of Borland's [Turbo\n" +
72"Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those\n" +
73"wishing to use the actual C++ Turbo Vision library, see [Sergio\n" +
74"Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
75"on many more platforms.\n" +
76"\n" +
e16dda65
KL
77"This library is licensed MIT. See the file LICENSE for the full license\n" +
78"for the details.\n");
a043164f 79
e3dfbd23
KL
80 }
81
82 /**
83 * Handle window/screen resize events.
84 *
85 * @param event resize event
86 */
87 @Override
88 public void onResize(final TResizeEvent event) {
89 if (event.getType() == TResizeEvent.Type.WIDGET) {
90 // Resize the text field
91 textField.setWidth(event.getWidth() - 4);
92 textField.setHeight(event.getHeight() - 4);
93 textField.reflow();
94 return;
95 }
96
97 // Pass to children instead
98 for (TWidget widget: getChildren()) {
99 widget.onResize(event);
100 }
101 }
e3dfbd23 102
efb7af1f
KL
103 /**
104 * Play with menu items.
105 */
106 public void onFocus() {
107 getApplication().enableMenuItem(2001);
108 getApplication().disableMenuItem(TMenu.MID_SHELL);
109 getApplication().disableMenuItem(TMenu.MID_EXIT);
110 }
111
112 /**
113 * Called by application.switchWindow() when another window gets the
114 * focus.
115 */
116 public void onUnfocus() {
117 getApplication().disableMenuItem(2001);
118 getApplication().enableMenuItem(TMenu.MID_SHELL);
119 getApplication().enableMenuItem(TMenu.MID_EXIT);
120 }
121
122}