2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 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]
31 import java
.util
.ResourceBundle
;
33 import jexer
.TApplication
;
34 import jexer
.TEditorWidget
;
37 import jexer
.event
.TResizeEvent
;
38 import static jexer
.TCommand
.*;
39 import static jexer
.TKeypress
.*;
42 * This window demonstates the TEditor widget.
44 public class DemoEditorWindow
extends TWindow
{
49 private static final ResourceBundle i18n
= ResourceBundle
.getBundle(DemoEditorWindow
.class.getName());
51 // ------------------------------------------------------------------------
52 // Variables --------------------------------------------------------------
53 // ------------------------------------------------------------------------
56 * Hang onto my TEditor so I can resize it with the window.
58 private TEditorWidget editField
;
60 // ------------------------------------------------------------------------
61 // Constructors -----------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Public constructor makes a text window out of any string.
67 * @param parent the main application
68 * @param title the text string
69 * @param text the text string
71 public DemoEditorWindow(final TApplication parent
, final String title
,
74 super(parent
, title
, 0, 0, 44, 22, RESIZABLE
);
75 editField
= addEditor(text
, 0, 0, 42, 20);
77 statusBar
= newStatusBar(i18n
.getString("statusBar"));
78 statusBar
.addShortcutKeypress(kbF1
, cmHelp
,
79 i18n
.getString("statusBarHelp"));
80 statusBar
.addShortcutKeypress(kbF2
, cmShell
,
81 i18n
.getString("statusBarShell"));
82 statusBar
.addShortcutKeypress(kbF10
, cmExit
,
83 i18n
.getString("statusBarExit"));
89 * @param parent the main application
91 public DemoEditorWindow(final TApplication parent
) {
92 this(parent
, i18n
.getString("windowTitle"),
93 "This is an example of an editable text field. Some example text follows.\n" +
95 "This library implements a text-based windowing system loosely\n" +
96 "reminiscent of Borland's [Turbo\n" +
97 "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those\n" +
98 "wishing to use the actual C++ Turbo Vision library, see [Sergio\n" +
99 "Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
100 "on many more platforms.\n" +
102 "This library is licensed MIT. See the file LICENSE for the full license\n" +
103 "for the details.\n" +
105 "package jexer.demos;\n" +
107 "import jexer.*;\n" +
108 "import jexer.event.*;\n" +
109 "import static jexer.TCommand.*;\n" +
110 "import static jexer.TKeypress.*;\n" +
113 " * This window demonstates the TText, THScroller, and TVScroller widgets.\n" +
115 "public class DemoEditorWindow extends TWindow {\n" +
123 // ------------------------------------------------------------------------
124 // TWindow ----------------------------------------------------------------
125 // ------------------------------------------------------------------------
128 * Handle window/screen resize events.
130 * @param event resize event
133 public void onResize(final TResizeEvent event
) {
134 if (event
.getType() == TResizeEvent
.Type
.WIDGET
) {
135 // Resize the text field
136 TResizeEvent editSize
= new TResizeEvent(TResizeEvent
.Type
.WIDGET
,
137 event
.getWidth() - 2, event
.getHeight() - 2);
138 editField
.onResize(editSize
);
142 // Pass to children instead
143 for (TWidget widget
: getChildren()) {
144 widget
.onResize(event
);