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