104715997261206c0d54b1cadd4bf54e70360751
2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import static jexer
.TCommand
.*;
34 import static jexer
.TKeypress
.*;
37 * This window demonstates the TEditor widget.
39 public class DemoEditorWindow
extends TWindow
{
41 // ------------------------------------------------------------------------
42 // Variables --------------------------------------------------------------
43 // ------------------------------------------------------------------------
46 * Hang onto my TEditor so I can resize it with the window.
48 private TEditorWidget editField
;
50 // ------------------------------------------------------------------------
51 // Constructors -----------------------------------------------------------
52 // ------------------------------------------------------------------------
55 * Public constructor makes a text window out of any string.
57 * @param parent the main application
58 * @param title the text string
59 * @param text the text string
61 public DemoEditorWindow(final TApplication parent
, final String title
,
64 super(parent
, title
, 0, 0, 44, 22, RESIZABLE
);
65 editField
= addEditor(text
, 0, 0, 42, 20);
67 statusBar
= newStatusBar("Editable text demo window");
68 statusBar
.addShortcutKeypress(kbF1
, cmHelp
, "Help");
69 statusBar
.addShortcutKeypress(kbF2
, cmShell
, "Shell");
70 statusBar
.addShortcutKeypress(kbF10
, cmExit
, "Exit");
76 * @param parent the main application
78 public DemoEditorWindow(final TApplication parent
) {
79 this(parent
, "Editor",
80 "This is an example of an editable text field. Some example text follows.\n" +
82 "This library implements a text-based windowing system loosely\n" +
83 "reminiscient of Borland's [Turbo\n" +
84 "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those\n" +
85 "wishing to use the actual C++ Turbo Vision library, see [Sergio\n" +
86 "Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
87 "on many more platforms.\n" +
89 "This library is licensed MIT. See the file LICENSE for the full license\n" +
90 "for the details.\n" +
92 "package jexer.demos;\n" +
95 "import jexer.event.*;\n" +
96 "import static jexer.TCommand.*;\n" +
97 "import static jexer.TKeypress.*;\n" +
100 " * This window demonstates the TText, THScroller, and TVScroller widgets.\n" +
102 "public class DemoEditorWindow extends TWindow {\n" +
110 // ------------------------------------------------------------------------
111 // TWindow ----------------------------------------------------------------
112 // ------------------------------------------------------------------------
115 * Handle window/screen resize events.
117 * @param event resize event
120 public void onResize(final TResizeEvent event
) {
121 if (event
.getType() == TResizeEvent
.Type
.WIDGET
) {
122 // Resize the text field
123 TResizeEvent editSize
= new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
124 event
.getWidth() - 2, event
.getHeight() - 2);
125 editField
.onResize(editSize
);
129 // Pass to children instead
130 for (TWidget widget
: getChildren()) {
131 widget
.onResize(event
);