Merge commit '77d3a60869e7a780c6ae069e51530e1eacece5e2'
[fanfix.git] / src / jexer / demos / DemoEditorWindow.java
CommitLineData
12b55d76
KL
1/*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
a69ed767 6 * Copyright (C) 2019 Kevin Lamonte
12b55d76
KL
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 */
29package jexer.demos;
30
a69ed767
KL
31import java.util.ResourceBundle;
32
33import jexer.TApplication;
34import jexer.TEditorWidget;
35import jexer.TWidget;
36import jexer.TWindow;
37import jexer.event.TResizeEvent;
12b55d76
KL
38import static jexer.TCommand.*;
39import static jexer.TKeypress.*;
40
41/**
71a389c9 42 * This window demonstates the TEditor widget.
12b55d76
KL
43 */
44public class DemoEditorWindow extends TWindow {
45
a69ed767
KL
46 /**
47 * Translated strings.
48 */
49 private static final ResourceBundle i18n = ResourceBundle.getBundle(DemoEditorWindow.class.getName());
50
43ad7b6c
KL
51 // ------------------------------------------------------------------------
52 // Variables --------------------------------------------------------------
53 // ------------------------------------------------------------------------
54
12b55d76
KL
55 /**
56 * Hang onto my TEditor so I can resize it with the window.
57 */
58 private TEditorWidget editField;
59
43ad7b6c
KL
60 // ------------------------------------------------------------------------
61 // Constructors -----------------------------------------------------------
62 // ------------------------------------------------------------------------
63
12b55d76
KL
64 /**
65 * Public constructor makes a text window out of any string.
66 *
67 * @param parent the main application
68 * @param title the text string
69 * @param text the text string
70 */
71 public DemoEditorWindow(final TApplication parent, final String title,
72 final String text) {
73
74 super(parent, title, 0, 0, 44, 22, RESIZABLE);
382bc294 75 editField = addEditor(text, 0, 0, 42, 20);
12b55d76 76
a69ed767
KL
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"));
12b55d76
KL
84 }
85
86 /**
87 * Public constructor.
88 *
89 * @param parent the main application
90 */
91 public DemoEditorWindow(final TApplication parent) {
a69ed767 92 this(parent, i18n.getString("windowTitle"),
12b55d76
KL
93"This is an example of an editable text field. Some example text follows.\n" +
94"\n" +
95"This library implements a text-based windowing system loosely\n" +
dd459b43 96"reminiscent of Borland's [Turbo\n" +
12b55d76
KL
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" +
101"\n" +
102"This library is licensed MIT. See the file LICENSE for the full license\n" +
e8a11f98
KL
103"for the details.\n" +
104"\n" +
105"package jexer.demos;\n" +
106"\n" +
107"import jexer.*;\n" +
108"import jexer.event.*;\n" +
109"import static jexer.TCommand.*;\n" +
110"import static jexer.TKeypress.*;\n" +
111"\n" +
112"/**\n" +
113" * This window demonstates the TText, THScroller, and TVScroller widgets.\n" +
114" */\n" +
115"public class DemoEditorWindow extends TWindow {\n" +
116"\n" +
117"1 2 3 123\n" +
118"\n"
119 );
12b55d76
KL
120
121 }
122
43ad7b6c
KL
123 // ------------------------------------------------------------------------
124 // TWindow ----------------------------------------------------------------
125 // ------------------------------------------------------------------------
126
12b55d76
KL
127 /**
128 * Handle window/screen resize events.
129 *
130 * @param event resize event
131 */
132 @Override
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);
139 return;
140 }
141
142 // Pass to children instead
143 for (TWidget widget: getChildren()) {
144 widget.onResize(event);
145 }
146 }
147
148}