TStatusBar
[fanfix.git] / src / jexer / demos / DemoTextWindow.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2016 Kevin Lamonte
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
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.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29 package jexer.demos;
30
31 import jexer.*;
32 import jexer.event.*;
33 import jexer.menu.*;
34 import static jexer.TCommand.*;
35 import static jexer.TKeypress.*;
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 statusBar = newStatusBar("Reflowable text window");
61 statusBar.addShortcutKeypress(kbF1, cmHelp, "Help");
62 statusBar.addShortcutKeypress(kbF2, cmShell, "Shell");
63 statusBar.addShortcutKeypress(kbF3, cmOpen, "Open");
64 statusBar.addShortcutKeypress(kbF10, cmExit, "Exit");
65 }
66
67 /**
68 * Public constructor.
69 *
70 * @param parent the main application
71 */
72 public DemoTextWindow(final TApplication parent) {
73 this(parent, "Text Area",
74 "This is an example of a reflowable text field. Some example text follows.\n" +
75 "\n" +
76 "Notice that some menu items should be disabled when this window has focus.\n" +
77 "\n" +
78 "This library implements a text-based windowing system loosely\n" +
79 "reminiscient of Borland's [Turbo\n" +
80 "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those\n" +
81 "wishing to use the actual C++ Turbo Vision library, see [Sergio\n" +
82 "Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
83 "on many more platforms.\n" +
84 "\n" +
85 "This library is licensed MIT. See the file LICENSE for the full license\n" +
86 "for the details.\n");
87
88 }
89
90 /**
91 * Handle window/screen resize events.
92 *
93 * @param event resize event
94 */
95 @Override
96 public void onResize(final TResizeEvent event) {
97 if (event.getType() == TResizeEvent.Type.WIDGET) {
98 // Resize the text field
99 textField.setWidth(event.getWidth() - 4);
100 textField.setHeight(event.getHeight() - 4);
101 textField.reflow();
102 return;
103 }
104
105 // Pass to children instead
106 for (TWidget widget: getChildren()) {
107 widget.onResize(event);
108 }
109 }
110
111 /**
112 * Play with menu items.
113 */
114 public void onFocus() {
115 getApplication().enableMenuItem(2001);
116 getApplication().disableMenuItem(TMenu.MID_SHELL);
117 getApplication().disableMenuItem(TMenu.MID_EXIT);
118 }
119
120 /**
121 * Called by application.switchWindow() when another window gets the
122 * focus.
123 */
124 public void onUnfocus() {
125 getApplication().disableMenuItem(2001);
126 getApplication().enableMenuItem(TMenu.MID_SHELL);
127 getApplication().enableMenuItem(TMenu.MID_EXIT);
128 }
129
130 }