TEditor 80% complete
[nikiroo-utils.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 * Hang onto my TEditor so I can resize it with the window.
43 */
44 private TEditorWidget editField;
45
46 /**
47 * Public constructor makes a text window out of any string.
48 *
49 * @param parent the main application
50 * @param title the text string
51 * @param text the text string
52 */
53 public DemoEditorWindow(final TApplication parent, final String title,
54 final String text) {
55
56 super(parent, title, 0, 0, 44, 22, RESIZABLE);
57 editField = addEditor(text, 0, 0, 42, 20);
58
59 statusBar = newStatusBar("Editable text demo window");
60 statusBar.addShortcutKeypress(kbF1, cmHelp, "Help");
61 statusBar.addShortcutKeypress(kbF2, cmShell, "Shell");
62 statusBar.addShortcutKeypress(kbF10, cmExit, "Exit");
63 }
64
65 /**
66 * Public constructor.
67 *
68 * @param parent the main application
69 */
70 public DemoEditorWindow(final TApplication parent) {
71 this(parent, "Editor",
72 "This is an example of an editable text field. Some example text follows.\n" +
73 "\n" +
74 "This library implements a text-based windowing system loosely\n" +
75 "reminiscient of Borland's [Turbo\n" +
76 "Vision](http://en.wikipedia.org/wiki/Turbo_Vision) library. For those\n" +
77 "wishing to use the actual C++ Turbo Vision library, see [Sergio\n" +
78 "Sigala's updated version](http://tvision.sourceforge.net/) that runs\n" +
79 "on many more platforms.\n" +
80 "\n" +
81 "This library is licensed MIT. See the file LICENSE for the full license\n" +
82 "for the details.\n" +
83 "\n" +
84 "package jexer.demos;\n" +
85 "\n" +
86 "import jexer.*;\n" +
87 "import jexer.event.*;\n" +
88 "import static jexer.TCommand.*;\n" +
89 "import static jexer.TKeypress.*;\n" +
90 "\n" +
91 "/**\n" +
92 " * This window demonstates the TText, THScroller, and TVScroller widgets.\n" +
93 " */\n" +
94 "public class DemoEditorWindow extends TWindow {\n" +
95 "\n" +
96 "1 2 3 123\n" +
97 "\n"
98 );
99
100 }
101
102 /**
103 * Handle window/screen resize events.
104 *
105 * @param event resize event
106 */
107 @Override
108 public void onResize(final TResizeEvent event) {
109 if (event.getType() == TResizeEvent.Type.WIDGET) {
110 // Resize the text field
111 TResizeEvent editSize = new TResizeEvent(TResizeEvent.Type.WIDGET,
112 event.getWidth() - 2, event.getHeight() - 2);
113 editField.onResize(editSize);
114 return;
115 }
116
117 // Pass to children instead
118 for (TWidget widget: getChildren()) {
119 widget.onResize(event);
120 }
121 }
122
123 }