104715997261206c0d54b1cadd4bf54e70360751
[fanfix.git] / src / jexer / demos / DemoEditorWindow.java
1 /*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2017 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 static jexer.TCommand.*;
34 import static jexer.TKeypress.*;
35
36 /**
37 * This window demonstates the TEditor widget.
38 */
39 public class DemoEditorWindow extends TWindow {
40
41 // ------------------------------------------------------------------------
42 // Variables --------------------------------------------------------------
43 // ------------------------------------------------------------------------
44
45 /**
46 * Hang onto my TEditor so I can resize it with the window.
47 */
48 private TEditorWidget editField;
49
50 // ------------------------------------------------------------------------
51 // Constructors -----------------------------------------------------------
52 // ------------------------------------------------------------------------
53
54 /**
55 * Public constructor makes a text window out of any string.
56 *
57 * @param parent the main application
58 * @param title the text string
59 * @param text the text string
60 */
61 public DemoEditorWindow(final TApplication parent, final String title,
62 final String text) {
63
64 super(parent, title, 0, 0, 44, 22, RESIZABLE);
65 editField = addEditor(text, 0, 0, 42, 20);
66
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");
71 }
72
73 /**
74 * Public constructor.
75 *
76 * @param parent the main application
77 */
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" +
81 "\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" +
88 "\n" +
89 "This library is licensed MIT. See the file LICENSE for the full license\n" +
90 "for the details.\n" +
91 "\n" +
92 "package jexer.demos;\n" +
93 "\n" +
94 "import jexer.*;\n" +
95 "import jexer.event.*;\n" +
96 "import static jexer.TCommand.*;\n" +
97 "import static jexer.TKeypress.*;\n" +
98 "\n" +
99 "/**\n" +
100 " * This window demonstates the TText, THScroller, and TVScroller widgets.\n" +
101 " */\n" +
102 "public class DemoEditorWindow extends TWindow {\n" +
103 "\n" +
104 "1 2 3 123\n" +
105 "\n"
106 );
107
108 }
109
110 // ------------------------------------------------------------------------
111 // TWindow ----------------------------------------------------------------
112 // ------------------------------------------------------------------------
113
114 /**
115 * Handle window/screen resize events.
116 *
117 * @param event resize event
118 */
119 @Override
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);
126 return;
127 }
128
129 // Pass to children instead
130 for (TWidget widget: getChildren()) {
131 widget.onResize(event);
132 }
133 }
134
135 }